コード例 #1
0
ファイル: CameraControl.cs プロジェクト: Chapmania/Juniper
 private bool GestureSatisfied(Mode mode)
 {
     if (mode == Mode.None)
     {
         return(false);
     }
     else if (mode == Mode.Gamepad || mode == Mode.MagicWindow)
     {
         return(true);
     }
     else if (mode == Mode.Touch)
     {
         if (UnityInput.touchCount != requiredTouchCount)
         {
             return(false);
         }
         else
         {
             var touchPhase = UnityInput.GetTouch(requiredTouchCount - 1).phase;
             return(touchPhase == TouchPhase.Moved ||
                    touchPhase == TouchPhase.Stationary);
         }
     }
     else if (mode == Mode.NetworkView)
     {
         return(NetworkPose.HasValue);
     }
     else
     {
         var btn     = (int)requiredMouseButton;
         var pressed = requiredMouseButton == InputEventButton.None || UnityInput.GetMouseButton(btn);
         var down    = requiredMouseButton != InputEventButton.None && UnityInput.GetMouseButtonDown(btn);
         return(pressed && !down && (mode != Mode.MouseLocked || Cursor.lockState == CursorLockMode.Locked));
     }
 }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        var mouseDelta = Input.mouseScrollDelta;

        if (mouseDelta != Vector2.zero)
        {
            Zoom(mouseDelta.y);
        }

        var mousePos = _mainCamera.ScreenToWorldPoint(Input.mousePosition);

        if (Input.GetMouseButtonDown(2) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonUp(2) || Input.GetMouseButtonUp(1))
        {
            _currentMouseOff = mousePos;
        }

        if (Input.GetMouseButton(2) || Input.GetMouseButton(1))
        {
            var offset = _currentMouseOff - mousePos;

            MoveCamera(offset);
        }

        _mainCamera.orthographicSize = Mathf.SmoothDamp(_mainCamera.orthographicSize, currentZoomLevel, ref _velocity, smoothTime);
    }
        private void HandleRotationIfNeeded()
        {
            if (UnityInput.GetMouseButton(settings.inputSceme.beginRotateButtonIndex))
            {
                Cursor.visible = false;
                var diff = Mathf.Abs(UnityInput.mousePosition.x - _previousMouseDrag.x);
                if (diff > _mouseDragTrashHold)
                {
                    _cachedMuseRotationArgs.horisontalWorldInputValue = UnityInput.mousePosition.x > _previousMouseDrag.x ? 1f : -1f;
                }
                else
                {
                    _cachedMuseRotationArgs.horisontalWorldInputValue = 0f;
                }

                _previousMouseDrag.x = UnityInput.mousePosition.x;
                InvokeInputEvent(EMovementInputType.drag, _cachedMuseRotationArgs);
            }
            else
            {
                Cursor.visible = true;

                _previousMouseDrag = Vector2.zero;
                _cachedMuseRotationArgs.horisontalWorldInputValue = 0;
                _cachedMuseRotationArgs.verticalWorldInputValue   = 0;
            }
        }
コード例 #4
0
        private void HandleMouseInput()
        {
            if (this.EnablePanning)
            {
                if (UnityInput.GetMouseButtonDown(this.MouseButtonIndexForPan))
                {
                    mPanningPosition = UnityInput.mousePosition;
                }
                else if (UnityInput.GetMouseButton(this.MouseButtonIndexForPan))
                {
                    // Only trigger this once if we actually moved.
                    // TODO: Determine if we need to add a 'deadzone' for panning difference detection
                    if (!mIsPanning && UnityInput.mousePosition != mPanningPosition)
                    {
                        mIsPanning = true;
                        this.OnBeginPanAction?.Invoke(mPanningPosition);
                    }

                    PanCameraTo(UnityInput.mousePosition);
                }
                else if (UnityInput.GetMouseButtonUp(this.MouseButtonIndexForPan))
                {
                    mIsPanning = false;
                    if (this.OnFinishedPanAction != null)
                    {
                        this.OnFinishedPanAction(mPanningPosition);
                    }
                }
            }
        }
