Пример #1
0
 public virtual void OnPointerExit(PointerEventData eventData)
 {
     if (!UnityTools.IsPointerOverUI())
     {
         ExecuteEvent <ITriggerPointerExit>(Execute, eventData);
     }
 }
Пример #2
0
 public void OnPointerClick(PointerEventData eventData)
 {
     //Check if  TriggerInputType.OnClick is included.
     if (triggerType.HasFlag <TriggerInputType>(TriggerInputType.OnClick) && !UnityTools.IsPointerOverUI())
     {
         Use();
     }
 }
 private void OnPointerTriggerClick(int button)
 {
     if (!UnityTools.IsPointerOverUI() &&
         triggerType.HasFlag <TriggerInputType>(TriggerInputType.LeftClick) && button == 0 ||
         triggerType.HasFlag <TriggerInputType>(TriggerInputType.RightClick) && button == 1 ||
         triggerType.HasFlag <TriggerInputType>(TriggerInputType.MiddleClick) && button == 2)
     {
         Use();
     }
 }
        // Update is called once per frame
        private void Update()
        {
            if (this.m_Focus)
            {
                Transform target          = this.m_ThirdPersonCamera.Target;
                Vector3   targetPosition  = target.position + this.m_OffsetPosition.x * target.right + this.m_OffsetPosition.y * target.up;
                Vector3   direction       = -m_Distance * transform.forward;
                Vector3   desiredPosition = targetPosition + direction;

                transform.position = Vector3.Lerp(transform.position, desiredPosition, this.m_Speed * Time.deltaTime);
                transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(this.m_Pitch, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z), this.m_Speed * Time.deltaTime);

                if (!this.m_TargetRotationFinished)
                {
                    Vector3 cameraDirection = transform.position - this.m_ThirdPersonCamera.Target.position;
                    cameraDirection.y = 0f;
                    Quaternion targetRotation = Quaternion.LookRotation(cameraDirection, Vector3.up);
                    this.m_ThirdPersonCamera.Target.rotation = Quaternion.Lerp(target.rotation, targetRotation, Time.deltaTime * this.m_Speed);
                    if (Quaternion.Angle(target.rotation, targetRotation) < 0.1f)
                    {
                        this.m_TargetRotationFinished = true;
                    }
                }
                else if (this.m_SpinTarget)
                {
                    if (Input.GetMouseButtonDown(0) && UnityTools.IsPointerOverUI())
                    {
                        this.m_GUIClick = true;
                    }
                    if (Input.GetMouseButtonUp(0))
                    {
                        this.m_GUIClick = false;
                    }

                    if (Input.GetMouseButton(0) && !this.m_GUIClick)
                    {
                        float input = Input.GetAxis("Mouse X") * -this.m_Speed;
                        target.Rotate(0, input, 0, Space.World);
                    }
                }
            }
        }
        private void Update()
        {
            if (!UnityTools.IsPointerOverUI())
            {
                RaycastHit hit;
                if (Physics.Raycast(this.m_Transform.position, this.m_Transform.forward, out hit, float.PositiveInfinity, this.m_LayerMask, QueryTriggerInteraction.Ignore))
                {
                    if (m_LastCameraHit != null && m_LastCameraHit != hit.collider.gameObject)
                    {
                        EventHandler.Execute <bool>(this.m_LastCameraHit, "OnCameraRaycast", false);
                    }
                    m_LastCameraHit = hit.collider.gameObject;
                    EventHandler.Execute <bool>(m_LastCameraHit, "OnCameraRaycast", true);
                }
                else
                {
                    if (m_LastCameraHit != null)
                    {
                        EventHandler.Execute <bool>(m_LastCameraHit, "OnCameraRaycast", false);
                        m_LastCameraHit = null;
                    }
                }

                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, float.PositiveInfinity, this.m_LayerMask, QueryTriggerInteraction.Ignore))
                {
                    if (m_LastMouseHit != null && m_LastMouseHit != hit.collider.gameObject)
                    {
                        EventHandler.Execute <bool>(this.m_LastMouseHit, "OnMouseRaycast", false);
                    }
                    m_LastMouseHit = hit.collider.gameObject;
                    EventHandler.Execute <bool>(m_LastMouseHit, "OnMouseRaycast", true);
                }
                else
                {
                    if (m_LastMouseHit != null)
                    {
                        EventHandler.Execute <bool>(m_LastMouseHit, "OnMouseRaycast", false);
                        m_LastMouseHit = null;
                    }
                }
            }
        }
        private void Update()
        {
            bool selected = false;

            //Selection
            if (Input.GetMouseButtonDown(0) && selectionType.HasFlag <SelectionInputType>(SelectionInputType.LeftClick) ||
                Input.GetMouseButtonDown(1) && selectionType.HasFlag <SelectionInputType>(SelectionInputType.RightClick) ||
                Input.GetMouseButtonDown(2) && selectionType.HasFlag <SelectionInputType>(SelectionInputType.MiddleClick))
            {
                selected = TrySelect(this.m_Camera.ScreenPointToRay(Input.mousePosition));
            }
            else if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && selectionType.HasFlag <SelectionInputType>(SelectionInputType.Raycast))
            {
                selected = TrySelect(new Ray(this.m_CameraTransform.position, this.m_CameraTransform.forward + this.m_RaycastOffset));
            }
            else if (Input.GetKeyDown(this.m_SelectionKey) && selectionType.HasFlag <SelectionInputType>(SelectionInputType.Key))
            {
                RaycastHit[] hits       = Physics.SphereCastAll(this.m_Transform.position, this.m_SelectionDistance, this.m_Transform.forward);
                ISelectable  selectable = GetBestSelectable(hits.Select(x => x.collider.GetComponent <ISelectable>()).OfType <ISelectable>().Where(x => x.enabled));
                if (selectable != null)
                {
                    Select(selectable);
                    selected = true;
                }
            }

            //Deselection
            if (!UnityTools.IsPointerOverUI())
            {
                if (!selected && (Input.GetMouseButtonDown(0) && deselectionType.HasFlag <DeselectionInputType>(DeselectionInputType.LeftClick) ||
                                  Input.GetMouseButtonDown(1) && deselectionType.HasFlag <DeselectionInputType>(DeselectionInputType.RightClick) ||
                                  Input.GetMouseButtonDown(2) && deselectionType.HasFlag <DeselectionInputType>(DeselectionInputType.MiddleClick) ||
                                  Input.GetKeyDown(this.m_DeselectionKey) && deselectionType.HasFlag <DeselectionInputType>(DeselectionInputType.Key)))
                {
                    Deselect();
                }
            }
        }
