Esempio n. 1
0
        public static void Unselect(UIBehaviour ui, int skipFrames = 0)
        {
            IndependentSelectable selectable = ui.GetComponent <IndependentSelectable>();

            if (selectable != null)
            {
                selectable.m_unselect = true;
                selectable.m_selectOnEventSystemLateUpdate = 1 + skipFrames;
            }
        }
Esempio n. 2
0
        public static void Unselect(GameObject go, int skipFrames = 0)
        {
            IndependentSelectable selectable = go.GetComponent <IndependentSelectable>();

            if (selectable != null)
            {
                selectable.m_unselect = true;
                selectable.m_selectOnEventSystemLateUpdate = 1 + skipFrames;
            }
        }
Esempio n. 3
0
        public static bool IsSelected(GameObject go)
        {
            IndependentSelectable selectable = go.GetComponent <IndependentSelectable>();

            if (selectable != null)
            {
                return(selectable.EventSystem.currentSelectedGameObject == go);
            }
            return(false);
        }
Esempio n. 4
0
        public static IndependentEventSystem GetEventSystem(UIBehaviour ui)
        {
            IndependentSelectable selectable = ui.GetComponent <IndependentSelectable>();

            if (selectable != null)
            {
                return(selectable.EventSystem);
            }

            return(null);
        }
Esempio n. 5
0
        public static IndependentEventSystem GetEventSystem(GameObject go)
        {
            IndependentSelectable selectable = go.GetComponent <IndependentSelectable>();

            if (selectable != null)
            {
                return(selectable.EventSystem);
            }

            return(null);
        }
Esempio n. 6
0
        private bool CanProcess(GameObject targetGO)
        {
            if (targetGO == null)
            {
                return(true);
            }


            IndependentSelectable targetEventHandler = targetGO.GetComponentInParent <IndependentSelectable>();

            if (targetEventHandler != null)
            {
                return(targetEventHandler.EventSystem == eventSystem);
            }
            return(true);
        }
Esempio n. 7
0
        public Selectable FindSelectable(Vector3 dir)
        {
            dir = dir.normalized;
            Vector3    localDir = Quaternion.Inverse(transform.rotation) * dir;
            Vector3    pos      = transform.TransformPoint(GetPointOnRectEdge(transform as RectTransform, localDir));
            float      maxScore = Mathf.NegativeInfinity;
            Selectable bestPick = null;

            for (int i = 0; i < Selectable.allSelectables.Count; ++i)
            {
                Selectable sel = Selectable.allSelectables[i];

                if (sel == this || sel == null)
                {
                    continue;
                }

                if (!sel.IsInteractable() || sel.navigation.mode == Navigation.Mode.None)
                {
                    continue;
                }

                IndependentSelectable independentSelectable = sel.GetComponent <IndependentSelectable>();
                if (independentSelectable == null)
                {
                    continue;
                }

                if (independentSelectable.EventSystem != m_eventSystem)
                {
                    continue;
                }

                var     selRect   = sel.transform as RectTransform;
                Vector3 selCenter = selRect != null ? (Vector3)selRect.rect.center : Vector3.zero;
                Vector3 myVector  = sel.transform.TransformPoint(selCenter) - pos;

                // Value that is the distance out along the direction.
                float dot = Vector3.Dot(dir, myVector);

                // Skip elements that are in the wrong direction or which have zero distance.
                // This also ensures that the scoring formula below will not have a division by zero error.
                if (dot <= 0)
                {
                    continue;
                }

                // This scoring function has two priorities:
                // - Score higher for positions that are closer.
                // - Score higher for positions that are located in the right direction.
                // This scoring function combines both of these criteria.
                // It can be seen as this:
                //   Dot (dir, myVector.normalized) / myVector.magnitude
                // The first part equals 1 if the direction of myVector is the same as dir, and 0 if it's orthogonal.
                // The second part scores lower the greater the distance is by dividing by the distance.
                // The formula below is equivalent but more optimized.
                //
                // If a given score is chosen, the positions that evaluate to that score will form a circle
                // that touches pos and whose center is located along dir. A way to visualize the resulting functionality is this:
                // From the position pos, blow up a circular balloon so it grows in the direction of dir.
                // The first Selectable whose center the circular balloon touches is the one that's chosen.
                float score = dot / myVector.sqrMagnitude;

                if (score > maxScore)
                {
                    maxScore = score;
                    bestPick = sel;
                }
            }
            return(bestPick);
        }