コード例 #5
0
        // Update is called once per frame
        void Update()
        {
            if (!isLocalPlayer)
            {
                return;
            }

            if (!Input.GetMouseButton((int)MouseButton.LeftMouse))
            {
                // We are not holding the mouse button. Release the object and return before checking for a new one
                if (rigidbodyOfObject != null)
                {
                    Drop();
                }

                return;
            }

            if (rigidbodyOfObject == null)
            {
                // We are not holding an object, look for one to pick up

                Debug.DrawLine(transform.position, transform.position + cameraFollow.transform.forward * MaxPickupDistance, Color.yellow);
                if (Physics.Raycast(transform.position, cameraFollow.transform.forward, out hit, MaxPickupDistance))
                {
                    // Don't pick up kinematic rigidbodies (they can't move)
                    if (hit.rigidbody != null && !hit.rigidbody.isKinematic)
                    {
                        PickUp();
                    }
                }
            }
            else
            {
                // We are already holding an object, listen for rotation input
                if (Input.GetKey(KeyCode.R))
                {
                    rotationInput += new Vector2(rotationInput.x, 1);
                }
                if (Input.GetKey(KeyCode.F))
                {
                    rotationInput -= new Vector2(rotationInput.x, 1);
                }
                if (Input.GetKey(KeyCode.Q))
                {
                    rotationInput += new Vector2(1, rotationInput.y);
                }
                if (Input.GetKey(KeyCode.E))
                {
                    rotationInput -= new Vector2(1, rotationInput.y);
                }
                if (Input.GetMouseButtonDown((int)MouseButton.RightMouse))
                {
                    isThrowing = true;
                }
            }
        }
コード例 #6
0
        protected override bool PollHeld(MouseButton inputBind)

        {
            bool bRet = UInput.GetMouseButton((int)inputBind);



            RetroEvents.Chapter("Input_" + BoundInputID.ToString()).Set(new KeyInputEvent(bRet, Time.deltaTime, false, BoundInputID));



            return(bRet);
        }
コード例 #7
0
        private void OnGUI()
        {
            if (SimpleWebXR.InSession)
            {
                return;
            }

            if (UInput.mouseScrollDelta.y != 0)
            {
                _lastScrollTime = Time.time;
            }

            var wheelScroll = (Time.time - _lastScrollTime) < 1;


            var txt = new StringBuilder();

            txt.Append("    <b>Help</b>\r\nMove camera with arrows : ");
            Append(txt, "LEFT", UInput.GetKey(KeyCode.LeftArrow));
            txt.Append(", ");
            Append(txt, "RIGHT", UInput.GetKey(KeyCode.RightArrow));
            txt.Append(", ");
            Append(txt, "UP", UInput.GetKey(KeyCode.UpArrow));
            txt.Append(", ");
            Append(txt, "DOWN", UInput.GetKey(KeyCode.DownArrow));

            txt.Append("\r\nRotate camera : ");
            Append(txt, "Right Mouse Button", UInput.GetMouseButton(1));

            txt.Append("\r\nMove hands : ");
            Append(txt, "Left Shift", UInput.GetKey(KeyCode.LeftShift));
            txt.Append(", ");
            Append(txt, "Space Bar", UInput.GetKey(KeyCode.Space));

            txt.Append("\r\nToggle hands : ");
            Append(txt, "T ", UInput.GetKey(KeyCode.T));
            txt.Append(", ");
            Append(txt, "Y", UInput.GetKey(KeyCode.Y));

            txt.Append("\r\nMove hand : ");
            Append(txt, "Left Shift + Wheel", UInput.GetKey(KeyCode.LeftShift) && wheelScroll);

            txt.Append("\r\nRotate hand : ");
            Append(txt, "Left Shift + Left CTRL + Wheel", UInput.GetKey(KeyCode.LeftShift) && UInput.GetKey(KeyCode.LeftControl) && wheelScroll);

            txt.Append("\r\nPinch / Select : ");
            Append(txt, "Left Mouse Button", UInput.GetMouseButton(0));

            GUI.Label(new Rect(0, 0, Screen.width, Screen.height), txt.ToString());
        }
