public virtual void CheckInput(bool p_force = false)
 {
     if ((p_force || Input.GetKeyDown(KeyCode.Tab)) && FocusGroup.IsUnderFocus(this.gameObject))
     {
         StartCoroutine(ChangeInput());
     }
 }
Beispiel #2
0
        public static FocusGroup GetFocus()
        {
            FocusOrder.RemoveNulls();
            FocusGroup v_container = FocusOrder.GetFirst();

            return(v_container);
        }
Beispiel #3
0
        public static void SetFocus(FocusGroup p_container)
        {
            FocusGroup v_oldFocus = GetFocus();

            if (p_container != null)
            {
                if (v_oldFocus != p_container)
                {
                    FocusOrder.RemoveChecking(p_container);
                    if (FocusOrder.Count > 0)
                    {
                        FocusOrder.Insert(0, p_container);
                    }
                    else
                    {
                        FocusOrder.Add(p_container);
                    }
                    //Call Focus Events
                    if (v_oldFocus != null && v_oldFocus.OnLoseFocusCallback != null)
                    {
                        v_oldFocus.OnLoseFocusCallback.Invoke();
                    }
                    if (p_container.OnGainFocusCallback != null)
                    {
                        p_container.OnGainFocusCallback.Invoke();
                    }
                }
            }
        }
Beispiel #4
0
 public static bool ContainFocus(FocusGroup p_container)
 {
     if (p_container != null && p_container == GetFocus())
     {
         return(true);
     }
     return(false);
 }
Beispiel #5
0
 public static bool ParentContainFocus(GameObject p_child)
 {
     if (p_child != null)
     {
         FocusGroup v_directParentFocus = GetDirectFocusGroupComponent(p_child);
         return(ContainFocus(v_directParentFocus));
     }
     return(false);
 }
