コード例 #1
0
        public void PrintContents()
        {
            Type type = typeof(ActionCameraConfig);

            FieldInfo[] properties = type.GetFields();


            foreach (FieldInfo property in properties)
            {
                PluginLog.Log("ActionCameraConfig", property.Name + " = " + property.GetValue(this));
            }
        }
コード例 #2
0
        public override void ApplyBehavior(ref Vector3 cameraTarget, ref Vector3 lookAtTarget, LivPlayerEntity player, bool isCameraAlreadyPlaced)
        {
            /**
             * Logic for betweenCamera
             * When Camera is triggering swap sides (when player moves head fast enough, and the direction does not match previous)
             *  use only the betweenCamera behavior.
             *  once timeBetween Change has been fully realized, then start applying current behavior as planned.
             */

            sbyte estimatedSide = (player.headRRadialDelta.x < 0 ? NEGATIVE_SBYTE : POSITIVE_SBYTE);

            if (!swappingSides && Mathf.Abs(player.headRRadialDelta.x) > pluginSettings.cameraShoulderSensitivity &&
                player.timerHelper.cameraActionTimer > GetBetweenTime() &&
                estimatedSide != currentSide)
            {
                PluginLog.Log("ShoulderCamera", "Swapping sides " + estimatedSide);
                swappingSides   = true;
                destinationSide = estimatedSide;
                player.timerHelper.ResetCameraActionTimer();
            }
            else if (swappingSides && player.timerHelper.cameraActionTimer > GetBetweenTime())
            {
                swappingSides = false;
                currentSide   = destinationSide;
                PluginLog.Log("ShoulderCamera", "Done Swapping");
                player.timerHelper.ResetCameraActionTimer();
            }

            if (swappingSides && pluginSettings.inBetweenCameraEnabled)
            {
                betweenCamera.ApplyBehavior(ref cameraTarget, ref lookAtTarget, player, isCameraAlreadyPlaced);
            }
            else
            {
                Vector3 cameraOffsetTarget = offset;
                sbyte   settingsReverse    = pluginSettings.reverseShoulder ? NEGATIVE_SBYTE : POSITIVE_SBYTE;

                cameraOffsetTarget.x = -currentSide *Mathf.Abs(cameraOffsetTarget.x) * settingsReverse;

                cameraTarget = player.head.TransformPoint(cameraOffsetTarget);

                // Floor and Ceiling Avoidance. Camera should not be too high or too low in ratio to player head position
                cameraTarget.y = Mathf.Clamp(cameraTarget.y, player.head.position.y * 0.2f, player.head.position.y * 1.2f);

                lookAtTarget = player.head.TransformPoint(lookAtOffset);

                if (pluginSettings.cameraVerticalLock)
                {
                    lookAtTarget.y = (player.waist.position.y + player.head.position.y) / 2;
                }
            }
        }
コード例 #3
0
        // Called when the Plugin is selected
        public void OnActivate(PluginCameraHelper helper)
        {
            PluginLog.Log("ActionCameraPlugin", "OnActivate");
            timerHelper = new TimerHelper();
            ConfigUtility utility = new ConfigUtility(_settings.configurationName);

            cameraDirector = new ActionCameraDirector(utility.Config, helper, ref timerHelper);

            AvatarManager avatarManager = Resources.FindObjectsOfTypeAll <AvatarManager>().FirstOrDefault();

            avatarRefSignal = avatarManager?.GetPrivateField <AvatarReferenceSignal>("_avatarInstantiated");
            avatarRefSignal?.OnChanged.AddListener(OnAvatarChanged);

            OnAvatarChanged(avatarRefSignal?.Value);
        }
コード例 #4
0
        // Next to FPS Camera, simplest Camerda
        public override void ApplyBehavior(ref Vector3 cameraTarget, ref Vector3 lookAtTarget, LivPlayerEntity player, bool isCameraAlreadyPlaced)
        {
            cameraTarget = player.head.TransformPoint(offset);
            lookAtTarget = player.head.TransformPoint(lookAtOffset);
            PluginLog.Log("SIMPLE CAMERA", "" + lookAtOffset);
            // average between Head and Waist to avoid head from flipping the camera around so much.s
            lookAtTarget = (lookAtTarget + player.waist.TransformPoint(lookAtOffset)) / 2;

            if (pluginSettings.cameraVerticalLock)
            {
                lookAtTarget.y = (player.waist.position.y + player.head.position.y) / 2;
            }

            cameraTarget.y = Mathf.Clamp(cameraTarget.y, player.head.position.y * 0.2f, player.head.position.y * 1.2f);
        }
