fr0stn1k

UnityProjectUI

Apr 5th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6.  
  7. public class UISetupExample : MonoBehaviour
  8. {
  9.  
  10.     public StoryStep[] Steps;
  11.  
  12.     public GameObject prefab;
  13.     private GameObject parent;
  14.     private GameObject newobj;
  15.  
  16.     private string _headerText;
  17.     private string _mainText;
  18.     private Sprite _image;
  19.  
  20.     void Start()
  21.     {
  22.         parent = gameObject;
  23.        
  24.         foreach (var field in Steps)
  25.         {
  26.             newobj = Instantiate(prefab);
  27.             newobj.transform.SetParent(parent.transform, true);
  28.  
  29.             if (field.Name.Any())
  30.             {
  31.                 _headerText = newobj.transform.Find("HeaderText").gameObject.GetComponent<Text>().text;
  32.                 _headerText = field.Name;
  33.             }
  34.             else Debug.Log("Can't assign name");
  35.  
  36.             if (field.Description.Any())
  37.             {
  38.                 _mainText = newobj.transform.Find("MainText").gameObject.GetComponent<Text>().text;
  39.                 _mainText = field.Description;
  40.             }
  41.             else Debug.Log("Can't assign description");
  42.  
  43.             if (field.Image != null)
  44.             {
  45.                 _image = newobj.transform.Find("Image").gameObject.GetComponent<Image>().sprite;
  46.                 _image = field.Image;
  47.             }
  48.             else Debug.Log("");
  49.  
  50.         }
  51.  
  52.        
  53.     }
  54.  
  55. }
  56.  
  57. [System.Serializable]
  58. public class StoryStep
  59. {
  60.     public string Name;
  61.     public string Description;
  62.     public Sprite Image;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment