示例#1
0
 private OptimizedDropdown.DropdownItem AddItem(
     OptimizedDropdown.OptionData data,
     Transform parent,
     List <OptimizedDropdown.DropdownItem> items)
 {
     OptimizedDropdown.DropdownItem dropdownItem = this._pool.Get();
     ((Transform)dropdownItem.RectTransform).SetParent(parent, false);
     ((Component)dropdownItem).get_gameObject().SetActive(true);
     ((Object)((Component)dropdownItem).get_gameObject()).set_name("Item " + (object)items.Count + (data.Text == null ? (object)string.Empty : (object)(": " + data.Text)));
     ((UnityEventBase)dropdownItem.Toggle.onValueChanged).RemoveAllListeners();
     if (Object.op_Inequality((Object)dropdownItem, (Object)null))
     {
         dropdownItem.Toggle.set_isOn(false);
     }
     if (Object.op_Implicit((Object)dropdownItem.Text))
     {
         dropdownItem.Text.set_text(data.Text);
     }
     if (Object.op_Implicit((Object)dropdownItem.Image))
     {
         dropdownItem.Image.set_sprite(data.Sprite);
         ((Behaviour)dropdownItem.Image).set_enabled(Object.op_Inequality((Object)dropdownItem.Image.get_sprite(), (Object)null));
     }
     items.Add(dropdownItem);
     return(dropdownItem);
 }
示例#2
0
 public void Release(OptimizedDropdown.DropdownItem element)
 {
     if (this._stack.Count > 0 && object.ReferenceEquals((object)this._stack.Peek(), (object)element))
     {
         Debug.LogError((object)"Internal error. Trying to destroy object that is already released to pool.");
     }
     if (this._onReleased != null)
     {
         this._onReleased(element);
     }
     this._stack.Push(element);
 }
示例#3
0
 private void SetupTemplate()
 {
     this._validTemplate = false;
     if (!Object.op_Implicit((Object)this._template))
     {
         Debug.LogError((object)"The dropdown template is not assigned. The template needs to be assigned must have a child GameObject with a Toggle component serving as the item.", (Object)this);
     }
     else
     {
         GameObject gameObject = ((Component)this._template).get_gameObject();
         gameObject.SetActive(true);
         Toggle componentInChildren = (Toggle)((Component)this._template).GetComponentInChildren <Toggle>();
         this._validTemplate = true;
         if (!Object.op_Implicit((Object)componentInChildren) || Object.op_Equality((Object)((Component)componentInChildren).get_transform(), (Object)this.Template))
         {
             this._validTemplate = false;
             Debug.LogError((object)"The dropdown template is not valid. The template must have a vhild GameObject with a child GameObject with a Toggle component serving as the item.", (Object)this.Template);
         }
         else if (Object.op_Inequality((Object)this.ItemText, (Object)null) && !((Component)this.ItemText).get_transform().IsChildOf(((Component)componentInChildren).get_transform()))
         {
             this._validTemplate = false;
             Debug.LogError((object)"The dropdown template is not valid. The Item Text must be on the item GameObject or children of it.", (Object)this.Template);
         }
         else if (Object.op_Inequality((Object)this.ItemImage, (Object)null) && !((Component)this.ItemImage).get_transform().IsChildOf(((Component)componentInChildren).get_transform()))
         {
             this._validTemplate = false;
             Debug.LogError((object)"The dropdown template is not valid. The Item Image must be on the item GameOBject or children of it.", (Object)this.Template);
         }
         if (!this._validTemplate)
         {
             gameObject.SetActive(false);
         }
         else
         {
             OptimizedDropdown.DropdownItem dropdownItem = (OptimizedDropdown.DropdownItem)((Component)componentInChildren).get_gameObject().AddComponent <OptimizedDropdown.DropdownItem>();
             dropdownItem.Text          = this._itemText;
             dropdownItem.Image         = this._itemImage;
             dropdownItem.Toggle        = componentInChildren;
             dropdownItem.RectTransform = ((Component)componentInChildren).get_transform() as RectTransform;
             Canvas orAddComponent = OptimizedDropdown.GetOrAddComponent <Canvas>(gameObject);
             orAddComponent.set_overrideSorting(true);
             orAddComponent.set_sortingOrder(30000);
             OptimizedDropdown.GetOrAddComponent <GraphicRaycaster>(gameObject);
             OptimizedDropdown.GetOrAddComponent <CanvasGroup>(gameObject);
             gameObject.SetActive(false);
             this._validTemplate = true;
         }
         this._pool = new OptimizedDropdown.DropdownItemPool((Action <OptimizedDropdown.DropdownItem>)null, (Action <OptimizedDropdown.DropdownItem>)null, ((Component)componentInChildren).get_gameObject());
     }
 }
示例#4
0
 protected virtual OptimizedDropdown.DropdownItem CreateItem(
     OptimizedDropdown.DropdownItem itemTemplate)
 {
     return((OptimizedDropdown.DropdownItem)Object.Instantiate <OptimizedDropdown.DropdownItem>((M0)itemTemplate));
 }
示例#5
0
        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)));
        }