Exemplo n.º 1
0
        public IEnumerator StorylistItem_Select_Story_Test()
        {
            //Create a blank canvas
            Canvas canvas = CreateTestGameObject <Canvas>();

            //Fetch a dummy story
            Story story = GetStories()[0];//GetResources<Story>("Content/Stories/DummyStory");

            //Fetch prefab from resources
            StorylistItem storylistItem = GetResources <StorylistItem>("Prefabs/UI elements/StorylistItem");

            //Instantiate the prefab to the canvas
            Object.Instantiate(storylistItem, canvas.transform);

            //Get references to the storylistitem content components
            Text   title       = storylistItem.transform.Find("txtStorylistItemTitle").GetComponent <Text>();
            Text   description = storylistItem.transform.Find("txtStorylistItemDesc").GetComponent <Text>();
            Button button      = storylistItem.GetComponent <Button>();

            //Create a substitute for the item select callback
            IOnStoryItemSelected callback = Substitute.For <IOnStoryItemSelected>();

            //Construct the list item
            storylistItem.Constructor(title, description);
            storylistItem.SetItemContent(story, callback);

            //Simulate a click on the item
            button.onClick.Invoke();

            //Move to the next frame
            yield return(null);

            //Check if the selection was registered
            callback.Received().OnStoryItemSelected(story);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Set content for this list item
 /// </summary>
 /// <param name="story"><see cref="Story"/> this item represents</param>
 /// <param name="callback">Callback for then the item is selected</param>
 public void SetItemContent(Story story, IOnStoryItemSelected callback)
 {
     _title.text = story.GetLocalizedTitle();
     _desc.text  = story.GetLocalizedDesc();
     _callback   = callback;
     _story      = story;
 }