Пример #1
0
        /// <summary>
        /// Pulls an object from the pool.
        /// </summary>
        /// <returns></returns>
        public new static CameraMessage Allocate()
        {
            // Grab the next available object
            CameraMessage lInstance = sPool.Allocate();

            if (lInstance == null)
            {
                lInstance = new CameraMessage();
            }

            // Reset the sent flags. We do this so messages are flagged as 'completed'
            // by default.
            lInstance.IsSent    = false;
            lInstance.IsHandled = false;

            // For this type, guarentee we have something
            // to hand back tot he caller
            return(lInstance);
        }
Пример #2
0
        /// <summary>
        /// Returns an element back to the pool.
        /// </summary>
        /// <param name="rEdge"></param>
        public static void Release(CameraMessage rInstance)
        {
            if (rInstance == null)
            {
                return;
            }

            // We should never release an instance unless we're
            // sure we're done with it. So clearing here is fine
            rInstance.Clear();

            // Reset the sent flags. We do this so messages are flagged as 'completed'
            // and removed by default.
            rInstance.IsSent    = true;
            rInstance.IsHandled = true;

            // Make it available to others.
            sPool.Release(rInstance);
        }
Пример #3
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);
        }