Пример #7
0
        private void Update()
        {
            if (!this.m_ControllerActive)
            {
                return;
            }

            if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && EventSystem.current != null && UnityTools.IsPointerOverUI())
            {
                this.m_GUIClick = true;
            }

            if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1))
            {
                this.m_GUIClick = false;
            }

            this.m_RawInput = new Vector3(Input.GetAxis(this.m_HorizontalInput), 0, Input.GetAxis(this.m_ForwardInput));

            switch (this.m_AimType)
            {
            case AimType.Button:
                IsAiming = Input.GetButton(this.m_AimInput) && !this.m_GUIClick;
                break;

            case AimType.Axis:
                float aim = Input.GetAxis(this.m_AimInput);
                if (Mathf.Abs(aim) > 0.01f)
                {
                    IsAiming          = true;
                    this.m_RawInput.x = aim;
                }
                else
                {
                    IsAiming = false;
                }
                break;

            case AimType.Toggle:
                if (Input.GetButtonDown(this.m_AimInput))
                {
                    IsAiming = !IsAiming;
                }
                break;
            }


            for (int j = 0; j < this.m_Motions.Count; j++)
            {
                MotionState motion = this.m_Motions [j];
                if (!motion.isActiveAndEnabled || motion.ConsumeInputOverUI && this.m_GUIClick)
                {
                    continue;
                }
                if (motion.StartType != StartType.Down && motion.StopType != StopType.Toggle || !Input.GetButtonDown(motion.InputName))
                {
                    if (motion.StopType == StopType.Up && Input.GetButtonUp(motion.InputName))
                    {
                        this.TryStopMotion(motion);
                        this.m_ToggleState [motion] = motion.StopType == StopType.Up && motion.IsActive;
                    }
                }
                else if (!motion.IsActive && motion.StartType == StartType.Down)
                {
                    this.TryStartMotion(motion);
                    this.m_ToggleState [motion] = (motion.StopType == StopType.Toggle || motion.StopType == StopType.Up) && motion.IsActive;
                }
                else if (motion.StopType == StopType.Toggle)
                {
                    this.TryStopMotion(motion);
                    this.m_ToggleState [motion] = motion.StopType == StopType.Toggle && motion.IsActive;
                    break;
                }
                if (motion.StartType == StartType.Press && Input.GetButton(motion.InputName))
                {
                    this.TryStartMotion(motion);
                }
            }
        }
