Exemplo n.º 1
0
        private void PerformLayoutCalculation(RectTransform rect, UnityAction <Component> action)
        {
            if ((UnityEngine.Object)rect == (UnityEngine.Object)null)
            {
                return;
            }
            List <Component> componentList = ListPool <Component> .Get();

            rect.GetComponents(typeof(ILayoutElement), componentList);
            LayoutRebuilder.StripDisabledBehavioursFromList(componentList);
            if (componentList.Count > 0)
            {
                for (int index = 0; index < rect.childCount; ++index)
                {
                    this.PerformLayoutCalculation(rect.GetChild(index) as RectTransform, action);
                }
                for (int index = 0; index < componentList.Count; ++index)
                {
                    action(componentList[index]);
                }
            }
            ListPool <Component> .Release(componentList);
        }
Exemplo n.º 2
0
        private void PerformLayoutCalculation(RectTransform rect, UnityAction <Component> action)
        {
            if (rect == null)
            {
                return;
            }
            List <Component> list = ListPool <Component> .Get();

            rect.GetComponents(typeof(ILayoutElement), list);
            StripDisabledBehavioursFromList(list);
            if (list.Count > 0)
            {
                for (int i = 0; i < rect.childCount; i++)
                {
                    PerformLayoutCalculation(rect.GetChild(i) as RectTransform, action);
                }
                for (int j = 0; j < list.Count; j++)
                {
                    action(list[j]);
                }
            }
            ListPool <Component> .Release(list);
        }
Exemplo n.º 3
0
        private void CacheCanvas()
        {
            var list = ListPool <Canvas> .Get();

            gameObject.GetComponentsInParent(false, list);
            if (list.Count > 0)
            {
                // Find the first active and enabled canvas.
                for (int i = 0; i < list.Count; ++i)
                {
                    if (list[i].isActiveAndEnabled)
                    {
                        m_Canvas = list[i];
                        break;
                    }
                }
            }
            else
            {
                m_Canvas = null;
            }
            ListPool <Canvas> .Release(list);
        }
Exemplo n.º 4
0
        public static void GetRectMasksForClip(RectMask2D clipper, List <RectMask2D> masks)
        {
            masks.Clear();
            Transform        transform = clipper.transform;
            List <Component> list      = ListPool <Component> .Get();

            for (; (Object)transform != (Object)null; transform = transform.parent)
            {
                transform.GetComponents(typeof(RectMask2D), list);
                for (int index = 0; index < list.Count; ++index)
                {
                    if ((Object)list[index] != (Object)null && ((UIBehaviour)list[index]).IsActive())
                    {
                        masks.Add((RectMask2D)list[index]);
                    }
                }
                if ((bool)((Object)transform.GetComponent <Canvas>()))
                {
                    break;
                }
            }
            ListPool <Component> .Release(list);
        }
Exemplo n.º 5
0
        private void DoMeshGeneration()
        {
            if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0)
            {
                OnPopulateMesh(s_VertexHelper);//更新顶点信息
            }
            else
            {
                s_VertexHelper.Clear(); // clear the vertex helper so invalid graphics dont draw.
            }
            var components = ListPool <Component> .Get();

            GetComponents(typeof(IMeshModifier), components);

            for (var i = 0; i < components.Count; i++)
            {
                ((IMeshModifier)components[i]).ModifyMesh(s_VertexHelper);//若由网格特效,则由特效继续更新顶点信息
            }
            ListPool <Component> .Release(components);

            s_VertexHelper.FillMesh(workerMesh);
            canvasRenderer.SetMesh(workerMesh);//设置当canvasRenderer中
        }
Exemplo n.º 6
0
        /// <summary>
        ///   <para>Find a root Canvas.</para>
        /// </summary>
        /// <param name="start">Search start.</param>
        /// <returns>
        ///   <para>Canvas transform.</para>
        /// </returns>
        public static Transform FindRootSortOverrideCanvas(Transform start)
        {
            List <Canvas> canvasList = ListPool <Canvas> .Get();

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

            for (int index = 0; index < canvasList.Count; ++index)
            {
                canvas = canvasList[index];
                if (canvas.overrideSorting)
                {
                    break;
                }
            }
            ListPool <Canvas> .Release(canvasList);

            if ((Object)canvas != (Object)null)
            {
                return(canvas.transform);
            }
            return((Transform)null);
        }
