コード例 #1
0
 private void ResetInputData()
 {
     this.currentCamera   = null;
     this.currentCollider = null;
     this.currentInput    = null;
     InputManager.Instance.RemoveHandler(this);
 }
コード例 #2
0
        private void OnInput(Lost.Input input)
        {
            if (input == null || input.InputState != InputState.Pressed)
            {
                return;
            }

            if (this.mainCamera == null)
            {
                this.mainCamera = Camera.main;
            }

            Ray ray = this.mainCamera.ScreenPointToRay(input.CurrentPosition);

            if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, this.layer))
            {
                Interactable interactable = hit.collider.gameObject.GetComponentInParent <Interactable>();

                if (interactable != null && interactable.HasInput == false)
                {
                    interactable.SetInputData(input, hit.collider, this.mainCamera);
                }
                else if (interactable == null)
                {
                    Debug.LogErrorFormat(hit.collider, "GameObject {0} has a collider on the {1} layer, but not Interactable component!", hit.collider.gameObject.name, Interactable.LayerName);
                }
            }
        }
コード例 #3
0
        void InputHandler.HandleInputs(List <Lost.Input> touches, Lost.Input mouse, Lost.Input pen)
        {
            this.OnInput(this.currentInput, this.currentCollider, this.currentCamera);

            if (this.currentInput != null && this.currentInput.InputState == InputState.Released)
            {
                this.ResetInputData();
            }
        }
コード例 #4
0
        void InputHandler.HandleInputs(List <Lost.Input> touches, Lost.Input mouse, Lost.Input pen)
        {
            this.OnInput(mouse);
            this.OnInput(pen);

            for (int i = 0; i < touches.Count; i++)
            {
                this.OnInput(touches[i]);
            }
        }
コード例 #5
0
 protected override void OnInput(Lost.Input input, Collider collider, Camera camera)
 {
     if (input.InputState == InputState.Released)
     {
         if (this.tappedEvent != null && collider.Raycast(camera.ScreenPointToRay(input.CurrentPosition), out RaycastHit hit, float.MaxValue))
         {
             this.tappedEvent.Invoke(hit);
         }
     }
 }
コード例 #6
0
        public void SetInputData(Lost.Input input, Collider collider, Camera camera)
        {
            if (input.InputState != InputState.Pressed || this.currentInput != null || this.isInteractable == false)
            {
                return;
            }

            this.currentCamera   = camera;
            this.currentInput    = input;
            this.currentCollider = collider;
            InputManager.Instance.AddHandler(this);

            this.OnInput(input, collider, camera);
        }
コード例 #7
0
        protected override void OnInput(Lost.Input input, Collider collider, Camera camera)
        {
            if (input.InputState == InputState.Released)
            {
                if (this.doubleTappedEvent != null && collider.Raycast(camera.ScreenPointToRay(input.CurrentPosition), out RaycastHit hit, float.MaxValue))
                {
                    float newTapTime = Time.realtimeSinceStartup;

                    if (newTapTime - this.lastTapTimeSinceStartup < this.doubleTapTimeLength)
                    {
                        this.doubleTappedEvent.Invoke(hit);
                        this.lastTapTimeSinceStartup = 0;
                    }
                    else
                    {
                        this.lastTapTimeSinceStartup = newTapTime;
                    }
                }
            }
        }
コード例 #8
0
        protected override void OnInput(Lost.Input input, Collider collider, Camera camera)
        {
            base.OnInput(input, collider, camera);

            this.isFingerDown = input.InputState != InputState.Released;

            float inputSqrMagnatude = (input.PreviousPosition - input.CurrentPosition).sqrMagnitude;

            if (inputSqrMagnatude < this.minimumPixelMovementSquared)
            {
                this.fingerStillTime += Time.deltaTime;
            }
            else if (inputSqrMagnatude >= this.minimumPixelMovementSquared || input.InputState == InputState.Released)
            {
                this.fingerStillTime = 0.0f;
            }

            this.Rotation = Mathf.Clamp(this.Rotation, -360.0f + this.degreesPerNumber, 360.0f - this.degreesPerNumber);

            if (this.lastNumber != this.CurrentNumber)
            {
                this.lastNumber = this.CurrentNumber;
                this.numberChangedEvent.InvokeIfNotNull();
            }

            // the user let go, so record the number they left it on
            if (input.InputState == InputState.Released)
            {
                this.recentNumbers.Add(this.CurrentNumber);

                this.ShowTextEffect(this.CurrentNumber);

                while (this.recentNumbers.Count > this.unlockCombo.Length)
                {
                    this.recentNumbers.RemoveAt(0);
                }

                this.StartCoroutine(this.ReturnToCenterCoroutine());
            }
        }
