コード例 #1
0
        public void SelectCamera()
        {
            player.CalculateInfo();
            if (timerHelper.controllerTimer >= CONTROLLER_THROTTLE)
            {
                // TODO: Take account movements of hands as well

                /* If user swining alot, an sample from x amount of time could tell if user is swinginig their hands in multiple directions
                 * (indicating meelee) or if they are steady
                 * Or if they have a rapid back and forth motion.
                 *
                 * Current Logic:
                 *
                 * While Aiming Forwards:
                 * If user turns their head to Right,  the direction left of the camera is true.
                 * the Left Angle, the controllers should be reverse of where the user is looking at.
                 * If looking completely down, user is most likely interacting with their inventory so show fps or full body
                 * If Looking up they are about to do something, so
                 */
                bool canSwapCamera = (timerHelper.globalTimer > pluginSettings.cameraSwapTimeLock);

                Vector3 averageHandPosition = player.handAverage;
                Vector3 handDirection;
                if (pluginSettings.rightHandDominant)
                {
                    handDirection = (player.leftHand.position - player.rightHand.position).normalized;
                }
                else
                {
                    handDirection = (player.rightHand.position - player.leftHand.position).normalized;
                }

                Vector3 headForwardPosition      = player.head.TransformPoint(Vector3.up * 0.05f);
                bool    areHandsAboveThreshold   = (headForwardPosition.y) > player.leftHand.position.y || (headForwardPosition.y) > player.rightHand.position.y;
                bool    isAimingTwoHandedForward = Mathf.Rad2Deg *
                                                   PluginUtility.GetConeAngle(player.head.position, averageHandPosition + handDirection * 4f, player.head.right) <
                                                   pluginSettings.cameraGunHeadAlignAngleTrigger * 1.2f;

                // player is looking down sights.
                if (!pluginSettings.disableGunCamera && areHandsAboveThreshold &&
                    Mathf.Abs(player.headRRadialDelta.x) < pluginSettings.controlMovementThreshold &&
                    Mathf.Abs(player.headRRadialDelta.y) < pluginSettings.controlVerticalMovementThreshold &&
                    isAimingTwoHandedForward && (canSwapCamera || pluginSettings.FPSCameraOverride) && !inGunMode)
                {
                    SetCamera(FPSCamera, true);
                    inGunMode = true;
                    SnapCamera(currentCamera);
                    timerHelper.ResetCameraGunTimer();
                    PluginLog.Log("ActionCameraDirector", "In FPS Override (two handed forward)");
                }
                else if (inGunMode && canSwapCamera)
                {
                    if (!(isAimingTwoHandedForward))
                    {
                        SnapCamera(lastCamera, true);
                        SetCamera(lastCamera);
                        PluginLog.Log("ActionCameraDirector", "Returning Back to earlier");
                        // Should actually just snap to the new positions instead, so
                    }
                    timerHelper.ResetCameraGunTimer();
                }
                else if (PluginUtility.AverageCosAngleOfControllers(player.rightHand, player.leftHand, player.headBelowDirection) < 45 &&
                         player.headRRadialDelta.y < -pluginSettings.controlVerticalMovementThreshold &&
                         !pluginSettings.disableFBTCamera && canSwapCamera)
                {
                    PluginLog.Log("ActionCameraDirector", "Pointing Down FullBody");

                    SetCamera(FullBodyActionCamera);
                }
                else if (PluginUtility.AverageCosAngleOfControllers(player.rightHand, player.leftHand, player.headAboveDirection) < 45 &&
                         player.headRRadialDelta.y > pluginSettings.controlVerticalMovementThreshold &&
                         !(pluginSettings.disableTopCamera && pluginSettings.disableFBTCamera) && canSwapCamera)
                {
                    // Hands Are Pointing up-ish, while head is moving up (probably checking on something, wrist, etc.)

                    PluginLog.Log("ActionCameraDirector", "Pointing Up, Moving Head Up: Tactical or FullBody");
                    if (randomizer.Next(0, 100) > 80 && !pluginSettings.disableTopCamera || pluginSettings.disableFBTCamera)
                    {
                        SetCamera(TacticalCamera);
                    }
                    else
                    {
                        SetCamera(FullBodyActionCamera);
                    }
                }
                // Looking Side to Side while pointing forwards. Action is ahead.
                else if ((PluginUtility.AverageCosAngleOfControllers(player.rightHand, player.leftHand, player.headForwardDirection) < 80) &&
                         Mathf.Abs(player.headRRadialDelta.x) > pluginSettings.controlMovementThreshold && canSwapCamera)
                {
                    PluginLog.Log("ActionCameraDirector", "Moving on Side, Shoulder");
                    SetCamera(OverShoulderCamera);
                }

                timerHelper.ResetControllerTimer();
            }
            HandleCameraView();
        }