/// <summary> /// Called by the replay system when the object should return to a previous state. /// </summary> /// <param name="state">The state object to deserialize the animator from</param> public override void OnReplayDeserialize(ReplayState state) { // Check for animator if (observedAnimator == null) { return; } // Read the number of layers int layerCount = state.Read32(); // Check if we need to reallocate if (layerCount > animatorStates.Length) { animatorStates = new ReplayAnimatorState[layerCount]; } // Read all layer information for (int i = 0; i < layerCount; i++) { // Update last values animatorStates[i].lastHash = animatorStates[i].targetHash; animatorStates[i].lastNormalizedTime = animatorStates[i].targetNormalizedTime; // Deserialize animator values animatorStates[i].targetHash = state.Read32(); animatorStates[i].targetNormalizedTime = state.ReadFloat(); } // Check for paused if (ReplayManager.IsPaused == true) { observedAnimator.speed = 0; } }
/// <summary> /// Deserializes all active <see cref="ReplayVariable"/> from the state. /// </summary> /// <param name="state">The <see cref="ReplayState"/> to read the variable data from</param> protected virtual void ReplayDeserializeVariables(ReplayState state) { // Get the size short size = state.Read16(); // Read all variables for (int i = 0; i < size; i++) { bool matchedVariable = false; // Read the variable name hash int variableHash = state.Read32(); // Check for matching variable foreach (ReplayVariable variable in replayVariables) { // We have found a matching variable if (variable.Name.GetHashCode() == variableHash) { // Deserialize the variable variable.OnReplayDeserialize(state); matchedVariable = true; break; } } // We failed to resolve the state - we cannot continue reading because the state contains invalid data if (matchedVariable == false) { break; } } }