예제 #1
0
    GameObject InitStoryContent(GameObject storyContent)
    {
        GameObject story = Instantiate(_StoryPrefab);

        Postcard[] postcardsInfo = storyContent.GetComponentsInChildren <Postcard>();

        int postcardId = 0;

        foreach (Postcard pInfo in postcardsInfo)
        {
            GameObject postcard = Instantiate(_PostcardPrefab);
            postcard.transform.parent = story.transform;
            postcard.transform.FindChild("Back/Content").GetComponent <Image>().sprite       = pInfo._frontImage;
            postcard.transform.FindChild("Back/Description/Year").GetComponent <Text>().text = pInfo._year;
            GameObject hotspots = postcard.transform.FindChild("Back/Hotspots").gameObject;

            int hotspotId = 0;

            Vector2 gridPos = new Vector2((int)postcardId % 3 * 240, -100 - 180 * (int)(postcardId / 3));

            postcard.GetComponent <RectTransform>().anchoredPosition = gridPos;

            PostcardController controller = postcard.GetComponent <PostcardController>();

            foreach (HotspotStory hotspotInfo in pInfo.GetComponentsInChildren <HotspotStory>())
            {
                GameObject hotspot = Instantiate(_PostcardHotspotPrefab);
                hotspot.transform.parent = hotspots.transform;
                HotspotStory content = hotspot.GetComponent <HotspotStory>();
                if (hotspotInfo._coolFact.Length > 0)
                {
                    content._coolFact = "Cool Fact: " + hotspotInfo._coolFact;
                }
                else
                {
                    content._coolFact = "";
                }

                content._description = hotspotInfo._description;
                content._sprite      = hotspotInfo._sprite;
                hotspot.GetComponent <RectTransform>().anchoredPosition = hotspotInfo._position;
                int tempHotspotId = hotspotId;
                hotspot.GetComponent <Button>().onClick.AddListener(() => controller.ToggleSides(tempHotspotId));
                hotspotId++;
            }
            postcardId++;
        }

        return(story);
        // GameObject postcard = Instantiate(_PostcardPrefab);
        // GameObject hotspots = postcard.transform.FindChild("Hotspots").gameObject;
    }
예제 #2
0
    void UpdateFrontInfo(int hotspotIndex)
    {
        // get hotspot information
        Transform    Hotspots  = _Back.transform.FindChild("Hotspots");
        HotspotStory storyInfo = Hotspots.GetChild(hotspotIndex).GetComponent <HotspotStory>();
        // update front page
        Text  description = _Front.transform.FindChild("HotspotDescription/Text").GetComponent <Text>();
        Text  coolfact    = _Front.transform.FindChild("HotspotDescription/CoolFact").GetComponent <Text>();
        Image image       = _Front.transform.FindChild("HotspotImage").GetComponent <Image>();

        if (storyInfo._coolFact.Length == 0)
        {
            _Divider.SetActive(false);
        }
        else
        {
            _Divider.SetActive(true);
        }
        description.text = storyInfo._description;
        coolfact.text    = storyInfo._coolFact;
        image.sprite     = storyInfo._sprite;
    }