ViewStack.cs 790 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using UnityEngine;
  2. using System.Collections;
  3. public class ViewStack : View
  4. {
  5. public View[] viewArr;
  6. protected virtual void Awake ()
  7. {
  8. viewArr = new View[transform.childCount];
  9. for(int i=0; i<viewArr.Length; i++)
  10. {
  11. Transform trans = transform.GetChild (i);
  12. View view = trans.gameObject.GetComponent<View> ();
  13. if (view == null)
  14. view = trans.gameObject.AddComponent<View> ();
  15. viewArr [i] = view;
  16. }
  17. }
  18. protected override void OnInitCompleted ()
  19. {
  20. if (m_ViewIndex == -1)
  21. viewIndex = 0;
  22. }
  23. private int m_ViewIndex = -1;
  24. public int viewIndex
  25. {
  26. set{
  27. if (m_ViewIndex == value)
  28. return;
  29. for(int i=0; i<viewArr.Length; i++)
  30. {
  31. viewArr [i].visible = i == value;
  32. }
  33. m_ViewIndex = value;
  34. }
  35. get{
  36. return m_ViewIndex;
  37. }
  38. }
  39. }