private void OnDisable()
        {
            SetJoystickOnOrigin();

            // When we disable, we just unregister our axis
            // It also happens before the game object is Destroyed
            CnInputManager.UnregisterVirtualAxis(HorizintalAxis);
            CnInputManager.UnregisterVirtualAxis(VerticalAxis);
        }
Beispiel #2
0
        private void Update()
        {
            // Now this is a bit tricky
            // As we are completely REPLACING the uGUI event system for the Editor, we need to handle both Touch and Mouse inputs

            // For every touch out there
            for (int i = 0; i < CnInputManager.TouchCount; i++)
            {
                var touch = CnInputManager.GetTouch(i);
                PointerEventDataCache.position = touch.position;

                // Check if it's inside our rectangle
                if (RectTransformUtility.RectangleContainsScreenPoint(_linkedButtonRectTransform, touch.position, UiRootCamera))
                {
                    // If it's inside, it's just started AND the button has not been pressed yet
                    if (touch.phase == TouchPhase.Began && LastFingerId == -1)
                    {
                        // We press the button
                        _linkedButton.OnPointerDown(PointerEventDataCache);
                        // Remember our pressed finger id
                        LastFingerId = touch.fingerId;
                        return;
                    }
                }

                // If it's just been lifted AND this is the finger that was pressing this button
                if (touch.phase == TouchPhase.Ended && touch.fingerId == LastFingerId)
                {
                    // We release the button
                    _linkedButton.OnPointerUp(PointerEventDataCache);
                    // Reset finger ID so we can Press again
                    LastFingerId = -1;
                    return;
                }
            }

            // Mouse input here
            // Same logic, but mouse is considered to be the finger with id of 255 so it's definitely won't interfere with actual fingers
            PointerEventDataCache.position = Input.mousePosition;
            if (RectTransformUtility.RectangleContainsScreenPoint(_linkedButtonRectTransform,
                                                                  PointerEventDataCache.position, UiRootCamera))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    _linkedButton.OnPointerDown(PointerEventDataCache);
                    LastFingerId = 255;
                    return;
                }
            }

            if (Input.GetMouseButtonUp(0) && LastFingerId == 255)
            {
                _linkedButton.OnPointerUp(PointerEventDataCache);
                LastFingerId = -1;
            }
        }
Beispiel #3
0
        private void OnEnable()
        {
            // When we enable, we get our virtual axis

            HorizintalAxis = HorizintalAxis ?? new VirtualAxis(HorizontalAxisName);
            VerticalAxis   = VerticalAxis ?? new VirtualAxis(VerticalAxisName);
            // And register them in our input system
            CnInputManager.RegisterVirtualAxis(HorizintalAxis);
            CnInputManager.RegisterVirtualAxis(VerticalAxis);
        }
Beispiel #4
0
        private void OnEnable()
        {
            // When we enable, we get our virtual axis

            MovementHAxis = MovementHAxis ?? new VirtualAxis(MovementHAxisName);
            MovementVAxis = MovementVAxis ?? new VirtualAxis(MovementVAxisName);

            // And register them in our input system

            CnInputManager.RegisterVirtualAxis(MovementHAxis);
            CnInputManager.RegisterVirtualAxis(MovementVAxis);
        }