Exemplo n.º 7
0
        private void DoMeshGeneration()
        {
            if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0)
            {
                OnPopulateMesh(s_VertexHelper);
            }
            else
            {
                s_VertexHelper.Clear();
            }

            var components = ListPool <Component> .Get();

            GetComponents(typeof(IMeshModifier), components);
            for (int i = 0; i < components.Count; i++)
            {
                ((IMeshModifier)components[i]).ModifyMesh(s_VertexHelper);
            }
            ListPool <Component> .Release(components);

            s_VertexHelper.FillMesh(workerMesh);
            canvasRenderer.SetMesh(workerMesh);
        }
Exemplo n.º 8
0
        public static int GetStencilDepth(Transform transform, Transform stopAfter)
        {
            int num = 0;
            int result;

            if (transform == stopAfter)
            {
                result = num;
            }
            else
            {
                Transform   parent = transform.parent;
                List <Mask> list   = ListPool <Mask> .Get();

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

                result = num;
            }
            return(result);
        }
Exemplo n.º 9
0
        private void DoMeshGeneration()
        {
            if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0)
            {
                OnPopulateMesh(s_VertexHelper);//在继承类中实现具体的元素信息
            }
            else
            {
                s_VertexHelper.Clear(); // clear the vertex helper so invalid graphics dont draw.
            }
            var components = ListPool <Component> .Get();

            GetComponents(typeof(IMeshModifier), components);
            //Text的描边和阴影都是通过IMeshModifier的ModifyMesh()实现出来的
            for (var i = 0; i < components.Count; i++)
            {
                ((IMeshModifier)components[i]).ModifyMesh(s_VertexHelper);
            }

            ListPool <Component> .Release(components);

            s_VertexHelper.FillMesh(workerMesh);
            canvasRenderer.SetMesh(workerMesh);//提交网格信息,开始合并网格
        }
Exemplo n.º 10
0
        public static void MarkLayoutForRebuild(RectTransform rect)
        {
            if (!(rect == null) && !(rect.gameObject == null))
            {
                List <Component> list = ListPool <Component> .Get();

                bool          flag           = true;
                RectTransform rectTransform  = rect;
                RectTransform rectTransform2 = rectTransform.parent as RectTransform;
                while (flag && !(rectTransform2 == null) && !(rectTransform2.gameObject == null))
                {
                    flag = false;
                    rectTransform2.GetComponents(typeof(ILayoutGroup), list);
                    for (int i = 0; i < list.Count; i++)
                    {
                        Component component = list[i];
                        if (component != null && component is Behaviour && ((Behaviour)component).isActiveAndEnabled)
                        {
                            flag          = true;
                            rectTransform = rectTransform2;
                            break;
                        }
                    }
                    rectTransform2 = (rectTransform2.parent as RectTransform);
                }
                if (rectTransform == rect && !LayoutRebuilder.ValidController(rectTransform, list))
                {
                    ListPool <Component> .Release(list);
                }
                else
                {
                    LayoutRebuilder.MarkLayoutRootForRebuild(rectTransform);
                    ListPool <Component> .Release(list);
                }
            }
        }
Exemplo n.º 11
0
        public static void GetRectMasksForClip(RectMask2D clipper, List <RectMask2D> masks)
        {
            masks.Clear();
            List <Canvas> results = ListPool <Canvas> .Get();

            List <RectMask2D> list2 = ListPool <RectMask2D> .Get();

            clipper.transform.GetComponentsInParent <RectMask2D>(false, list2);
            if (list2.Count > 0)
            {
                clipper.transform.GetComponentsInParent <Canvas>(false, results);
                for (int i = list2.Count - 1; i >= 0; i--)
                {
                    if (!list2[i].IsActive())
                    {
                        continue;
                    }
                    bool flag = true;
                    for (int j = results.Count - 1; j >= 0; j--)
                    {
                        if (!IsDescendantOrSelf(results[j].transform, list2[i].transform) && results[j].overrideSorting)
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        masks.Add(list2[i]);
                    }
                }
            }
            ListPool <RectMask2D> .Release(list2);

            ListPool <Canvas> .Release(results);
        }
