//次のアニメーションのプレイアブル作成 private void SetNextAnimationPlayable() { if (setPlayAnimation != null && playableGraph.IsValid()) { if (mixer.IsValid()) { playableGraph.Disconnect(mixer, 0); playableGraph.Disconnect(mixer, 1); } else { mixer = AnimationMixerPlayable.Create(playableGraph, 2, true); var output = AnimationPlayableOutput.Create(playableGraph, "output", GetComponent <Animator>()); output.SetSourcePlayable(mixer); } if (_beforePlayAnimation.IsValid()) { _beforePlayAnimation.Destroy(); } if (_nowPlayAnimation.IsValid()) { _beforePlayAnimation = _nowPlayAnimation; } //今のアニメーションに設定 nowPlayAnimation = setPlayAnimation; _beforeNowPlayClip = nowPlayAnimation; setPlayAnimation = null; //アニメーションプレイアブル作成 _nowPlayAnimation = AnimationClipPlayable.Create(playableGraph, nowPlayAnimation); mixer.ConnectInput(0, _nowPlayAnimation, 0); mixer.ConnectInput(1, _beforePlayAnimation, 0); } }
/// <summary> /// We generate some extra states at times to handle blending properly. This cleans out the ones of those that are done blending out. /// </summary> private void ClearFinishedTransitionStates() { var currentInputCount = stateMixer.GetInputCount(); for (int i = currentInputCount - 1; i >= states.Count; i--) { if (stateMixer.GetInputWeight(i) < 0.01f) { activeWhenBlendStarted.RemoveAt(i); valueWhenBlendStarted.RemoveAt(i); var removedPlayable = stateMixer.GetInput(i); removedPlayable.Destroy(); //Shift all excess playables one index down. for (int j = i + 1; j < stateMixer.GetInputCount(); j++) { var playable = stateMixer.GetInput(j); var weight = stateMixer.GetInputWeight(j); containingGraph.Disconnect(stateMixer, j); containingGraph.Connect(playable, 0, stateMixer, j - 1); stateMixer.SetInputWeight(j - 1, weight); } stateMixer.SetInputCount(stateMixer.GetInputCount() - 1); } } }
public void ClickClose() { // ...这里暂无判空等检测 graph.Disconnect(mixer, 0); graph.Disconnect(mixer, 1); graph.DestroyPlayable(mixer); graph.DestroyOutput(output); // cube位置会停在销毁的时刻 }
//別のAnimationが次に再生するアニメーションとしてセットされたらPlayableを変更する private void SetAnimationPlayable() { //次に再生するアニメーションが登録されていればアニメーションを変更 if (setClip != null) { frameCount = 0; if (playableGraph.IsValid() && mixer.IsValid()) { mixer.SetTime(0); nowClipPlayable.SetTime(0); if (beforeClipPlayable.IsValid()) { beforeClipPlayable.SetTime(0); } } //mixerがすでに生成されていればmixerの登録を削除 if (mixer.IsValid()) { playableGraph.Disconnect(mixer, 0); playableGraph.Disconnect(mixer, 1); } //されていなければ生成、登録 else { mixer = AnimationMixerPlayable.Create(playableGraph, 2, true); var output = AnimationPlayableOutput.Create(playableGraph, "output", GetComponent <Animator>()); output.SetSourcePlayable(mixer); } //前のアニメーションがあればそれを削除 if (beforeClipPlayable.IsValid()) { beforeClipPlayable.Destroy(); } //前のアニメーションに現在のアニメーションを登録 if (nowClipPlayable.IsValid()) { beforeClipPlayable = nowClipPlayable; } //現在のアニメーションにセットされたアニメーションを設定 nowClip = setClip; beforeClip = nowClip; setClip = null; //アニメーションプレイアブル作成 nowClipPlayable = AnimationClipPlayable.Create(playableGraph, nowClip); mixer.ConnectInput(0, nowClipPlayable, 0); mixer.ConnectInput(1, beforeClipPlayable, 0); } }
/// <summary> /// Stop animation. /// </summary> public void StopAnimationClip() { // Remove from motion state list. if (_motionState == null) { return; } _playableGraph.Disconnect(_motionState.ClipMixer, 0); _motionState = null; _isFinished = true; StopAllAnimation(); }
void Update() { //if(!isLocalPlayer) return; // if(player.GetButtonDown("Light")) anim.SetTrigger("VSlash_01"); // if(player.GetButtonDown("Medium")) anim.SetTrigger("VSlash2HSlash"); // if(player.GetButtonDown("Heavy")) anim.SetTrigger("FireSwd01"); foreach (var combo in combos) { /* combo.Init(player); * if(combo.Check(player)) */ { //AnimationPlayableUtilities.PlayClip(anim, combo.specialMove, out playGraph); clips.Enqueue(combo.specialMove); } } if (clips.Count > 0) { playGraph.Disconnect(clipPlayable, 0); clipPlayable = AnimationClipPlayable.Create(playGraph, clips.Dequeue()); playGraph.Connect(clipPlayable, 0, mixPlayer, 0); } weight = Mathf.Clamp01(weight); mixPlayer.SetInputWeight(0, 1.0f - weight); mixPlayer.SetInputWeight(1, weight); }
private void ChangeAnimation(RuntimeAnimatorController animatorController, float time) { if (!init) { Start(); } currentConnectedIdx = (currentConnectedIdx + 1) % 2; previousAnimator = currentAnimatorPlayable; currentAnimatorPlayable = AnimatorControllerPlayable.Create(playableGraph, animatorController); playableGraph.Disconnect(mixPlayable, currentConnectedIdx); //mixPlayable = AnimationMixerPlayable.Create(playableGraph, 2); //mixPlayable.ConnectInput(0, previousAnimator, 0); mixPlayable.ConnectInput(currentConnectedIdx, currentAnimatorPlayable, 0); //playableOutput.SetSourcePlayable(mixPlayable); transTime = 0; transTotalTime = time; weight = 0; if (currentAnimatorController) { Debug.Log(currentAnimatorController.ToString() + "->" + animatorController.ToString()); } currentAnimatorController = animatorController; //playableGraph.Play(); }
/* * //</public Methods> */ /* * //<private Methods> */ private bool ConnectProcess(AnimBox anim_box) { graph.Disconnect(mixer, 0); graph.Disconnect(mixer, 1); if (prePlayable.IsValid()) { prePlayable.Destroy(); } prePlayable = currentPlayable; currentAnim = anim_box; currentPlayable = AnimationClipPlayable.Create(graph, anim_box.clip); mixer.ConnectInput(1, prePlayable, 0); mixer.ConnectInput(0, currentPlayable, 0); once = false; return(true); }
public bool ChangeAnimation(RuntimeAnimatorController animatorController, float time) { StopAllCoroutines(); animatorPlayables[next] = AnimatorControllerPlayable.Create(playableGraph, animatorController); playableGraph.Disconnect(mixPlayable, next); playableGraph.Connect(animatorPlayables[next], 0, mixPlayable, next); mixPlayable.SetInputWeight(current, 1); mixPlayable.SetInputWeight(next, 0); nextAnimatorController = animatorController; transit = true; this.NumericAnimate(time, tick: (t) => { //Debug.Log(t); mixPlayable.SetInputWeight(current, 1 - t); mixPlayable.SetInputWeight(next, t); }, complete: () => { mixPlayable.SetInputWeight(current, 0); mixPlayable.SetInputWeight(next, 1); current++; currentAnimatorController = nextAnimatorController; nextAnimatorController = null; transit = false; }); return(true); }
//AnimationClipの切り替え public void reconnect(AnimationClip clip) { //切断 graph.Disconnect(mixer, 0); graph.Disconnect(mixer, 1); if (beforePlayable.IsValid()) { beforePlayable.Destroy(); } //更新 beforePlayable = nowPlayable; nowPlayable = AnimationClipPlayable.Create(graph, clip); //再接続 mixer.ConnectInput(1, beforePlayable, 0); mixer.ConnectInput(0, nowPlayable, 0); if (playParam.reverse) { //逆再生時の時間設定 nowPlayable.SetTime(nowPlayable.GetAnimationClip().length); nowPlayable.SetSpeed(-1f); } else { //通常時の時間設定 nowPlayable.SetSpeed(1f); } //同期遷移時の時間設定 if (playParam.syncTrans) { nowPlayable.SetTime(beforePlayable.GetTime()); } //遷移コルーチンがあるなら停止する(重複して遷移コルーチンが走らないようにする) if (fadeCoroutine != null) { player.StopCoroutine(fadeCoroutine); } //遷移中のモーションミックス開始 fadeCoroutine = player.StartCoroutine(crossFadeCoroutine(playParam.fadeDuration, playParam.waitFade)); }
public void Blend(AnimationScriptPlayable playable, float duration, AnimationCurve transitionCurve) { if (tweening && lastTween != null) { lastTween.callOnCompletes(); lastTween.setOnUpdate((float value) => { }); lastTween.setOnComplete(() => { }); // LeanTween.pause(lastTween.id); } // tweenPlayable = AnimatorControllerPlayable.Create(playableGraph, ac); tweenPlayable = playable; mixerPlayable = AnimationMixerPlayable.Create(playableGraph, 2); mixerPlayable.ConnectInput(0, activePlayable, 0); mixerPlayable.ConnectInput(1, tweenPlayable, 0); // Plays the Graph. mixerPlayable.SetInputWeight(0, 1); playableOutput.SetSourcePlayable(mixerPlayable); lastTween = LeanTween .value(playerController.gameObject, 0f, 1f, duration) .setEase(transitionCurve) .setOnUpdate((float value) => { mixerPlayable.SetInputWeight(0, 1f - value); mixerPlayable.SetInputWeight(1, value); }) .setOnComplete(() => { tweening = false; playableGraph.Disconnect(mixerPlayable, 0); playableGraph.Disconnect(mixerPlayable, 1); playableOutput.SetSourcePlayable(tweenPlayable); var prevActive = activePlayable; activePlayable = tweenPlayable; // prevActive.Destroy(); mixerPlayable.Destroy(); }); tweening = true; }
public void Disconnect() { if (IsConnect == false) { throw new System.Exception("AnimNode is disconnected."); } IsConnect = false; _graph.Disconnect(_parent, InputPort); }
public void Play(AnimationClip nextAnimationClip, float fadeTime, float speed) { if (nextAnimationClip == null) { return; } if (currentAnimationClip == null) { graph.Disconnect(mixer, 1); currentPlayable = AnimationClipPlayable.Create(graph, nextAnimationClip); currentPlayable.SetSpeed(speed); mixer.ConnectInput(0, currentPlayable, 0); mixer.SetInputWeight(0, 1f); currentAnimationClip = nextAnimationClip; } else if (!currentAnimationClip.name.StartsWith(nextAnimationClip.name)) { graph.Disconnect(mixer, 0); graph.Disconnect(mixer, 1); if (previousPlayable.IsValid()) { previousPlayable.Destroy(); } currentAnimationClip = nextAnimationClip; previousPlayable = currentPlayable; currentPlayable = AnimationClipPlayable.Create(graph, nextAnimationClip); currentPlayable.SetSpeed(speed); mixer.ConnectInput(0, currentPlayable, 0); mixer.ConnectInput(1, previousPlayable, 0); if (fadeTime <= 0f) { mixer.SetInputWeight(0, 1f); mixer.SetInputWeight(1, 0f); return; } if (mixerCoroutine != null) { StopCoroutine(mixerCoroutine); mixerCoroutine = null; } mixerCoroutine = StartCoroutine(PlayCoroutine(fadeTime)); } }
/* * //</public Methods> */ private void ConnectProcess(AnimationClip animation_clip) { if (animation_clip == GetCurrentMotion) { PlayAble = false; return; } PlayAble = true; graph.Disconnect(mixer, 0); graph.Disconnect(mixer, 1); if (prePlayable.IsValid()) { prePlayable.Destroy(); } prePlayable = currentPlayable; GetCurrentMotion = animation_clip; currentPlayable = AnimationClipPlayable.Create(graph, animation_clip); mixer.ConnectInput(1, prePlayable, 0); mixer.ConnectInput(0, currentPlayable, 0); }
//============================================================================================================ //モーションを再生する public bool play(AnimationClip clip, MotionPlayerParam param) { if (clip == null || param == null) { return(false); } MotionMixer motionMixer = motionMixers[param.layer]; motionMixer.playParam = param; //切断 graph.Disconnect(layerMixer, param.layer); //再接続 motionMixer.reconnect(clip); layerMixer.ConnectInput(param.layer, motionMixer.mixer, sourceOutputIndex: 0, weight: 1f); //出力 output.SetSourcePlayable(layerMixer); return(true); }
private void DisconnectInput(int index) { m_Graph.Disconnect(m_Mixer, index); }