<?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 — cvs data for popups]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=1290</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1290&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in cvs data for popups.]]></description>
		<lastBuildDate>Fri, 12 Jul 2019 19:06:33 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: cvs data for popups]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5297#p5297</link>
			<description><![CDATA[<p>Rad, thank you.</p>]]></description>
			<author><![CDATA[null@example.com (cloudlessrain)]]></author>
			<pubDate>Fri, 12 Jul 2019 19:06:33 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5297#p5297</guid>
		</item>
		<item>
			<title><![CDATA[Re: cvs data for popups]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5296#p5296</link>
			<description><![CDATA[<p>Example:<br /></p><div class="codebox"><pre><code>using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
using UnityEngine.UI;

public class UIBubblePopupFromCVS : MonoBehaviour
{
    /// &lt;summary&gt;
    /// Root canvas
    /// &lt;/summary&gt;
    public Canvas canvas;

    /// &lt;summary&gt;
    /// Bubble popup
    /// &lt;/summary&gt;
    public GameObject bubble;

    /// &lt;summary&gt;
    /// Title text
    /// &lt;/summary&gt;
    public Text title;

    /// &lt;summary&gt;
    /// Address text
    /// &lt;/summary&gt;
    public Text address;

    /// &lt;summary&gt;
    /// Photo RawImage
    /// &lt;/summary&gt;
    public RawImage photo;

    public List&lt;CData&gt; datas;

    /// &lt;summary&gt;
    /// Reference to active marker
    /// &lt;/summary&gt;
    private OnlineMapsMarker targetMarker;

    /// &lt;summary&gt;
    /// This method is called when downloading photo texture.
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;texture2D&quot;&gt;Photo texture&lt;/param&gt;
    private void OnDownloadPhotoComplete(OnlineMapsWWW www)
    {
        Texture2D texture = new Texture2D(1, 1);
        www.LoadImageIntoTexture(texture);

        // Set place texture to bubble popup
        photo.texture = texture;
    }

    /// &lt;summary&gt;
    /// This method is called by clicking on the map
    /// &lt;/summary&gt;
    private void OnMapClick()
    {
        // Remove active marker reference
        targetMarker = null;

        // Hide the popup
        bubble.SetActive(false);
    }

    /// &lt;summary&gt;
    /// This method is called by clicking on the marker
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;marker&quot;&gt;The marker on which clicked&lt;/param&gt;
    private void OnMarkerClick(OnlineMapsMarkerBase marker)
    {
        // Set active marker reference
        targetMarker = marker as OnlineMapsMarker;

        // Get a result item from instance of the marker
        CData data = marker[&quot;data&quot;] as CData;
        if (data == null) return;

        // Show the popup
        bubble.SetActive(true);

        // Set title and address
        title.text = data.title;
        //address.text = data.address;

        // Destroy the previous photo
        if (photo.texture != null)
        {
            OnlineMapsUtils.Destroy(photo.texture);
            photo.texture = null;
        }

        OnlineMapsWWW www = new OnlineMapsWWW(data.photo_url);
        www.OnComplete += OnDownloadPhotoComplete;

        // Initial update position
        UpdateBubblePosition();
    }

    /// &lt;summary&gt;
    /// Start is called on the frame when a script is enabled just before any of the Update methods are called the first time.
    /// &lt;/summary&gt;
    private void Start()
    {
        // Subscribe to events of the map 
        OnlineMaps.instance.OnChangePosition += UpdateBubblePosition;
        OnlineMaps.instance.OnChangeZoom += UpdateBubblePosition;
        OnlineMapsControlBase.instance.OnMapClick += OnMapClick;

        if (OnlineMapsControlBaseDynamicMesh.instance != null)
        {
            OnlineMapsControlBaseDynamicMesh.instance.OnMeshUpdated += UpdateBubblePosition;
        }

        if (OnlineMapsCameraOrbit.instance != null)
        {
            OnlineMapsCameraOrbit.instance.OnCameraControl += UpdateBubblePosition;
        }

        if (datas == null) datas = new List&lt;CData&gt;();

        ReadCVS();

        foreach (CData data in datas)
        {
            OnlineMapsMarker marker = OnlineMapsMarkerManager.CreateItem(data.longitude, data.latitude);
            marker[&quot;data&quot;] = data;
            marker.OnClick += OnMarkerClick;
        }


        // Initial hide popup
        bubble.SetActive(false);
    }

    private void ReadCVS()
    {
        string filename = &quot;e:/HolySites.csv&quot;;
        if (!File.Exists(filename)) return;

        string[] lines = File.ReadAllLines(filename, Encoding.UTF8);

        for (int i = 1; i &lt; lines.Length; i++)
        {
            string[] parts = lines[i].Split(&#039;,&#039;);
            CData data = new CData
            {
                longitude = double.Parse(parts[4], OnlineMapsUtils.numberFormat),
                latitude = double.Parse(parts[3], OnlineMapsUtils.numberFormat),
                title = parts[0],
                status = parts[1],
                tradition = parts[2],
                photo_url = parts[5],
                webpage = parts[6],
                description = parts[7]
            };

            datas.Add(data);
        }
    }

    /// &lt;summary&gt;
    /// Updates the popup position
    /// &lt;/summary&gt;
    private void UpdateBubblePosition()
    {
        // If no marker is selected then exit.
        if (targetMarker == null) return;

        // Hide the popup if the marker is outside the map view
        if (!targetMarker.inMapView)
        {
            if (bubble.activeSelf) bubble.SetActive(false);
        }
        else if (!bubble.activeSelf) bubble.SetActive(true);

        // Convert the coordinates of the marker to the screen position.
        Vector2 screenPosition = OnlineMapsControlBase.instance.GetScreenPosition(targetMarker.position);

        // Add marker height
        screenPosition.y += targetMarker.height;

        // Get a local position inside the canvas.
        Vector2 point;
        RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, screenPosition, null, out point);

        // Set local position of the popup
        (bubble.transform as RectTransform).localPosition = point;
    }

    [Serializable]
    public class CData
    {
        public string title;
        public string status;
        public string tradition;
        public string address;
        public string photo_url;
        public string webpage;
        public string description;
        public double longitude;
        public double latitude;
    }
}</code></pre></div><p>P.S. Note that this script reads cvs from the file system.<br />If you want, you can modify it and read the file from Assets.<br /><a href="https://docs.unity3d.com/ScriptReference/TextAsset.html">https://docs.unity3d.com/ScriptReference/TextAsset.html</a></p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Fri, 12 Jul 2019 18:46:46 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5296#p5296</guid>
		</item>
		<item>
			<title><![CDATA[Re: cvs data for popups]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5295#p5295</link>
			<description><![CDATA[<p>Thanks for the help!&nbsp; Yes, I forgot about the CData class. </p><p>Here&#039;s my csv.&nbsp; Again thanks for the help, your asset is great, I just wish I was a better programmer!</p>]]></description>
			<author><![CDATA[null@example.com (cloudlessrain)]]></author>
			<pubDate>Fri, 12 Jul 2019 18:01:32 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5295#p5295</guid>
		</item>
		<item>
			<title><![CDATA[Re: cvs data for popups]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5293#p5293</link>
			<description><![CDATA[<p>Hello.</p><p>CData is a regular class that you can create with an inspector or runtime.<br />How to create this runtime:<br /></p><div class="codebox"><pre><code>CData newData = new CData
{
    longitude = myLongitude,
    latitude = myLatitude,
    address = &quot;My Address&quot;,
    // etc
};

datas.Add(newData); // If you want to create runtime objects, it’s more convenient to use List&lt;CData&gt; datas.</code></pre></div><p>If you still have problems with CData, show me an example of your CVS, and I will give you an example of how to use it.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Fri, 12 Jul 2019 17:11:31 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5293#p5293</guid>
		</item>
		<item>
			<title><![CDATA[cvs data for popups]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5290#p5290</link>
			<description><![CDATA[<p>I hate to ask a basic programming question here but I&#039;ve been working on this for days.&nbsp; </p><p>I want to input spreadsheet data (presumably with an imported cvs file) into the UI Bubble Popup script.&nbsp; For the life of me I can&#039;t figure it out.&nbsp; There&#039;s a lot of documentation out ther for applying cvs data to scriptable objects, but this script, using a serializable class (CData), is a little different.&nbsp; Any help or hints would be appreciated. </p><p>I&#039;d attach a script but I&#039;m really not working with anything meaningfully different than the example UI Bubble Popup script.&nbsp; <br />- -thanks</p>]]></description>
			<author><![CDATA[null@example.com (cloudlessrain)]]></author>
			<pubDate>Fri, 12 Jul 2019 03:56:53 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5290#p5290</guid>
		</item>
	</channel>
</rss>