Exemplo n.º 12
0
        private void PerformLayoutCalculation(RectTransform rect, UnityAction <Component> action)
        {
            if (rect == null)
            {
                return;
            }
            var components = ListPool <Component> .Get();

            rect.GetComponents(typeof(ILayoutElement), components);
            StripDisabledBehavioursFromList(components);
            if (components.Count > 0 || rect.GetComponent(typeof(ILayoutGroup)))
            {
                for (int i = 0; i < rect.childCount; i++)
                {
                    PerformLayoutCalculation(rect.GetChild(i) as RectTransform, action);
                }

                for (int i = 0; i < components.Count; i++)
                {
                    action(components[i]);
                }
            }
            ListPool <Component> .Release(components);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Find the stencil depth for a given element.
        /// </summary>
        /// <param name="transform">The starting transform to search.</param>
        /// <param name="stopAfter">Where the search of parents should stop</param>
        /// <returns>What the proper stencil buffer index should be.</returns>
        public static int GetStencilDepth(Transform transform, Transform stopAfter)
        {
            var depth = 0;

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

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

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

                if (t == stopAfter)
                {
                    break;
                }

                t = t.parent;
            }

            ListPool <Mask> .Release(components);

            return(depth);
        }
Exemplo n.º 14
0
        private void DoMeshGeneration3D()
        {
            if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0)
            {
                OnPopulateMesh3D(s_VertexHelper);
            }
            else
            {
                s_VertexHelper.Clear(); // clear the vertex helper so invalid graphics dont draw.
            }

            var components = ListPool <Component> .Get();

            GetComponents(typeof(IMeshModifier), components);

            for (var i = 0; i < components.Count; i++)
            {
                ((IMeshModifier)components[i]).ModifyMesh(s_VertexHelper);
            }

            ListPool <Component> .Release(components);

            s_VertexHelper.FillMesh(m_mesh);
        }
Exemplo n.º 15
0
        // ILayoutElement Interface
        public virtual void CalculateLayoutInputHorizontal()
        {
            m_RectChildren.Clear();
            var toIgnoreList = ListPool <Component> .Get();

            for (int i = 0; i < rectTransform.childCount; i++)
            {
                var rect = rectTransform.GetChild(i) as RectTransform;
                if (rect == null || !rect.gameObject.activeInHierarchy)
                {
                    continue;
                }

                rect.GetComponents(typeof(ILayoutIgnorer), toIgnoreList);

                if (toIgnoreList.Count == 0)
                {
                    m_RectChildren.Add(rect);
                    continue;
                }

                for (int j = 0; j < toIgnoreList.Count; j++)
                {
                    var ignorer = (ILayoutIgnorer)toIgnoreList[j];
                    if (!ignorer.ignoreLayout)
                    {
                        m_RectChildren.Add(rect);
                        break;
                    }
                }
            }

            ListPool <Component> .Release(toIgnoreList);

            m_Tracker.Clear();
        }
Exemplo n.º 16
0
        /// <summary>
        ///
        /// <para>
        /// Cleanup allocated memory.
        /// </para>
        ///
        /// </summary>
        public void Dispose()
        {
            ListPool <Vector3> .Release(this.m_Positions);

            ListPool <Color32> .Release(this.m_Colors);

            ListPool <Vector2> .Release(this.m_Uv0S);

            ListPool <Vector2> .Release(this.m_Uv1S);

            ListPool <Vector3> .Release(this.m_Normals);

            ListPool <Vector4> .Release(this.m_Tangents);

            ListPool <int> .Release(this.m_Indices);

            this.m_Positions = (List <Vector3>)null;
            this.m_Colors    = (List <Color32>)null;
            this.m_Uv0S      = (List <Vector2>)null;
            this.m_Uv1S      = (List <Vector2>)null;
            this.m_Normals   = (List <Vector3>)null;
            this.m_Tangents  = (List <Vector4>)null;
            this.m_Indices   = (List <int>)null;
        }
