Пример #1
0
        /// <summary>
        /// Called by the replay system when the object should be recorded.
        /// </summary>
        /// <param name="state">The state object to serialize the animator into</param>
        public override void OnReplaySerialize(ReplayState state)
        {
            // Check for animator
            if (observedAnimator == null)
            {
                return;
            }

            // Calcualte the number of layers we want to serialize
            int layerCount = (recordAllLayers == true) ? observedAnimator.layerCount : 1;

            //// Write the layer count
            state.Write(layerCount);

            // Serialize all layer info
            for (int i = 0; i < layerCount; i++)
            {
                // Get the current animator state
                AnimatorStateInfo info = observedAnimator.GetCurrentAnimatorStateInfo(i);

                // Get the normalized time
                float normalizedTime = info.normalizedTime;

                // Store the state information
                state.Write(info.fullPathHash);
                state.Write(normalizedTime);
            }
        }
Пример #2
0
        /// <summary>
        /// Serializes all active <see cref="ReplayVariable"/> to the state.
        /// </summary>
        /// <param name="state">The <see cref="ReplayState"/> to write the varaible data to</param>
        protected virtual void ReplaySerializeVariables(ReplayState state)
        {
            // Get size
            short size = (short)replayVariables.Length;

            // Write the size to the state
            state.Write(size);

            // Write all variables
            foreach (ReplayVariable variable in replayVariables)
            {
                // Write the hash code of the name so we can identify the data later
                state.Write(variable.Name.GetHashCode());

                // Write the variable to the state
                variable.OnReplaySerialize(state);
            }
        }
Пример #3
0
        /// <summary>
        /// Serializes all awaiting <see cref="ReplayEvent"/> to the state.
        /// </summary>
        /// <param name="state">The <see cref="ReplayState"/> to write the varaible data to</param>
        protected virtual void ReplaySerializeEvents(ReplayState state)
        {
            // Get the number of events
            short size = (short)replayEvents.Count;

            // Write the size to the state
            state.Write(size);

            // Write all events
            while (replayEvents.Count > 0)
            {
                // Get the next event
                ReplayEvent evt = replayEvents.Dequeue();

                // Write the event id
                state.Write(evt.eventID);

                // Write the size and event data
                state.Write((byte)evt.eventData.Size);
                state.Write(evt.eventData);
            }
        }
Пример #4
0
        /// <summary>
        /// Called by the replay system when this <see cref="ReplayObject"/> should serialize its replay data.
        /// </summary>
        /// <param name="state">The <see cref="ReplayState"/> to serialize the data to</param>
        public void OnReplaySerialize(ReplayState state)
        {
            // Check for empty components
            if (observedComponents.Length == 0)
            {
                return;
            }

            // Always write the prefab name
            state.Write(prefabIdentity);

            // Serialize all components
            foreach (ReplayBehaviour behaviour in observedComponents)
            {
                // Check for destroyed components
                if (behaviour == null)
                {
                    continue;
                }

                // Clear the shared buffer
                behaviourState.Clear();

                // Serialzie the behaviour
                behaviour.OnReplaySerialize(behaviourState);

                // Check for no data - dont waste memory and time serializing nothing
                if (behaviourState.Size == 0)
                {
                    continue;
                }

                // Write the meta data
                state.Write(behaviour.Identity);
                state.Write((short)behaviourState.Size);

                state.Write(behaviourState);
            }
        }
Пример #5
0
        public override void OnReplaySerialize(ReplayState state)
        {
            // Require particle system
            if (observedParticleSystem == null)
            {
                return;
            }

            // Check for playing particles system - Dont waste data when nothing is happening
            //if (particles.isPlaying == false)
            //    return;

            // Write particle time
            state.Write(observedParticleSystem.time);
        }