コード例 #9
0
 protected override void OnInput(Lost.Input input, Collider collider, Camera camera)
 {
     // if (this.previousHitVector == InvalidVector && input.InputState == InputState.Pressed)
     // {
     //     if (collider.Raycast(camera.ScreenPointToRay(input.CurrentPosition), out RaycastHit previousHit, float.MaxValue))
     //     {
     //         this.previousHitVector = (previousHit.point - collider.transform.position).normalized;
     //         return;
     //     }
     // }
     // else if (this.previousHitVector == InvalidVector || Time.deltaTime == 0.0f)
     // {
     //     return;
     // }
     //
     // Transform colliderTransform = collider.transform;
     // Vector3 colliderPosition = colliderTransform.position;
     //
     // var moveVector = Vector3.zero;
     // moveVector += GetMoveVector(Axis.X, new Plane(colliderPosition, colliderPosition + colliderTransform.up, colliderPosition + colliderTransform.forward));
     // moveVector += GetMoveVector(Axis.Y, new Plane(colliderPosition, colliderPosition + colliderTransform.forward, colliderPosition + colliderTransform.right));
     // moveVector += GetMoveVector(Axis.Z, new Plane(colliderPosition, colliderPosition + colliderTransform.up, colliderPosition + colliderTransform.right));
     //
     // // Translate this movevector into worldspace and apply it to our this.objectToMove
     // var worldMoveVector = this.transform.localToWorldMatrix.MultiplyVector(moveVector);
     // this.objectToMove.transform.position += worldMoveVector;
     //
     // // this.previousHitVector = input.InputState == InputState.Released ? InvalidVector : currentHitVector;
     //
     // Vector3 GetMoveVector(Axis axis, Plane plane)
     // {
     //     Ray inputRay = camera.ScreenPointToRay(input.CurrentPosition);
     //
     //     float enter;
     //     if (plane.Raycast(inputRay, out enter) == false)
     //     {
     //         // if we didnt' hit the plane
     //         return Vector3.zero;
     //     }
     //
     //     // calculating the current hit vector
     //     Vector3 hitPoint = inputRay.GetPoint(enter);
     //     Vector3 currentHitVector = (hitPoint - collider.transform.position).normalized;
     //
     //     float cosTheta = Vector3.Dot(currentHitVector, this.previousHitVector);
     //     Vector3 cross = Vector3.Cross(this.previousHitVector, currentHitVector);
     //     float theta = 0.0f;
     //
     //     // NOTE [bgish]: Sometimes, if cosTheta is too close to 1, but slightly off (by 1 bit), it turns costTheta into a NaN and breaks every
     //     //               00111111 10000000 00000000 00000000 - C# thinks it's 1.00000000 and this is fine (0x3F800000)
     //     //               00111111 10000000 00000000 00000001 - C# thinks it's 1.00000000 and this is bad  (0x3F800001)
     //     //               Debug.Log("0x3F800000 = " + Mathf.Acos(BitConverter.ToSingle(BitConverter.GetBytes(0x3F800000), 0)));  // 0x3F800000 = 1
     //     //               Debug.Log("0x3F800001 = " + Mathf.Acos(BitConverter.ToSingle(BitConverter.GetBytes(0x3F800001), 0)));  // 0x3F800001 = NaN
     //     // if (cosTheta < 0.999999f)
     //     // {
     //     //     bool didFingerMove = (input.PreviousPosition - input.CurrentPosition).sqrMagnitude > minimumPixelMovementSquared;
     //     //
     //     //     if (didFingerMove)
     //     //     {
     //     //         Vector3 crossVector;
     //     //
     //     //         if (this.rotationalAxis == Axis.X)
     //     //         {
     //     //             crossVector = collider.transform.right;
     //     //         }
     //     //         else if (this.rotationalAxis == Axis.Y)
     //     //         {
     //     //             crossVector = collider.transform.up;
     //     //         }
     //     //         else if (this.rotationalAxis == Axis.Z)
     //     //         {
     //     //             crossVector = collider.transform.forward;
     //     //         }
     //     //         else
     //     //         {
     //     //             Debug.LogErrorFormat("CircleInteractable found unknown rotationalAxis {0}", this.rotationalAxis);
     //     //             crossVector = Vector3.zero;
     //     //         }
     //     //
     //     //         theta = Mathf.Acos(cosTheta) * 180.0f / Mathf.PI * (Vector3.Dot(cross, crossVector) > 0 ? 1 : -1);
     //     //     }
     //     // }
     //
     //     return Vector3.zero;
     // }
 }
コード例 #10
0
 protected abstract void OnInput(Lost.Input input, Collider collider, Camera camera);