Exemplo n.º 17
0
        public void Dispose()
        {
            ListPool <Vector3> .Release(m_Positions);

            ListPool <Color32> .Release(m_Colors);

            ListPool <Vector2> .Release(m_Uv0S);

            ListPool <Vector2> .Release(m_Uv1S);

            ListPool <Vector3> .Release(m_Normals);

            ListPool <Vector4> .Release(m_Tangents);

            ListPool <int> .Release(m_Indices);

            m_Positions = null;
            m_Colors    = null;
            m_Uv0S      = null;
            m_Uv1S      = null;
            m_Normals   = null;
            m_Tangents  = null;
            m_Indices   = null;
        }
Exemplo n.º 18
0
        public static void GetRectMasksForClip(RectMask2D clipper, List <RectMask2D> masks)
        {
            masks.Clear();
            Transform        parent  = clipper.transform;
            List <Component> results = ListPool <Component> .Get();

            while (parent != null)
            {
                parent.GetComponents(typeof(RectMask2D), results);
                for (int i = 0; i < results.Count; i++)
                {
                    if ((results[i] != null) && ((RectMask2D)results[i]).IsActive())
                    {
                        masks.Add((RectMask2D)results[i]);
                    }
                }
                if (parent.GetComponent <Canvas>() != null)
                {
                    break;
                }
                parent = parent.parent;
            }
            ListPool <Component> .Release(results);
        }
        public virtual bool Raycast(Vector2 sp, Camera eventCamera)
        {
            if (!isActiveAndEnabled)
            {
                return(false);
            }

            var t          = transform;
            var components = ListPool <Component> .Get();

            bool ignoreParentGroups = false;
            bool continueTraversal  = true;

            while (t != null)
            {
                t.GetComponents(components);
                for (var i = 0; i < components.Count; i++)
                {
                    var canvas = components[i] as Canvas;
                    if (canvas != null && canvas.overrideSorting)
                    {
                        continueTraversal = false;
                    }

                    var filter = components[i] as ICanvasRaycastFilter;

                    if (filter == null)
                    {
                        continue;
                    }

                    var raycastValid = true;

                    var group = components[i] as CanvasGroup;
                    if (group != null)
                    {
                        if (ignoreParentGroups == false && group.ignoreParentGroups)
                        {
                            ignoreParentGroups = true;
                            raycastValid       = filter.IsRaycastLocationValid(sp, eventCamera);
                        }
                        else if (!ignoreParentGroups)
                        {
                            raycastValid = filter.IsRaycastLocationValid(sp, eventCamera);
                        }
                    }
                    else
                    {
                        raycastValid = filter.IsRaycastLocationValid(sp, eventCamera);
                    }

                    if (!raycastValid)
                    {
                        ListPool <Component> .Release(components);

                        return(false);
                    }
                }
                t = continueTraversal ? t.parent : null;
            }
            ListPool <Component> .Release(components);

            return(true);
        }
Exemplo n.º 20
0
        // 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);
        }
Exemplo n.º 21
0
        public virtual bool Raycast(Vector2 sp, Camera eventCamera)
        {
            if (!isActiveAndEnabled)
            {
                return(false);
            }

            var t          = transform;
            var components = ListPool <Component> .Get();

            bool ignoreParentGroups = false;
            bool continueTraversal  = true;

            while (t != null)
            {
                t.GetComponents(components);
                for (var i = 0; i < components.Count; i++)
                {
                    var canvas = components[i] as Canvas;
                    // 如果挂载了canvas组件,并且overrideSorting为true,这个一般是嵌套的canvas
                    if (canvas != null && canvas.overrideSorting)
                    {
                        continueTraversal = false;
                    }

                    // 实现ICanvasRaycastFilter接口的组件,CanvasGroup也实现了此接口
                    var filter = components[i] as ICanvasRaycastFilter;

                    if (filter == null)
                    {
                        continue;
                    }

                    var raycastValid = true;

                    var group = components[i] as CanvasGroup;
                    // 这里有坑,检测完子节点再检测父节点,父节点IsRaycastLocationValid完全有可能返回false
                    if (group != null)
                    {
                        // 勾选了ignoreParentGroups,那么只有这层的canvasGroup会进行检测
                        if (ignoreParentGroups == false && group.ignoreParentGroups)
                        {
                            ignoreParentGroups = true;
                            raycastValid       = filter.IsRaycastLocationValid(sp, eventCamera);
                        }
                        else if (!ignoreParentGroups)
                        {
                            raycastValid = filter.IsRaycastLocationValid(sp, eventCamera);
                        }
                    }
                    else
                    {
                        // 调用IsRaycastLocationValid方法
                        raycastValid = filter.IsRaycastLocationValid(sp, eventCamera);
                    }

                    if (!raycastValid)
                    {
                        ListPool <Component> .Release(components);

                        return(false);
                    }
                }
                t = continueTraversal ? t.parent : null;
            }
            ListPool <Component> .Release(components);

            return(true);
        }
