示例#1
0
 void ControlWithJoyStick()
 {
     //DirectionalMoveListenerController();
     if (_ControlMethod.joystick)
     {
         if (_EventSystem.currentSelectedGameObject == null)
         {
             if (_ActiveItem != null)
             {
                 _EventSystem.SetSelectedGameObject(_ActiveItem.gameObject);
             }
             else
             {
                 _EventSystem.SetSelectedGameObject(_EventSystem.firstSelectedGameObject);
             }
         }
         if (_ActiveItem == null)
         {
             return;
         }
         UISelectable selected = _ActiveItem.gameObject.GetComponent <UISelectable>();
         if (Input.GetButtonUp("Fire2_Pad"))
         {
             selected.UIPrimaryAction();
         }
         if (Input.GetButtonUp("Secondary_Action_Pad"))
         {
             selected.UISecondaryAction();
         }
     }
 }
示例#2
0
        public static void DrawDebugger(UISelectableHolder selectableHolder)
        {
            GUITools.Space(2);
            EditorGUILayout.LabelField("Debug:", GUITools.boldLabel);
            debugMessage = EditorGUILayout.TextArea(debugMessage);
            buttons      = EditorGUILayout.IntField("Buttons Count", buttons);

            if (GUILayout.Button("Start Debug"))
            {
                selectableHolder.RemoveAllElements();

                int randomSelected = Random.Range(0, buttons);
                selectableHolder.SetMainText(debugMessage);
                for (int i = 0; i < buttons; i++)
                {
                    // UISelectable s = selectableHolder.AddNewElement( "ButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtonsButtons" + i, false);
                    UISelectable s = selectableHolder.AddNewElement("Buttons " + i, false);

                    s.selected = i == randomSelected;
                }
                UpdateElementLayoutAndSetDirty(selectableHolder);
            }
            if (GUILayout.Button("End Debug"))
            {
                selectableHolder.RemoveAllElements();
                UpdateElementLayoutAndSetDirty(selectableHolder);
            }
        }
示例#3
0
    public UISelectable FindSelectable(Vector2 dir)
    {
        dir = dir.normalized;
        Vector3      currentPosition = transform.TransformPoint(GetPointOnRectEdge(transform as RectTransform, Quaternion.Inverse(transform.rotation) * dir));
        float        maxScore        = float.NegativeInfinity;
        UISelectable bestCandidate   = null;

        for (int index = 0; index < allSelectablesArray.Count; index++)
        {
            UISelectable selectable2 = allSelectablesArray[index];
            if (selectable2 != this || selectable2 != null)
            {
                RectTransform rect        = selectable2.transform as RectTransform;
                Vector3       position    = rect == null ? Vector3.zero : (Vector3)rect.rect.center;
                Vector3       rhs         = selectable2.transform.TransformPoint(position) - currentPosition;
                float         angleFactor = Vector3.Dot(dir, rhs);
                if (angleFactor > 0)
                {
                    float score = angleFactor / rhs.sqrMagnitude;
                    if (score > maxScore)
                    {
                        maxScore      = score;
                        bestCandidate = selectable2;
                    }
                }
            }
        }
        return(bestCandidate);
    }
示例#4
0
 //为可点击区域添加点击组件
 private void InitGameArea()
 {
     for (int i = 0; i < 9; i++)
     {
         Transform    gameArea          = view.GameBG.Find("GameArea" + i.ToString());
         UISelectable gameAreaComponent = gameArea.GetComponent <UISelectable>();
         clickAbleList.Add(gameAreaComponent);
     }
 }
示例#5
0
    internal void Unregister(UISelectable uISelectable)
    {
        if (selectables == null)
        {
            selectables = new List <UISelectable>();
        }

        selectables.Remove(uISelectable);
    }
示例#6
0
    internal void Register(UISelectable uISelectable)
    {
        if (selectables == null)
        {
            selectables = new List <UISelectable>();
        }

        selectables.Add(uISelectable);
    }
示例#7
0
    //初始化点击事件
    private void InitGameAreaClickEvent()
    {
        for (int i = 0; i < clickAbleList.Count; i++)
        {
            UISelectable selectable = clickAbleList[i];
            int          index      = i;

            selectable.OnClick = () =>
            {
                OnGameAreaClick(index);
            };
        }
    }
示例#8
0
    internal void Select(UISelectable selectable)
    {
        if (selected == selectable)
        {
            return;
        }

        if (selected != null)
        {
            selected.OnDeselect(null);
        }

        selected = selectable;

        if (selected != null)
        {
            selected.OnSelect(null);
        }
    }
