/// <summary> /// Adds the current state to the list /// </summary> void PushState() { EnemyTimeState ets = new EnemyTimeState(); ets.position = rb2d.position; ets.rotation = rb2d.rotation; ets.linearVelocity = rb2d.velocity; ets.angularVelocity = rb2d.angularVelocity; ets.isDead = isDead; ets.isReallyDead = isReallyDead; ets.moveTimerSecondsLeft = moveTimer.SecondsLeft; ets.movingLeft = movingLeft; states.Add(ets); }
/// <summary> /// Sets the files of the gameObject according to the last stored state /// </summary> void PopState() { int lastIndex = states.Count - 1; if (lastIndex > -1) { // pop the state from the list EnemyTimeState lastState = states[lastIndex]; states.RemoveAt(lastIndex); // Resurrect if currently dead if (isReallyDead & !lastState.isReallyDead) { ReallyResurrect(); } else if (isDead && !lastState.isDead) { Resurrect(); } // set the fields according to the current state rb2d.position = lastState.position; rb2d.rotation = lastState.rotation; rb2d.velocity = lastState.linearVelocity; rb2d.angularVelocity = lastState.angularVelocity; isDead = lastState.isDead; isReallyDead = lastState.isReallyDead; moveTimer.Duration = lastState.moveTimerSecondsLeft; movingLeft = lastState.movingLeft; } else { // no states left ... // Despawn if gameObject has a spawner if (spawner) { // vanish Destroy(gameObject); //EventManager.RemoveKnightDeathInvoker(this); EventManager.RemoveEnemyDeathInvoker(spawner, this); } } }