Пример #8
0
        private void UpdateInput()
        {
            this.m_ConsumeTurn = false;
            this.m_ConsumeZoom = false;
            if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && EventSystem.current != null && UnityTools.IsPointerOverUI())
            {
                this.m_GUIClick = true;
            }

            if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1))
            {
                this.m_GUIClick = false;
            }

            if (!this.m_GUIClick)
            {
                for (int i = 0; i < this.m_Presets.Length; i++)
                {
                    CameraSettings preset = this.m_Presets[i];
                    switch (preset.Activation)
                    {
                    case CameraSettings.ActivationType.Button:
                        if (Input.GetButtonDown(preset.InputName))
                        {
                            preset.IsActive = true;
                        }
                        if (Input.GetButtonUp(preset.InputName))
                        {
                            preset.IsActive = false;
                        }
                        break;

                    case CameraSettings.ActivationType.Toggle:
                        if (Input.GetButtonDown(preset.InputName))
                        {
                            preset.IsActive = !preset.IsActive;
                        }
                        break;
                    }
                }
            }
            for (int i = 0; i < this.m_Presets.Length; i++)
            {
                CameraSettings preset = this.m_Presets[i];
                if (preset.IsActive)
                {
                    if (this.m_ActivePreset != preset)
                    {
                        this.m_ActivePreset = preset;
                        ApplyCrosshair(this.m_ActivePreset.Crosshair);
                    }
                    break;
                }
            }

            if (this.m_ActivePreset.ConsumeInputOverUI && this.m_GUIClick)
            {
                this.m_ConsumeTurn = true;
                this.m_ConsumeZoom = true;
            }

            if (!this.m_ConsumeTurn && (string.IsNullOrEmpty(this.m_ActivePreset.TurnButton) || Input.GetButton(this.m_ActivePreset.TurnButton)))
            {
                float x = Input.GetAxis("Mouse X") * this.m_ActivePreset.TurnSpeed;
                float y = Input.GetAxis("Mouse Y") * this.m_ActivePreset.TurnSpeed;

                if (this.m_ActivePreset.VisibilityDelta == 0f || Mathf.Abs(x) > this.m_ActivePreset.VisibilityDelta || Mathf.Abs(y) > this.m_ActivePreset.VisibilityDelta)
                {
                    Cursor.lockState        = CursorLockMode.Locked;
                    Cursor.visible          = false;
                    this.m_RotatedLastFrame = true;
                }
                this.m_MouseX += x;
                this.m_MouseY -= y;


                if (Mathf.Abs(this.m_ActivePreset.YawLimit.x) + Mathf.Abs(this.m_ActivePreset.YawLimit.y) < 360)
                {
                    this.m_MouseX = ClampAngle(this.m_MouseX, this.m_ActivePreset.YawLimit.x, this.m_ActivePreset.YawLimit.y);
                }
                this.m_MouseY = ClampAngle(this.m_MouseY, this.m_ActivePreset.PitchLimit.x, this.m_ActivePreset.PitchLimit.y);
            }
            else if (this.m_RotatedLastFrame)
            {
                Cursor.lockState        = this.m_ActivePreset.CursorMode;
                Cursor.visible          = this.m_ActivePreset.CursorMode == CursorLockMode.Locked ? false : true;
                this.m_RotatedLastFrame = false;
            }

            if (!this.m_ConsumeZoom)
            {
                this.m_ActivePreset.Zoom -= Input.GetAxis("Mouse ScrollWheel") * this.m_ActivePreset.ZoomSpeed;
                this.m_ActivePreset.Zoom  = Mathf.Clamp(this.m_ActivePreset.Zoom, this.m_ActivePreset.ZoomLimit.x - this.m_ActivePreset.Distance, this.m_ActivePreset.ZoomLimit.y - this.m_ActivePreset.Distance);
            }
        }