コード例 #8
0
ファイル: Brick.cs プロジェクト: xiechyun/BrickAndBall
        protected override void LockUpdate()
        {
            if (!this.isRunning)
            {
                return;
            }

            if (Judge.GameType == GameType.PVE && !this.isPlayer)
            {
                this.timer.Update();
            }

            if (this.isPlayer)
            {
                this.dragging.Drag(ViceCamera.MousePosition, UInput.GetMouseButton(0));
            }
        }
コード例 #9
0
 public void Execute()
 {
     _entities
     .SlinqWithIndex()
     .ForEach(value =>
     {
         value.Match()
         .Where(v => UniInput.GetMouseButtonDown(v.Item2))
         .Do(v => value.Item1.ReplaceButtonDown(Camera.main.ScreenToWorldPoint(UniInput.mousePosition)))
         .Where(v => UniInput.GetMouseButton(v.Item2))
         .Do(v => value.Item1.ReplaceButtonPressed(Camera.main.ScreenToWorldPoint(UniInput.mousePosition)))
         .Where(v => UniInput.GetMouseButtonUp(v.Item2))
         .Do(v => value.Item1.ReplaceButtonUp(Camera.main.ScreenToWorldPoint(UniInput.mousePosition)))
         .IgnoreElse()
         .Exec();
     });
 }
コード例 #10
0
ファイル: ModInput.cs プロジェクト: YLMAPI/YLMAPI
        static ModInput()
        {
            // TODO: This mapping list.
            _InitButtonMap(9, "Jump", "A");
            _InitButtonMap(10, "Fly");
            _InitButtonMap(12, "Context");
            _InitButtonMap(14, "TongueEdibleItem", "B");
            _InitButtonMap_Not(input => UEInput.GetMouseButton(1), "B");
            _InitButtonMap(15, "Invisibility");
            _InitButtonMap(16, "BasicAttack", "ShootEatenItem", "X");
            _InitButtonMap_Not(input => UEInput.GetMouseButton(0), "X");
            _InitButtonMap(18, "WheelSpin");
            _InitButtonMap(19, "FartBubble");
            _InitButtonMap(20, "Crouch", "LT", "L2");
            _InitButtonMap(21, "GroundPound");
            _InitButtonMap(22, "SwimUnderwater");
            _InitButtonMap(23, "Wheel", "RT", "R2");
            _InitButtonMap(24, "RB", "R1");
            _InitButtonMap_Not(50, "RB", "R1");
            _InitButtonMap_Not(input => UEInput.GetMouseButton(2), "RB", "R1");
            _InitButtonMap(25, "LB", "L1");
            _InitButtonMap_Not(input => UEInput.mouseScrollDelta.y > 0f, "LB", "L1");
            _InitButtonMap(27, "SonarBlastAttack", "Y");
            _InitButtonMap(28, "SonarBoomAttack");
            _InitButtonMap(29, "SonarShieldAttack");
            _InitButtonMap(30, "Aiming");
            _InitButtonMap(39, "EmoteHappy", "DPadUp");
            _InitButtonMap(40, "EmoteTaunt", "DPadRight");
            _InitButtonMap(41, "EmoteDisappointed", "DPadDown");
            _InitButtonMap(42, "EmoteAngry", "DPadLeft");
            _InitButtonMap(49, "LS", "L3");
            _InitButtonMap(50, "RS", "R3");
            _InitButtonMap(51, "SwimUnderwaterAlt");

            AxisMap["Horizontal"]   = input => input.GetAxis(0) + (UEInput.GetKey(KeyCode.A) ? -1f : UEInput.GetKey(KeyCode.D) ? 1f : 0f);
            AxisMap["Vertical"]     = input => input.GetAxis(1) + (UEInput.GetKey(KeyCode.S) ? -1f : UEInput.GetKey(KeyCode.W) ? 1f : 0f);
            AxisMap["FPV Camera X"] = input => input.GetAxisRaw(4) * 0.4f + input.GetAxisRaw(47) * 0.07f;
            AxisMap["FPV Camera Y"] = input => input.GetAxisRaw(5) * 0.4f + input.GetAxisRaw(48) * 0.07f;
            AxisMap["Mouse X"]      = input => input.GetAxisRaw(47);
            AxisMap["Mouse Y"]      = input => input.GetAxisRaw(48);
        }
