static int FlipLayoutOnAxis(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 4); RectTransform arg0 = (RectTransform)LuaScriptMgr.GetUnityObject(L, 1, typeof(RectTransform)); int arg1 = (int)LuaScriptMgr.GetNumber(L, 2); bool arg2 = LuaScriptMgr.GetBoolean(L, 3); bool arg3 = LuaScriptMgr.GetBoolean(L, 4); RectTransformUtility.FlipLayoutOnAxis(arg0, arg1, arg2, arg3); return(0); }
void DoFlip() { if (axis == RectTransformFlipOptions.Both) { RectTransformUtility.FlipLayoutAxes(agent, keepPositioning.value, recursive.value); } else if (axis == RectTransformFlipOptions.Horizontal) { RectTransformUtility.FlipLayoutOnAxis(agent, 0, keepPositioning.value, recursive.value); } else if (axis == RectTransformFlipOptions.Vertical) { RectTransformUtility.FlipLayoutOnAxis(agent, 1, keepPositioning.value, recursive.value); } }
static void CreateHorizontalScrollRectEx(MenuCommand command) { // Verticalを生成 CreateVerticalScrollRectEx(null); var ex = Selection.activeGameObject.GetComponent <ScrollRectEx>(); ex.name = "Scroll View (Horizontal)"; // horizontalに設定. ex.scrollRect.horizontal = true; ex.scrollRect.vertical = false; // 全体を回転. RectTransformUtility.FlipLayoutAxes(ex.transform as RectTransform, false, true); // コンテンツアンカー調整 SetRt(ex.scrollRect.content, HAnchor.Left, VAnchor.Expand, TextAnchor.MiddleLeft, Vector2.zero, new Vector2(300, 0)); // スクロールバーをHorizontalに変更 var bar = ex.scrollRect.verticalScrollbar; ex.scrollRect.horizontalScrollbar = bar; ex.scrollRect.verticalScrollbar = null; bar.direction = Scrollbar.Direction.LeftToRight; RectTransformUtility.FlipLayoutOnAxis(bar.transform as RectTransform, 1, false, false); (bar.transform as RectTransform).sizeDelta = new Vector2(0, 20); // インジケータ RectTransformUtility.FlipLayoutOnAxis(ex.indicator.transform as RectTransform, 1, false, false); // ボタン調整 Button b = ex.naviModule.nextButton; b.GetComponentInChildren <Text>().text = ">"; RectTransformUtility.FlipLayoutOnAxis(b.transform as RectTransform, 0, false, false); b = ex.naviModule.previousButton; b.GetComponentInChildren <Text>().text = "<"; RectTransformUtility.FlipLayoutOnAxis(b.transform as RectTransform, 0, false, false); // VerticalLayoutを全てHorizontalLayoutに foreach (var vl in ex.GetComponentsInChildren <VerticalLayoutGroup>(true)) { ConvertTo <HorizontalLayoutGroup>(vl); } }
public void SetDirection(Slider.Direction direction, bool includeRectLayouts) { Slider.Axis axis = this.axis; bool reverseValue = this.reverseValue; this.direction = direction; if (includeRectLayouts) { if (this.axis != axis) { RectTransformUtility.FlipLayoutAxes(base.transform as RectTransform, true, true); } if (this.reverseValue != reverseValue) { RectTransformUtility.FlipLayoutOnAxis(base.transform as RectTransform, (int)this.axis, true, true); } } }
public void SetDirection(Direction direction, bool includeRectLayouts) { Axis axis = this.axis; bool reverseValue = this.reverseValue; this.direction = direction; if (includeRectLayouts) { if (this.axis != axis) { RectTransformUtility.FlipLayoutAxes(base.transform as RectTransform, keepPositioning: true, recursive: true); } if (this.reverseValue != reverseValue) { RectTransformUtility.FlipLayoutOnAxis(base.transform as RectTransform, (int)this.axis, keepPositioning: true, recursive: true); } } }
public void SetDirection(Scrollbar.Direction direction, bool includeRectLayouts) { Scrollbar.Axis axis = this.axis; bool reverseValue = this.reverseValue; this.direction = direction; if (!includeRectLayouts) { return; } if (this.axis != axis) { RectTransformUtility.FlipLayoutAxes(this.transform as RectTransform, true, true); } if (this.reverseValue == reverseValue) { return; } RectTransformUtility.FlipLayoutOnAxis(this.transform as RectTransform, (int)this.axis, true, true); }
public void SetDirection(Direction direction, bool includeRectLayouts) { Axis oldAxis = behavior.axis; bool oldReverse = behavior.reverse; this.direction = direction; if (!includeRectLayouts) { return; } if (behavior.axis != oldAxis) { RectTransformUtility.FlipLayoutAxes(transform as RectTransform, true, true); } if (behavior.reverse != oldReverse) { RectTransformUtility.FlipLayoutOnAxis(transform as RectTransform, behavior.axisValue, true, true); } }
public void SetDirection(Direction direction, bool includeRectLayouts) { Axis oldAxis = axis; bool oldReverse = reverseValue; this.direction = direction; if (!includeRectLayouts) { return; } if (axis != oldAxis) { RectTransformUtility.FlipLayoutAxes(transform as RectTransform, true, true); } if (reverseValue != oldReverse) { RectTransformUtility.FlipLayoutOnAxis(transform as RectTransform, (int)axis, true, true); } }
public static int FlipLayoutOnAxis_s(IntPtr l) { int result; try { RectTransform rect; LuaObject.checkType <RectTransform>(l, 1, out rect); int axis; LuaObject.checkType(l, 2, out axis); bool keepPositioning; LuaObject.checkType(l, 3, out keepPositioning); bool recursive; LuaObject.checkType(l, 4, out recursive); RectTransformUtility.FlipLayoutOnAxis(rect, axis, keepPositioning, recursive); LuaObject.pushValue(l, true); result = 1; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
void DoFlip() { GameObject go = Fsm.GetOwnerDefaultTarget(gameObject); if (go != null) { RectTransform _rt = go.GetComponent <RectTransform>(); if (_rt != null) { if (axis == RectTransformFlipOptions.Both) { RectTransformUtility.FlipLayoutAxes(_rt, keepPositioning.Value, recursive.Value); } else if (axis == RectTransformFlipOptions.Horizontal) { RectTransformUtility.FlipLayoutOnAxis(_rt, 0, keepPositioning.Value, recursive.Value); } else if (axis == RectTransformFlipOptions.Vertical) { RectTransformUtility.FlipLayoutOnAxis(_rt, 1, keepPositioning.Value, recursive.Value); } } } }
public void Show() { if (!((UIBehaviour)this).IsActive() || !this.IsInteractable() || Object.op_Inequality((Object)this._dropdown, (Object)null) && this._dropdown.get_activeSelf()) { return; } if (!this._validTemplate) { this.SetupTemplate(); if (!this._validTemplate) { return; } } List <Canvas> toRelease = ListPool <Canvas> .Get(); ((Component)this).GetComponentsInParent <Canvas>(false, (List <M0>)toRelease); if (toRelease.Count <= 0) { return; } Canvas rootCanvas = toRelease[0]; ListPool <Canvas> .Release(toRelease); ((Component)this._template).get_gameObject().SetActive(true); if (Object.op_Equality((Object)this._dropdown, (Object)null)) { this._dropdown = (GameObject)Object.Instantiate <GameObject>((M0)((Component)this._template).get_gameObject()); ((Object)this._dropdown).set_name("Dropdown List"); ((Component)this._dropdown.GetComponentInChildren <OptimizedDropdown.DropdownItem>()).get_gameObject().SetActive(false); this._scrollRect = (ScrollRect)this._dropdown.GetComponent <ScrollRect>(); } this._dropdown.SetActive(true); RectTransform transform1 = this._dropdown.get_transform() as RectTransform; ((Transform)transform1).SetParent(((Component)this._template).get_transform().get_parent(), false); OptimizedDropdown.DropdownItem componentInChildren = (OptimizedDropdown.DropdownItem)((Component)this._template).GetComponentInChildren <OptimizedDropdown.DropdownItem>(); GameObject gameObject = ((Component)((Component)this._dropdown.GetComponentInChildren <OptimizedDropdown.DropdownItem>(true)).get_transform().get_parent()).get_gameObject(); RectTransform transform2 = gameObject.get_transform() as RectTransform; ((Component)componentInChildren.RectTransform).get_gameObject().SetActive(true); if (!this._rect.HasValue) { this._rect = new Rect?(transform2.get_rect()); } Rect rect1 = componentInChildren.RectTransform.get_rect(); Vector2 min1 = ((Rect) ref rect1).get_min(); Rect rect2 = this._rect.Value; Vector2 min2 = ((Rect) ref rect2).get_min(); Vector2 vector2_1 = Vector2.op_Addition(Vector2.op_Subtraction(min1, min2), Vector2.op_Implicit(((Transform)componentInChildren.RectTransform).get_localPosition())); Vector2 max1 = ((Rect) ref rect1).get_max(); Rect rect3 = this._rect.Value; Vector2 max2 = ((Rect) ref rect3).get_max(); Vector2 vector2_2 = Vector2.op_Addition(Vector2.op_Subtraction(max1, max2), Vector2.op_Implicit(((Transform)componentInChildren.RectTransform).get_localPosition())); Vector2 size = ((Rect) ref rect1).get_size(); this._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 OptimizedDropdown.\u003CShow\u003Ec__AnonStorey0 showCAnonStorey0 = new OptimizedDropdown.\u003CShow\u003Ec__AnonStorey0(); // ISSUE: reference to a compiler-generated field showCAnonStorey0.\u0024this = this; // ISSUE: reference to a compiler-generated field showCAnonStorey0.index = index; OptimizedDropdown.DropdownItem dropdownItem = this.AddItem(this.Options[index], gameObject.get_transform(), this._items); if (Object.op_Inequality((Object)dropdownItem, (Object)null)) { dropdownItem.Toggle.set_isOn(this.Value == index); // ISSUE: method pointer ((UnityEvent <bool>)dropdownItem.Toggle.onValueChanged).AddListener(new UnityAction <bool>((object)showCAnonStorey0, __methodptr(\u003C\u003Em__0))); if (Object.op_Inequality((Object)toggle, (Object)null)) { Navigation navigation1 = ((Selectable)toggle).get_navigation(); Navigation navigation2 = ((Selectable)dropdownItem.Toggle).get_navigation(); ((Navigation) ref navigation1).set_mode((Navigation.Mode) 4); ((Navigation) ref navigation2).set_mode((Navigation.Mode) 4); ((Navigation) ref navigation1).set_selectOnDown((Selectable)dropdownItem.Toggle); ((Navigation) ref navigation1).set_selectOnRight((Selectable)dropdownItem.Toggle); ((Navigation) ref navigation2).set_selectOnLeft((Selectable)toggle); ((Navigation) ref navigation2).set_selectOnUp((Selectable)toggle); ((Selectable)toggle).set_navigation(navigation1); ((Selectable)dropdownItem.Toggle).set_navigation(navigation2); } toggle = dropdownItem.Toggle; } } Vector2 sizeDelta = transform2.get_sizeDelta(); sizeDelta.y = (__Null)(size.y * (double)this._items.Count + vector2_1.y - vector2_2.y); transform2.set_sizeDelta(sizeDelta); Rect rect4 = transform1.get_rect(); double height1 = (double)((Rect) ref rect4).get_height(); Rect rect5 = transform2.get_rect(); double height2 = (double)((Rect) ref rect5).get_height(); float num1 = (float)(height1 - height2); if ((double)num1 > 0.0) { transform1.set_sizeDelta(new Vector2((float)transform1.get_sizeDelta().x, (float)transform1.get_sizeDelta().y - num1)); } Vector3[] vector3Array = new Vector3[4]; transform1.GetWorldCorners(vector3Array); RectTransform transform3 = ((Component)rootCanvas).get_transform() as RectTransform; Rect rect6 = transform3.get_rect(); for (int index1 = 0; index1 < 2; ++index1) { bool flag = false; for (int index2 = 0; index2 < 4; ++index2) { Vector3 vector3 = ((Transform)transform3).InverseTransformPoint(vector3Array[index2]); double num2 = (double)((Vector3) ref vector3).get_Item(index1); Vector2 min3 = ((Rect) ref rect6).get_min(); double num3 = (double)((Vector2) ref min3).get_Item(index1); int num4; if (num2 >= num3) { double num5 = (double)((Vector3) ref vector3).get_Item(index1); Vector2 max3 = ((Rect) ref rect6).get_max(); double num6 = (double)((Vector2) ref max3).get_Item(index1); num4 = num5 > num6 ? 1 : 0; } else { num4 = 1; } if (num4 != 0) { flag = true; break; } } if (flag) { RectTransformUtility.FlipLayoutOnAxis(transform1, index1, false, false); } } for (int index = 0; index < this._items.Count; ++index) { RectTransform rectTransform = this._items[index].RectTransform; rectTransform.set_anchorMin(new Vector2((float)rectTransform.get_anchorMin().x, 0.0f)); rectTransform.set_anchorMax(new Vector2((float)rectTransform.get_anchorMax().x, 0.0f)); rectTransform.set_anchoredPosition(new Vector2((float)rectTransform.get_anchoredPosition().x, (float)(vector2_1.y + size.y * (double)(this._items.Count - 1 - index) + size.y * rectTransform.get_pivot().y))); rectTransform.set_sizeDelta(new Vector2((float)rectTransform.get_sizeDelta().x, (float)size.y)); } this.AlphaFadeList(0.15f, 0.0f, 1f, (Action)(() => {})); ((Component)this._template).get_gameObject().SetActive(false); this._blocker = this.CreateBlocker(rootCanvas); if (!this._focusedSelectedItem) { return; } RectTransform transform4 = ((Component)((IEnumerable <Toggle>)((Component)this._scrollRect.get_content()).GetComponentsInChildren <Toggle>()).FirstOrDefault <Toggle>((Func <Toggle, bool>)(x => x.get_isOn()))).get_transform() as RectTransform; Rect rect7 = this._scrollRect.get_content().get_rect(); double height3 = (double)((Rect) ref rect7).get_height(); Rect rect8 = this._scrollRect.get_viewport().get_rect(); double height4 = (double)((Rect) ref rect8).get_height(); float num7 = (float)(height3 - height4); // ISSUE: variable of the null type __Null y = transform4.get_anchoredPosition().y; Rect rect9 = transform4.get_rect(); double num8 = (double)((Rect) ref rect9).get_height() / 2.0; double num9 = y - num8; Rect rect10 = this._scrollRect.get_viewport().get_rect(); double num10 = (double)((Rect) ref rect10).get_height() / 2.0; float num11 = (float)(num9 - num10); this._scrollRect.get_verticalScrollbar().set_value(Mathf.InverseLerp(0.0f, num7, Mathf.Clamp(num11, 0.0f, num7))); }
// Show the dropdown. // // Plan for dropdown scrolling to ensure dropdown is contained within screen. // // We assume the Canvas is the screen that the dropdown must be kept inside. // This is always valid for screen space canvas modes. // For world space canvases we don't know how it's used, but it could be e.g. for an in-game monitor. // We consider it a fair constraint that the canvas must be big enough to contains dropdowns. public void Show() { m_isShow = true; lastValue = m_Value; m_isOnHideChangedExecutionOnce = true; if (!IsActive() || !IsInteractable() || m_Dropdown != null) { return; } if (!validTemplate) { SetupTemplate(); if (!validTemplate) { return; } } // Get root Canvas. var list = ListPool <Canvas> .Get(); gameObject.GetComponentsInParent(false, list); if (list.Count == 0) { return; } Canvas rootCanvas = list[0]; ListPool <Canvas> .Release(list); m_Template.gameObject.SetActive(true); // Instantiate the drop-down template m_Dropdown = CreateDropdownList(m_Template.gameObject); m_Dropdown.name = "Dropdown List"; m_Dropdown.SetActive(true); // Make drop-down RectTransform have same values as original. RectTransform dropdownRectTransform = m_Dropdown.transform as RectTransform; dropdownRectTransform.SetParent(m_Template.transform.parent, false); // Instantiate the drop-down list items // Find the dropdown item and disable it. DropdownItem itemTemplate = m_Dropdown.GetComponentInChildren <DropdownItem>(); GameObject content = itemTemplate.rectTransform.parent.gameObject; RectTransform contentRectTransform = content.transform as RectTransform; itemTemplate.rectTransform.gameObject.SetActive(true); // Get the rects of the dropdown and item Rect dropdownContentRect = contentRectTransform.rect; Rect itemTemplateRect = itemTemplate.rectTransform.rect; // Calculate the visual offset between the item's edges and the background's edges Vector2 offsetMin = itemTemplateRect.min - dropdownContentRect.min + (Vector2)itemTemplate.rectTransform.localPosition; Vector2 offsetMax = itemTemplateRect.max - dropdownContentRect.max + (Vector2)itemTemplate.rectTransform.localPosition; Vector2 itemSize = itemTemplateRect.size; m_Items.Clear(); IMCToggle prev = null; for (int i = 0; i < options.Count; ++i) { OptionData data = options[i]; DropdownItem item = AddItem(data, value == i, itemTemplate, m_Items); if (item == null) { continue; } // Automatically set up a toggle state change listener item.toggle.isOn = value == i; item.toggle.onValueChanged.AddListener(x => OnSelectItem(item.toggle)); // Select current option if (item.toggle.isOn) { item.toggle.Select(); } // Automatically set up explicit navigation if (prev != null) { Navigation prevNav = prev.navigation; Navigation toggleNav = item.toggle.navigation; prevNav.mode = Navigation.Mode.Explicit; toggleNav.mode = Navigation.Mode.Explicit; prevNav.selectOnDown = item.toggle; prevNav.selectOnRight = item.toggle; toggleNav.selectOnLeft = prev; toggleNav.selectOnUp = prev; prev.navigation = prevNav; item.toggle.navigation = toggleNav; } prev = item.toggle; } if (ShowItemAction != null) { ShowItemAction(); } // Reposition all items now that all of them have been added Vector2 sizeDelta = contentRectTransform.sizeDelta; sizeDelta.y = itemSize.y * m_Items.Count /*+ offsetMin.y - offsetMax.y*/; contentRectTransform.sizeDelta = sizeDelta; float extraSpace = dropdownRectTransform.rect.height - contentRectTransform.rect.height; if (extraSpace > 0) { dropdownRectTransform.sizeDelta = new Vector2(dropdownRectTransform.sizeDelta.x, dropdownRectTransform.sizeDelta.y - extraSpace); } // Invert anchoring and position if dropdown is partially or fully outside of canvas rect. // Typically this will have the effect of placing the dropdown above the button instead of below, // but it works as inversion regardless of initial setup. Vector3[] corners = new Vector3[4]; dropdownRectTransform.GetWorldCorners(corners); bool outside = false; RectTransform rootCanvasRectTransform = rootCanvas.transform as RectTransform; for (int i = 0; i < 4; i++) { Vector3 corner = rootCanvasRectTransform.InverseTransformPoint(corners[i]); if (!rootCanvasRectTransform.rect.Contains(corner)) { outside = true; break; } } if (outside) { RectTransformUtility.FlipLayoutOnAxis(dropdownRectTransform, 0, false, false); RectTransformUtility.FlipLayoutOnAxis(dropdownRectTransform, 1, false, false); } for (int i = 0; i < m_Items.Count; i++) { RectTransform itemRect = m_Items[i].rectTransform; itemRect.anchorMin = new Vector2(itemRect.anchorMin.x, 0); itemRect.anchorMax = new Vector2(itemRect.anchorMax.x, 0); itemRect.anchoredPosition = new Vector2(itemRect.anchoredPosition.x, /* offsetMin.y*/ +itemSize.y * (m_Items.Count - 1 - i) + itemSize.y * itemRect.pivot.y); itemRect.sizeDelta = new Vector2(itemRect.sizeDelta.x, itemSize.y); } // Fade in the popup AlphaFadeList(0.15f, 0f, 1f); // Make drop-down template and item template inactive m_Template.gameObject.SetActive(false); itemTemplate.gameObject.SetActive(false); m_Blocker = CreateBlocker(rootCanvas); }
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); } } }
public void Show() { if (!IsActive() || !IsInteractable() || m_Dropdown != null) { return; } if (!validTemplate) { SetupTemplate(); if (!validTemplate) { return; } } List <Canvas> list = ListPool <Canvas> .Get(); base.gameObject.GetComponentsInParent(includeInactive: false, list); if (list.Count == 0) { return; } Canvas canvas = list[0]; ListPool <Canvas> .Release(list); m_Template.gameObject.SetActive(value: true); m_Dropdown = CreateDropdownList(m_Template.gameObject); m_Dropdown.name = "Dropdown List"; m_Dropdown.SetActive(value: true); RectTransform rectTransform = m_Dropdown.transform as RectTransform; rectTransform.SetParent(m_Template.transform.parent, worldPositionStays: false); DropdownItem componentInChildren = m_Dropdown.GetComponentInChildren <DropdownItem>(); GameObject gameObject = componentInChildren.rectTransform.parent.gameObject; RectTransform rectTransform2 = gameObject.transform as RectTransform; componentInChildren.rectTransform.gameObject.SetActive(value: true); Rect rect = rectTransform2.rect; Rect rect2 = componentInChildren.rectTransform.rect; Vector2 vector = rect2.min - rect.min + (Vector2)componentInChildren.rectTransform.localPosition; Vector2 vector2 = rect2.max - rect.max + (Vector2)componentInChildren.rectTransform.localPosition; Vector2 size = rect2.size; m_Items.Clear(); Toggle toggle = null; for (int i = 0; i < options.Count; i++) { OptionData data = options[i]; DropdownItem item = AddItem(data, value == i, componentInChildren, m_Items); if (!(item == null)) { item.toggle.isOn = (value == i); item.toggle.onValueChanged.AddListener(delegate { 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)m_Items.Count + vector.y - vector2.y; rectTransform2.sizeDelta = sizeDelta; float num = rectTransform.rect.height - rectTransform2.rect.height; if (num > 0f) { RectTransform rectTransform3 = rectTransform; Vector2 sizeDelta2 = rectTransform.sizeDelta; float x2 = sizeDelta2.x; Vector2 sizeDelta3 = rectTransform.sizeDelta; rectTransform3.sizeDelta = new Vector2(x2, sizeDelta3.y - num); } Vector3[] array = new Vector3[4]; rectTransform.GetWorldCorners(array); RectTransform rectTransform4 = canvas.transform as RectTransform; Rect rect3 = rectTransform4.rect; for (int j = 0; j < 2; j++) { bool flag = false; for (int k = 0; k < 4; k++) { Vector3 vector3 = rectTransform4.InverseTransformPoint(array[k]); if (vector3[j] < rect3.min[j] || vector3[j] > rect3.max[j]) { flag = true; break; } } if (flag) { RectTransformUtility.FlipLayoutOnAxis(rectTransform, j, keepPositioning: false, recursive: false); } } for (int l = 0; l < m_Items.Count; l++) { RectTransform rectTransform5 = m_Items[l].rectTransform; RectTransform rectTransform6 = rectTransform5; Vector2 anchorMin = rectTransform5.anchorMin; rectTransform6.anchorMin = new Vector2(anchorMin.x, 0f); RectTransform rectTransform7 = rectTransform5; Vector2 anchorMax = rectTransform5.anchorMax; rectTransform7.anchorMax = new Vector2(anchorMax.x, 0f); RectTransform rectTransform8 = rectTransform5; Vector2 anchoredPosition = rectTransform5.anchoredPosition; float x3 = anchoredPosition.x; float num2 = vector.y + size.y * (float)(m_Items.Count - 1 - l); float y = size.y; Vector2 pivot = rectTransform5.pivot; rectTransform8.anchoredPosition = new Vector2(x3, num2 + y * pivot.y); RectTransform rectTransform9 = rectTransform5; Vector2 sizeDelta4 = rectTransform5.sizeDelta; rectTransform9.sizeDelta = new Vector2(sizeDelta4.x, size.y); } AlphaFadeList(0.15f, 0f, 1f); m_Template.gameObject.SetActive(value: false); componentInChildren.gameObject.SetActive(value: false); m_Blocker = CreateBlocker(canvas); }
static void FlipLayoutOnHorizontal(MenuCommand command) { RectTransformUtility.FlipLayoutOnAxis((command.context as RectTransform), 0, false, false); }
// Show the dropdown. // // Plan for dropdown scrolling to ensure dropdown is contained within screen. // // We assume the Canvas is the screen that the dropdown must be kept inside. // This is always valid for screen space canvas modes. // For world space canvases we don't know how it's used, but it could be e.g. for an in-game monitor. // We consider it a fair constraint that the canvas must be big enough to contains dropdowns. public void Show() { if (!IsActive() || !IsInteractable() || m_Dropdown != null) { return; } if (!validTemplate) { SetupTemplate(); if (!validTemplate) { return; } } // Get root Canvas. Canvas rootCanvas = transform.GetComponentInParent <Canvas>(); m_Template.gameObject.SetActive(true); // Instantiate the drop-down template m_Dropdown = CreateDropdownList(m_Template.gameObject); m_Dropdown.name = "Dropdown List"; m_Dropdown.SetActive(true); // Make drop-down RectTransform have same values as original. RectTransform dropdownRectTransform = m_Dropdown.transform as RectTransform; dropdownRectTransform.SetParent(m_Template.transform.parent, false); // Instantiate the drop-down list items // Find the dropdown item and disable it. DropdownItem itemTemplate = m_Dropdown.GetComponentInChildren <DropdownItem>(); GameObject content = itemTemplate.rectTransform.parent.gameObject; RectTransform contentRectTransform = content.transform as RectTransform; itemTemplate.rectTransform.gameObject.SetActive(true); // Get the rects of the dropdown and item Rect dropdownContentRect = contentRectTransform.rect; Rect itemTemplateRect = itemTemplate.rectTransform.rect; // Calculate the visual offset between the item's edges and the background's edges Vector2 offsetMin = itemTemplateRect.min - dropdownContentRect.min + (Vector2)itemTemplate.rectTransform.localPosition; Vector2 offsetMax = itemTemplateRect.max - dropdownContentRect.max + (Vector2)itemTemplate.rectTransform.localPosition; Vector2 itemSize = itemTemplateRect.size; m_Items.Clear(); Button prev = null; for (int i = 0; i < options.Count; ++i) { OptionData data = options[i]; DropdownItem item = AddItem(data, itemTemplate, m_Items); if (item == null) { continue; } int index = i; item.button.onClick.AddListener(() => { onItemSelected.Invoke(index); Hide(); }); // Automatically set up explicit navigation if (prev != null) { Navigation prevNav = prev.navigation; Navigation toggleNav = item.button.navigation; prevNav.mode = Navigation.Mode.Explicit; toggleNav.mode = Navigation.Mode.Explicit; prevNav.selectOnDown = item.button; prevNav.selectOnRight = item.button; toggleNav.selectOnLeft = prev; toggleNav.selectOnUp = prev; prev.navigation = prevNav; item.button.navigation = toggleNav; } prev = item.button; } // Reposition all items now that all of them have been added Vector2 sizeDelta = contentRectTransform.sizeDelta; sizeDelta.y = itemSize.y * m_Items.Count + offsetMin.y - offsetMax.y; contentRectTransform.sizeDelta = sizeDelta; float extraSpace = dropdownRectTransform.rect.height - contentRectTransform.rect.height; if (extraSpace > 0) { dropdownRectTransform.sizeDelta = new Vector2(dropdownRectTransform.sizeDelta.x, dropdownRectTransform.sizeDelta.y - extraSpace); } // Invert anchoring and position if dropdown is partially or fully outside of canvas rect. // Typically this will have the effect of placing the dropdown above the button instead of below, // but it works as inversion regardless of initial setup. Vector3[] corners = new Vector3[4]; dropdownRectTransform.GetWorldCorners(corners); RectTransform rootCanvasRectTransform = rootCanvas.transform as RectTransform; Rect rootCanvasRect = rootCanvasRectTransform.rect; for (int axis = 0; axis < 2; axis++) { bool outside = false; for (int i = 0; i < 4; i++) { Vector3 corner = rootCanvasRectTransform.InverseTransformPoint(corners[i]); if (corner[axis] < rootCanvasRect.min[axis] || corner[axis] > rootCanvasRect.max[axis]) { outside = true; break; } } if (outside) { RectTransformUtility.FlipLayoutOnAxis(dropdownRectTransform, axis, false, false); } } for (int i = 0; i < m_Items.Count; i++) { RectTransform itemRect = m_Items[i].rectTransform; itemRect.anchorMin = new Vector2(itemRect.anchorMin.x, 0); itemRect.anchorMax = new Vector2(itemRect.anchorMax.x, 0); itemRect.anchoredPosition = new Vector2(itemRect.anchoredPosition.x, offsetMin.y + itemSize.y * (m_Items.Count - 1 - i) + itemSize.y * itemRect.pivot.y); itemRect.sizeDelta = new Vector2(itemRect.sizeDelta.x, itemSize.y); } // Fade in the popup AlphaFadeList(m_Dropdown.GetComponent <CanvasGroup>(), 0.15f, 0f, 1f); // Make drop-down template and item template inactive m_Template.gameObject.SetActive(false); itemTemplate.gameObject.SetActive(false); m_Blocker = CreateBlocker(rootCanvas); }
/// <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); }
public override void OnEnter() { base.OnEnter(); RectTransformUtility.FlipLayoutOnAxis(transform, axis.Value, keepPositioning.Value, recursive.Value); Finish(); }
public unsafe void Show() { //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_029d: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02de: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Unknown result type (might be due to invalid IL or missing references) //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_032d: Unknown result type (might be due to invalid IL or missing references) //IL_0344: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Unknown result type (might be due to invalid IL or missing references) //IL_035c: Unknown result type (might be due to invalid IL or missing references) //IL_0385: Unknown result type (might be due to invalid IL or missing references) //IL_038a: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Unknown result type (might be due to invalid IL or missing references) //IL_03a4: Unknown result type (might be due to invalid IL or missing references) //IL_03a9: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_03bb: Unknown result type (might be due to invalid IL or missing references) //IL_03d3: Unknown result type (might be due to invalid IL or missing references) //IL_03d8: Unknown result type (might be due to invalid IL or missing references) //IL_042e: Unknown result type (might be due to invalid IL or missing references) //IL_043d: Unknown result type (might be due to invalid IL or missing references) //IL_044b: Unknown result type (might be due to invalid IL or missing references) //IL_045a: Unknown result type (might be due to invalid IL or missing references) //IL_0468: Unknown result type (might be due to invalid IL or missing references) //IL_0472: Unknown result type (might be due to invalid IL or missing references) //IL_0479: Unknown result type (might be due to invalid IL or missing references) //IL_0493: Unknown result type (might be due to invalid IL or missing references) //IL_049c: Unknown result type (might be due to invalid IL or missing references) //IL_04a8: Unknown result type (might be due to invalid IL or missing references) //IL_04b6: Unknown result type (might be due to invalid IL or missing references) //IL_04c0: Unknown result type (might be due to invalid IL or missing references) //IL_04c7: Unknown result type (might be due to invalid IL or missing references) if (!this.IsActive() || !this.IsInteractable() || m_Dropdown != null) { return; } if (!validTemplate) { SetupTemplate(); if (!validTemplate) { return; } } Canvas rootCanvas = this.get_gameObject().GetRootCanvas(); if (rootCanvas == null) { return; } m_Template.get_gameObject().SetActive(true); m_Dropdown = CreateDropdownList(m_Template.get_gameObject()); m_Dropdown.set_name("Dropdown List"); m_Dropdown.SetActive(true); RectTransform val = m_Dropdown.get_transform() as RectTransform; val.SetParent(m_Template.get_transform().get_parent(), false); DropdownItem componentInChildren = m_Dropdown.GetComponentInChildren <DropdownItem>(); RectTransform val2 = componentInChildren.rectTransform.get_parent().get_gameObject().get_transform() as RectTransform; componentInChildren.rectTransform.get_gameObject().SetActive(true); Rect rect = val2.get_rect(); Rect rect2 = componentInChildren.rectTransform.get_rect(); Vector2 val3 = rect2.get_min() - rect.get_min() + Vector2.op_Implicit(componentInChildren.rectTransform.get_localPosition()); Vector2 val4 = rect2.get_max() - rect.get_max() + Vector2.op_Implicit(componentInChildren.rectTransform.get_localPosition()); Vector2 size = rect2.get_size(); m_Items.Clear(); Toggle val5 = null; for (int i = 0; i < options.Count; i++) { OptionData data = options[i]; DropdownItem item = AddItem(data, value == i, componentInChildren, m_Items); if (!(item == null)) { item.toggle.set_isOn(value == i); _003C_003Ec__DisplayClass49_0 _003C_003Ec__DisplayClass49_; item.toggle.onValueChanged.AddListener(new UnityAction <bool>((object)_003C_003Ec__DisplayClass49_, (IntPtr)(void *) /*OpCode not supported: LdFtn*/)); if (item.toggle.get_isOn()) { item.toggle.Select(); } if (val5 != null) { Navigation navigation = val5.get_navigation(); Navigation navigation2 = item.toggle.get_navigation(); navigation.set_mode(4); navigation2.set_mode(4); navigation.set_selectOnDown(item.toggle); navigation.set_selectOnRight(item.toggle); navigation2.set_selectOnLeft(val5); navigation2.set_selectOnUp(val5); val5.set_navigation(navigation); item.toggle.set_navigation(navigation2); } val5 = item.toggle; } } Vector2 sizeDelta = val2.get_sizeDelta(); sizeDelta.y = ((IntPtr)(void *)size).y * (float)m_Items.Count + ((IntPtr)(void *)val3).y - ((IntPtr)(void *)val4).y; val2.set_sizeDelta(sizeDelta); Rect rect3 = val.get_rect(); float height = rect3.get_height(); rect3 = val2.get_rect(); float num = height - rect3.get_height(); if (num > 0f) { val.set_sizeDelta(new Vector2(((IntPtr)(void *)val.get_sizeDelta()).x, ((IntPtr)(void *)val.get_sizeDelta()).y - num)); } Vector3[] array = (Vector3[])new Vector3[4]; val.GetWorldCorners(array); RectTransform val6 = rootCanvas.get_transform() as RectTransform; Rect rect4 = val6.get_rect(); for (int j = 0; j < 2; j++) { bool flag = false; int num2 = 0; while (num2 < 4) { Vector3 val7 = val6.InverseTransformPoint(array[num2]); float num3 = val7.get_Item(j); Vector2 val8 = rect4.get_min(); if (!(num3 < val8.get_Item(j))) { float num4 = val7.get_Item(j); val8 = rect4.get_max(); if (!(num4 > val8.get_Item(j))) { num2++; continue; } } flag = true; break; } if (flag) { RectTransformUtility.FlipLayoutOnAxis(val, j, false, false); } } for (int k = 0; k < m_Items.Count; k++) { RectTransform rectTransform = m_Items[k].rectTransform; rectTransform.set_anchorMin(new Vector2(((IntPtr)(void *)rectTransform.get_anchorMin()).x, 0f)); rectTransform.set_anchorMax(new Vector2(((IntPtr)(void *)rectTransform.get_anchorMax()).x, 0f)); rectTransform.set_anchoredPosition(new Vector2(((IntPtr)(void *)rectTransform.get_anchoredPosition()).x, ((IntPtr)(void *)val3).y + ((IntPtr)(void *)size).y * (float)(m_Items.Count - 1 - k) + ((IntPtr)(void *)size).y * ((IntPtr)(void *)rectTransform.get_pivot()).y)); rectTransform.set_sizeDelta(new Vector2(((IntPtr)(void *)rectTransform.get_sizeDelta()).x, ((IntPtr)(void *)size).y)); } m_Template.get_gameObject().SetActive(false); componentInChildren.get_gameObject().SetActive(false); m_Blocker = CreateBlocker(rootCanvas); }
void charGui() { GameObject p1Panel = CreatePanel("Player 1 Gui", Color.black, 0f, 0.85f, 0.4f, 1f, ingameGui, true); GameObject p1pImg = CreatePanel("Player 1 Image", Color.black, 0.01f, 0.06f, 0.3f, 0.98f, p1Panel, true); p1pImg.AddComponent <Mask>(); GameObject p1Image = CreateImage("Image", p1pImg, 0, 0, 1, 1); p1Image.GetComponent <Image> ().sprite = charArray[chID]; p1Image.GetComponent <RectTransform> ().pivot = new Vector2(0.5f, 1); p1Image.GetComponent <RectTransform> ().localScale = new Vector3(1f, 2f, 1f); p1Image.GetComponent <RectTransform> ().anchoredPosition = new Vector2(0f, 0f); GameObject p1Info = CreatePanel("Player 1 Info", Color.black, 0.31f, 0.06f, 0.98f, 0.98f, p1Panel, true); GameObject p1Text = createText("Player 1 Text", p1Info, 0f, 0.7f, 1f, 1f); p1Text.GetComponent <Text> ().fontSize = 20; p1Text.GetComponent <Text> ().color = Color.white; p1Text.GetComponent <Text> ().text = The.p1; playerHp = CreateLoader("PlayerHp", p1Info, bSprite, fSprite, 0f, 0.4f, 1f, 0.7f, new Vector2(0, 0)); playerHp.GetComponent <Slider>().maxValue = 100; pVal = playerHp.GetComponent <Slider>(); GameObject p1Spec1 = CreateLoader("Spec1", p1Info, bSprite, fSprite, 0f, 0f, 0.49f, 0.37f, new Vector2(0, 0)); GameObject p1Spec2 = CreateLoader("Spec1", p1Info, bSprite, fSprite, 0.51f, 0f, 1f, 0.37f, new Vector2(0, 0)); GameObject p2Panel = CreatePanel("Player 2 Gui", Color.black, 0.6f, 0.85f, 1f, 1f, ingameGui, true); p2Panel.GetComponent <RectTransform> ().localScale = new Vector3(-1f, 1f, 1f); GameObject p2pImg = CreatePanel("Player 2 Image", Color.black, 0.01f, 0.06f, 0.3f, 0.98f, p2Panel, true); p2pImg.AddComponent <Mask>(); GameObject p2Image = CreateImage("Image", p2pImg, 0, 0, 1, 1); p2Image.GetComponent <Image> ().sprite = charArray[chID2]; p2Image.GetComponent <RectTransform> ().pivot = new Vector2(0.5f, 1); p2Image.GetComponent <RectTransform> ().localScale = new Vector3(-1f, 2f, 1f); p2Image.GetComponent <RectTransform> ().anchoredPosition = new Vector2(0f, 0f); GameObject p2Info = CreatePanel("Player 2 Info", Color.black, 0.31f, 0.06f, 0.98f, 0.98f, p2Panel, true); GameObject p2Text = createText("p2 Text", p2Info, 0f, 0.7f, 1f, 1f); p2Text.GetComponent <Text> ().fontSize = 20; p2Text.GetComponent <Text> ().color = Color.white; p2Text.GetComponent <Text> ().text = The.p2; enemyHp = CreateLoader("PlayerHp", p2Info, bSprite, fSprite, 0f, 0.4f, 1f, 0.7f, new Vector2(0, 0)); enemyHp.GetComponent <Slider>().maxValue = 100; RectTransformUtility.FlipLayoutOnAxis(enemyHp.GetComponent <RectTransform> (), 0, true, false); enemyHp.GetComponent <Slider>().direction = Slider.Direction.RightToLeft; eVal = enemyHp.GetComponent <Slider>(); GameObject p2Spec1 = CreateLoader("Spec1", p2Info, bSprite, fSprite, 0.51f, 0f, 1f, 0.37f, new Vector2(0, 0)); GameObject p2Spec2 = CreateLoader("Spec2", p2Info, bSprite, fSprite, 0f, 0f, 0.49f, 0.37f, new Vector2(0, 0)); p2Spec1.GetComponent <Slider>().direction = Slider.Direction.RightToLeft; p2Spec2.GetComponent <Slider>().direction = Slider.Direction.RightToLeft; p1Spec1.GetComponent <Slider>().maxValue = The.player.GetComponent <Shotgun>().maxCooldown; p1Spec2.GetComponent <Slider>().maxValue = The.player.GetComponent <Charge>().maxCooldown; p2Spec1.GetComponent <Slider>().maxValue = The.enemy.GetComponent <Shotgun>().maxCooldown; p2Spec2.GetComponent <Slider>().maxValue = The.enemy.GetComponent <Charge>().maxCooldown; p1Spec1Val = p1Spec1.GetComponent <Slider>(); p1Spec2Val = p1Spec2.GetComponent <Slider>(); p2Spec1Val = p2Spec1.GetComponent <Slider>(); p2Spec2Val = p2Spec2.GetComponent <Slider>(); }
public void Show() { if (!IsActive() || !IsInteractable() || m_Dropdown != null || UpdateDropdownOption == null) { return; } if (!validTemplate) { SetupTemplate(); if (!validTemplate) { return; } } m_Template.gameObject.SetActive(true); // Instantiate the drop-down template m_Dropdown = Instantiate(Template.gameObject); m_Dropdown.name = "Dropdown List"; m_Dropdown.SetActive(true); RectTransform dropdownRectTransform = m_Dropdown.transform as RectTransform; dropdownRectTransform.SetParent(Template.parent, false); var layout = GetOrAddComponent <VerticalLayoutGroup> (m_Dropdown); layout.childForceExpandHeight = false; layout.childForceExpandWidth = true; var fitter = GetOrAddComponent <ContentSizeFitter> (m_Dropdown); fitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained; fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; PreciseManeuverDropdownItem itemPrefab = m_Dropdown.GetComponentInChildren <PreciseManeuverDropdownItem> (); itemPrefab.gameObject.SetActive(true); Toggle prev = null; for (int i = 0; i < OptionCount; ++i) { PreciseManeuverDropdownItem item = AddItem(i, itemPrefab); if (item == null) { continue; } // Automatically set up a toggle state change listener item.Toggle.isOn = (Value == i); item.Toggle.onValueChanged.AddListener(x => OnSelectItem(item.Index)); // Select current option if (item.Toggle.isOn) { item.Toggle.Select(); } // Automatically set up explicit navigation if (prev != null) { Navigation prevNav = prev.navigation; Navigation toggleNav = item.Toggle.navigation; prevNav.mode = Navigation.Mode.Explicit; toggleNav.mode = Navigation.Mode.Explicit; prevNav.selectOnDown = item.Toggle; prevNav.selectOnRight = item.Toggle; toggleNav.selectOnLeft = prev; toggleNav.selectOnUp = prev; prev.navigation = prevNav; item.Toggle.navigation = toggleNav; } prev = item.Toggle; } // Invert anchoring and position if dropdown is partially or fully outside of canvas rect. // Typically this will have the effect of placing the dropdown above the button instead of below, // but it works as inversion regardless of initial setup. Vector3[] corners = new Vector3[4]; dropdownRectTransform.GetWorldCorners(corners); bool outside = false; RectTransform rootCanvasRectTransform = m_RootCanvas.transform as RectTransform; for (int i = 0; i < 4; i++) { Vector3 corner = rootCanvasRectTransform.InverseTransformPoint(corners[i]); if (!rootCanvasRectTransform.rect.Contains(corner)) { outside = true; break; } } if (outside) { RectTransformUtility.FlipLayoutOnAxis(dropdownRectTransform, 0, false, false); RectTransformUtility.FlipLayoutOnAxis(dropdownRectTransform, 1, false, false); } // Fade in the popup SetAlpha(0f); AlphaFadeList(0.15f, 1f); // Make drop-down template and item template inactive Template.gameObject.SetActive(false); itemPrefab.gameObject.SetActive(false); Destroy(itemPrefab); m_Blocker = CreateBlocker(m_RootCanvas); }
/// <summary> /// Show the dropdown. /// /// Plan for dropdown scrolling to ensure dropdown is contained within screen. /// /// We assume the Canvas is the screen that the dropdown must be kept inside. /// This is always valid for screen space canvas modes. /// For world space canvases we don't know how it's used, but it could be e.g. for an in-game monitor. /// We consider it a fair constraint that the canvas must be big enough to contain dropdowns. /// </summary> public void Show() { if (m_Coroutine != null) { StopCoroutine(m_Coroutine); ImmediateDestroyDropdownList(); } if (!IsActive() || !IsInteractable() || m_Dropdown != null) { return; } // Get root Canvas. var list = TMP_ListPool <Canvas> .Get(); gameObject.GetComponentsInParent(false, list); if (list.Count == 0) { return; } Canvas rootCanvas = list[list.Count - 1]; for (int i = 0; i < list.Count; i++) { if (list[i].isRootCanvas) { rootCanvas = list[i]; break; } } TMP_ListPool <Canvas> .Release(list); if (!validTemplate) { SetupTemplate(); if (!validTemplate) { return; } } m_Template.gameObject.SetActive(true); // popupCanvas used to assume the root canvas had the default sorting Layer, next line fixes (case 958281 - [UI] Dropdown list does not copy the parent canvas layer when the panel is opened) m_Template.GetComponent <Canvas>().sortingLayerID = rootCanvas.sortingLayerID; // Instantiate the drop-down template m_Dropdown = CreateDropdownList(m_Template.gameObject); m_Dropdown.name = "Dropdown List"; m_Dropdown.SetActive(true); // Make drop-down RectTransform have same values as original. RectTransform dropdownRectTransform = m_Dropdown.transform as RectTransform; dropdownRectTransform.SetParent(m_Template.transform.parent, false); // Instantiate the drop-down list items // Find the dropdown item and disable it. DropdownItem itemTemplate = m_Dropdown.GetComponentInChildren <DropdownItem>(); GameObject content = itemTemplate.rectTransform.parent.gameObject; RectTransform contentRectTransform = content.transform as RectTransform; itemTemplate.rectTransform.gameObject.SetActive(true); // Get the rects of the dropdown and item Rect dropdownContentRect = contentRectTransform.rect; Rect itemTemplateRect = itemTemplate.rectTransform.rect; // Calculate the visual offset between the item's edges and the background's edges Vector2 offsetMin = itemTemplateRect.min - dropdownContentRect.min + (Vector2)itemTemplate.rectTransform.localPosition; Vector2 offsetMax = itemTemplateRect.max - dropdownContentRect.max + (Vector2)itemTemplate.rectTransform.localPosition; Vector2 itemSize = itemTemplateRect.size; m_Items.Clear(); Toggle prev = null; for (int i = 0; i < options.Count; ++i) { OptionData data = options[i]; DropdownItem item = AddItem(data, value == i, itemTemplate, m_Items); if (item == null) { continue; } // Automatically set up a toggle state change listener item.toggle.isOn = value == i; item.toggle.onValueChanged.AddListener(x => OnSelectItem(item.toggle)); // Select current option if (item.toggle.isOn) { item.toggle.Select(); } // Automatically set up explicit navigation if (prev != null) { Navigation prevNav = prev.navigation; Navigation toggleNav = item.toggle.navigation; prevNav.mode = Navigation.Mode.Explicit; toggleNav.mode = Navigation.Mode.Explicit; prevNav.selectOnDown = item.toggle; prevNav.selectOnRight = item.toggle; toggleNav.selectOnLeft = prev; toggleNav.selectOnUp = prev; prev.navigation = prevNav; item.toggle.navigation = toggleNav; } prev = item.toggle; } // Reposition all items now that all of them have been added Vector2 sizeDelta = contentRectTransform.sizeDelta; sizeDelta.y = itemSize.y * m_Items.Count + offsetMin.y - offsetMax.y; contentRectTransform.sizeDelta = sizeDelta; float extraSpace = dropdownRectTransform.rect.height - contentRectTransform.rect.height; if (extraSpace > 0) { dropdownRectTransform.sizeDelta = new Vector2(dropdownRectTransform.sizeDelta.x, dropdownRectTransform.sizeDelta.y - extraSpace); } // Invert anchoring and position if dropdown is partially or fully outside of canvas rect. // Typically this will have the effect of placing the dropdown above the button instead of below, // but it works as inversion regardless of initial setup. Vector3[] corners = new Vector3[4]; dropdownRectTransform.GetWorldCorners(corners); RectTransform rootCanvasRectTransform = rootCanvas.transform as RectTransform; Rect rootCanvasRect = rootCanvasRectTransform.rect; for (int axis = 0; axis < 2; axis++) { bool outside = false; for (int i = 0; i < 4; i++) { Vector3 corner = rootCanvasRectTransform.InverseTransformPoint(corners[i]); if ((corner[axis] < rootCanvasRect.min[axis] && !Mathf.Approximately(corner[axis], rootCanvasRect.min[axis])) || (corner[axis] > rootCanvasRect.max[axis] && !Mathf.Approximately(corner[axis], rootCanvasRect.max[axis]))) { outside = true; break; } } if (outside) { RectTransformUtility.FlipLayoutOnAxis(dropdownRectTransform, axis, false, false); } } for (int i = 0; i < m_Items.Count; i++) { RectTransform itemRect = m_Items[i].rectTransform; itemRect.anchorMin = new Vector2(itemRect.anchorMin.x, 0); itemRect.anchorMax = new Vector2(itemRect.anchorMax.x, 0); itemRect.anchoredPosition = new Vector2(itemRect.anchoredPosition.x, offsetMin.y + itemSize.y * (m_Items.Count - 1 - i) + itemSize.y * itemRect.pivot.y); itemRect.sizeDelta = new Vector2(itemRect.sizeDelta.x, itemSize.y); } // Fade in the popup AlphaFadeList(m_AlphaFadeSpeed, 0f, 1f); // Make drop-down template and item template inactive m_Template.gameObject.SetActive(false); itemTemplate.gameObject.SetActive(false); m_Blocker = CreateBlocker(rootCanvas); }
// Show the dropdown. // // Plan for dropdown scrolling to ensure dropdown is contained within screen. // // We assume the Canvas is the screen that the dropdown must be kept inside. // This is always valid for screen space canvas modes. // For world space canvases we don't know how it's used, but it could be e.g. for an in-game monitor. // We consider it a fair constraint that the canvas must be big enough to contains dropdowns. public void Show() { if (!IsActive() || !IsInteractable() || m_Dropdown != null) { return; } //初始状态时validTemplate为false来触发对于列表模板的初始化设置 if (!validTemplate) { //模板初始化方法:检测并设置模板,初始化模板绑定相关组件并调整模板UI层级,若没有通过检查则模板标记为不可用状态。 SetupTemplate(); //若检测不通过则无法正常显示下拉列表 if (!validTemplate) { return; } } // Get root Canvas. var list = ListPool <Canvas> .Get(); gameObject.GetComponentsInParent(false, list); if (list.Count == 0) { return; } //获取父级路径下最近的canvas Canvas rootCanvas = list[0]; ListPool <Canvas> .Release(list); //显示模板准备复制列表 m_Template.gameObject.SetActive(true); // Instantiate the drop-down template //复制列表模板 m_Dropdown = CreateDropdownList(m_Template.gameObject); //进行改名 m_Dropdown.name = "Dropdown List"; m_Dropdown.SetActive(true); // Make drop-down RectTransform have same values as original. // 设置新的列表模板的父级 RectTransform dropdownRectTransform = m_Dropdown.transform as RectTransform; dropdownRectTransform.SetParent(m_Template.transform.parent, false); // Instantiate the drop-down list items // 创建列表Item // Find the dropdown item and disable it. DropdownItem itemTemplate = m_Dropdown.GetComponentInChildren <DropdownItem>(); GameObject content = itemTemplate.rectTransform.parent.gameObject; RectTransform contentRectTransform = content.transform as RectTransform; itemTemplate.rectTransform.gameObject.SetActive(true); // Get the rects of the dropdown and item Rect dropdownContentRect = contentRectTransform.rect; Rect itemTemplateRect = itemTemplate.rectTransform.rect; // Calculate the visual offset between the item's edges and the background's edges //计算Item与背景边界的偏移量 Vector2 offsetMin = itemTemplateRect.min - dropdownContentRect.min + (Vector2)itemTemplate.rectTransform.localPosition; Vector2 offsetMax = itemTemplateRect.max - dropdownContentRect.max + (Vector2)itemTemplate.rectTransform.localPosition; Vector2 itemSize = itemTemplateRect.size; //清空DropdownItem List 准备开始选项Itme的创建 m_Items.Clear(); Toggle prev = null; for (int i = 0; i < options.Count; ++i) { OptionData data = options[i]; //创建Item DropdownItem item = AddItem(data, value == i, itemTemplate, m_Items); if (item == null) { continue; } // Automatically set up a toggle state change listener // 设置toggle初始状态以及注册事件监听 item.toggle.isOn = value == i; item.toggle.onValueChanged.AddListener(x => OnSelectItem(item.toggle)); // Select current option //标记当前选项 if (item.toggle.isOn) { item.toggle.Select(); } // Automatically set up explicit navigation // 设置Item的导航 if (prev != null) { Navigation prevNav = prev.navigation; Navigation toggleNav = item.toggle.navigation; prevNav.mode = Navigation.Mode.Explicit; toggleNav.mode = Navigation.Mode.Explicit; prevNav.selectOnDown = item.toggle; prevNav.selectOnRight = item.toggle; toggleNav.selectOnLeft = prev; toggleNav.selectOnUp = prev; prev.navigation = prevNav; item.toggle.navigation = toggleNav; } prev = item.toggle; } // Reposition all items now that all of them have been added // 计算内容区域的高度 Vector2 sizeDelta = contentRectTransform.sizeDelta; sizeDelta.y = itemSize.y * m_Items.Count + offsetMin.y - offsetMax.y; contentRectTransform.sizeDelta = sizeDelta; //计算是否有额外空区域(当内容区域小于列表本身的区域时调整列表大小) float extraSpace = dropdownRectTransform.rect.height - contentRectTransform.rect.height; if (extraSpace > 0) { dropdownRectTransform.sizeDelta = new Vector2(dropdownRectTransform.sizeDelta.x, dropdownRectTransform.sizeDelta.y - extraSpace); } // Invert anchoring and position if dropdown is partially or fully outside of canvas rect. // Typically this will have the effect of placing the dropdown above the button instead of below, // but it works as inversion regardless of initial setup. // 当列表处于canvas外部时,将其按坐标轴进行翻转 Vector3[] corners = new Vector3[4]; dropdownRectTransform.GetWorldCorners(corners); RectTransform rootCanvasRectTransform = rootCanvas.transform as RectTransform; Rect rootCanvasRect = rootCanvasRectTransform.rect; for (int axis = 0; axis < 2; axis++) { bool outside = false; for (int i = 0; i < 4; i++) { Vector3 corner = rootCanvasRectTransform.InverseTransformPoint(corners[i]); if (corner[axis] < rootCanvasRect.min[axis] || corner[axis] > rootCanvasRect.max[axis]) { outside = true; break; } } if (outside) { RectTransformUtility.FlipLayoutOnAxis(dropdownRectTransform, axis, false, false); } } for (int i = 0; i < m_Items.Count; i++) { RectTransform itemRect = m_Items[i].rectTransform; itemRect.anchorMin = new Vector2(itemRect.anchorMin.x, 0); itemRect.anchorMax = new Vector2(itemRect.anchorMax.x, 0); itemRect.anchoredPosition = new Vector2(itemRect.anchoredPosition.x, offsetMin.y + itemSize.y * (m_Items.Count - 1 - i) + itemSize.y * itemRect.pivot.y); itemRect.sizeDelta = new Vector2(itemRect.sizeDelta.x, itemSize.y); } // Fade in the popup // 下拉列表渐出效果 AlphaFadeList(0.15f, 0f, 1f); // Make drop-down template and item template inactive // 隐藏模板 m_Template.gameObject.SetActive(false); itemTemplate.gameObject.SetActive(false); // 创建拦截模板,用于监听点击事件来隐藏下拉列表,层级会低于下拉列表(2999) m_Blocker = CreateBlocker(rootCanvas); }