Пример #1
0
        /// <summary>
        /// Returns element pressed up state.
        /// </summary>
        /// <param name="chirality">Controller chirality</param>
        /// <param name="element">Controller element</param>
        /// <returns>Was the controller element pressed up</returns>
        public static bool GetPressUp(FinchChirality chirality, FinchControllerElement element)
        {
            bool leftUp  = FinchInput.GetPressUp(FinchNodeType.LeftHand, element);
            bool rightUp = FinchInput.GetPressUp(FinchNodeType.RightHand, element);

            bool leftPress  = FinchInput.GetPress(FinchNodeType.LeftHand, element);
            bool rightPress = FinchInput.GetPress(FinchNodeType.RightHand, element);

            switch (chirality)
            {
            case FinchChirality.Right:
                return(rightUp);

            case FinchChirality.Left:
                return(leftUp);

            case FinchChirality.Any:
                return(leftUp || rightUp);

            case FinchChirality.Both:
                return(leftUp && !rightPress || rightUp && !leftPress);

            default:
                return(false);
            }
        }
Пример #2
0
        private void BatteryUpdate()
        {
            if (BatteryObject == null)
            {
                return;
            }

            bool isBatteryActive = (FinchInput.IsConnected(controller.Node)) && BatteryLevels.Length > 0;

            if (BatteryObject.gameObject.activeSelf != isBatteryActive)
            {
                BatteryObject.gameObject.SetActive(isBatteryActive);
            }

            float currentBatteryLevel = Mathf.Clamp(FinchInput.GetBatteryCharge(controller.Node), 0f, 99.9f);

            if (isBatteryActive && Math.Abs(currentBatteryLevel - batteryLevel) > chargeLevelEpsilon)
            {
                Sprite batterySprite = null;
                float  maxBorder     = 0;

                batteryLevel = currentBatteryLevel;

                foreach (BatteryLevel i in BatteryLevels)
                {
                    if (currentBatteryLevel > i.MinimumBatteryBorder && maxBorder <= i.MinimumBatteryBorder)
                    {
                        maxBorder     = i.MinimumBatteryBorder;
                        batterySprite = i.BatteryMaterial;
                    }
                }

                BatteryObject.sprite = batterySprite;
            }
        }
Пример #3
0
        public override void Init(int id)
        {
            base.Init(id);

            if (FinchCore.Interop.FinchIsUpperArmReverted(FinchCore.Interop.FinchChirality.Left) == 1)
            {
                FinchCore.Interop.FinchRevertUpperArm(FinchCore.Interop.FinchChirality.Left);
            }

            if (FinchCore.Interop.FinchIsUpperArmReverted(FinchCore.Interop.FinchChirality.Right) == 1)
            {
                FinchCore.Interop.FinchRevertUpperArm(FinchCore.Interop.FinchChirality.Right);
            }

            FinchCore.Interop.FinchResetCalibration(FinchCore.Interop.FinchChirality.Left);
            FinchCore.Interop.FinchResetCalibration(FinchCore.Interop.FinchChirality.Right);

            bool rightDifferentNodes = FinchController.Right.IsConnected && FinchInput.IsConnected(FinchNodeType.LeftUpperArm);
            bool leftDifferentNodes  = FinchController.Left.IsConnected && FinchInput.IsConnected(FinchNodeType.RightUpperArm);

            if (FinchCore.NodesState.GetUpperArmCount() == 1 && (rightDifferentNodes || leftDifferentNodes))
            {
                FinchCore.SwapNodes(FinchNodeType.LeftUpperArm, FinchNodeType.RightUpperArm);
            }

            tremblePass    = FinchCore.NodesState.GetUpperArmCount() < 2;
            leftArmShaking = false;

            ResetValue();
            TryPassStepWithoutRedefine();
        }
Пример #4
0
        /// <summary>
        /// Returns time of pressing.
        /// </summary>
        /// <param name="chirality">Controller chirality</param>
        /// <param name="element">Controller element</param>
        /// <returns>Controller element pressing time.</returns>
        public static float GetPressTime(FinchChirality chirality, FinchControllerElement element)
        {
            if (chirality > FinchChirality.Left)
            {
                throw new ArgumentException();
            }

            return(FinchInput.GetPressTime((FinchNodeType)chirality, element));
        }
