Example #1
0
        public void OnJoyStickThumTouchMove(Vector2 vec)
        {
            lastJoyStickDir = curJoyStickDir;

            float _angle = Vector2.Angle(vec, Vector2.up);

            if (vec.x >= 0 && _angle <= 135)
            {
                curJoyStickDir = JoyStickDirection.Forward;
            }
            else if (vec.x < 0 && _angle <= 135)
            {
                curJoyStickDir = JoyStickDirection.Backward;
            }
            else if (_angle > 135)
            {
                curJoyStickDir = JoyStickDirection.Down;
            }

            if (OnJoyStickTouchMove != null)
            {
                OnJoyStickTouchMove.Invoke(curJoyStickDir);
            }

            if (lastJoyStickDir != curJoyStickDir)
            {
                switch (curJoyStickDir)
                {
                case JoyStickDirection.Forward:
                    arrow.localRotation = Quaternion.Euler(new Vector3(0, 0, -90));
                    break;

                case JoyStickDirection.Backward:
                    arrow.localRotation = Quaternion.Euler(new Vector3(0, 0, 90));
                    break;

                case JoyStickDirection.Down:
                    arrow.localRotation = Quaternion.Euler(new Vector3(0, 0, 180));
                    break;
                }

                if (!arrow.gameObject.activeSelf)
                {
                    arrow.gameObject.SetActive(true);
                }

                if (OnJoyStickTouchChangeDir != null)
                {
                    lastJoyStickDir = curJoyStickDir;
                    OnJoyStickTouchChangeDir.Invoke(curJoyStickDir);
                }
            }
        }
Example #2
0
        public void OnJoyStickThumTouchEnd()
        {
            if (arrow.gameObject.activeSelf)
            {
                arrow.gameObject.SetActive(false);
            }

            if (OnJoyStickTouchEnd != null)
            {
                OnJoyStickTouchEnd.Invoke();
            }

            curJoyStickDir = JoyStickDirection.None;
            if (curJoyStickDir != lastJoyStickDir)
            {
                if (OnJoyStickTouchChangeDir != null)
                {
                    lastJoyStickDir = curJoyStickDir;
                    OnJoyStickTouchChangeDir.Invoke(curJoyStickDir);
                }
            }
        }