Exemplo n.º 22
0
        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);
                }
            }
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
        /// <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);
        }
Exemplo n.º 25
0
        // 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.
            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();

            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] || 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);

            m_Blocker = CreateBlocker(rootCanvas);
        }
Exemplo n.º 26
0
        private void OnCombineMesh()
        {
            RichText[]  texts     = GetComponentsInChildren <RichText>(false);
            RichImage[] images    = GetComponentsInChildren <RichImage>(false);
            var         meshCount = texts.Length + images.Length;

            if (meshCount == 0)
            {
                if (m_meshRender)
                {
                    m_meshRender.enabled = false;
                }
                return;
            }

            if (m_meshRender == null)
            {
                m_meshRender           = gameObject.GetOrAddComponent <MeshRenderer>();
                m_meshRender.hideFlags = MeshHideflags;

                m_meshFilter           = gameObject.GetOrAddComponent <MeshFilter>();
                m_meshFilter.hideFlags = MeshHideflags;

                m_mesh = new Mesh();
                m_mesh.MarkDynamic();
                m_mesh.hideFlags = MeshHideflags;
            }

            Material material = null;

            var meshes = ListPool <MeshOrder> .Get();

            var worldToLocalMatrix = this.transform.worldToLocalMatrix;

            for (int i = 0; i < images.Length; ++i)
            {
                var image = images[i];

                if (!image.IsActive())
                {
                    continue;
                }

                var mesh = image.Mesh();
                if (mesh == null)
                {
                    continue;
                }

                var meshOrder = new MeshOrder();
                meshOrder.mesh   = mesh;
                meshOrder.matrix = worldToLocalMatrix * image.transform.localToWorldMatrix;
                meshOrder.z      = image.transform.localPosition.z;

                meshes.Add(meshOrder);

                if (material == null)
                {
                    material = image.material;
                }
            }
            for (int j = 0; j < texts.Length; ++j)
            {
                var text = texts[j];

                if (!text.IsActive())
                {
                    continue;
                }

                var mesh = text.Mesh();
                if (mesh == null)
                {
                    continue;
                }

                var meshOrder = new MeshOrder();
                meshOrder.mesh   = mesh;
                meshOrder.matrix = worldToLocalMatrix * text.transform.localToWorldMatrix;
                meshOrder.z      = text.transform.localPosition.z;

                meshes.Add(meshOrder);

                if (material == null)
                {
                    material = text.material;
                }
            }

            if (meshes.Count == 0)
            {
                if (m_meshRender)
                {
                    m_meshRender.enabled = false;
                }
                return;
            }
            m_meshRender.enabled = true;

            meshes.Sort((lhs, rhs) => rhs.z.CompareTo(lhs.z));

            CombineInstance[] combine = new CombineInstance[meshes.Count];
            for (int i = 0; i < meshes.Count; ++i)
            {
                combine[i].mesh      = meshes[i].mesh;
                combine[i].transform = meshes[i].matrix;
            }

            ListPool <MeshOrder> .Release(meshes);

            m_mesh.CombineMeshes(combine, true);
            m_meshFilter.sharedMesh     = m_mesh;
            m_meshRender.sharedMaterial = material;
        }
