Exemplo n.º 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;
    }
Exemplo n.º 2
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;
    }
Exemplo n.º 3
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));
    }
Exemplo n.º 4
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");
 }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
    public void Play(string name)
    {
        PlayableGraph.Stop();
        AnimationClipPlayable clipPlayable;

        if (ClipPlayables.TryGetValue(name, out clipPlayable))
        {
            //Debug.Log("Play : " + name);
            PlayableOutput.SetSourcePlayable(clipPlayable);
            PlayableGraph.Play();
        }
        else
        {
            Debug.LogWarning("Attempting to play animation " + name + " failed.  Cannot be found.");
        }
    }