public PlayableClipMixerState GetState(int stateId) { PlayableClipMixerState rlt = null; _states.TryGetValue(stateId, out rlt); return(rlt); }
private void OnAttackUpdate(PlayableClipMixerState state) { if (state.IsComplete()) { _stateMachine.ChangeState(0); } }
public void ChangeState(int stateId) { PlayableClipMixerState newState = GetState(stateId); if (newState == null) { return; } if (_currentState == newState) { return; } Debug.Log("change state:" + stateId); if (_currentState == null) { newState.Enter(); _currentState = newState; } else { _nextState = newState; _crossFade.SetData(_currentState, newState); _isCrossfading = true; } }
private void OnRunStateUpdate(PlayableClipMixerState state) { if (!Input.GetKey(KeyCode.W)) { _stateMachine.ChangeState(0); } }
private void OnIdleStateUpdate(PlayableClipMixerState obj) { if (Input.GetKey(KeyCode.W)) { _stateMachine.ChangeState(2); } if (Input.GetKey(KeyCode.K)) { _stateMachine.ChangeState(1); } }
public void SetData(PlayableClipMixerState prevMixerState, PlayableClipMixerState nextMixerState, float?duration = null) { _currentTime = 0; _prevMixerState = prevMixerState; _nextMixerState = nextMixerState; if (duration != null) { _duration = duration.GetValueOrDefault(); } }
public void Update(float dt) { if (_isCrossfading) { _crossFade.Update(dt); if (_crossFade.IsComplete()) { _isCrossfading = false; _currentState = _nextState; _nextState.Enter(); _nextState = null; } return; } _currentState.Update(dt); }
void Awake() { _btnChangeState.onClick.AddListener(OnBtnChangeStateClick); PlayableGraph graph = PlayableGraph.Create("test_play_queue_graph"); _graph = graph; graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); AnimationPlayableOutput animOutput = AnimationPlayableOutput.Create(graph, "anim", _animator); AnimationMixerPlayable mixer = AnimationMixerPlayable.Create(graph, _anims.Count); animOutput.SetSourcePlayable(mixer); for (int i = 0; i < _anims.Count; i++) { AnimationClipPlayable clipPlayable = AnimationClipPlayable.Create(graph, _anims[i]); graph.Connect(clipPlayable, 0, mixer, i); PlayableClipMixerState mixerState = new PlayableClipMixerState(i, clipPlayable, mixer, i); _stateMachine.AddState(mixerState); _stateIds.Add(mixerState.Id); } _stateMachine.SetCrossFadeDuration(0.1f); //attack->idle when anim finished _stateMachine.GetState(1).OnUpdate += OnAttackUpdate; _stateMachine.GetState(2).OnUpdate += OnRunStateUpdate; _stateMachine.GetState(0).OnUpdate += OnIdleStateUpdate; _stateMachine.ChangeState(0); graph.Play(); // for (int i = 0; i < mixer.GetInputCount(); i++) // { // Playable playable = mixer.GetInput(i); // Debug.Log(playable.GetPlayableType()); // } }
public void AddState(PlayableClipMixerState mixerState) { mixerState.StateMachine = this; _states.Add(mixerState.Id, mixerState); }