コード例 #1
0
    // 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;
    }
コード例 #2
0
    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;
    }
コード例 #3
0
ファイル: CubismMotionLayer.cs プロジェクト: ryozaa/wankosoba
        /// <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;
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
            }
        }
コード例 #6
0
    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;
    }
コード例 #7
0
        /// <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;
        }
コード例 #8
0
    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));
    }
コード例 #9
0
 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");
 }
コード例 #10
0
        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;
        }
コード例 #11
0
        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();
        }
コード例 #12
0
    public override Type GetContentType()
    {
        PlayableOutput p = PlayableOutput.Null;

        try
        {
            p = ((PlayableOutput)content);
        }
        catch
        {
            // Ignore.
        }
        return(!p.IsOutputValid() ? null : p.GetPlayableOutputType());
    }
コード例 #13
0
        public override Type GetContentType()
        {
            PlayableOutput po = PlayableOutput.Null;

            try
            {
                po = (PlayableOutput)content;
            }
            catch
            {
                // Ignore.
            }

            return(po.IsOutputValid() ? po.GetPlayableOutputType() : null);
        }
コード例 #14
0
    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);
    }
コード例 #15
0
    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);
    }
コード例 #16
0
        /// <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;
        }
コード例 #17
0
    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);
    }
コード例 #18
0
 static void Trigger_internal(Playable playable, PlayableOutput output, ref NotificationEntry e)
 {
     output.PushNotification(playable, e.payload);
     e.notificationFired = true;
 }
コード例 #19
0
 public PlayableOutputNode(PlayableOutput content)
     : base(content, content.GetWeight(), true)
 {
 }
コード例 #20
0
 private PlayableOutputNode CreateNodeFromPlayableOutput(PlayableOutput h)
 {
     return(new PlayableOutputNode(h));
 }