Пример #5
0
 private FinchChirality GetUpperArmChirality()
 {
     if (FinchInput.IsConnected(FinchNodeType.LeftHand))
     {
         return(FinchChirality.Left);
     }
     else
     {
         return(FinchChirality.Right);
     }
 }
        private void TryPassStepWithRedefine()
        {
            timeLeft -= Time.deltaTime;

            waitingResult |= timeLeft > TimeErrorShow;

            if (timeLeft > TimeErrorShow)
            {
                leftArm.UpdateState();
                rightArm.UpdateState();
            }

            bool leftToRightRatio = leftArm.TrembleCount / Mathf.Max(rightArm.TrembleCount, epsilon) > accelerationRatio;
            bool rightToLeftRatio = rightArm.TrembleCount / Mathf.Max(leftArm.TrembleCount, epsilon) > accelerationRatio;

            bool tremble = Mathf.Max(leftArm.TrembleCount, rightArm.TrembleCount) > minShakingCount && (leftToRightRatio || rightToLeftRatio);
            bool leftDirectionCorrect  = !FinchInput.IsConnected(FinchNodeType.LeftUpperArm) || leftArm.DirectionPass;
            bool rightDirectionCorrect = !FinchInput.IsConnected(FinchNodeType.RightUpperArm) || rightArm.DirectionPass;
            bool twoUpperArms          = FinchCore.NodesState.GetUpperArmCount() == 2;

            if (timeLeft < TimeErrorShow || tremble && !tremblePass)
            {
                if (waitingResult)
                {
                    waitingResult = false;

                    if ((tremblePass || tremble) && leftDirectionCorrect && rightDirectionCorrect)
                    {
                        BindsOrientation(leftToRightRatio && twoUpperArms);
                        BindsChirality(leftToRightRatio && twoUpperArms);
                        BindUpperArms();
                        NextStep();
                        return;
                    }

                    if (tremble && !tremblePass)
                    {
                        BindsChirality(leftToRightRatio && twoUpperArms);
                        tremblePass = true;
                        ResetValue();
                        return;
                    }

                    WarningImage.sprite        = tremblePass ? WarningArmsDown : WarningShake;
                    WarningNotification.sprite = GetErrorSprite(tremble || tremblePass);
                }

                if (timeLeft < 0)
                {
                    ResetValue();
                }
            }
        }
Пример #7
0
        private void TryBindChiralityManually()
        {
            bool pressLeft  = FinchInput.GetPressDown(FinchNodeType.LeftUpperArm, FinchControllerElement.HomeButton);
            bool pressRight = FinchInput.GetPressDown(FinchNodeType.RightUpperArm, FinchControllerElement.HomeButton);

            if (pressLeft || pressRight)
            {
                if (pressLeft)
                {
                    FinchCore.SwapNodes(FinchNodeType.LeftUpperArm, FinchNodeType.RightUpperArm);
                }

                if (!tremblePass)
                {
                    ResetValue();
                    tremblePass = true;
                }
            }
        }
Пример #8
0
        private void TryPassStepWithRedefine()
        {
            if (Time.time <= timeGetResult)
            {
                leftArm.UpdateState();
                rightArm.UpdateState();
            }

            bool leftToRightRatio = leftArm.TrembleCount / Mathf.Max(rightArm.TrembleCount, epsilon) > accelerationRatio;
            bool rightToLeftRatio = rightArm.TrembleCount / Mathf.Max(leftArm.TrembleCount, epsilon) > accelerationRatio;

            bool tremble = Mathf.Max(leftArm.TrembleCount, rightArm.TrembleCount) > minShakingCount && (leftToRightRatio || rightToLeftRatio);
            bool leftDirectionCorrect  = !FinchInput.IsConnected(FinchNodeType.LeftUpperArm) || leftArm.DirectionPass;
            bool rightDirectionCorrect = !FinchInput.IsConnected(FinchNodeType.RightUpperArm) || rightArm.DirectionPass;
            bool swapNodes             = FinchCore.NodesState.GetUpperArmCount() == 2 && leftToRightRatio;

            if (Time.time > timeGetResult || tremble && !tremblePass)
            {
                if ((tremblePass || tremble) && leftDirectionCorrect && rightDirectionCorrect)
                {
                    BindsOrientation(swapNodes);
                    BindsChirality(swapNodes);
                    BindUpperArms();
                    NextStep();
                    return;
                }

                if (tremble && !tremblePass)
                {
                    BindsChirality(leftToRightRatio);
                    tremblePass = true;
                    ResetValue();
                    return;
                }

                leftArmShaking = Mathf.Max(leftArm.TrembleCount, rightArm.TrembleCount) > minShakingCount;

                ResetValue();
            }
        }
