// Use this for initialization void Start() { animator = Entity.GetComponent <Animator>(); playableGraph = PlayableGraph.Create(); playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", Entity.GetComponent <Animator>()); previousAnimator = AnimatorControllerPlayable.Create(playableGraph, null); currentAnimatorPlayable = AnimatorControllerPlayable.Create(playableGraph, null); movementController = AnimatorControllerPlayable.Create(playableGraph, DefaultMovement); mixPlayable = AnimationMixerPlayable.Create(playableGraph, 2); playableGraph.Connect(previousAnimator, 0, mixPlayable, 0); playableGraph.Connect(currentAnimatorPlayable, 0, mixPlayable, 1); //playableGraph.Connect(movementController, 0, mixPlayable, 2); mixPlayable.SetInputWeight(0, 0); mixPlayable.SetInputWeight(1, 0); //mixPlayable.SetInputWeight(2, 1); layerMixer = AnimationLayerMixerPlayable.Create(playableGraph, 2); playableGraph.Connect(mixPlayable, 0, layerMixer, 0); playableGraph.Connect(movementController, 0, layerMixer, 1); layerMixer.SetInputWeight(0, 1); layerMixer.SetInputWeight(1, 1); //layerMixer.SetLayerAdditive(0, true); playableOutput.SetSourcePlayable(layerMixer); playableGraph.Play(); currentAnimatorController = null; init = true; }
public void Initialize() { if (this.initialized) { return; } this.animator = this.GetComponent <Animator>(); Debug.Assert(this.animationClip != null && this.animationClip[0] != null, "No Animation Clips !"); Debug.Assert(this.animator.runtimeAnimatorController == null, "AnimationController is set......"); this.graph = PlayableGraph.Create("Animation Player"); this.graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); this.output = AnimationPlayableOutput.Create(this.graph, this.name, this.animator); this.clips = new AnimationClipPlayable[this.animationClip.Length]; for (int i = 0; i < this.animationClip.Length; ++i) { this.clips[i] = AnimationClipPlayable.Create(this.graph, this.animationClip[i]); this.clips[i].SetApplyFootIK(false); this.clips[i].SetApplyPlayableIK(false); } this.initialized = true; }
/// <summary> /// Play animation. /// </summary> /// <param name="clip">Animation clip.</param> /// <param name="isLoop">Animation is loop.</param> /// <param name="speed">Animation speed.</param> public void PlayAnimation(AnimationClip clip, bool isLoop = true, float speed = 1.0f) { // Create cubism motion state. var state = CubismMotionState.CreateCubismMotionState(_playableGraph, clip, isLoop, speed); if (_motionStates.Count > 0) { _motionStates[_motionStates.Count - 1].ConnectClipMixer(state.ClipMixer); } else { PlayableOutput.DisconnectInput(0); PlayableOutput.ConnectInput(0, state.ClipMixer, 0); PlayableOutput.SetInputWeight(0, 1.0f); } _motionStates.Add(state); // Set last motion end time and fade in start time; if (_playingMotions.Count > 0) { var lastMotion = _playingMotions[_playingMotions.Count - 1]; lastMotion.FadeInStartTime = Time.time; lastMotion.EndTime = Time.time + lastMotion.Motion.FadeOutTime; _playingMotions[_playingMotions.Count - 1] = lastMotion; } // Create fade playing motion. var playingMotion = CreateFadePlayingMotion(clip, speed); _playingMotions.Add(playingMotion); _isFinished = false; }
void TriggerSignals (Playable playable, PlayableOutput output, float previous, float current) { _signalPool.ResetFrame(); var t0 = ConvertSecondToTicks(previous); var t1 = ConvertSecondToTicks(current); // Resolve wrapping-around cases by offsetting. if (t1 < t0) { t1 += (t0 / duration + 1) * duration; } // Offset both the points to make t0 < duration. var offs = (t0 / duration) * duration; t0 -= offs; t1 -= offs; // Resolve loops. for (; t1 >= duration; t1 -= duration) { // Trigger signals between t0 and the end of the clip. TriggerSignalsTick(playable, output, t0, 0xffffffffu); t0 = 0; } // Trigger signals between t0 and t1. TriggerSignalsTick(playable, output, t0, t1); }
void TriggerSignalsTick (Playable playable, PlayableOutput output, uint previous, uint current) { foreach (var e in events) { if (e.tick >= current) { break; } if (e.tick < previous) { continue; } if (e.IsTempoSet) { tempo = e.data2; continue; } if (!e.IsNote) { continue; } output.PushNotification(playable, _signalPool.Allocate(e)); } }
private void Start() { if (init) { return; } init = true; var animator = Entity.GetComponent <Animator>(); playableGraph = PlayableGraph.Create(); playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", Entity.GetComponent <Animator>()); animatorPlayables = new AnimatorControllerPlayable[2]; animatorPlayables[0] = AnimatorControllerPlayable.Create(playableGraph, DefaultMovement); animatorPlayables[1] = AnimatorControllerPlayable.Create(playableGraph, null); mixPlayable = AnimationMixerPlayable.Create(playableGraph, 2); playableGraph.Connect(animatorPlayables[0], 0, mixPlayable, 0); playableGraph.Connect(animatorPlayables[1], 0, mixPlayable, 1); mixPlayable.SetInputWeight(0, 1); mixPlayable.SetInputWeight(1, 0); playableOutput.SetSourcePlayable(mixPlayable); playableGraph.Play(); currentAnimatorController = DefaultMovement; }
/// <summary> /// Play animation. /// </summary> /// <param name="clip">Animation clip.</param> /// <param name="isLoop">Animation is loop.</param> /// <param name="speed">Animation speed.</param> public void PlayAnimation(AnimationClip clip, bool isLoop = true, float speed = 1.0f) { if (_motionState != null) { _playableGraph.Disconnect(_motionState.ClipMixer, 0); } // Create cubism motion state. _motionState = CubismMotionState.CreateCubismMotionState(_playableGraph, clip, isLoop, speed); #if UNITY_2018_2_OR_NEWER PlayableOutput.DisconnectInput(0); #else PlayableOutput.GetGraph().Disconnect(PlayableOutput, 0); #endif PlayableOutput.ConnectInput(0, _motionState.ClipMixer, 0); PlayableOutput.SetInputWeight(0, 1.0f); // Set last motion end time and fade in start time; if ((_playingMotions.Count > 0) && (_playingMotions[_playingMotions.Count - 1].Motion != null)) { var motion = _playingMotions[_playingMotions.Count - 1]; var time = Time.time; var newEndTime = time + motion.Motion.FadeOutTime; if (newEndTime < 0.0f || newEndTime < motion.EndTime) { motion.EndTime = newEndTime; } while (motion.IsLooping) { if ((motion.StartTime + motion.Motion.MotionLength) >= time) { break; } motion.StartTime += motion.Motion.MotionLength; } _playingMotions[_playingMotions.Count - 1] = motion; } // Create fade playing motion. var playingMotion = CreateFadePlayingMotion(clip, isLoop, speed); _playingMotions.Add(playingMotion); _isFinished = false; }
public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount) { if (Application.isPlaying) { PlayableOutput playableOutput = graph.GetOutput(0); if (playableOutput.IsOutputValid()) { ScriptPlayable <TimeNotificationBehaviour> scriptPlayable = (ScriptPlayable <TimeNotificationBehaviour>)playableOutput.GetSourcePlayable().GetInput(0); TimeNotificationBehaviour timeNotificationBehaviour = scriptPlayable.GetBehaviour(); var simpleMarkers = this.GetMarkers().OfType <SimpleMarker>(); m_Receiver = new ReceiverExample(); playableOutput.AddNotificationReceiver(m_Receiver); foreach (var marker in simpleMarkers) { scriptPlayable.GetBehaviour().AddNotification(marker.time, marker); } } else { playableOutput = ScriptPlayableOutput.Create(graph, "NotificationOutput"); m_Receiver = new ReceiverExample(); //why also here and in "outputs" playableOutput.AddNotificationReceiver(m_Receiver); //Create a TimeNotificationBehaviour var timeNotificationPlayable = ScriptPlayable <TimeNotificationBehaviour> .Create(graph); playableOutput.SetSourcePlayable(graph.GetRootPlayable(0)); timeNotificationPlayable.GetBehaviour().timeSource = playableOutput.GetSourcePlayable(); playableOutput.GetSourcePlayable().SetInputCount(playableOutput.GetSourcePlayable().GetInputCount() + 1); graph.Connect(timeNotificationPlayable, 0, playableOutput.GetSourcePlayable(), playableOutput.GetSourcePlayable().GetInputCount() - 1); var simpleMarkers = this.GetMarkers().OfType <SimpleMarker>(); foreach (var marker in simpleMarkers) { timeNotificationPlayable.GetBehaviour().AddNotification(marker.time, marker); } } } return(base.CreateTrackMixer(graph, go, inputCount)); }
private void AnimatorAwake() { PlayableGraph = PlayableGraph.Create(); Anim = GetParentActor().GetComponentInChildren <Animator>(); Debug.Assert(Anim != null, "Animator not found. Player Animation will not work."); PlayableOutput = AnimationPlayableOutput.Create(PlayableGraph, "Animation", Anim); CreateAllClipPlayables(); PlayableOutput.SetSourcePlayable(ClipPlayables["sideJump"]); PlayableGraph.Play(); GraphVisualizerClient.Show(PlayableGraph, "MSV_Animator"); }
static void Trigger_internal(Playable playable, PlayableOutput output, ref NotificationEntry e) { var notify = TimelineUtil.Interface?.notify; if (notify != null) { notify(playable, e.payload); e.notificationFired = true; } //output.PushNotification(playable, e.payload); //e.notificationFired = true; }
private void Awake() { PlayableGraph = PlayableGraph.Create("Animation Graph"); RootNode = new MixerNode(); RootNode.CreatePlayable(PlayableGraph); PlayableOutput = AnimationPlayableOutput.Create(PlayableGraph, "Animation Output", GetComponent <Animator>()); PlayableOutput.SetSourcePlayable(RootNode.Playable); PlayableOutput.SetAnimationStreamSource(AnimationStreamSource.DefaultValues); PlayableGraph.Play(); }
public override Type GetContentType() { PlayableOutput p = PlayableOutput.Null; try { p = ((PlayableOutput)content); } catch { // Ignore. } return(!p.IsOutputValid() ? null : p.GetPlayableOutputType()); }
public override Type GetContentType() { PlayableOutput po = PlayableOutput.Null; try { po = (PlayableOutput)content; } catch { // Ignore. } return(po.IsOutputValid() ? po.GetPlayableOutputType() : null); }
private List <Node> GetInputsFromPlayableOutputNode(PlayableOutput h) { var inputs = new List <Node>(); if (h.IsOutputValid()) { Playable playable = h.GetSourcePlayable(); if (playable.IsValid()) { Node node = CreateNodeFromPlayable(playable, 1); inputs.Add(node); } } return(inputs); }
public static int constructor(IntPtr l) { int result; try { PlayableOutput playableOutput = default(PlayableOutput); LuaObject.pushValue(l, true); LuaObject.pushValue(l, playableOutput); result = 2; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
/// <summary> /// Play animation. /// </summary> /// <param name="clip">Animation clip.</param> /// <param name="isLoop">Animation is loop.</param> /// <param name="speed">Animation speed.</param> public void PlayAnimation(AnimationClip clip, bool isLoop = true, float speed = 1.0f) { if (_motionState != null) { _playableGraph.Disconnect(_motionState.ClipMixer, 0); } // Create cubism motion state. _motionState = CubismMotionState.CreateCubismMotionState(_playableGraph, clip, isLoop, speed); #if UNITY_2018_2_OR_NEWER PlayableOutput.DisconnectInput(0); #else PlayableOutput.GetGraph().Disconnect(PlayableOutput, 0); #endif PlayableOutput.ConnectInput(0, _motionState.ClipMixer, 0); PlayableOutput.SetInputWeight(0, 1.0f); // Set last motion end time and fade in start time; for (var i = 0; i < _playingMotions.Count; ++i) { var motion = _playingMotions[i]; if (motion.Motion == null) { continue; } var newEndTime = Time.time + motion.Motion.FadeOutTime; motion.EndTime = newEndTime; _playingMotions[i] = motion; } // Create fade playing motion. var playingMotion = CreateFadePlayingMotion(clip, speed); _playingMotions.Add(playingMotion); _isFinished = false; }
public static int GetOutput(IntPtr l) { int result; try { PlayableGraph playableGraph; LuaObject.checkValueType <PlayableGraph>(l, 1, out playableGraph); int index; LuaObject.checkType(l, 2, out index); PlayableOutput output = playableGraph.GetOutput(index); LuaObject.pushValue(l, true); LuaObject.pushValue(l, output); result = 2; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
static void Trigger_internal(Playable playable, PlayableOutput output, ref NotificationEntry e) { output.PushNotification(playable, e.payload); e.notificationFired = true; }
public PlayableOutputNode(PlayableOutput content) : base(content, content.GetWeight(), true) { }
private PlayableOutputNode CreateNodeFromPlayableOutput(PlayableOutput h) { return(new PlayableOutputNode(h)); }