public void SaveToSnapshot(ref KinematicCharacterSubsystemState subsystemState)
        {
            subsystemState.CharacterStates.Clear();
            foreach (var c in Characters)
            {
                IdentifiedData <MyCharacterState> charState = new IdentifiedData <MyCharacterState>();

                charState.DataId = c.Key;

                charState.DataStruct.MotorState = c.Value.Motor.GetState();

                charState.DataStruct.JumpConsumed            = c.Value.JumpConsumed;
                charState.DataStruct.TimeSinceJumpRequested  = c.Value.TimeSinceJumpRequested;
                charState.DataStruct.TimeSinceLastAbleToJump = c.Value.TimeSinceLastAbleToJump;

                charState.DataStruct.IsStunned         = c.Value.IsStunned;
                charState.DataStruct.StunTimeRemaining = c.Value.StunTimeRemaining;

                subsystemState.CharacterStates.Add(charState);
            }

            for (int i = 0; i < MovingPlatforms.Length; i++)
            {
                subsystemState.MovingPlatformStates[i].MoverState   = MovingPlatforms[i].Mover.GetState();
                subsystemState.MovingPlatformStates[i].DirectorTime = (float)MovingPlatforms[i].Director.time;
            }
        }
        public void RestoreStateFromSnapshot(ref KinematicCharacterSubsystemState subsystemState)
        {
            foreach (IdentifiedData <MyCharacterState> charState in subsystemState.CharacterStates)
            {
                MyCharacterController c;
                if (Characters.TryGetValue(charState.DataId, out c))
                {
                    c.Motor.ApplyState(charState.DataStruct.MotorState, false);

                    c.JumpConsumed            = charState.DataStruct.JumpConsumed;
                    c.TimeSinceJumpRequested  = charState.DataStruct.TimeSinceJumpRequested;
                    c.TimeSinceLastAbleToJump = charState.DataStruct.TimeSinceLastAbleToJump;

                    c.IsStunned         = charState.DataStruct.IsStunned;
                    c.StunTimeRemaining = charState.DataStruct.StunTimeRemaining;
                }
            }

            for (int i = 0; i < MovingPlatforms.Length; i++)
            {
                MovingPlatforms[i].Mover.ApplyState(subsystemState.MovingPlatformStates[i].MoverState);
                MovingPlatforms[i].EvaluateAtTime(subsystemState.MovingPlatformStates[i].DirectorTime);
            }
        }
 public void InitializeSnapshot(ref KinematicCharacterSubsystemState subsystemState, int maxCharacters)
 {
     subsystemState.CharacterStates      = new List <IdentifiedData <MyCharacterState> >(maxCharacters);
     subsystemState.MovingPlatformStates = new MyMovingPlatformState[MovingPlatforms.Length];
 }