Exemplo n.º 27
0
        /// <summary>
        /// Gets a calculated layout property for the layout element with the given RectTransform.
        /// </summary>
        /// <param name="rect">The RectTransform of the layout element to get a property for.</param>
        /// <param name="property">The property to calculate.</param>
        /// <param name="defaultValue">The default value to use if no component on the layout element supplies the given property</param>
        /// <param name="source">Optional out parameter to get the component that supplied the calculated value.</param>
        /// <returns>The calculated value of the layout property.</returns>
        public static float GetLayoutProperty(RectTransform rect, System.Func <ILayoutElement, float> property, float defaultValue, out ILayoutElement source)
        {
            source = null;
            if (rect == null)
            {
                return(0);
            }
            float min         = defaultValue;
            int   maxPriority = System.Int32.MinValue;
            var   components  = ListPool <Component> .Get();

            rect.GetComponents(typeof(ILayoutElement), components);

            //遍历每一个实现ILayoutElement接口的子对象(Image和Text都实现了ILayoutElement接口)
            //或者绑定了LayoutElement对象的脚本也实现了ILayoutElement接口
            for (int i = 0; i < components.Count; i++)
            {
                //确保layoutComp对象有效
                var layoutComp = components[i] as ILayoutElement;
                if (layoutComp is Behaviour && !((Behaviour)layoutComp).isActiveAndEnabled)
                {
                    continue;
                }

                //确保当前优先级小于最大优先级
                int priority = layoutComp.layoutPriority;
                // If this layout components has lower priority than a previously used, ignore it.
                if (priority < maxPriority)
                {
                    continue;
                }

                float prop = property(layoutComp);
                // If this layout property is set to a negative value, it means it should be ignored.
                if (prop < 0)
                {
                    continue;
                }

                //如果有更高的优先级,那么就覆盖最小数值,并且覆盖最大优先级数值
                // If this layout component has higher priority than all previous ones,
                // overwrite with this one's value.
                if (priority > maxPriority)
                {
                    min         = prop;
                    maxPriority = priority;
                    source      = layoutComp;
                }
                // If the layout component has the same priority as a previously used,
                // use the largest of the values with the same priority.
                else if (prop > min)
                {
                    min    = prop;
                    source = layoutComp;
                }
            }

            ListPool <Component> .Release(components);

            return(min);
        }
Exemplo n.º 28
0
        public virtual bool Raycast(Vector2 sp, Camera eventCamera)
        {
            bool result;

            if (!base.isActiveAndEnabled)
            {
                result = false;
            }
            else
            {
                Transform        transform = base.transform;
                List <Component> list      = ListPool <Component> .Get();

                bool flag  = false;
                bool flag2 = true;
                while (transform != null)
                {
                    transform.GetComponents <Component>(list);
                    for (int i = 0; i < list.Count; i++)
                    {
                        Canvas canvas = list[i] as Canvas;
                        if (canvas != null && canvas.overrideSorting)
                        {
                            flag2 = false;
                        }
                        ICanvasRaycastFilter canvasRaycastFilter = list[i] as ICanvasRaycastFilter;
                        if (canvasRaycastFilter != null)
                        {
                            bool        flag3       = true;
                            CanvasGroup canvasGroup = list[i] as CanvasGroup;
                            if (canvasGroup != null)
                            {
                                if (!flag && canvasGroup.ignoreParentGroups)
                                {
                                    flag  = true;
                                    flag3 = canvasRaycastFilter.IsRaycastLocationValid(sp, eventCamera);
                                }
                                else if (!flag)
                                {
                                    flag3 = canvasRaycastFilter.IsRaycastLocationValid(sp, eventCamera);
                                }
                            }
                            else
                            {
                                flag3 = canvasRaycastFilter.IsRaycastLocationValid(sp, eventCamera);
                            }
                            if (!flag3)
                            {
                                ListPool <Component> .Release(list);

                                return(false);
                            }
                        }
                    }
                    transform = ((!flag2) ? null : transform.parent);
                }
                ListPool <Component> .Release(list);

                result = true;
            }
            return(result);
        }