예제 #1
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);
            }
        }
예제 #2
0
        /// <summary>
        /// Called by the replay system when all replay state information should be deserialized.
        /// </summary>
        /// <param name="state">The <see cref="ReplayState"/> to read the data from</param>
        public virtual void OnReplayDeserialize(ReplayState state)
        {
            // Check if we can read
            if (state.EndRead == true)
            {
                return;
            }

            // Get the flag byte
            ReplayBehaviourDataFlags flags = (ReplayBehaviourDataFlags)state.ReadByte();

            // Deserialize events if there are any
            if ((flags & ReplayBehaviourDataFlags.Events) != 0)
            {
                ReplayDeserializeEvents(state);
            }

            // Deserialize variables if there are any
            if ((flags & ReplayBehaviourDataFlags.Variables) != 0)
            {
                ReplayDeserializeVariables(state);
            }
        }