示例#9
0
    // Update is called once per frame
    void Update()
    {
        if (inputModule != null)
        {
            float horizontal = inputModule.GetAxis(NeverdawnInputAxis.HorizontalLeft);
            float vertical   = inputModule.GetAxis(NeverdawnInputAxis.VerticalLeft);

            Vector3 input = inputModule.normalizedDirection;

            if (input.sqrMagnitude < 0.1f)
            {
                if (center != null)
                {
                    center.Select();
                }
                else if (selected != null)
                {
                    selected.Deselect();
                }

                selected = null;
            }

            if (input.sqrMagnitude > 0.1f)
            {
                float inputAngle = Vector3.SignedAngle(Vector3.forward, input, Vector3.up);

                if (inputAngle < 0.0f)
                {
                    inputAngle = 360.0f + inputAngle;
                }

                inputAngle += angle / 2.0f;

                int index = NeverdawnUtility.RepeatIndex((int)(inputAngle / angle), peripherals.Length);

                selected = peripherals[index];
                peripherals[index].Select();
            }

            previousInput = input;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (inputModule != null)
        {
            float horizontal = inputModule.GetAxis(NeverdawnInputAxis.HorizontalLeft);
            float vertical   = inputModule.GetAxis(NeverdawnInputAxis.VerticalLeft);

            Vector3 input = inputModule.normalizedDirection;

            if (input.sqrMagnitude < 0.1f)
            {
                if (center != null)
                {
                    center.Select();
                }
                else if (selected != null)
                {
                    selected.Deselect();
                }

                selected = null;
            }

            if (input.sqrMagnitude > 0.1f)
            {
                float inputAngle = Mathf.Clamp(-Vector3.SignedAngle(Vector3.forward, input, Vector3.up), -90.0f, 90.0f);

                inputAngle += angle / 2.0f;

                int index = Mathf.Clamp((int)(inputAngle / angle) + (peripherals.Length / 2), 0, peripherals.Length - 1);

                selected = peripherals[index];
                peripherals[index].Select();
            }

            previousInput = input;
        }
    }
示例#11
0
 public InterfaceButton(UIDisplayable displayable, UISelectable selectable)
 {
     this.displayabe = displayable;
     this.selectable = selectable;
 }
 private void InitVariable()
 {
     uISelectable = ViewInstance.GetComponentInChildren <UISelectable>();
 }
示例#13
0
    void Update()
    {
        if (inputModules != null && inputModules.Length > 0 && inputModules[0] != null)
        {
            if (selected == null || !selected.gameObject.activeInHierarchy)
            {
                Select(null);
            }

            foreach (InputModule inputModule in inputModules)
            {
                if (inputModule.GetButtonDown(NeverdawnInputButton.Confirm))
                {
                    pressed = selected;

                    if (selected != null)
                    {
                        selected.OnPointerDown(null);
                    }
                }

                if (inputModule.GetButtonUp(NeverdawnInputButton.Confirm))
                {
                    if (selected != null)
                    {
                        if (selected == pressed)
                        {
                            selected.OnPointerUp(null);
                        }
                    }

                    pressed = null;
                }

                if (selected != null)
                {
                    if (inputModule.GetButtonDown(NeverdawnInputButton.Left))
                    {
                        selectLeft();
                    }

                    if (inputModule.GetButtonDown(NeverdawnInputButton.Right))
                    {
                        selectRight();
                    }


                    if (inputModule.GetAxisDown(NeverdawnInputAxis.HorizontalLeft, NeverdawnInputAxisDirection.Positive) ||
                        inputModule.GetAxisDown(NeverdawnInputAxis.HorizontalDPad, NeverdawnInputAxisDirection.Positive))
                    {
                        selectRight();
                    }

                    if (inputModule.GetAxisDown(NeverdawnInputAxis.HorizontalLeft, NeverdawnInputAxisDirection.Negative) ||
                        inputModule.GetAxisDown(NeverdawnInputAxis.HorizontalDPad, NeverdawnInputAxisDirection.Negative))
                    {
                        selectLeft();
                    }

                    if (inputModule.GetAxisDown(NeverdawnInputAxis.VerticalLeft, NeverdawnInputAxisDirection.Positive) ||
                        inputModule.GetAxisDown(NeverdawnInputAxis.VerticalDPad, NeverdawnInputAxisDirection.Positive))
                    {
                        selectTop();
                    }

                    if (inputModule.GetAxisDown(NeverdawnInputAxis.VerticalLeft, NeverdawnInputAxisDirection.Negative) ||
                        inputModule.GetAxisDown(NeverdawnInputAxis.VerticalDPad, NeverdawnInputAxisDirection.Negative))
                    {
                        selectBottom();
                    }
                }

                if (inputModule.HasCursor)
                {
                    if (selectables != null && canvasGroup.alpha > 0.0f)
                    {
                        Vector3 cursorPosition = inputModule.cursorPosition;

                        bool childSelected = false;

                        foreach (UISelectable selectable in selectables)
                        {
                            if (selectable.gameObject.activeInHierarchy && selectable.rectangle.Contains(cursorPosition))
                            {
                                childSelected = true;
                                selectable.Select();
                                break;
                            }
                        }

                        if (!childSelected)
                        {
                            Deselect();
                        }
                    }
                }
            }
        }
    }