Beispiel #5
0
        private void Update()
        {
            if (HorizontalAxisName == "Horizontal1")
            {
                if (Player != null)
                {
                    if (!Player.GetComponent <PlayerController>().enabled)
                    {
                        HorizintalAxis.Value = 0;
                        VerticalAxis.Value   = 0;
                        CnInputManager.UnregisterVirtualAxis(HorizintalAxis);
                        CnInputManager.UnregisterVirtualAxis(VerticalAxis);
                        return;
                    }
                }
            }

            if (HorizontalAxisName == "Horizontal2")
            {
                if (Player != null)
                {
                    if (Player.GetComponent <PlayerSkill>().TempCDtime > 0)
                    {
                        Hide(true);
                    }
                    else
                    {
                        Hide(false);
                    }

                    if (Player.GetComponent <GlacierEffect>())
                    {
                        if (Player.GetComponent <GlacierEffect>().EndTime > 0)
                        {
                            Hide(true);
                        }
                        else if (Player.GetComponent <GlacierEffect>().EndTime <= 0)
                        {
                            Hide(false);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        private void OnDisable()
        {
            // When we disable, we just unregister our axis
            // It also happens before the game object is Destroyed
            CnInputManager.UnregisterVirtualAxis(HorizintalAxis);
            CnInputManager.UnregisterVirtualAxis(VerticalAxis);

            // When we lift our finger, we reset everything to the initial state
            _baseTransform.anchoredPosition  = _initialBasePosition;
            _stickTransform.anchoredPosition = _initialStickPosition;
            _intermediateStickPosition       = _initialStickPosition;

            HorizintalAxis.Value = VerticalAxis.Value = 0f;

            // We also hide it if we specified that behaviour
            if (HideOnRelease)
            {
                Hide(true);
            }
        }
        private void Update()
        {
            // For every touch out there
            for (int i = 0; i < CnInputManager.TouchCount; i++)
            {
                var touch = CnInputManager.GetTouch(i);
                PointerEventDataCache.position  = touch.position;
                PointerEventDataCache.pointerId = touch.fingerId;

                if (touch.phase == TouchPhase.Began)
                {
                    _linkedDpad.OnPointerDown(PointerEventDataCache);
                    return;
                }
                if (touch.phase == TouchPhase.Ended)
                {
                    _linkedDpad.OnPointerUp(PointerEventDataCache);
                    return;
                }
            }
            // Mouse input here
            // Same logic, but mouse is considered to be the finger with id of 255 so it's definitely won't interfere with actual fingers
            PointerEventDataCache.position  = Input.mousePosition;
            PointerEventDataCache.pointerId = 255;

            if (Input.GetMouseButtonDown(0))
            {
                _linkedDpad.OnPointerDown(PointerEventDataCache);
                return;
            }
            if (Input.GetMouseButtonUp(0))
            {
                _linkedDpad.OnPointerUp(PointerEventDataCache);
                return;
            }
        }
Beispiel #8
0
 /// <summary>
 /// When we disable, we unregister our button
 /// </summary>
 private void OnDisable()
 {
     CnInputManager.UnregisterVirtualButton(_virtualButton);
 }
Beispiel #9
0
 /// <summary>
 /// It's pretty simple here
 /// When we enable, we register our button in the input system
 /// </summary>
 private void OnEnable()
 {
     _virtualButton = _virtualButton ?? new VirtualButton(ButtonName);
     CnInputManager.RegisterVirtualButton(_virtualButton);
 }
Beispiel #10
0
 private void OnDisable()
 {
     CnInputManager.UnregisterVirtualAxis(_virtualAxis);
 }
        public void Update()
        {
            // Now this is a bit tricky
            // As we are completely REPLACING the uGUI event system for the Editor, we need to handle both Touch and Mouse inputs

            // For every touch out there
            for (int i = 0; i < CnInputManager.TouchCount; i++)
            {
                var touch = CnInputManager.GetTouch(i);
                PointerEventDataCache.position = touch.position;
                PointerEventDataCache.delta    = touch.deltaPosition;

                // Check if it's inside our rectangle
                if (RectTransformUtility.RectangleContainsScreenPoint(_touchpadTouchRect, touch.position, UiRootCamera))
                {
                    // If it's inside, it's just started AND the joystick is not being tweaked yet
                    if (touch.phase == TouchPhase.Began && LastFingerId == -1)
                    {
                        // We press the joystick
                        _linkedTouchpad.OnPointerDown(PointerEventDataCache);
                        // Remember our pressed finger id
                        LastFingerId = touch.fingerId;
                        return;
                    }
                }

                // If it's just been lifted AND this is the finger that was tweaking this joystick
                if (touch.phase == TouchPhase.Ended && touch.fingerId == LastFingerId)
                {
                    // We release the joystick
                    _linkedTouchpad.OnPointerUp(PointerEventDataCache);
                    // Reset finger ID so we can Press again
                    LastFingerId = -1;
                    return;
                }

                if (touch.phase == TouchPhase.Moved && touch.fingerId == LastFingerId)
                {
                    _linkedTouchpad.OnDrag(PointerEventDataCache);
                    return;
                }
            }

            // Mouse input here
            // Same logic, but mouse is considered to be the finger with id of 255 so it's definitely won't interfere with actual fingers
            PointerEventDataCache.position = Input.mousePosition;
            PointerEventDataCache.delta    = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
            PointerEventDataCache.delta   *= 10f;
            if (RectTransformUtility.RectangleContainsScreenPoint(_touchpadTouchRect,
                                                                  PointerEventDataCache.position, UiRootCamera))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    _linkedTouchpad.OnPointerDown(PointerEventDataCache);
                    LastFingerId = 255;
                    return;
                }
            }

            if (Input.GetMouseButtonUp(0) && LastFingerId == 255)
            {
                _linkedTouchpad.OnPointerUp(PointerEventDataCache);
                LastFingerId = -1;
                return;
            }

            if (Input.GetMouseButton(0) && LastFingerId == 255 && PointerEventDataCache.delta.sqrMagnitude > 0.000000001f)
            {
                _linkedTouchpad.OnDrag(PointerEventDataCache);
            }
        }