コード例 #5
0
        public void CalculateOffset()
        {
            float radianAngle = Mathf.Deg2Rad * pluginSettings.cameraBodyAngle;

            float y = pluginSettings.cameraBodyDistance * Mathf.Cos(radianAngle);
            float x = pluginSettings.cameraBodyDistance * Mathf.Sin(radianAngle);

            Vector3 calculatedOffset = new Vector3(x, 0.4f, y);

            //  calculatedOffset.z = Mathf.Sqrt(Mathf.Abs(Mathf.Pow(offset.z, 2f) - Mathf.Pow(offset.x, 2f)));
            PluginLog.Log("FullBodyActionCamera", "Calculated Position " + calculatedOffset);
            offset         = calculatedOffset;
            lookAtOffset.y = pluginSettings.cameraBodyVerticalTargetOffset;
            lookAtOffset.z = pluginSettings.cameraBodyLookAtForward;
        }
コード例 #6
0
        public override void ApplyBehavior(ref Vector3 cameraTarget, ref Vector3 lookAtTarget, LivPlayerEntity player, bool isCameraAlreadyPlaced)
        {
            Vector3 cameraPositionOffsetTarget = offset;

            sbyte estimatedSide = (player.headRRadialDelta.x < 0 ? NEGATIVE_SBYTE : POSITIVE_SBYTE);

            if (!swappingSides && Mathf.Abs(player.headRRadialDelta.x) > pluginSettings.cameraBodySensitivity &&
                player.timerHelper.cameraActionTimer > GetBetweenTime() &&
                estimatedSide != currentSide)
            {
                PluginLog.Log("FullBodyActionCamera", "Swapping sides " + estimatedSide);
                swappingSides   = true;
                destinationSide = estimatedSide;
                player.timerHelper.ResetCameraActionTimer();
            }
            else if (swappingSides && player.timerHelper.cameraActionTimer > GetBetweenTime())
            {
                swappingSides = false;
                currentSide   = destinationSide;

                PluginLog.Log("FullBodyActionCamera", "Done Swapping ");
                player.timerHelper.ResetCameraActionTimer();
            }

            if (swappingSides && pluginSettings.inBetweenCameraEnabled)
            {
                betweenCamera.ApplyBehavior(ref cameraTarget, ref lookAtTarget, player, isCameraAlreadyPlaced);
            }
            else
            {
                sbyte settingsReverse = pluginSettings.reverseFBT ? NEGATIVE_SBYTE : POSITIVE_SBYTE;
                cameraPositionOffsetTarget.x = -currentSide *Mathf.Abs(cameraPositionOffsetTarget.x) * settingsReverse;

                cameraTarget = player.head.TransformPoint(cameraPositionOffsetTarget);

                // Floor and Ceiling Avoidance. Camera should not be too high or too low in ratio to player head position
                cameraTarget.y = Mathf.Clamp(cameraTarget.y, player.head.position.y * 0.2f, player.head.position.y * 1.2f);


                lookAtTarget = (player.waist.position + player.head.TransformPoint(lookAtOffset)) / 2;

                if (pluginSettings.cameraVerticalLock)
                {
                    lookAtTarget.y = (player.waist.position.y + player.head.position.y) / 2;
                }
            }
        }
コード例 #7
0
        public void SnapCamera(ActionCamera camera, bool revert = false)
        {
            PluginLog.Log("ActionCameraDirector", "SNAP ");
            camera.ApplyBehavior(ref cameraPositionTarget, ref cameraLookAtTarget, player, isCameraStatic);

            if (revert)
            {
                cameraLookAtVelocity = cameraLastLookAtVelocity;
                cameraVelocity       = cameraLastVelocity;
            }
            else
            {
                cameraLastLookAtVelocity = cameraLookAt;
                cameraLastVelocity       = cameraVelocity;
                cameraLookAtVelocity     = Vector3.zero;
                cameraVelocity           = Vector3.zero;
            }

            cameraPosition = cameraPositionTarget;
            cameraLookAt   = cameraLookAtTarget;
        }
コード例 #8
0
 // Called when Plugin component is destroyed.
 public void OnDestroy()
 {
     PluginLog.Log("ActionCameraPlugin", "OnDestroy");
 }
コード例 #9
0
 public void OnAvatarChanged(Avatar avatar)
 {
     PluginLog.Log("ActionCameraPlugin", "OnAvatarChanged ");
     cameraDirector.SetAvatar(avatar);
 }
コード例 #10
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();
        }