Beispiel #6
0
 //If Any Parent or Self contain Focus, Or Focus equal null and panel is Opened or GameObject is Active
 public static bool IsUnderFocus(GameObject p_object)
 {
     if (p_object != null)
     {
         FocusGroup     v_focus      = FocusGroup.GetFocus();
         PanelStateEnum v_panelState = v_focus == null ? PanelStateEnum.Opened : TweenContainerUtils.GetContainerVisibility(v_focus.gameObject);
         if (v_panelState == PanelStateEnum.Opened && (FocusGroup.GetDirectFocusGroupComponent(p_object) == v_focus))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #7
0
        protected virtual void CheckFocus(PanelStateEnum p_panelState, bool p_ignoreChildrenFocus)
        {
            if (p_panelState == PanelStateEnum.Opening || p_panelState == PanelStateEnum.Opened)
            {
                FocusGroup v_currentFocus          = FocusGroup.GetFocus();
                bool       v_canIgnoreCurrentFocus = p_ignoreChildrenFocus || v_currentFocus == null || !TweenContainerUtils.IsChildObject(this.gameObject, v_currentFocus.gameObject, false);
                if (v_canIgnoreCurrentFocus)
                {
                    FocusGroup.SetFocus(this);
                }
                else
                {
                    //Find index to add self to Focus (Index after your last children)
                    int v_indexToAddThis = 0;
                    FocusGroup.FocusOrder.RemoveChecking(this);
                    for (int i = 0; i < FocusGroup.FocusOrder.Count; i++)
                    {
                        FocusGroup v_container           = FocusGroup.FocusOrder[i];
                        bool       v_isChildrenContainer = v_container != null && TweenContainerUtils.IsChildObject(this.gameObject, v_container.gameObject, false);
                        if (v_isChildrenContainer)
                        {
                            v_indexToAddThis = i + 1;
                        }
                    }
                    FocusGroup.FocusOrder.Insert(v_indexToAddThis, this);
                }
                if (FullScreenRendering)
                {
                    FocusGroup.CorrectFullScreenRendering(p_panelState == PanelStateEnum.Opening);
                }
            }
            else if (p_panelState == PanelStateEnum.Closing || p_panelState == PanelStateEnum.Closed)
            {
                if (FullScreenRendering)
                {
                    FocusGroup.CorrectFullScreenRendering(p_panelState == PanelStateEnum.Closing);
                }
                FocusGroup.RemoveFocus(this);

                if (p_panelState == PanelStateEnum.Closed)
                {
                    //set Renderer To False After Remove
                    SetCanvasEnabled(false);
                }
            }
        }
Beispiel #8
0
 public static FocusGroup GetDirectFocusGroupComponent(GameObject p_child)
 {
     if (p_child != null)
     {
         FocusGroup[] v_parentsFocus      = p_child.GetComponentsInParent <FocusGroup>();
         FocusGroup   v_directParentFocus = null;
         foreach (FocusGroup v_parentFocus in v_parentsFocus)
         {
             if (v_parentFocus != null && v_parentFocus.enabled)
             {
                 v_directParentFocus = v_parentFocus;
                 break;
             }
         }
         return(v_directParentFocus);
     }
     return(null);
 }
Beispiel #9
0
 public static void RemoveFocus(FocusGroup p_container)
 {
     if (p_container != null)
     {
         FocusGroup v_oldFocus = GetFocus();
         FocusOrder.RemoveChecking(p_container);
         //Call Focus Events
         if (v_oldFocus == p_container)
         {
             FocusGroup v_newFocus = GetFocus();
             if (v_oldFocus.OnLoseFocusCallback != null)
             {
                 v_oldFocus.OnLoseFocusCallback.Invoke();
             }
             if (v_newFocus != null && v_newFocus.OnGainFocusCallback != null)
             {
                 v_newFocus.OnGainFocusCallback.Invoke();
             }
         }
     }
 }
Beispiel #10
0
        protected static void CorrectFullScreenRendering(bool p_isTransition)
        {
            FocusGroup v_firstFullScreenRenderingContainer  = null;
            FocusGroup v_secondFullScreenRenderingContainer = null;

            foreach (FocusGroup v_container in FocusOrder)
            {
                if (v_container != null && v_container.FullScreenRendering)
                {
                    v_container.CheckCanvasAndGraphicsRaycaster();
                    if (v_firstFullScreenRenderingContainer == null)
                    {
                        v_firstFullScreenRenderingContainer = v_container;
                    }
                    else if (p_isTransition && v_firstFullScreenRenderingContainer != null && v_secondFullScreenRenderingContainer == null)
                    {
                        v_secondFullScreenRenderingContainer = v_container;
                    }

                    bool v_canvasEnabled = v_firstFullScreenRenderingContainer == v_container || v_secondFullScreenRenderingContainer == v_container;
                    v_container.SetCanvasEnabled(v_canvasEnabled, v_canvasEnabled);
                }
            }
        }
        protected virtual IEnumerator ChangeInput()
        {
            if (!_checking)
            {
                _checking = true;
                EventSystem v_eventSystem = EventSystem.current;
                if (v_eventSystem != null)
                {
                    bool       v_moveBack = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
                    GameObject v_currentSelectedGameObject = v_eventSystem.currentSelectedGameObject;
                    Selectable v_currentSelectedComponent  = v_currentSelectedGameObject != null?v_currentSelectedGameObject.GetComponent <Selectable>() : null;

                    if (!(v_currentSelectedComponent is InputField) || !(((InputField)v_currentSelectedComponent).multiLine))
                    {
                        List <Selectable> v_currentSelectables = new List <Selectable>();
#if UNITY_2019_1_OR_NEWER
                        IList <Selectable> v_allSelectables = Selectable.allSelectablesArray;
#else
                        IList <Selectable> v_allSelectables = Selectable.allSelectables;
#endif
                        for (int i = 0; i < v_allSelectables.Count; i++)
                        {
                            Selectable v_selectableComponent = v_allSelectables[i];
                            v_currentSelectables.RemoveChecking(v_selectableComponent);
                            if (v_selectableComponent != null && v_selectableComponent.enabled && v_selectableComponent.gameObject.activeInHierarchy && v_selectableComponent.gameObject.activeSelf && v_selectableComponent.navigation.mode != Navigation.Mode.None && FocusGroup.IsUnderFocus(v_selectableComponent.gameObject))
                            {
                                //Sort with SelectionUpDown Index
                                int  v_indexDown         = v_currentSelectables.IndexOf(v_selectableComponent.navigation.selectOnDown);
                                int  v_indexUp           = v_currentSelectables.IndexOf(v_selectableComponent.navigation.selectOnUp);
                                bool v_insertingComplete = false;
                                int  v_indexToInsert     = v_indexDown >= 0 && v_indexDown < v_currentSelectables.Count ? v_indexDown : (v_indexUp >= 0 && v_indexUp < v_currentSelectables.Count ? v_indexUp + 1 : -1);
                                if (v_indexToInsert >= 0 && v_indexToInsert < v_currentSelectables.Count + 1)
                                {
                                    try
                                    {
                                        v_currentSelectables.Insert(v_indexToInsert, v_selectableComponent);
                                        v_insertingComplete = true;
                                    }
                                    catch { }
                                }
                                if (!v_insertingComplete)
                                {
                                    v_insertingComplete = true;
                                    v_currentSelectables.Add(v_selectableComponent);
                                }
                            }
                        }

                        if (v_currentSelectedComponent != null)
                        {
                            int v_index = v_currentSelectables.IndexOf(v_currentSelectedComponent);
                            v_index = v_moveBack ? v_index - 1 : v_index + 1;
                            v_currentSelectedComponent  = v_index >= 0 && v_index < v_currentSelectables.Count ? v_currentSelectables[v_index] : null;
                            v_currentSelectedGameObject = v_currentSelectedComponent != null ? v_currentSelectedComponent.gameObject : null;
                        }
                        if (v_currentSelectedComponent == null)
                        {
                            v_currentSelectedComponent  = v_moveBack ? v_currentSelectables.GetLast() : v_currentSelectables.GetFirst();
                            v_currentSelectedGameObject = v_currentSelectedComponent != null ? v_currentSelectedComponent.gameObject : null;
                        }

                        v_eventSystem.SetSelectedGameObject(v_currentSelectedGameObject);
                        if (v_currentSelectedComponent != null)
                        {
                            InputField v_inputfield = v_currentSelectedComponent.GetComponent <InputField>();
                            if (v_inputfield != null)
                            {
                                v_inputfield.OnPointerClick(new PointerEventData(v_eventSystem));
                            }
                            yield return(new WaitForSecondsRealtime(0.05f));
                        }
                    }
                }
                _checking = false;
            }
        }