Пример #9
0
        private void OnAnimatorIK(int layerIndex)
        {
            PlayerAnimator.SetLookAtWeight(0.0f, 0.0f, 1.0f, 1.0f, 0.25f);
            transform.rotation = FinchInput.GetBoneRotation(FinchBone.Chest, fPose: false);
            transform.position = FinchInput.GetBonePosition(FinchBone.Chest) + Vector3.up * Floor;

            PlayerAnimator.SetLookAtPosition(FinchInput.GetBonePosition(FinchBone.Head));

            PlayerAnimator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1);
            PlayerAnimator.SetIKRotationWeight(AvatarIKGoal.RightHand, 1);
            PlayerAnimator.SetIKHintPositionWeight(AvatarIKHint.RightElbow, 1);

            PlayerAnimator.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1);
            PlayerAnimator.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1);
            PlayerAnimator.SetIKHintPositionWeight(AvatarIKHint.LeftElbow, 1);

            PlayerAnimator.SetIKPosition(AvatarIKGoal.RightHand, FinchInput.GetBonePosition(FinchBone.RightHand));
            PlayerAnimator.SetIKRotation(AvatarIKGoal.RightHand, FinchInput.GetBoneRotation(FinchBone.RightHand, fPose: false) * Quaternion.Euler(0, 90.0f, 0));
            PlayerAnimator.SetIKHintPosition(AvatarIKHint.RightElbow, FinchInput.GetBonePosition(FinchBone.RightLowerArm));

            PlayerAnimator.SetIKPosition(AvatarIKGoal.LeftHand, FinchInput.GetBonePosition(FinchBone.LeftHand));
            PlayerAnimator.SetIKRotation(AvatarIKGoal.LeftHand, FinchInput.GetBoneRotation(FinchBone.LeftHand, fPose: false) * Quaternion.Euler(0, -90.0f, 0));
            PlayerAnimator.SetIKHintPosition(AvatarIKHint.LeftElbow, FinchInput.GetBonePosition(FinchBone.LeftLowerArm));
        }
 private void Update()
 {
     transform.position = FinchInput.GetPosition(Chirality);
     transform.rotation = FinchInput.GetRotation(Chirality);
 }
Пример #11
0
 /// <summary>
 /// Returns time of pressing.
 /// </summary>
 /// <param name="element">Controller element</param>
 /// <returns>Controller element press time state.</returns>
 public float GetPressTime(FinchControllerElement element)
 {
     return(FinchInput.GetPressTime(Node, element));
 }
Пример #12
0
 /// <summary>
 /// Returns element pressed up state.
 /// </summary>
 /// <param name="element">Controller element</param>
 /// <returns>Was the controller element pressed up</returns>
 public bool GetPressUp(FinchControllerElement element)
 {
     return(FinchInput.GetPressUp(Node, element));
 }
Пример #13
0
 /// <summary>
 /// Returns time of pressing.
 /// </summary>
 /// <param name="chirality">Controller chirality</param>
 /// <param name="element">Controller element</param>
 /// <returns>Controller element pressing time.</returns>
 public static float GetPressTime(FinchChirality chirality, FinchControllerElement element)
 {
     return(FinchInput.GetPressTime((FinchNodeType)chirality, element));
 }