示例#1
0
        /// <summary>
        /// Function to get the Stencil ID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static int GetStencilID(GameObject obj)
        {
            int count = 0;

            var maskComponents = TMP_ListPool <Mask> .Get();

            obj.GetComponentsInParent <Mask>(false, maskComponents);
            for (int i = 0; i < maskComponents.Count; i++)
            {
#if UNITY_5_2 || UNITY_5_3_OR_NEWER
                if (maskComponents[i].IsActive())
                {
                    count += 1;
                }
#else
                if (maskComponents[i].MaskEnabled())
                {
                    count += 1;
                }
#endif
            }

            TMP_ListPool <Mask> .Release(maskComponents);

            return(Mathf.Min((1 << count) - 1, 255));
        }
        public static int GetStencilID(GameObject obj)
        {
            int       num       = 0;
            Transform transform = obj.transform;
            Transform y         = TMP_MaterialManager.FindRootSortOverrideCanvas(transform);

            if (transform == y)
            {
                return(num);
            }
            Transform   parent = transform.parent;
            List <Mask> list   = TMP_ListPool <Mask> .Get();

            while (parent != null)
            {
                parent.GetComponents <Mask>(list);
                for (int i = 0; i < list.Count; i++)
                {
                    Mask mask = list[i];
                    if (mask != null && mask.MaskEnabled() && mask.graphic.IsActive())
                    {
                        num++;
                        break;
                    }
                }
                if (parent == y)
                {
                    break;
                }
                parent = parent.parent;
            }
            TMP_ListPool <Mask> .Release(list);

            return(Mathf.Min((1 << num) - 1, 255));
        }
示例#3
0
        public static int GetStencilID(GameObject obj)
        {
            int         num  = 0;
            List <Mask> list = TMP_ListPool <Mask> .Get();

            obj.GetComponentsInParent(false, list);
            for (int i = 0; i < list.Count; i++)
            {
                if (((UIBehaviour)list[i]).IsActive())
                {
                    num++;
                }
            }
            TMP_ListPool <Mask> .Release(list);

            return(Mathf.Min((1 << num) - 1, 255));
        }
        private static Transform FindRootSortOverrideCanvas(Transform start)
        {
            List <Canvas> list = TMP_ListPool <Canvas> .Get();

            start.GetComponentsInParent <Canvas>(false, list);
            Canvas canvas = null;

            for (int i = 0; i < list.Count; i++)
            {
                canvas = list[i];
                if (canvas.overrideSorting)
                {
                    break;
                }
            }
            TMP_ListPool <Canvas> .Release(list);

            return((!(canvas != null)) ? null : canvas.transform);
        }
        public static Material GetMaterialForRendering(MaskableGraphic graphic, Material baseMaterial)
        {
            if (baseMaterial == null)
            {
                return(null);
            }
            List <IMaterialModifier> list = TMP_ListPool <IMaterialModifier> .Get();

            graphic.GetComponents <IMaterialModifier>(list);
            Material material = baseMaterial;

            for (int i = 0; i < list.Count; i++)
            {
                material = list[i].GetModifiedMaterial(material);
            }
            TMP_ListPool <IMaterialModifier> .Release(list);

            return(material);
        }
        /// <summary>
        /// Function to get the Stencil ID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static int GetStencilID(GameObject obj)
        {
            int count = 0;

            var maskComponents = TMP_ListPool <Mask> .Get();

            obj.GetComponentsInParent <Mask>(false, maskComponents);
            for (int i = 0; i < maskComponents.Count; i++)
            {
                if (maskComponents[i].IsActive())
                {
                    count += 1;
                }
            }

            TMP_ListPool <Mask> .Release(maskComponents);

            return(Mathf.Min((1 << count) - 1, 255));
        }
        /// <summary>
        /// Function to get the Stencil ID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static int GetStencilID(GameObject obj)
        {
            // Implementation is almost copied from Unity UI

            var count = 0;

            var transform = obj.transform;
            var stopAfter = FindRootSortOverrideCanvas(transform);

            if (transform == stopAfter)
            {
                return(count);
            }

            var t          = transform.parent;
            var components = TMP_ListPool <Mask> .Get();

            while (t != null)
            {
                t.GetComponents <Mask>(components);
                for (var i = 0; i < components.Count; ++i)
                {
                    var mask = components[i];
                    if (mask != null && mask.MaskEnabled() && mask.graphic.IsActive())
                    {
                        ++count;
                        break;
                    }
                }

                if (t == stopAfter)
                {
                    break;
                }

                t = t.parent;
            }
            TMP_ListPool <Mask> .Release(components);

            return(Mathf.Min((1 << count) - 1, 255));
        }
        public static Material GetMaterialForRendering(MaskableGraphic graphic, Material baseMaterial)
        {
            if (baseMaterial == null)
            {
                return(null);
            }

            var modifiers = TMP_ListPool <IMaterialModifier> .Get();

            graphic.GetComponents(modifiers);

            var result = baseMaterial;

            for (int i = 0; i < modifiers.Count; i++)
            {
                result = modifiers[i].GetModifiedMaterial(result);
            }

            TMP_ListPool <IMaterialModifier> .Release(modifiers);

            return(result);
        }
        private static Transform FindRootSortOverrideCanvas(Transform start)
        {
            // Implementation is copied from Unity UI

            var canvasList = TMP_ListPool <Canvas> .Get();

            start.GetComponentsInParent(false, canvasList);
            Canvas canvas = null;

            for (int i = 0; i < canvasList.Count; ++i)
            {
                canvas = canvasList[i];

                // We found the canvas we want to use break
                if (canvas.overrideSorting)
                {
                    break;
                }
            }
            TMP_ListPool <Canvas> .Release(canvasList);

            return(canvas != null ? canvas.transform : null);
        }
        /// <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);
        }