コード例 #11
0
ファイル: TightRope.cs プロジェクト: Turmolt/ludum-dare-46
        void Update()
        {
            if (!isPlaying)
            {
                return;
            }

            if (LifeSlider.value == 0f)
            {
                GameOver();
            }

            if (Input.GetMouseButton(0) || Input.GetKey(KeyCode.LeftArrow))
            {
                SetDelta(delta - minDelta);
            }

            if (Input.GetMouseButton(1) || Input.GetKey(KeyCode.RightArrow))
            {
                SetDelta(delta + minDelta);
            }

            var pullMultiplier = 2.0f;

            if (BalanceSlider.value < .5f)
            {
                var d = (.5f - BalanceSlider.value) / (1.75f - difficulty / 30f);
                SetDelta(delta - d * minDelta * pullMultiplier);
            }
            else
            {
                var d = (BalanceSlider.value - .5f) / (1.75f - difficulty / 30f);
                SetDelta(delta + d * minDelta * pullMultiplier);
            }

            BalanceSlider.value = Mathf.Clamp01(BalanceSlider.value + delta);
            Skater.eulerAngles  = Skater.eulerAngles.xy(90 - (180 * BalanceSlider.value));
            UpdateLife();
        }
コード例 #12
0
        void Update()
        {
            LastFrame = CurrentFrame;

            CurrentFrame.MouseLeftHeld = I.GetMouseButton(0);
            CurrentFrame.MouseLeftDown = I.GetMouseButtonDown(0);
            CurrentFrame.MouseLeftUp   = I.GetMouseButtonUp(0);

            CurrentFrame.MouseRightHeld = I.GetMouseButton(1);
            CurrentFrame.MouseRightDown = I.GetMouseButtonDown(1);
            CurrentFrame.MouseRightUp   = I.GetMouseButtonUp(1);

            CurrentFrame.MouseMiddleHeld = I.GetMouseButton(2);
            CurrentFrame.MouseMiddleDown = I.GetMouseButtonDown(2);
            CurrentFrame.MouseMiddleUp   = I.GetMouseButtonUp(2);

            CurrentFrame.MouseScreenPosition = UnityEngine.Input.mousePosition;
            CurrentFrame.MouseScreenDelta    = CurrentFrame.MouseScreenPosition - LastFrame.MouseScreenPosition;

            CurrentFrame.MouseLeftDragging    = CurrentFrame.MouseLeftHeld;
            CurrentFrame.MouseLeftDragStarted = CurrentFrame.MouseLeftDragging && !LastFrame.MouseLeftDragging;
            CurrentFrame.MouseLeftDragStopped = !CurrentFrame.MouseLeftDragging && LastFrame.MouseLeftDragging;

            CurrentFrame.MouseRightDragging    = CurrentFrame.MouseRightHeld;
            CurrentFrame.MouseRightDragStarted = CurrentFrame.MouseRightDragging && !LastFrame.MouseRightDragging;
            CurrentFrame.MouseRightDragStopped = !CurrentFrame.MouseRightDragging && LastFrame.MouseRightDragging;

            var mainCamera = CameraController.Instance;
            var ray        = mainCamera.MainCamera.ScreenPointToRay(CurrentFrame.MouseScreenPosition);

            CurrentFrame.MouseScreenPositionLeftDown   = CurrentFrame.MouseLeftDown ? CurrentFrame.MouseScreenPosition : LastFrame.MouseScreenPositionLeftDown;
            CurrentFrame.MouseScreenPositionRightDown  = CurrentFrame.MouseRightDown ? CurrentFrame.MouseScreenPosition : LastFrame.MouseScreenPositionRightDown;
            CurrentFrame.MouseScreenPositionMiddleDown = CurrentFrame.MouseMiddleDown ? CurrentFrame.MouseScreenPosition : LastFrame.MouseScreenPositionMiddleDown;

            if (Physics.RaycastNonAlloc(ray, m_Results) > 0)
            {
                CurrentFrame.MouseLocalPosition = m_Results[0].point / mainCamera.Data.Units;
                CurrentFrame.MouseLocalDelta    = CurrentFrame.MouseLeftDragStarted ? float3.zero : CurrentFrame.MouseLocalPosition - LastFrame.MouseLocalPosition;

                CurrentFrame.MouseWorldPosition = mainCamera.Data.LookAtPosition + CurrentFrame.MouseLocalPosition;
                CurrentFrame.MouseWorldDelta    = CurrentFrame.MouseLeftDragStarted ? double3.zero : CurrentFrame.MouseWorldPosition - LastFrame.MouseWorldPosition;
            }
            else
            {
                CurrentFrame.MouseLocalPosition = LastFrame.MouseLocalPosition;
                CurrentFrame.MouseLocalDelta    = LastFrame.MouseLocalDelta;
                CurrentFrame.MouseWorldPosition = LastFrame.MouseWorldPosition;
                CurrentFrame.MouseWorldDelta    = LastFrame.MouseWorldDelta;
            }

            var topLeft = mainCamera.MainCamera.ScreenPointToRay(new Vector3(Screen.width, Screen.height, 0f));

            if (Physics.RaycastNonAlloc(topLeft, m_Results) > 0)
            {
                CurrentFrame.TopLeftLocalPosition = m_Results[0].point / mainCamera.Data.Units;
                CurrentFrame.TopLeftWorldPosition = mainCamera.Data.LookAtPosition + CurrentFrame.TopLeftLocalPosition;
            }
            else
            {
                CurrentFrame.TopLeftLocalPosition = LastFrame.TopLeftLocalPosition;
                CurrentFrame.TopLeftWorldPosition = LastFrame.TopLeftWorldPosition;
            }

            CurrentFrame.PrimaryAxis   = new float2(I.GetAxis("Horizontal"), I.GetAxis("Vertical"));
            CurrentFrame.SecondaryAxis = new float2(I.GetAxis("Mouse ScrollWheel"), 0f);

            CurrentFrame.MouseLeftClicked = CurrentFrame.MouseLeftUp && LastFrame.MouseLeftHeld &&
                                            math.lengthsq(CurrentFrame.MouseScreenPosition - CurrentFrame.MouseScreenPositionLeftDown) < 2;

            CurrentFrame.MouseRightClicked = CurrentFrame.MouseRightUp && LastFrame.MouseRightHeld &&
                                             math.lengthsq(CurrentFrame.MouseScreenPosition - CurrentFrame.MouseScreenPositionRightDown) < 2;

            CurrentFrame.MouseMiddleClicked = CurrentFrame.MouseMiddleUp && LastFrame.MouseMiddleHeld &&
                                              math.lengthsq(CurrentFrame.MouseScreenPosition - CurrentFrame.MouseScreenPositionMiddleDown) < 2;

            CurrentFrame.PrimaryAction    = I.GetAxis("Fire1") > 0f;
            CurrentFrame.SecondaryAction  = I.GetAxis("Fire2") > 0f;
            CurrentFrame.TertiaryAction   = I.GetAxis("Fire3") > 0f;
            CurrentFrame.QuaternaryAction = I.GetAxis("Jump") > 0f;

            CurrentFrame.CycleForwardAction  = I.GetKeyUp(KeyCode.Equals);
            CurrentFrame.CycleBackwardAction = I.GetKeyUp(KeyCode.Minus);

            CurrentFrame.CancelAction = I.GetKeyUp(KeyCode.Escape);

            CurrentFrame.SubActions[0]  = I.GetKeyUp(KeyCode.F1);
            CurrentFrame.SubActions[1]  = I.GetKeyUp(KeyCode.F2);
            CurrentFrame.SubActions[2]  = I.GetKeyUp(KeyCode.F3);
            CurrentFrame.SubActions[3]  = I.GetKeyUp(KeyCode.F4);
            CurrentFrame.SubActions[4]  = I.GetKeyUp(KeyCode.F5);
            CurrentFrame.SubActions[5]  = I.GetKeyUp(KeyCode.F6);
            CurrentFrame.SubActions[6]  = I.GetKeyUp(KeyCode.F7);
            CurrentFrame.SubActions[7]  = I.GetKeyUp(KeyCode.F8);
            CurrentFrame.SubActions[8]  = I.GetKeyUp(KeyCode.F9);
            CurrentFrame.SubActions[9]  = I.GetKeyUp(KeyCode.F10);
            CurrentFrame.SubActions[10] = I.GetKeyUp(KeyCode.F11);
            CurrentFrame.SubActions[11] = I.GetKeyUp(KeyCode.F12);
        }
