<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Infinity Code Forum — Large tour setup - loading from JSON?]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=1663</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1663&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Large tour setup - loading from JSON?.]]></description>
		<lastBuildDate>Tue, 15 Dec 2020 03:31:03 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Large tour setup - loading from JSON?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=7008#p7008</link>
			<description><![CDATA[<p>Thank you! This should definitely help us get started. I&#039;ll let you know how it goes, or if I have any additional questions.</p>]]></description>
			<author><![CDATA[null@example.com (ryahes)]]></author>
			<pubDate>Tue, 15 Dec 2020 03:31:03 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=7008#p7008</guid>
		</item>
		<item>
			<title><![CDATA[Re: Large tour setup - loading from JSON?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=7007#p7007</link>
			<description><![CDATA[<p>Unfortunately I didn&#039;t understand the structure of your data and how it should work.<br />Here&#039;s an example of how to create a tour from your JSON.<br />I hope this helps you get started.</p><p>Place the script in the Editor folder, and select the uPano / Create Tour From JSON menu item.<br /></p><div class="codebox"><pre><code>using System.IO;
using System.Text;
using InfinityCode.uPano;
using InfinityCode.uPano.Actions;
using InfinityCode.uPano.Actions.HotSpots;
using InfinityCode.uPano.Controls;
using InfinityCode.uPano.Directions;
using InfinityCode.uPano.Editors.Utils;
using InfinityCode.uPano.HotSpots;
using InfinityCode.uPano.Json;
using InfinityCode.uPano.Plugins;
using InfinityCode.uPano.Tours;
using UnityEditor;
using UnityEditor.Events;
using UnityEngine;

public static class CreateTourFromJSON
{
    [MenuItem(&quot;uPano/Create Tour From JSON&quot;)]
    private static void Create()
    {
        string filename = EditorUtility.OpenFilePanel(&quot;Select JSON&quot;, EditorApplication.applicationContentsPath, &quot;json&quot;);
        if (string.IsNullOrEmpty(filename) || !File.Exists(filename)) return;

        string content = File.ReadAllText(filename, Encoding.UTF8);
        Record[] records;

        try
        {
            records = JSON.Deserialize&lt;Record[]&gt;(content);
        }
        catch
        {
            return;
        }

        if (records == null || records.Length == 0) return;

        Tour tour = CreateTour();

        foreach (Record record in records)
        {
            //Debug.Log(record.type);

            if (record.type == &quot;Scene&quot;) CreatePanorama(tour, record);
            else if (record.type == &quot;Video&quot;) CreateVideo(tour, record);
            else if (record.type == &quot;Image&quot;) CreateImage(tour, record);
        }

        if (tour.items.Count &gt; 1)
        {
            int r = 400;
            float d = 360f / tour.items.Count;

            for (int i = 0; i &lt; tour.items.Count; i++)
            {
                float a = i * d * Mathf.Deg2Rad;
                tour.items[i].position = new Vector2(Mathf.Cos(a) * r, Mathf.Sin(a) * r);
            }
        }
    }

    private static void CreateImage(Tour tour, Record record)
    {
        // Do something
    }

    private static TourItem CreatePanorama(Tour tour, Record record)
    {
        TourItem item = TourItem.Create(tour);
        tour.items.Add(item);
        if (tour.startItem == null) tour.startItem = item;
        return item;
    }

    private static Tour CreateTour()
    {
        GameObject go = new GameObject(&quot;uPano Tour&quot;);
        Tour tour = go.AddComponent&lt;Tour&gt;();
        GlobalSettings globalSettings = go.AddComponent&lt;GlobalSettings&gt;();
        globalSettings.defaultHotSpotPrefab = AssetDatabase.LoadAssetAtPath&lt;GameObject&gt;(EditorUtils.assetPath + &quot;\\Examples\\Prefabs\\Hot Spots\\Hot Spot Arrow.prefab&quot;);
        globalSettings.defaultDirectionPrefab = AssetDatabase.LoadAssetAtPath&lt;GameObject&gt;(EditorUtils.assetPath + &quot;\\Examples\\Prefabs\\Directions\\Direction Arrow.prefab&quot;);
        globalSettings.beforeTransitionPrefab = AssetDatabase.LoadAssetAtPath&lt;GameObject&gt;(EditorUtils.assetPath + &quot;\\Examples\\Transitions\\ExampleFadeOut.prefab&quot;);
        globalSettings.afterTransitionPrefab = AssetDatabase.LoadAssetAtPath&lt;GameObject&gt;(EditorUtils.assetPath + &quot;\\Examples\\Transitions\\ExampleFadeIn.prefab&quot;);
        go.AddComponent&lt;MouseControl&gt;();
        go.AddComponent&lt;KeyboardControl&gt;();
        go.AddComponent&lt;Limits&gt;();
        HotSpotGlobalActions hsga = go.AddComponent&lt;HotSpotGlobalActions&gt;();
        DirectionGlobalActions dga = go.AddComponent&lt;DirectionGlobalActions&gt;();

        GameObject events = new GameObject(&quot;Events&quot;);
        events.transform.parent = go.transform;

        GameObject enterGO = new GameObject(&quot;Pointer Enter&quot;);
        enterGO.transform.parent = events.transform;
        SetScale enterScale = enterGO.AddComponent&lt;SetScale&gt;();
        enterScale.scale = new Vector3(1.2f, 1.2f, 1.2f);
        UnityEventTools.AddPersistentListener(hsga.OnPointerEnter, enterScale.Invoke);
        UnityEventTools.AddPersistentListener(dga.OnPointerEnter, enterScale.Invoke);

        GameObject exitGO = new GameObject(&quot;Pointer Exit&quot;);
        exitGO.transform.parent = events.transform;
        SetScale exitScale = exitGO.AddComponent&lt;SetScale&gt;();
        UnityEventTools.AddPersistentListener(hsga.OnPointerExit, exitScale.Invoke);
        UnityEventTools.AddPersistentListener(dga.OnPointerExit, exitScale.Invoke);

        GameObject tooltip = new GameObject(&quot;Show Tooltip&quot;);
        tooltip.transform.parent = events.transform;
        ShowTooltip showTooltip = tooltip.AddComponent&lt;ShowTooltip&gt;();
        showTooltip.tooltipPrefab = AssetDatabase.LoadAssetAtPath&lt;GameObject&gt;(EditorUtils.assetPath + &quot;\\Examples\\Prefabs\\Tooltips\\Tooltip.prefab&quot;);
        showTooltip.getTextFromElement = true;
        UnityEventTools.AddPersistentListener(hsga.OnPointerEnter, showTooltip.Invoke);
        UnityEventTools.AddPersistentListener(hsga.OnPointerExit, showTooltip.Hide);

        return tour;
    }

    private static void CreateVideo(Tour tour, Record record)
    {
        // Do something
    }

    internal class Record
    {
        [JSON.Alias(&quot;Hierarchy ID&quot;)]
        public string hierarchyID;

        [JSON.Alias(&quot;Type&quot;)]
        public string type;

        [JSON.Alias(&quot;Hotspot Image URL&quot;)]
        public string hotSpotURL;

        [JSON.Alias(&quot;Title&quot;)]
        public string title;

        [JSON.Alias(&quot;Content URL&quot;)]
        public string contentURL;

        [JSON.Alias(&quot;Description&quot;)]
        public string description;
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Mon, 14 Dec 2020 19:23:18 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=7007#p7007</guid>
		</item>
		<item>
			<title><![CDATA[Re: Large tour setup - loading from JSON?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=7002#p7002</link>
			<description><![CDATA[<p>Sure thing - here: <a href="https://pastebin.com/ePsPs9n5">https://pastebin.com/ePsPs9n5</a></p>]]></description>
			<author><![CDATA[null@example.com (ryahes)]]></author>
			<pubDate>Mon, 14 Dec 2020 00:43:41 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=7002#p7002</guid>
		</item>
		<item>
			<title><![CDATA[Re: Large tour setup - loading from JSON?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6999#p6999</link>
			<description><![CDATA[<p>Unfortunately I don&#039;t know how to convert Google Sheet to JSON.<br />Please attach JSON file.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Sun, 13 Dec 2020 10:56:26 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6999#p6999</guid>
		</item>
		<item>
			<title><![CDATA[Re: Large tour setup - loading from JSON?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6998#p6998</link>
			<description><![CDATA[<p>Thanks - it seems that for format, we are actually using a Google Sheet exported as tab separated value though we could potentially export as JSON if necessary.</p><p>Here is the sheet:<br /><a href="https://docs.google.com/spreadsheets/d/1piANH99N8_ChScv21Rm4ydvEUz2FbisJHTv0f2-MgMY/edit?usp=sharing">https://docs.google.com/spreadsheets/d/ … sp=sharing</a></p><p>Basically the whole thing is a tree structure and we have elements labeled with an ID. </p><p>0 is the main pano hub. </p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-0</p><p>Panos you can get to from hotspots in the main hub. </p><p>&nbsp; &nbsp; &nbsp;-1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-2</p><p>Panos you can get to from hotspots in previous level</p><p>&nbsp; -1.1 -1.2 -1.3&nbsp; &nbsp; &nbsp;-2.1 -2.2 -2.3</p><p>All the items at the end of the tree are image or video hotspots.</p><p>&nbsp; -1.1.1, -1.1.2, x.x.x etc</p>]]></description>
			<author><![CDATA[null@example.com (ryahes)]]></author>
			<pubDate>Sun, 13 Dec 2020 05:52:34 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6998#p6998</guid>
		</item>
		<item>
			<title><![CDATA[Re: Large tour setup - loading from JSON?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6997#p6997</link>
			<description><![CDATA[<p>Hello.</p><p>Please show me an example of the JSON you have and I&#039;ll make an example for you how to automate the creation of tours.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Sun, 13 Dec 2020 00:14:38 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6997#p6997</guid>
		</item>
		<item>
			<title><![CDATA[Large tour setup - loading from JSON?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6996#p6996</link>
			<description><![CDATA[<p>Hi, I have a few upcoming projects that require about 20 panorama scenes, each with 3-4 interactive hotspots. I&#039;d like to try importing the scene and hotspot data from JSON in order to create the tour object, panos and connections procedurally. </p><p>Do you have any existing tools, or suggestions as to how to do this in a reasonable way? Thank you, my team is really appreciative of this package so far and it will save us a lot of time.</p>]]></description>
			<author><![CDATA[null@example.com (ryahes)]]></author>
			<pubDate>Sun, 13 Dec 2020 00:10:26 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6996#p6996</guid>
		</item>
	</channel>
</rss>