コード例 #11
0
        protected override void OnInput(Lost.Input input, Collider collider, Camera camera)
        {
            if (this.previousHitVector == InvalidVector && input.InputState == InputState.Pressed)
            {
                if (collider.Raycast(camera.ScreenPointToRay(input.CurrentPosition), out RaycastHit hit, float.MaxValue))
                {
                    this.previousHitVector = (hit.point - collider.transform.position).normalized;
                    return;
                }
            }
            else if (this.previousHitVector == InvalidVector || Time.deltaTime == 0.0f)
            {
                return;
            }

            Transform colliderTransform = collider.transform;
            Vector3   colliderPosition  = colliderTransform.position;

            Plane interactablePlane;

            if (this.rotationalAxis == Axis.X)
            {
                interactablePlane = new Plane(colliderPosition, colliderPosition + colliderTransform.up, colliderPosition + colliderTransform.forward);
            }
            else if (this.rotationalAxis == Axis.Y)
            {
                interactablePlane = new Plane(colliderPosition, colliderPosition + colliderTransform.forward, colliderPosition + colliderTransform.right);
            }
            else if (this.rotationalAxis == Axis.Z)
            {
                interactablePlane = new Plane(colliderPosition, colliderPosition + colliderTransform.up, colliderPosition + colliderTransform.right);
            }
            else
            {
                Debug.LogError($"CircleInteractable found unknown rotationalAxis {this.rotationalAxis}", this);
                interactablePlane = default;
            }

            Ray inputRay = camera.ScreenPointToRay(input.CurrentPosition);

            if (interactablePlane.Raycast(inputRay, out float enter) == false)
            {
                // if we didnt' hit the plane
                this.rotationalVelocity = this.useRotationalVelocity ? this.previousVelocity : 0.0f;
                this.previousHitVector  = InvalidVector;
                this.previousVelocity   = 0.0f;

                return;
            }

            // calculating the current hit vector
            Vector3 hitPoint         = inputRay.GetPoint(enter);
            Vector3 currentHitVector = (hitPoint - collider.transform.position).normalized;

            float   cosTheta = Vector3.Dot(currentHitVector, this.previousHitVector);
            Vector3 cross    = Vector3.Cross(this.previousHitVector, currentHitVector);
            float   theta    = 0.0f;

            // NOTE [bgish]: Sometimes, if cosTheta is too close to 1, but slightly off (by 1 bit), it turns costTheta into a NaN and breaks every
            //               00111111 10000000 00000000 00000000 - C# thinks it's 1.00000000 and this is fine (0x3F800000)
            //               00111111 10000000 00000000 00000001 - C# thinks it's 1.00000000 and this is bad  (0x3F800001)
            //               Debug.Log("0x3F800000 = " + Mathf.Acos(BitConverter.ToSingle(BitConverter.GetBytes(0x3F800000), 0)));  // 0x3F800000 = 1
            //               Debug.Log("0x3F800001 = " + Mathf.Acos(BitConverter.ToSingle(BitConverter.GetBytes(0x3F800001), 0)));  // 0x3F800001 = NaN
            if (cosTheta < 0.999999f)
            {
                bool didFingerMove = (input.PreviousPosition - input.CurrentPosition).sqrMagnitude > this.minimumPixelMovementSquared;

                if (didFingerMove)
                {
                    Vector3 crossVector;

                    if (this.rotationalAxis == Axis.X)
                    {
                        crossVector = collider.transform.right;
                    }
                    else if (this.rotationalAxis == Axis.Y)
                    {
                        crossVector = collider.transform.up;
                    }
                    else if (this.rotationalAxis == Axis.Z)
                    {
                        crossVector = collider.transform.forward;
                    }
                    else
                    {
                        Debug.LogErrorFormat("CircleInteractable found unknown rotationalAxis {0}", this.rotationalAxis);
                        crossVector = Vector3.zero;
                    }

                    theta = Mathf.Acos(cosTheta) * 180.0f / Mathf.PI * (Vector3.Dot(cross, crossVector) > 0 ? 1 : -1);
                }
            }

            this.Rotation += theta;

            if (input.InputState == InputState.Released)
            {
                this.rotationalVelocity = this.useRotationalVelocity ? Mathf.Clamp(this.previousVelocity, -this.maxRotationalVelocity, this.maxRotationalVelocity) : 0.0f;
                this.previousVelocity   = 0.0f;
            }
            else
            {
                this.rotationalVelocity = 0.0f;
                this.previousVelocity   = theta / Time.deltaTime;
            }

            this.previousHitVector = input.InputState == InputState.Released ? InvalidVector : currentHitVector;
        }