Exemple #1
0
        /// <summary>
        /// Updates the motor over time. This is called by the controller
        /// every update cycle so movement can be updated.
        /// </summary>
        /// <param name="rDeltaTime">Time since the last frame (or fixed update call)</param>
        /// <param name="rUpdateIndex">Index of the update to help manage dynamic/fixed updates. [0: Invalid update, >=1: Valid update]</param>
        /// <param name="rTiltAngle">Amount of tilting the camera needs to do to match the anchor</param>
        public override CameraTransform RigLateUpdate(float rDeltaTime, int rUpdateIndex, float rTiltAngle = 0f)
        {
            if (mPath == null)
            {
                return(mRigTransform);
            }
            if (RigController == null)
            {
                return(mRigTransform);
            }

            bool lHasArrived = false;

            if (mHasStarted && !mIsPaused)
            {
                float lSpeed = _Speed.Evaluate(DistanceTravelledNormalized);
                mDistanceTravelled += lSpeed * rDeltaTime;
            }

            if (mDistanceTravelled >= mPathLength)
            {
                if (_Loop)
                {
                    mDistanceTravelled -= mPathLength;
                }
                else
                {
                    mDistanceTravelled = mPathLength;
                }

                lHasArrived = true;
            }

            float lPercent = mDistanceTravelled / mPathLength;

            Vector3 lPosition = mPath.GetPoint(lPercent);

            if (mLastPosition == Vector3.zero)
            {
                mLastPosition = lPosition;
            }

            mRigTransform.Position = lPosition;

            if (_RotateToAnchor)
            {
                mRigTransform.Rotation = Quaternion.LookRotation(AnchorPosition - lPosition, Vector3.up);
            }
            else if (_RotateToMovementDirection)
            {
                if ((lPosition - mLastPosition).sqrMagnitude != 0f)
                {
                    mRigTransform.Rotation = Quaternion.LookRotation(lPosition - mLastPosition, Vector3.up);
                }
            }

            mLastPosition = lPosition;

            if (lHasArrived && mHasStarted)
            {
                if (_ActivateMotorOnComplete)
                {
                    if (_EndMotorIndex >= 0 && _EndMotorIndex < RigController.Motors.Count)
                    {
                        RigController.ActivateMotor(_EndMotorIndex);
                    }
                }

                if (RigController.MotorArrived != null)
                {
                    RigController.MotorArrived(this);
                }

                // Send the message
                CameraMessage lMessage = CameraMessage.Allocate();
                lMessage.ID    = 204;
                lMessage.Motor = this;

                if (RigController.ActionTriggeredEvent != null)
                {
                    RigController.ActionTriggeredEvent.Invoke(lMessage);
                }

#if USE_MESSAGE_DISPATCHER || OOTII_MD
                MessageDispatcher.SendMessage(lMessage);
#endif

                CameraMessage.Release(lMessage);

                // Reset the flags
                if (!_Loop)
                {
                    mHasStarted = false;
                }
            }

            return(mRigTransform);
        }
Exemple #2
0
        /// <summary>
        /// Updates the motor over time. This is called by the controller
        /// every update cycle so movement can be updated.
        /// </summary>
        /// <param name="rDeltaTime">Time since the last frame (or fixed update call)</param>
        /// <param name="rUpdateIndex">Index of the update to help manage dynamic/fixed updates. [0: Invalid update, >=1: Valid update]</param>
        /// <param name="rTiltAngle">Amount of tilting the camera needs to do to match the anchor</param>
        public override CameraTransform RigLateUpdate(float rDeltaTime, int rUpdateIndex, float rTiltAngle = 0f)
        {
            if (mPath == null)
            {
                return(mRigTransform);
            }
            if (RigController == null)
            {
                return(mRigTransform);
            }

            bool lHasArrived = false;

            if (mHasStarted && !mIsPaused)
            {
                float lSpeed = _Speed.Evaluate(DistanceTravelledNormalized);
                mDistanceTravelled += lSpeed * rDeltaTime;
            }

            if (mDistanceTravelled >= mPathLength)
            {
                if (_Loop)
                {
                    mDistanceTravelled -= mPathLength;
                }
                else
                {
                    mDistanceTravelled = mPathLength;
                }

                lHasArrived = true;
            }

            float lPercent = mDistanceTravelled / mPathLength;

            Vector3 lPosition = mPath.GetPoint(lPercent);

            if (mLastPosition == Vector3.zero)
            {
                mLastPosition = lPosition;
            }

            mRigTransform.Position = lPosition;

            if (_RotateToAnchor)
            {
                mRigTransform.Rotation = Quaternion.LookRotation(AnchorPosition - lPosition, Vector3.up);
            }
            else if (_RotateToMovementDirection)
            {
                if ((lPosition - mLastPosition).sqrMagnitude != 0f)
                {
                    mRigTransform.Rotation = Quaternion.LookRotation(lPosition - mLastPosition, Vector3.up);
                }
            }

            mLastPosition = lPosition;

            if (lHasArrived && mHasStarted)
            {
                if (_ActivateMotorOnComplete)
                {
                    if (_EndMotorIndex >= 0 && _EndMotorIndex < RigController.Motors.Count)
                    {
                        RigController.ActivateMotor(_EndMotorIndex);
                    }
                }

                if (RigController.MotorArrived != null)
                {
                    RigController.MotorArrived(this);
                }

                if (!_Loop)
                {
                    mHasStarted = false;
                }
            }

            return(mRigTransform);
        }