Пример #1
0
 private void AddItem(object data)
 {
     if (itemPrefab != null)
     {
         Vector3[] array = new Vector3[4];
         itemPrefab.GetComponent <RectTransform>().GetLocalCorners(array);
         Vector3 position = array[0];
         float   num      = position.y - array[2].y;
         position.y = (float)items.Count * num;
         StyledItem    styledItem = Object.Instantiate(itemPrefab, position, root.itemRoot.rotation) as StyledItem;
         RectTransform component  = styledItem.GetComponent <RectTransform>();
         styledItem.Populate(data);
         component.SetParent(root.itemRoot.transform, worldPositionStays: false);
         component.pivot            = new Vector2(0f, 1f);
         component.anchorMin        = new Vector2(0f, 1f);
         component.anchorMax        = Vector2.one;
         component.anchoredPosition = new Vector2(0f, position.y);
         items.Add(styledItem);
         component.offsetMin = new Vector2(0f, position.y + num);
         component.offsetMax = new Vector2(0f, position.y);
         RectTransform itemRoot  = root.itemRoot;
         Vector2       offsetMin = root.itemRoot.offsetMin;
         itemRoot.offsetMin = new Vector2(offsetMin.x, (float)(items.Count + 2) * num);
         Button button   = styledItem.GetButton();
         int    curIndex = items.Count - 1;
         if (button != null)
         {
             button.onClick.AddListener(delegate
             {
                 OnItemClicked(styledItem, curIndex);
             });
         }
     }
 }
Пример #2
0
 private void CreateMenuButton(object data)
 {
     if (root.menuItem.transform.childCount > 0)
     {
         for (int num = root.menuItem.transform.childCount - 1; num >= 0; num--)
         {
             Object.DestroyObject(root.menuItem.transform.GetChild(num).gameObject);
         }
     }
     if (itemMenuPrefab != null && root.menuItem != null)
     {
         StyledItem styledItem = Object.Instantiate(itemMenuPrefab) as StyledItem;
         styledItem.Populate(data);
         styledItem.transform.SetParent(root.menuItem.transform, worldPositionStays: false);
         RectTransform component = styledItem.GetComponent <RectTransform>();
         component.pivot           = new Vector2(0.5f, 0.5f);
         component.anchorMin       = Vector2.zero;
         component.anchorMax       = Vector2.one;
         component.offsetMin       = Vector2.zero;
         component.offsetMax       = Vector2.zero;
         root.gameObject.hideFlags = HideFlags.HideInHierarchy;
         Button button = styledItem.GetButton();
         if (button != null)
         {
             button.onClick.AddListener(TogglePanelState);
         }
     }
 }
Пример #3
0
 private void CreateMenuButton(object data)
 {
     if (this.root.menuItem.transform.childCount > 0)
     {
         for (int i = this.root.menuItem.transform.childCount - 1; i >= 0; i--)
         {
             UnityEngine.Object.DestroyObject(this.root.menuItem.transform.GetChild(i).gameObject);
         }
     }
     if ((this.itemMenuPrefab != null) && (this.root.menuItem != null))
     {
         StyledItem item = UnityEngine.Object.Instantiate(this.itemMenuPrefab) as StyledItem;
         item.Populate(data);
         item.transform.SetParent(this.root.menuItem.transform, false);
         RectTransform component = item.GetComponent <RectTransform>();
         component.pivot                = new Vector2(0.5f, 0.5f);
         component.anchorMin            = Vector2.zero;
         component.anchorMax            = Vector2.one;
         component.offsetMin            = Vector2.zero;
         component.offsetMax            = Vector2.zero;
         this.root.gameObject.hideFlags = HideFlags.HideInHierarchy;
         Button button = item.GetButton();
         if (button != null)
         {
             button.onClick.AddListener(new UnityAction(this.TogglePanelState));
         }
     }
 }
Пример #4
0
 private void CreateMenuButton(StyledItem toCreate)
 {
     if (root.menuItem.transform.childCount > 0)
     {
         for (int i = root.menuItem.transform.childCount - 1; i >= 0; --i)
         {
             DestroyObject(root.menuItem.transform.GetChild(i).gameObject);
         }
     }
     if (toCreate != null && root.menuItem != null)
     {
         StyledItem menuItem = Instantiate(toCreate) as StyledItem;
         menuItem.transform.SetParent(root.menuItem.transform, false);
         RectTransform mt = menuItem.GetComponent <RectTransform>();
         mt.pivot     = new Vector2(0.5f, 0.5f);
         mt.anchorMin = Vector2.zero;
         mt.anchorMax = Vector2.one;
         mt.offsetMin = Vector2.zero;
         mt.offsetMax = Vector2.zero;
         root.gameObject.hideFlags = HideFlags.HideInHierarchy;             // should really be HideAndDontSave, but unity crashes
         Button b = menuItem.GetButton();
         if (b != null)
         {
             b.onClick.AddListener(TogglePanelState);
         }
     }
 }
Пример #5
0
    private void AddItem(object data)
    {
        if (itemPrefab != null)
        {
            Vector3[] corners = new Vector3[4];
            itemPrefab.GetComponent <RectTransform>().GetLocalCorners(corners);
            Vector3 pos   = corners[0];
            float   sizeY = pos.y - corners[2].y;
            pos.y = items.Count * sizeY - 5f;
            StyledItem    styledItem = Instantiate(itemPrefab, pos, root.itemRoot.rotation) as StyledItem;
            RectTransform trans      = styledItem.GetComponent <RectTransform>();
            styledItem.Populate(data);
            trans.SetParent(root.itemRoot.transform, false);

            trans.pivot            = new Vector2(0, 1);
            trans.anchorMin        = new Vector2(0, 1);
            trans.anchorMax        = Vector2.one;
            trans.anchoredPosition = new Vector2(0.0f, pos.y);
            items.Add(styledItem);

            trans.offsetMin = new Vector2(0, pos.y + sizeY);
            trans.offsetMax = new Vector2(0, pos.y);
            float offsetSize = (items.Count + 1) * sizeY;
            if (-offsetSize > root.GetComponent <RectTransform> ().rect.height)
            {
                scrollControl.vertical = true;
                scrollControl.verticalScrollbar.gameObject.SetActive(true);
            }
            root.itemRoot.offsetMin = new Vector2(root.itemRoot.offsetMin.x, offsetSize);

            Button b        = styledItem.GetButton();
            int    curIndex = items.Count - 1;
            if (b != null)
            {
                b.onClick.AddListener(delegate() { OnItemClicked(styledItem, curIndex); });
            }
        }
    }