private void SetupTemplate() { this.validTemplate = false; if (!this.m_Template) { UnityEngine.Debug.LogError("The dropdown template is not assigned. The template needs to be assigned and must have a child GameObject with a Toggle component serving as the item.", this); } else { GameObject gameObject = this.m_Template.gameObject; gameObject.SetActive(true); Toggle componentInChildren = this.m_Template.GetComponentInChildren <Toggle>(); this.validTemplate = true; if (!componentInChildren || componentInChildren.transform == this.template) { this.validTemplate = false; UnityEngine.Debug.LogError("The dropdown template is not valid. The template must have a child GameObject with a Toggle component serving as the item.", this.template); } else if (!(componentInChildren.transform.parent is RectTransform)) { this.validTemplate = false; UnityEngine.Debug.LogError("The dropdown template is not valid. The child GameObject with a Toggle component (the item) must have a RectTransform on its parent.", this.template); } else if (this.itemText != null && !this.itemText.transform.IsChildOf(componentInChildren.transform)) { this.validTemplate = false; UnityEngine.Debug.LogError("The dropdown template is not valid. The Item Text must be on the item GameObject or children of it.", this.template); } else if (this.itemImage != null && !this.itemImage.transform.IsChildOf(componentInChildren.transform)) { this.validTemplate = false; UnityEngine.Debug.LogError("The dropdown template is not valid. The Item Image must be on the item GameObject or children of it.", this.template); } if (!this.validTemplate) { gameObject.SetActive(false); } else { Dropdown.DropdownItem dropdownItem = componentInChildren.gameObject.AddComponent <Dropdown.DropdownItem>(); dropdownItem.text = this.m_ItemText; dropdownItem.image = this.m_ItemImage; dropdownItem.toggle = componentInChildren; dropdownItem.rectTransform = (RectTransform)componentInChildren.transform; Canvas orAddComponent = Dropdown.GetOrAddComponent <Canvas>(gameObject); orAddComponent.overrideSorting = true; orAddComponent.sortingOrder = 30000; Dropdown.GetOrAddComponent <GraphicRaycaster>(gameObject); Dropdown.GetOrAddComponent <CanvasGroup>(gameObject); gameObject.SetActive(false); this.validTemplate = true; } } }
private Dropdown.DropdownItem AddItem(Dropdown.OptionData data, bool selected, Dropdown.DropdownItem itemTemplate, List <Dropdown.DropdownItem> items) { Dropdown.DropdownItem dropdownItem = this.CreateItem(itemTemplate); dropdownItem.rectTransform.SetParent(itemTemplate.rectTransform.parent, false); dropdownItem.gameObject.SetActive(true); dropdownItem.gameObject.name = "Item " + items.Count + ((data.text == null) ? "" : (": " + data.text)); if (dropdownItem.toggle != null) { dropdownItem.toggle.isOn = false; } if (dropdownItem.text) { dropdownItem.text.text = data.text; } if (dropdownItem.image) { dropdownItem.image.sprite = data.image; dropdownItem.image.enabled = (dropdownItem.image.sprite != null); } items.Add(dropdownItem); return(dropdownItem); }
private Dropdown.DropdownItem AddItem(Dropdown.OptionData data, bool selected, Dropdown.DropdownItem itemTemplate, List <Dropdown.DropdownItem> items) { Dropdown.DropdownItem dropdownItem = this.CreateItem(itemTemplate); dropdownItem.rectTransform.SetParent(itemTemplate.rectTransform.parent, false); dropdownItem.gameObject.SetActive(true); dropdownItem.gameObject.name = "Item " + (object)items.Count + (string)(data.text == null ? (object)string.Empty : (object)(": " + data.text)); if ((UnityEngine.Object)dropdownItem.toggle != (UnityEngine.Object)null) { dropdownItem.toggle.isOn = false; } if ((bool)((UnityEngine.Object)dropdownItem.text)) { dropdownItem.text.text = data.text; } if ((bool)((UnityEngine.Object)dropdownItem.image)) { dropdownItem.image.sprite = data.image; dropdownItem.image.enabled = (UnityEngine.Object)dropdownItem.image.sprite != (UnityEngine.Object)null; } items.Add(dropdownItem); return(dropdownItem); }
protected virtual void DestroyItem(Dropdown.DropdownItem item) { }
protected virtual Dropdown.DropdownItem CreateItem(Dropdown.DropdownItem itemTemplate) { return(UnityEngine.Object.Instantiate <Dropdown.DropdownItem>(itemTemplate)); }
public void Show() { if (this.IsActive() && this.IsInteractable() && !(this.m_Dropdown != null)) { if (!this.validTemplate) { this.SetupTemplate(); if (!this.validTemplate) { return; } } List <Canvas> list = ListPool <Canvas> .Get(); base.gameObject.GetComponentsInParent <Canvas>(false, list); if (list.Count != 0) { Canvas canvas = list[0]; ListPool <Canvas> .Release(list); this.m_Template.gameObject.SetActive(true); this.m_Dropdown = this.CreateDropdownList(this.m_Template.gameObject); this.m_Dropdown.name = "Dropdown List"; this.m_Dropdown.SetActive(true); RectTransform rectTransform = this.m_Dropdown.transform as RectTransform; rectTransform.SetParent(this.m_Template.transform.parent, false); Dropdown.DropdownItem componentInChildren = this.m_Dropdown.GetComponentInChildren <Dropdown.DropdownItem>(); GameObject gameObject = componentInChildren.rectTransform.parent.gameObject; RectTransform rectTransform2 = gameObject.transform as RectTransform; componentInChildren.rectTransform.gameObject.SetActive(true); Rect rect = rectTransform2.rect; Rect rect2 = componentInChildren.rectTransform.rect; Vector2 vector = rect2.min - rect.min + componentInChildren.rectTransform.localPosition; Vector2 vector2 = rect2.max - rect.max + componentInChildren.rectTransform.localPosition; Vector2 size = rect2.size; this.m_Items.Clear(); Toggle toggle = null; for (int i = 0; i < this.options.Count; i++) { Dropdown.OptionData data = this.options[i]; Dropdown.DropdownItem item = this.AddItem(data, this.value == i, componentInChildren, this.m_Items); if (!(item == null)) { item.toggle.isOn = (this.value == i); item.toggle.onValueChanged.AddListener(delegate(bool x) { this.OnSelectItem(item.toggle); }); if (item.toggle.isOn) { item.toggle.Select(); } if (toggle != null) { Navigation navigation = toggle.navigation; Navigation navigation2 = item.toggle.navigation; navigation.mode = Navigation.Mode.Explicit; navigation2.mode = Navigation.Mode.Explicit; navigation.selectOnDown = item.toggle; navigation.selectOnRight = item.toggle; navigation2.selectOnLeft = toggle; navigation2.selectOnUp = toggle; toggle.navigation = navigation; item.toggle.navigation = navigation2; } toggle = item.toggle; } } Vector2 sizeDelta = rectTransform2.sizeDelta; sizeDelta.y = size.y * (float)this.m_Items.Count + vector.y - vector2.y; rectTransform2.sizeDelta = sizeDelta; float num = rectTransform.rect.height - rectTransform2.rect.height; if (num > 0f) { rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, rectTransform.sizeDelta.y - num); } Vector3[] array = new Vector3[4]; rectTransform.GetWorldCorners(array); RectTransform rectTransform3 = canvas.transform as RectTransform; Rect rect3 = rectTransform3.rect; for (int j = 0; j < 2; j++) { bool flag = false; for (int k = 0; k < 4; k++) { Vector3 vector3 = rectTransform3.InverseTransformPoint(array[k]); if (vector3[j] < rect3.min[j] || vector3[j] > rect3.max[j]) { flag = true; break; } } if (flag) { RectTransformUtility.FlipLayoutOnAxis(rectTransform, j, false, false); } } for (int l = 0; l < this.m_Items.Count; l++) { RectTransform rectTransform4 = this.m_Items[l].rectTransform; rectTransform4.anchorMin = new Vector2(rectTransform4.anchorMin.x, 0f); rectTransform4.anchorMax = new Vector2(rectTransform4.anchorMax.x, 0f); rectTransform4.anchoredPosition = new Vector2(rectTransform4.anchoredPosition.x, vector.y + size.y * (float)(this.m_Items.Count - 1 - l) + size.y * rectTransform4.pivot.y); rectTransform4.sizeDelta = new Vector2(rectTransform4.sizeDelta.x, size.y); } this.AlphaFadeList(0.15f, 0f, 1f); this.m_Template.gameObject.SetActive(false); componentInChildren.gameObject.SetActive(false); this.m_Blocker = this.CreateBlocker(canvas); } } }
/// <summary> /// /// <para> /// Show the dropdown list. /// </para> /// /// </summary> public void Show() { if (!this.IsActive() || !this.IsInteractable() || (UnityEngine.Object) this.m_Dropdown != (UnityEngine.Object)null) { return; } if (!this.validTemplate) { this.SetupTemplate(); if (!this.validTemplate) { return; } } List <Canvas> list = ListPool <Canvas> .Get(); this.gameObject.GetComponentsInParent <Canvas>(false, list); if (list.Count == 0) { return; } Canvas rootCanvas = list[0]; ListPool <Canvas> .Release(list); this.m_Template.gameObject.SetActive(true); this.m_Dropdown = this.CreateDropdownList(this.m_Template.gameObject); this.m_Dropdown.name = "Dropdown List"; this.m_Dropdown.SetActive(true); RectTransform rect1 = this.m_Dropdown.transform as RectTransform; rect1.SetParent(this.m_Template.transform.parent, false); Dropdown.DropdownItem componentInChildren = this.m_Dropdown.GetComponentInChildren <Dropdown.DropdownItem>(); RectTransform rectTransform1 = componentInChildren.rectTransform.parent.gameObject.transform as RectTransform; componentInChildren.rectTransform.gameObject.SetActive(true); Rect rect2 = rectTransform1.rect; Rect rect3 = componentInChildren.rectTransform.rect; Vector2 vector2_1 = rect3.min - rect2.min + (Vector2)componentInChildren.rectTransform.localPosition; Vector2 vector2_2 = rect3.max - rect2.max + (Vector2)componentInChildren.rectTransform.localPosition; Vector2 size = rect3.size; this.m_Items.Clear(); Toggle toggle = (Toggle)null; for (int index = 0; index < this.options.Count; ++index) { // ISSUE: object of a compiler-generated type is created // ISSUE: variable of a compiler-generated type Dropdown.\u003CShow\u003Ec__AnonStorey6 showCAnonStorey6 = new Dropdown.\u003CShow\u003Ec__AnonStorey6(); // ISSUE: reference to a compiler-generated field showCAnonStorey6.\u003C\u003Ef__this = this; Dropdown.OptionData data = this.options[index]; // ISSUE: reference to a compiler-generated field showCAnonStorey6.item = this.AddItem(data, this.value == index, componentInChildren, this.m_Items); // ISSUE: reference to a compiler-generated field if (!((UnityEngine.Object)showCAnonStorey6.item == (UnityEngine.Object)null)) { // ISSUE: reference to a compiler-generated field showCAnonStorey6.item.toggle.isOn = this.value == index; // ISSUE: reference to a compiler-generated field // ISSUE: reference to a compiler-generated method showCAnonStorey6.item.toggle.onValueChanged.AddListener(new UnityAction <bool>(showCAnonStorey6.\u003C\u003Em__2)); // ISSUE: reference to a compiler-generated field if (showCAnonStorey6.item.toggle.isOn) { // ISSUE: reference to a compiler-generated field showCAnonStorey6.item.toggle.Select(); } if ((UnityEngine.Object)toggle != (UnityEngine.Object)null) { Navigation navigation1 = toggle.navigation; // ISSUE: reference to a compiler-generated field Navigation navigation2 = showCAnonStorey6.item.toggle.navigation; navigation1.mode = Navigation.Mode.Explicit; navigation2.mode = Navigation.Mode.Explicit; // ISSUE: reference to a compiler-generated field navigation1.selectOnDown = (Selectable)showCAnonStorey6.item.toggle; // ISSUE: reference to a compiler-generated field navigation1.selectOnRight = (Selectable)showCAnonStorey6.item.toggle; navigation2.selectOnLeft = (Selectable)toggle; navigation2.selectOnUp = (Selectable)toggle; toggle.navigation = navigation1; // ISSUE: reference to a compiler-generated field showCAnonStorey6.item.toggle.navigation = navigation2; } // ISSUE: reference to a compiler-generated field toggle = showCAnonStorey6.item.toggle; } } Vector2 sizeDelta = rectTransform1.sizeDelta; sizeDelta.y = size.y * (float)this.m_Items.Count + vector2_1.y - vector2_2.y; rectTransform1.sizeDelta = sizeDelta; float num = rect1.rect.height - rectTransform1.rect.height; if ((double)num > 0.0) { rect1.sizeDelta = new Vector2(rect1.sizeDelta.x, rect1.sizeDelta.y - num); } Vector3[] fourCornersArray = new Vector3[4]; rect1.GetWorldCorners(fourCornersArray); RectTransform rectTransform2 = rootCanvas.transform as RectTransform; Rect rect4 = rectTransform2.rect; for (int axis = 0; axis < 2; ++axis) { bool flag = false; for (int index = 0; index < 4; ++index) { Vector3 vector3 = rectTransform2.InverseTransformPoint(fourCornersArray[index]); if ((double)vector3[axis] < (double)rect4.min[axis] || (double)vector3[axis] > (double)rect4.max[axis]) { flag = true; break; } } if (flag) { RectTransformUtility.FlipLayoutOnAxis(rect1, axis, false, false); } } for (int index = 0; index < this.m_Items.Count; ++index) { RectTransform rectTransform3 = this.m_Items[index].rectTransform; rectTransform3.anchorMin = new Vector2(rectTransform3.anchorMin.x, 0.0f); rectTransform3.anchorMax = new Vector2(rectTransform3.anchorMax.x, 0.0f); rectTransform3.anchoredPosition = new Vector2(rectTransform3.anchoredPosition.x, (float)((double)vector2_1.y + (double)size.y * (double)(this.m_Items.Count - 1 - index) + (double)size.y * (double)rectTransform3.pivot.y)); rectTransform3.sizeDelta = new Vector2(rectTransform3.sizeDelta.x, size.y); } this.AlphaFadeList(0.15f, 0.0f, 1f); this.m_Template.gameObject.SetActive(false); componentInChildren.gameObject.SetActive(false); this.m_Blocker = this.CreateBlocker(rootCanvas); }