コード例 #13
0
 public static bool IsMouseButtonPressed(MouseButton mouseButton)
 {
     return(UnityInput.GetMouseButton((int)mouseButton));
 }
コード例 #14
0
ファイル: InputSystem.cs プロジェクト: yabos/SaveTheQueen
        private void MouseUpdate()
        {
            if (EditMouseUpdate == false)
            {
                return;
            }

            float scroll = UInput.GetAxis("Mouse ScrollWheel");

            if (scroll != 0.0f)
            {
                Vector2 mousePos   = UInput.mousePosition;
                Rect    gameScreen = new Rect(0.0f, 0.0f, Screen.width, Screen.height);
                if (gameScreen.Contains(mousePos))
                {
                    MouseEvent mouseEvent = m_mouseTranslator.MouseWheel(mousePos, -scroll);
                    if (CallBackMouseEvent != null && mouseEvent != MouseEvent.None)
                    {
                        CallBackMouseEvent(mouseEvent);
                    }
                }
            }

            bool updateRaycast = false;

            for (int i = 0; i < 3; ++i)
            {
                if (UInput.GetMouseButton(i) || UInput.GetMouseButtonUp(i) || m_mouseDown)
                {
                    updateRaycast = true;
                    break;
                }
            }

            Vector3 mouseposition;

            if (updateRaycast)
            {
                mouseposition = UInput.mousePosition;
            }
            else
            {
                return;
            }

            MouseEvent.E_Buttons eventbutton = MouseEvent.E_Buttons.Left;
            for (int i = 0; i < 3; ++i)
            {
                bool pressed   = UInput.GetMouseButtonDown(i);
                bool unpressed = UInput.GetMouseButtonUp(i);
                //bool pressing = Input.GetMouseButton(i);

                //E_MOUSE_EVENT dowingEvent = E_MOUSE_EVENT.LDOWNING;


                if (i == 0)
                {
                    eventbutton = MouseEvent.E_Buttons.Left;
                    //dowingEvent = E_MOUSE_EVENT.LDOWNING;
                }
                else if (i == 1)
                {
                    eventbutton = MouseEvent.E_Buttons.Right;
                    //dowingEvent = E_MOUSE_EVENT.RDOWNING;
                }
                else if (i == 2)
                {
                    eventbutton = MouseEvent.E_Buttons.Middle;
                    //dowingEvent = E_MOUSE_EVENT.MDOWNING;
                }


                if (pressed)
                {
                    PushTouchesEventMsg(mouseposition, true, eventbutton);
                    m_mouseDown = true;
                }

                if (unpressed)
                {
                    PushTouchesEventMsg(mouseposition, false, eventbutton);
                    m_mouseDown = false;
                }
            }


            bool Moved = UInput.GetAxis("Mouse X") != 0.0f || UInput.GetAxis("Mouse Y") != 0.0f;

            if (Moved)
            {
                PushTouchesEventMsg(mouseposition, false, eventbutton, true);
            }
        }