Пример #6
0
        /// <summary>
        /// Called by the replay system when all replay state information should be serialized.
        /// </summary>
        /// <param name="state">The <see cref="ReplayState"/> to write the data to</param>
        public virtual void OnReplaySerialize(ReplayState state)
        {
#if UNITY_EDITOR
            // Serialize may be called by the editor in which case we will need to find variables on each call
            if (Application.isPlaying == false)
            {
                ReplayFindVariables();
            }
#endif

            ReplayBehaviourDataFlags flags = ReplayBehaviourDataFlags.None;

            // Generate the data flags so we can read the correct data back
            if (replayEvents.Count > 0)
            {
                flags |= ReplayBehaviourDataFlags.Events;
            }
            if (replayVariables.Length > 0)
            {
                flags |= ReplayBehaviourDataFlags.Variables;
            }

            // Always write the flag byte
            state.Write((byte)flags);

            // Serialize replay events
            if ((flags & ReplayBehaviourDataFlags.Events) != 0)
            {
                // Serialize all events
                ReplaySerializeEvents(state);
            }

            // Serialize all replay variables by default
            if ((flags & ReplayBehaviourDataFlags.Variables) != 0)
            {
                // Serialize all variables
                ReplaySerializeVariables(state);
            }
        }
        /// <summary>
        /// Called by the replay system when the object should be recorded.
        /// </summary>
        /// <param name="state">The state object to serialize the transform into</param>
        public override void OnReplaySerialize(ReplayState state)
        {
            // Calcualte the flags
            ReplayTransformFlags flags = 0;

            // Build the flag information
            if (recordPosition != ReplayTransformRecordSpace.None)
            {
                flags |= ReplayTransformFlags.Position;

                if (recordPosition == ReplayTransformRecordSpace.Local)
                {
                    flags |= ReplayTransformFlags.LocalPosition;
                }
            }
            if (recordRotation != ReplayTransformRecordSpace.None)
            {
                flags |= ReplayTransformFlags.Rotation;

                if (recordRotation == ReplayTransformRecordSpace.Local)
                {
                    flags |= ReplayTransformFlags.LocalRotation;
                }
            }
            if (recordScale == true)
            {
                flags |= ReplayTransformFlags.Scale;
            }

            // Check for any flags
            if (flags == 0)
            {
                return;
            }

            // Check for low precision
            if (lowPrecision == true)
            {
                flags |= ReplayTransformFlags.LowPrecision;
            }

            // Write the flags
            state.Write((short)flags);

            // Check for low precision mode
            if (lowPrecision == false)
            {
                // Write the position
                if ((flags & ReplayTransformFlags.Position) != 0)
                {
                    if ((flags & ReplayTransformFlags.LocalPosition) != 0)
                    {
                        state.Write(transform.localPosition);
                    }
                    else
                    {
                        state.Write(transform.position);
                    }
                }

                // Write the rotation
                if ((flags & ReplayTransformFlags.Rotation) != 0)
                {
                    if ((flags & ReplayTransformFlags.LocalRotation) != 0)
                    {
                        state.Write(transform.localRotation);
                    }
                    else
                    {
                        state.Write(transform.rotation);
                    }
                }

                // Write the scale
                if ((flags & ReplayTransformFlags.Scale) != 0)
                {
                    state.Write(transform.localScale);
                }
            }
            else
            {
                // Write the position
                if ((flags & ReplayTransformFlags.Position) != 0)
                {
                    if ((flags & ReplayTransformFlags.LocalPosition) != 0)
                    {
                        state.WriteLowPrecision(transform.localPosition);
                    }
                    else
                    {
                        state.WriteLowPrecision(transform.position);
                    }
                }

                // Write the rotation
                if ((flags & ReplayTransformFlags.Rotation) != 0)
                {
                    if ((flags & ReplayTransformFlags.LocalRotation) != 0)
                    {
                        state.WriteLowPrecision(transform.localRotation);
                    }
                    else
                    {
                        state.WriteLowPrecision(transform.rotation);
                    }
                }

                // Write the scale
                if ((flags & ReplayTransformFlags.Scale) != 0)
                {
                    state.WriteLowPrecision(transform.localScale);
                }
            }
        }