/// <summary> /// Update the animation/FSM state for the player. /// </summary> /// <param name="player">The player character.</param> /// <param name="driver">The state driver for the target state.</param> /// <param name="playable">The playable associated with this clip.</param> /// <param name="pose">Information about the player's pose.</param> private void UpdateState(PlayerCharacter player, StateDriver driver, Playable playable, PoseInfo pose) { if (driver == null) { return; } #if UNITY_EDITOR if (Application.isPlaying) { #endif if (!driver.IsInState(player.FSM)) { driver.ForceStateChangeOn(player.FSM); } #if UNITY_EDITOR } else { // In-Editor we don't want to actually change the Finite State Machine, // so just play the appropriate animation. float totalTrackTime = (float)playable.GetTime(); float currentTimeInClip = totalTrackTime - pose.StartTime; driver.SampleClip(player.FSM, currentTimeInClip); } #endif }
//------------------------------------------------------------------------- // Auto Node API //------------------------------------------------------------------------- public override void Handle(GraphEngine graphEngine) { if (State != null) { Type t = Type.GetType(State); if (t != null) { StateDriver driver = StateDriver.For(State); if (!driver.IsInState(GameManager.Player.FSM)) { driver.ForceStateChangeOn(player.FSM); } } } }
/// <summary> /// Restore the state the player's state machine was in. /// </summary> /// <param name="player">The player character.</param> public void RestoreState(PlayerCharacter player) { #if UNITY_EDITOR if (Application.isPlaying) { #endif if (driver != null && !driver.IsInState(player.FSM)) { driver.ForceStateChangeOn(player.FSM); } player.SetFacing(facing); player.gameObject.SetActive(active); player.Sprite.sprite = sprite; #if UNITY_EDITOR } #endif }