コード例 #15
0
 public static bool IsMouseButtonReleased(MouseButton mouseButton)
 {
     return(!UnityInput.GetMouseButton((int)mouseButton));
 }
コード例 #16
0
        private void Update()
        {
            if (EditorMode && EventSystem.current != null && EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            var leftDown   = Input.GetMouseButtonDown(0);
            var rightDown  = Input.GetMouseButtonDown(1);
            var rightHold  = Input.GetMouseButton(1);
            var middleDown = Input.GetMouseButtonDown(2);
            var middleHold = Input.GetMouseButton(2);
            var delDown    = Input.GetKeyDown(KeyCode.Delete);

            if (!(leftDown || rightHold || rightDown || middleDown || middleHold || delDown))
            {
                return;
            }

            var        ray = _camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit unitHit;
            var        unitRaycastHit = Physics.Raycast(ray, out unitHit, Mathf.Infinity, LayerMask.GetMask("Units"));
            RaycastHit terrainHit;
            var        terrainRaycastHit = Physics.Raycast(ray, out terrainHit, Mathf.Infinity, LayerMask.GetMask("Terrain"));

            if (EditorMode)
            {
                if (leftDown)
                {
                    if (unitRaycastHit && IsUnit(unitHit.collider))
                    {
                        _selection = unitHit.transform.parent;
                        ShowHandle(_selection);
                    }
                    else if (terrainRaycastHit)
                    {
                        _selection = Instantiate(
                            _activeUnitPrefab,
                            terrainHit.point,
                            Quaternion.identity,
                            _unitWrapper).transform;
                        ShowHandle(_selection);
                    }
                }
                else if (rightHold)
                {
                    if (_selection == null)
                    {
                        return;
                    }

                    if (terrainRaycastHit)
                    {
                        _selection.position = terrainHit.point;
                    }
                }
                else if (middleDown)
                {
                    if (_selection == null)
                    {
                        return;
                    }

                    _startRotation      = _selection.rotation;
                    _startMousePosition = Input.mousePosition;
                }
                else if (middleHold)
                {
                    if (_selection == null)
                    {
                        return;
                    }

                    _selection.rotation = _startRotation * Quaternion.AngleAxis(_startMousePosition.x - Input.mousePosition.x, Vector3.up);
                }
                else if (delDown)
                {
                    if (_selection == null)
                    {
                        return;
                    }

                    Destroy(_selection.gameObject);
                }
            }
            else
            {
                if (leftDown)
                {
                    _activeAgent = unitRaycastHit ? unitHit.collider.GetComponentInParent <NavMeshAgent>() : null;
                }
                else if (rightDown)
                {
                    if (_activeAgent != null)
                    {
                        _activeAgent.SetDestination(terrainHit.point);
                    }
                }
            }
        }
コード例 #17
0
        private void Update()
        {
#if UNITY_EDITOR
            if (UInput.GetMouseButtonDown(0))
            {
                _lastMousePosition = UInput.mousePosition;
                TouchInputEvent tie = new TouchInputEvent()
                {
                    touchPos   = _lastMousePosition,
                    touchDelta = Vector3.zero
                };
                OnTouchStart?.Invoke(tie);
            }
            else if (UInput.GetMouseButton(0))
            {
                TouchInputEvent tie = new TouchInputEvent()
                {
                    touchPos = UInput.mousePosition
                };
                tie.touchDelta     = tie.touchPos - _lastMousePosition;
                _lastMousePosition = tie.touchPos;
                OnTouchStay?.Invoke(tie);
            }
            else if (UInput.GetMouseButtonUp(0))
            {
                TouchInputEvent tie = new TouchInputEvent()
                {
                    touchPos   = UInput.mousePosition,
                    touchDelta = Vector3.zero
                };
                OnTouchRelease?.Invoke(tie);
            }
#elif UNITY_ANDROID
            if (UInput.touchCount > 0)
            {
                // Only polling touch 0
                Touch           touch = UInput.GetTouch(0);
                TouchInputEvent tie   = new TouchInputEvent()
                {
                    touchPos   = touch.position,
                    touchDelta = touch.deltaPosition
                };

                // Send the respective event depending on touch phase state
                switch (touch.phase)
                {
                case TouchPhase.Began:
                    OnTouchStart?.Invoke(tie);
                    break;

                case TouchPhase.Moved:
                case TouchPhase.Stationary:
                    OnTouchStay?.Invoke(tie);
                    break;

                case TouchPhase.Canceled:
                case TouchPhase.Ended:
                    OnTouchRelease?.Invoke(tie);
                    break;
                }
            }
#endif
        }
コード例 #18
0
ファイル: InputController.cs プロジェクト: otoolew/Aberdeen
    /// <summary>
    /// Perform logic to update mouse/pointing device
    /// </summary>
    void UpdateMouse()
    {
        basicMouseInfo.previousPosition = basicMouseInfo.currentPosition;
        basicMouseInfo.currentPosition  = UnityInput.mousePosition;
        basicMouseInfo.delta            = basicMouseInfo.currentPosition - basicMouseInfo.previousPosition;
        mouseMovedOnThisFrame           = basicMouseInfo.delta.sqrMagnitude >= Mathf.Epsilon;
        mouseButtonPressedThisFrame     = false;

        // Move event
        if (basicMouseInfo.delta.sqrMagnitude > Mathf.Epsilon)
        {
            if (mouseMoved != null)
            {
                mouseMoved(basicMouseInfo);
            }
        }
        // Button events
        for (int i = 0; i < trackMouseButtons; ++i)
        {
            MouseButtonInfo mouseButton = m_MouseInfo[i];
            mouseButton.delta            = basicMouseInfo.delta;
            mouseButton.previousPosition = basicMouseInfo.previousPosition;
            mouseButton.currentPosition  = basicMouseInfo.currentPosition;
            if (UnityInput.GetMouseButton(i))
            {
                if (!mouseButton.isDown)
                {
                    // First press
                    mouseButtonPressedThisFrame = true;
                    mouseButton.isDown          = true;
                    mouseButton.startPosition   = UnityInput.mousePosition;
                    mouseButton.startTime       = Time.realtimeSinceStartup;
                    mouseButton.startedOverUI   = EventSystem.current.IsPointerOverGameObject(-mouseButton.mouseButtonId - 1);

                    // Reset some stuff
                    mouseButton.totalMovement = 0;
                    mouseButton.isDrag        = false;
                    mouseButton.wasHold       = false;
                    mouseButton.isHold        = false;
                    mouseButton.flickVelocity = Vector2.zero;

                    if (pressed != null)
                    {
                        pressed(mouseButton);
                    }
                }
                else
                {
                    float moveDist = mouseButton.delta.magnitude;
                    // Dragging?
                    mouseButton.totalMovement += moveDist;
                    if (mouseButton.totalMovement > dragThresholdMouse)
                    {
                        bool wasDrag = mouseButton.isDrag;

                        mouseButton.isDrag = true;
                        if (mouseButton.isHold)
                        {
                            mouseButton.wasHold = mouseButton.isHold;
                            mouseButton.isHold  = false;
                        }

                        // Did it just start now?
                        if (!wasDrag)
                        {
                            if (startedDrag != null)
                            {
                                startedDrag(mouseButton);
                            }
                        }
                        if (dragged != null)
                        {
                            dragged(mouseButton);
                        }

                        // Flick?
                        if (moveDist > flickThreshold)
                        {
                            mouseButton.flickVelocity =
                                (mouseButton.flickVelocity * (1 - k_FlickAccumulationFactor)) +
                                (mouseButton.delta * k_FlickAccumulationFactor);
                        }
                        else
                        {
                            mouseButton.flickVelocity = Vector2.zero;
                        }
                    }
                    else
                    {
                        // Stationary?
                        if (!mouseButton.isHold &&
                            !mouseButton.isDrag &&
                            Time.realtimeSinceStartup - mouseButton.startTime >= holdTime)
                        {
                            mouseButton.isHold = true;
                            if (startedHold != null)
                            {
                                startedHold(mouseButton);
                            }
                        }
                    }
                }
            }
            else // Mouse button not up
            {
                if (mouseButton.isDown) // Released
                {
                    mouseButton.isDown = false;
                    // Quick enough (with no drift) to be a tap?
                    if (!mouseButton.isDrag &&
                        Time.realtimeSinceStartup - mouseButton.startTime < tapTime)
                    {
                        if (tapped != null)
                        {
                            tapped(mouseButton);
                        }
                    }
                    if (released != null)
                    {
                        released(mouseButton);
                    }
                }
            }
        }

        // Mouse wheel
        if (Mathf.Abs(UnityInput.GetAxis("Mouse ScrollWheel")) > Mathf.Epsilon)
        {
            if (spunWheel != null)
            {
                spunWheel(new WheelInfo
                {
                    scrollAmount = UnityInput.GetAxis("Mouse ScrollWheel") * mouseWheelSensitivity
                });
            }
        }
    }