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); }); } } }
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); } } }
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)); } } }
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); } } }
private void AddItem(object data) { if (ItemPrefab != null) { var corners = new Vector3[4]; ItemPrefab.GetComponent <RectTransform>().GetLocalCorners(corners); var pos = corners[0]; var sizeY = pos.y - corners[2].y; pos.y = _items.Count * sizeY - 5f; var styledItem = Instantiate(ItemPrefab, pos, _root.ItemRoot.rotation); var 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); var 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); var b = styledItem.GetButton(); var curIndex = _items.Count - 1; if (b != null) { b.onClick.AddListener(delegate { OnItemClicked(styledItem, curIndex); }); } } }
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); }); } } }