示例#11
0
        public void Show()
        {
            bool flag = !this.IsActive() || !this.IsInteractable() || this.m_Dropdown != null;

            if (!flag)
            {
                bool flag2 = !this.validTemplate;
                if (flag2)
                {
                    this.SetupTemplate();
                    bool flag3 = !this.validTemplate;
                    if (flag3)
                    {
                        return;
                    }
                }
                List <Canvas> list = TMP_ListPool <Canvas> .Get();

                base.gameObject.GetComponentsInParent <Canvas>(false, list);
                bool flag4 = list.Count == 0;
                if (!flag4)
                {
                    Canvas canvas = list[0];
                    TMP_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);
                    TMP_Dropdown.DropdownItem componentInChildren = this.m_Dropdown.GetComponentInChildren <TMP_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 + new Vector2(componentInChildren.rectTransform.localPosition.x, componentInChildren.rectTransform.localPosition.y);
                    Vector2 vector2 = rect2.max - rect.max + new Vector2(componentInChildren.rectTransform.localPosition.x, componentInChildren.rectTransform.localPosition.y);
                    Vector2 size    = rect2.size;
                    this.m_Items.Clear();
                    Toggle toggle = null;
                    for (int i = 0; i < this.options.Count; i++)
                    {
                        TMP_Dropdown.OptionData   data = this.options[i];
                        TMP_Dropdown.DropdownItem item = this.AddItem(data, this.value == i, componentInChildren, this.m_Items);
                        bool flag5 = item == null;
                        if (!flag5)
                        {
                            item.toggle.isOn = (this.value == i);
                            item.toggle.onValueChanged.AddListener(delegate(bool x)
                            {
                                this.OnSelectItem(item.toggle);
                            });
                            bool isOn = item.toggle.isOn;
                            if (isOn)
                            {
                                item.toggle.Select();
                            }
                            bool flag6 = toggle != null;
                            if (flag6)
                            {
                                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;
                    bool  flag7 = num > 0f;
                    if (flag7)
                    {
                        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 flag8 = false;
                        for (int k = 0; k < 4; k++)
                        {
                            Vector3 vector3 = rectTransform3.InverseTransformPoint(array[k]);
                            bool    flag9   = vector3[j] < rect3.min[j] || vector3[j] > rect3.max[j];
                            if (flag9)
                            {
                                flag8 = true;
                                break;
                            }
                        }
                        bool flag10 = flag8;
                        if (flag10)
                        {
                            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);
                }
            }
        }
示例#12
0
        public void Show()
        {
            if (!IsActive() || !IsInteractable() || m_Dropdown != null)
            {
                return;
            }
            if (!validTemplate)
            {
                SetupTemplate();
                if (!validTemplate)
                {
                    return;
                }
            }
            List <Canvas> list = TMP_ListPool <Canvas> .Get();

            base.gameObject.GetComponentsInParent(includeInactive: false, list);
            if (list.Count == 0)
            {
                return;
            }
            Canvas canvas = list[0];

            TMP_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)
            {
                Vector2 sizeDelta2 = rectTransform.sizeDelta;
                float   x2         = sizeDelta2.x;
                Vector2 sizeDelta3 = rectTransform.sizeDelta;
                rectTransform.sizeDelta = new Vector2(x2, sizeDelta3.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, keepPositioning: false, recursive: false);
                }
            }
            for (int l = 0; l < m_Items.Count; l++)
            {
                RectTransform rectTransform4 = m_Items[l].rectTransform;
                Vector2       anchorMin      = rectTransform4.anchorMin;
                rectTransform4.anchorMin = new Vector2(anchorMin.x, 0f);
                Vector2 anchorMax = rectTransform4.anchorMax;
                rectTransform4.anchorMax = new Vector2(anchorMax.x, 0f);
                Vector2 anchoredPosition = rectTransform4.anchoredPosition;
                float   x3    = anchoredPosition.x;
                float   num2  = vector.y + size.y * (float)(m_Items.Count - 1 - l);
                float   y     = size.y;
                Vector2 pivot = rectTransform4.pivot;
                rectTransform4.anchoredPosition = new Vector2(x3, num2 + y * pivot.y);
                Vector2 sizeDelta4 = rectTransform4.sizeDelta;
                rectTransform4.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);
        }