示例#1
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;
            }
        }
        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();
        }
示例#3
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();
                }
            }
        }
        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();
            }
        }