IEnumerator fetchSource(SpatioAsset asset, SpatioButton button, string source)
    {
        string    prestring = "https://drive.google.com/open?id=";
        Texture2D t         = new Texture2D(1, 1);

        //Convert address
        if (source.StartsWith(prestring))
        {
            source = "https://drive.google.com/uc?export=download&id=" + source.Substring(prestring.Length);
        }
        Debug.Log(source);
        //source = "http://www.cartoonthrills.com/images/headerlogo.jpg";
        //WWW site = new WWW(source);
        t = Resources.Load <Texture2D>(source);
        yield return(t);

        //site.LoadImageIntoTexture(t);
        Sprite s = Sprite.Create(t, new Rect(0, 0, t.width, t.height), new Vector2(0.5f, 0.5f));

        //Debug.Log("Texture data: " + site.text);

        asset.image.sprite  = s;
        button.image.sprite = s;
        asset.gameObject.SetActive(false);
    }
    void LoadData(int line_number, List <string> line)
    {
        if (line_number == 0)
        {
            fieldList = new List <string>(line);
            foreach (string str in fieldList)
            {
                Debug.Log("FST-" + str);
            }
        }
        else
        {
            Dictionary <string, string> csvData = new Dictionary <string, string>();
            for (int i = 0; i < fieldList.Count; i++)
            {
                if (fieldList[i] == "")
                {
                    continue;
                }
                if (i >= line.Count)
                {
                    //Debug.Log("Adding <" + fieldList[i] + ", (Empty)>");
                    csvData.Add(fieldList[i], "");
                }
                else
                {
                    //Debug.Log("Adding <" + fieldList[i] + ", " + line[i] + ">");
                    csvData.Add(fieldList[i], line[i]);
                }
            }

            //Create a spatioasset and spatiobutton
            SpatioAsset  asset  = (SpatioAsset)Instantiate(assetPrefab, Vector3.zero, Quaternion.identity);
            SpatioButton button = (SpatioButton)Instantiate(buttonPrefab, Vector3.zero, Quaternion.identity);
            button.asset = asset.gameObject;
            RectTransform btnRect = button.GetComponent <RectTransform>();
            btnRect.anchorMin = new Vector2(0.5f, 1.0f);
            btnRect.anchorMax = new Vector2(0.5f, 1.0f);
            RectTransform assetRect = asset.GetComponent <RectTransform>();
            assetRect.offsetMax = new Vector2(Screen.height / 2, Screen.width / 2);


            DocumentsPanel.AddButton(button);
            Debug.Log(btnRect.offsetMin);
            Debug.Log(btnRect.offsetMax);
            asset.transform.SetParent(UI.transform, false);
            assetRect.offsetMin = new Vector2((Screen.width - 381) / 2, -(Screen.height + 275) / 2);
            assetRect.offsetMax = new Vector2((Screen.width + 381) / 2, -(Screen.height - 275) / 2);
            button.transform.SetParent(DocumentsPanel.transform, false);
            //Associate them with the UI
            StartCoroutine(fetchSource(asset, button, csvData["Host"]));
            asset.SetAssetFields(csvData);
            //asset.gameObject.SetActive(false);
        }
    }
Beispiel #3
0
    IEnumerator fetchSource(SpatioAsset asset, SpatioButton button, string source)
    {
        WWW site = new WWW(source);

        yield return(site);

        Texture2D t = new Texture2D(4, 4, TextureFormat.DXT1, false);;

        site.LoadImageIntoTexture(t);


        //site.LoadImageIntoTexture(t);
        Sprite s = Sprite.Create(t, new Rect(0, 0, t.width, t.height), new Vector2(0.5f, 0.5f));

        //Debug.Log("Texture data: " + site.text);

        asset.image.sprite  = s;
        button.image.sprite = s;
        asset.gameObject.SetActive(false);
    }
Beispiel #4
0
    void LoadData(int line_number, List <string> line)
    {
        if (line_number == 0)
        {
            //builds a new data structure at the start of the stream
            fieldList = new List <string>(line);
        }
        else
        {
            Dictionary <string, string> csvData = new Dictionary <string, string>();
            for (int i = 0; i < fieldList.Count; i++)
            {
                if (fieldList[i] == "")
                {
                    continue;
                }

                if (i >= line.Count)
                {
                    //Debug.Log("Adding <" + fieldList[i] + ", (Empty)>");
                    csvData.Add(fieldList[i], "");
                }
                else
                {
                    //Debug.Log("Adding <" + fieldList[i] + ", " + line[i] + ">");
                    csvData.Add(fieldList[i], line[i]);
                    //Debug.Log(line[i]);
                }
            }
            //Debug.Log(fieldList);


            //Create a spatioasset and spatiobutton
            //For storing and displaying Documents
            SpatioAsset  asset  = (SpatioAsset)Instantiate(assetPrefab, Vector3.zero, Quaternion.identity);
            SpatioButton button = (SpatioButton)Instantiate(buttonPrefab, Vector3.zero, Quaternion.identity);
            //assigns the SpatioAsset to be the asset associated with the SpatioButton
            button.asset = asset.gameObject;
            RectTransform btnRect = button.GetComponent <RectTransform>();
            btnRect.anchorMin = new Vector2(0.5f, 1.0f);
            btnRect.anchorMax = new Vector2(0.5f, 1.0f);
            RectTransform assetRect = asset.GetComponent <RectTransform>();
            assetRect.offsetMax = new Vector2(Screen.height / 2, Screen.width / 2);

            //test to overfill the documents panel
            //increment i higher than 0 to cheaply duplicate assets and see how the document panel adapts or does not adapt
            //Panel does not adapt, but rather overfills
            //needs to be scrollable.....find UI element that will work for that "scrollable rectangle"?
            for (int i = 0; i < 1; i++)
            {
                //Adds the button sprite to the Documents Panel
                //DocumentsPanel.AddButton(button);
                //Adds the button sprite to the Documents Panel subobject ScrollPanel - trying to reset the pointer for DocumentsPanel to the ScrollPanel Sub Object
                DocumentsPanel.AddButton(button);
                asset.transform.SetParent(UI.transform, false);
                assetRect.offsetMin = new Vector2((Screen.width - 381) / 2, -(Screen.height + 275) / 2);
                assetRect.offsetMax = new Vector2((Screen.width + 381) / 2, -(Screen.height - 275) / 2);
                button.transform.SetParent(DocumentsPanel.transform, false);
                //Associate them with the UI
                //starts a coroutine to find the image file online?
                StartCoroutine(fetchSource(asset, button, csvData["Host"]));
                //populates the asset fields with the metadata from the csv
                asset.SetAssetFields(csvData);

                //asset.gameObject.SetActive(false);
            }
        }
    }