Esempio n. 1
0
    void Start()

    {
        // Creates the graph, the mixer and binds them to the Animator.

        playableGraph = PlayableGraph.Create();

        var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>());

        mixerPlayable = AnimationMixerPlayable.Create(playableGraph, 2);

        playableOutput.SetSourcePlayable(mixerPlayable);

        // Creates AnimationClipPlayable and connects them to the mixer.

        var clipPlayable0 = AnimationClipPlayable.Create(playableGraph, clip0);

        var clipPlayable1 = AnimationClipPlayable.Create(playableGraph, clip1);

        playableGraph.Connect(clipPlayable0, 0, mixerPlayable, 0);

        playableGraph.Connect(clipPlayable1, 0, mixerPlayable, 1);



        // Plays the Graph.

        playableGraph.Play();
    }
    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;
    }
        //Create and play the playable graph
        void CreateAndPlayTree()
        {
            graph           = PlayableGraph.Create();
            animationOutput = AnimationPlayableOutput.Create(graph, "Animation", animator);
            masterMixer     = AnimationLayerMixerPlayable.Create(graph, siblingTracks.Count + 2);
            for (var i = 0; i < siblingTracks.Count; i++)
            {
                var animatorTrack = siblingTracks[i];
                var mix           = animatorTrack.CreateClipsMixer(graph);
                graph.Connect(mix, 0, masterMixer, i);
                masterMixer.SetInputWeight(i, 1f);
                if (animatorTrack.mask != null)
                {
                    masterMixer.SetLayerMaskFromAvatarMask((uint)i, animatorTrack.mask);
                }
                masterMixer.SetLayerAdditive((uint)i, animatorTrack.blendMode == AnimationBlendMode.Additive);
            }

            animatorPlayable = AnimatorControllerPlayable.Create(graph, animator.runtimeAnimatorController);
            graph.Connect(animatorPlayable, 0, masterMixer, siblingTracks.Count + 1);
            masterMixer.SetInputWeight(siblingTracks.Count + 1, 0f);

            animationOutput.SetSourcePlayable(masterMixer);

            // graph.Play();
            // masterMixer.Pause();

            // GraphVisualizerClient.Show(graph, this.name);
        }
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, AnimGraph_Move8Dir settings)
        {
            m_settings      = settings;
            m_EntityManager = entityManager;
            m_Owner         = owner;

            m_locomotionMixer = AnimationLayerMixerPlayable.Create(graph, 3);

            // Movement
            m_BlendTree = new BlendTree2dSimpleDirectional(graph, settings.blendSpaceNodes);
            graph.Connect(m_BlendTree.GetRootPlayable(), 0, m_locomotionMixer, 0);
            m_locomotionMixer.SetInputWeight(0, 1.0f);
            m_BlendTree.masterSpeed = m_settings.animMovePlaySpeed;

            // Aim
            if (settings.animAim != null)
            {
                m_clipAim = AnimationClipPlayable.Create(graph, settings.animAim);
                m_clipAim.SetApplyFootIK(false);
                m_clipAim.Pause();
                m_aimTimeFactor = m_clipAim.GetAnimationClip().length / 180.0f;

                m_locomotionMixer.SetLayerAdditive(1, true);
                graph.Connect(m_clipAim, 0, m_locomotionMixer, 1);
                m_locomotionMixer.SetInputWeight(1, 1.0f);
            }

            // Actions
            m_actionMixer = AnimationLayerMixerPlayable.Create(graph);
            var port = m_actionMixer.AddInput(m_locomotionMixer, 0);

            m_actionMixer.SetInputWeight(port, 1);

            m_actionAnimationHandler = new ActionAnimationHandler(m_actionMixer, settings.actionAnimations);
        }
Esempio n. 5
0
    public void SetGraphParameters()
    {
        var blenderPlayable = ScriptPlayable <BlenderPlayableBehaviourZero> .Create(pg, 1);

        if (pg.IsValid())
        {
            Debug.Log("There is a player graph");
        }
        else
        {
            Debug.Log("There is no player graph!");
        }

        BlenderPlayableBehaviourZero g = blenderPlayable.GetBehaviour();

        var animOutput = AnimationPlayableOutput.Create(pg, "AnimationOutput", GetComponent <Animator>());

        Debug.Log(animOutput + " Hi!");
        var mixerPlayable = AnimationMixerPlayable.Create(pg, 2, false);

        Debug.Log(mixerPlayable + " Nope!");
        blenderPlayable.GetBehaviour().mixerPlayable = mixerPlayable;

        pg.Connect(mixerPlayable, 0, blenderPlayable, 0);

        animOutput.SetSourcePlayable(blenderPlayable);
        animOutput.SetSourceInputPort(0);

        g.animOutput    = animOutput;
        g.mixerPlayable = mixerPlayable;
    }
Esempio n. 6
0
        /// <summary>
        /// Use animation Playables API to control keyed values, blended between the first frame of 2 animation clips.
        /// </summary>
        /// <param name="valueForAdaptationCurve">A value to evaluate into adaptation curve producing a real blend value for 2 clips.</param>
        /// <param name="animator">The control target for animation playables. The clips used must be able to control the keyed fields traveling down from this animator component.</param>
        public void Adapt(float valueForAdaptationCurve, Animator animator)
        {
            if (!Adaptable)
            {
                return;
            }

            float blend = adaptationCurve.Evaluate(valueForAdaptationCurve);

            //Connect up a playable graph, evaluate once, then we're done with them.
            PlayableGraph pg = PlayableGraph.Create("AdaptationGraph");

            pg.SetTimeUpdateMode(DirectorUpdateMode.Manual);

            var mixer = AnimationMixerPlayable.Create(pg, 2, normalizeWeights: true);

            //Not sure if the mixer should be "cross fade" like this, or should we do 0~1 weight over 1 weight?
            //But I think that's for AnimationLayerMixerPlayable ?
            mixer.SetInputWeight(inputIndex: 0, weight: 1 - blend);
            mixer.SetInputWeight(inputIndex: 1, weight: blend);


            var normalStateAcp       = AnimationClipPlayable.Create(pg, normalState);
            var fullyAdaptedStateAcp = AnimationClipPlayable.Create(pg, fullyAdaptedState);

            pg.Connect(normalStateAcp, sourceOutputPort: 0, mixer, destinationInputPort: 0);
            pg.Connect(fullyAdaptedStateAcp, sourceOutputPort: 0, mixer, destinationInputPort: 1);

            var output = AnimationPlayableOutput.Create(pg, "AdaptationGraphOutput", animator);

            output.SetSourcePlayable(mixer);

            pg.Evaluate();
            pg.Destroy();
        }
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_SprintBlend settings)
        {
            // TODO: Remove the members that are not needed
            m_Settings       = settings;
            m_EntityManager  = entityManager;
            m_Owner          = owner;
            m_AnimStateOwner = animStateOwner;

            m_RunController                  = new AnimationControllerEntry();
            m_RunController.controller       = settings.runTemplate.Instatiate(entityManager, owner, graph, animStateOwner);
            m_RunController.animStateUpdater = m_RunController.controller as IGraphState;
            m_RunController.port             = 0;

            m_SprintController                  = new AnimationControllerEntry();
            m_SprintController.controller       = settings.sprintTemplate.Instatiate(entityManager, owner, graph, animStateOwner);
            m_SprintController.animStateUpdater = m_SprintController.controller as IGraphState;
            m_SprintController.port             = 1;

            m_RootMixer = AnimationMixerPlayable.Create(graph, 2);

            // TODO: Put into function?
            var outputPlayable = Playable.Null;
            var outputPort     = 0;

            m_RunController.controller.GetPlayableOutput(m_RunController.port, ref outputPlayable, ref outputPort);
            graph.Connect(outputPlayable, outputPort, m_RootMixer, 0);

            m_SprintController.controller.GetPlayableOutput(m_SprintController.port, ref outputPlayable, ref outputPort);
            graph.Connect(outputPlayable, outputPort, m_RootMixer, 1);

            m_RootMixer.SetInputWeight(0, 1f);
        }
        //Create playable tree
        void CreateAndPlayTree()
        {
            var clipActions = clips.OfType <PlayAnimatorClip>().ToList();
            var inputCount  = 1 + clipActions.Count;

            ports = new Dictionary <PlayAnimatorClip, int>();
            graph = PlayableGraph.CreateGraph();
            mixerPlayableHandle = graph.CreateAnimationMixerPlayable(inputCount, true);
            mixerPlayableHandle.SetInputWeight(0, 1f);
            baseClipPlayableHandle           = graph.CreateAnimationClipPlayable(baseAnimationClip);
            baseClipPlayableHandle.playState = PlayState.Paused;
            graph.Connect(baseClipPlayableHandle, 0, mixerPlayableHandle, 0);

            var index = 1;             //0 is baseclip

            foreach (var playAnimClip in clipActions)
            {
                var clipPlayableHandle = graph.CreateAnimationClipPlayable(playAnimClip.animationClip);
                graph.Connect(clipPlayableHandle, 0, mixerPlayableHandle, index);
                mixerPlayableHandle.SetInputWeight(index, 0f);
                ports[playAnimClip]          = index;
                clipPlayableHandle.playState = PlayState.Paused;
                index++;
            }

            animationOutput = graph.CreateAnimationOutput("Animation", animator);
            animationOutput.sourcePlayable = mixerPlayableHandle;
            mixerPlayableHandle.playState  = PlayState.Paused;
            graph.Play();

            // GraphVisualizerClient.Show(graph, animator.name);
        }
Esempio n. 9
0
    void Start()

    {
        playableGraph = PlayableGraph.Create("测试");

        playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

        var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>());

        // Wrap the clip in a playable

        m_Mixer = AnimationMixerPlayable.Create(playableGraph, 2);

        AnimationClipPlayable clipPlayable0 = AnimationClipPlayable.Create(playableGraph, clip0);
        AnimationClipPlayable clipPlayable1 = AnimationClipPlayable.Create(playableGraph, clip1);

        playableGraph.Connect(clipPlayable0, 0, m_Mixer, 0);
        playableGraph.Connect(clipPlayable1, 0, m_Mixer, 1);

        m_Mixer.SetInputWeight(0, 1);
        m_Mixer.SetInputWeight(1, 0);
        // Connect the Playable to an output

        playableOutput.SetSourcePlayable(m_Mixer);
        playableOutput.SetSortingOrder(0);

        // Plays the Graph.
        leftTime = tranTime;
        playableGraph.Play();
    }
Esempio n. 10
0
        internal static Playable CreatePlayable(PlayableGraph graph, AnimationClip clip, Vector3 positionOffset, Vector3 eulerOffset, bool removeStartOffset, AppliedOffsetMode mode, bool applyFootIK, LoopMode loop)
        {
            if (clip == null || clip.legacy)
            {
                return(Playable.Null);
            }


            var clipPlayable = AnimationClipPlayable.Create(graph, clip);

            clipPlayable.SetRemoveStartOffset(removeStartOffset);
            clipPlayable.SetApplyFootIK(applyFootIK);
            clipPlayable.SetOverrideLoopTime(loop != LoopMode.UseSourceAsset);
            clipPlayable.SetLoopTime(loop == LoopMode.On);

            Playable root = clipPlayable;

            if (ShouldApplyScaleRemove(mode))
            {
                var removeScale = AnimationRemoveScalePlayable.Create(graph, 1);
                graph.Connect(root, 0, removeScale, 0);
                removeScale.SetInputWeight(0, 1.0f);
                root = removeScale;
            }

            if (ShouldApplyOffset(mode, clip))
            {
                var offsetPlayable = AnimationOffsetPlayable.Create(graph, positionOffset, Quaternion.Euler(eulerOffset), 1);
                graph.Connect(root, 0, offsetPlayable, 0);
                offsetPlayable.SetInputWeight(0, 1.0F);
                root = offsetPlayable;
            }

            return(root);
        }
Esempio n. 11
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;
    }
    // Use this for initialization
    void Start()
    {
        // Create the PlayableGraph.
        m_Graph = PlayableGraph.Create();

        // Add an AnimationPlayableOutput to the graph.
        var animOutput = AnimationPlayableOutput.Create(m_Graph, "AnimationOutput", GetComponent <Animator>());

        // Add an AnimationMixerPlayable to the graph.
        var mixerPlayable = AnimationMixerPlayable.Create(m_Graph, 2, false);

        // Add two AnimationClipPlayable to the graph.
        var clipPlayableA = AnimationClipPlayable.Create(m_Graph, clipA);
        var clipPlayableB = AnimationClipPlayable.Create(m_Graph, clipB);

        // Add a custom PlayableBehaviour to the graph.
        // This behavior will change the weights of the mixer dynamically.
        var blenderPlayable = ScriptPlayable <BlenderPlayableBehaviour> .Create(m_Graph, 1);

        blenderPlayable.GetBehaviour().mixerPlayable = mixerPlayable;
        blenderPlayable.SetInputWeight(0, 1.0f);

        // Create the topology, connect the AnimationClipPlayable to the
        // AnimationMixerPlayable.  Also add the BlenderPlayableBehaviour.
        m_Graph.Connect(clipPlayableA, 0, mixerPlayable, 0);
        m_Graph.Connect(clipPlayableB, 0, mixerPlayable, 1);
        m_Graph.Connect(mixerPlayable, 0, blenderPlayable, 0);

        // Use the AnimationMixerPlayable as the source for the AnimationPlayableOutput.
        animOutput.SetSourcePlayable(blenderPlayable);

        // Play the graph.
        m_Graph.Play();
    }
Esempio n. 13
0
            public Instance(AnimStateController controller, PlayableGraph graph, AnimGraphStand settings)
            {
                m_Settings       = settings;
                m_AnimState      = controller.GetComponent <AnimStateData>();
                m_PredictedState = controller.GetComponent <LogicStateData>();

                m_Mask = 1 << LayerMask.NameToLayer("Default") | 1 << LayerMask.NameToLayer("Platform");

                m_LocomotionMixer = AnimationMixerPlayable.Create(graph, (int)LocoMixerPort.Count);

                m_AnimIdle = AnimationClipPlayable.Create(graph, settings.animIdle);
                graph.Connect(m_AnimIdle, 0, m_LocomotionMixer, (int)LocoMixerPort.Idle);
                m_LocomotionMixer.SetInputWeight((int)LocoMixerPort.Idle, 1.0f);

                m_AnimTurnL = CreateTurnPlayable(graph, settings.animTurnL, m_LocomotionMixer, LocoMixerPort.TurnL);
                m_AnimTurnR = CreateTurnPlayable(graph, settings.animTurnR, m_LocomotionMixer, LocoMixerPort.TurnR);

                var ports = new int[] { (int)LocoMixerPort.Idle, (int)LocoMixerPort.TurnL, (int)LocoMixerPort.TurnR };

                m_Transition = new SimpleTranstion <AnimationMixerPlayable>(m_LocomotionMixer, ports);

                if (settings.animTurnL.events.Length != 0)
                {
                    m_LeftTurnFootFalls  = ExtractFootFalls(settings.animTurnL);
                    m_RightTurnFootFalls = ExtractFootFalls(settings.animTurnR);
                }

                var animator  = controller.GetComponent <Animator>();
                var skeleton  = controller.GetComponent <Skeleton>();
                var leftToes  = skeleton.bones[skeleton.GetBoneIndex(settings.leftToeBone.GetHashCode())];
                var rightToes = skeleton.bones[skeleton.GetBoneIndex(settings.rightToeBone.GetHashCode())];

                var ikJob = new FootIkJob
                {
                    settings = settings.footIK,
                    leftToe  = animator.BindStreamTransform(leftToes),
                    rightToe = animator.BindStreamTransform(rightToes)
                };

                m_FootIk = AnimationScriptPlayable.Create(graph, ikJob, 1);
                graph.Connect(m_LocomotionMixer, 0, m_FootIk, 0);
                m_FootIk.SetInputWeight(0, 1f);

                m_AimMixer = AnimationMixerPlayable.Create(graph, (int)AimMixerPort.Count, true);

                m_AnimAimLeft  = CreateAimPlayable(graph, settings.animAimLeft, m_AimMixer, AimMixerPort.AimLeft);
                m_AnimAimMid   = CreateAimPlayable(graph, settings.animAimMid, m_AimMixer, AimMixerPort.AimMid);
                m_AnimAimRight = CreateAimPlayable(graph, settings.animAimRight, m_AimMixer, AimMixerPort.AimRight);

                m_AdditiveMixer = AnimationLayerMixerPlayable.Create(graph);

                var locoMixerPort = m_AdditiveMixer.AddInput(m_FootIk, 0);

                m_AdditiveMixer.SetInputWeight(locoMixerPort, 1);

                var aimMixerPort = m_AdditiveMixer.AddInput(m_AimMixer, 0);

                m_AdditiveMixer.SetInputWeight(aimMixerPort, 1);
                m_AdditiveMixer.SetLayerAdditive((uint)aimMixerPort, true);
            }
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, AnimGraph_DamageReaction settings)
        {
            m_settings      = settings;
            m_graph         = graph;
            m_EntityManager = entityManager;
            m_Owner         = owner;

            m_rootMixer = AnimationLayerMixerPlayable.Create(graph, 2);
            m_rootMixer.SetInputWeight(0, 1f);

            // Setup blend mixer
            m_blendMixer = AnimationMixerPlayable.Create(graph, 4);
            GameDebug.Assert(m_settings.clips != null && m_settings.clips.Length > 0, "No animation clips added to damagereaction settings:{0}", settings.name);
            for (var i = 0; i < m_settings.clips.Length; i++)
            {
                var clipPlayable = AnimationClipPlayable.Create(graph, m_settings.clips[i]);
                clipPlayable.SetApplyFootIK(false);
                clipPlayable.Pause();
                graph.Connect(clipPlayable, 0, m_blendMixer, i);

                if (m_settings.clips[i].length > m_reactionAnimDuration)
                {
                    m_reactionAnimDuration = m_settings.clips[i].length;
                }
            }
            m_reactionAnimAngleSpan = 360 / m_blendMixer.GetInputCount();
            graph.Connect(m_blendMixer, 0, m_rootMixer, m_blendMixerPort);
            m_rootMixer.SetLayerAdditive(m_blendMixerPort, true);
        }
Esempio n. 15
0
        public AnimationClipPlayable Play(AnimationClip clip, float transition = 0, int toLayer = 0)
        {
            var playable = AnimationClipPlayable.Create(_playableGraph, clip);

            int inputIndex;

            if (AnimationPlayLayers.Length > 1)
            {
                var animationMixerPlayable = (AnimationMixerPlayable)layerMixerPlayable.GetInput(toLayer);
                inputIndex = GetInputIndex(animationMixerPlayable);
                _playableGraph.Connect(playable, 0, animationMixerPlayable, inputIndex);
            }
            else
            {
                if (AnimationClipIsPlaying(mixerPlayable, clip, out var playingPlayable))
                {
                    return(playingPlayable);
                }
                inputIndex = GetInputIndex(mixerPlayable);
                var layer = AnimationPlayLayers[toLayer];
                layer.Add(inputIndex, transition);
                _playableGraph.Connect(playable, 0, mixerPlayable, inputIndex);
                if (layer.bInputIndex == -1)
                {
                    mixerPlayable.SetInputWeight(layer.aInputIndex, 1f);
                }
            }
            return(playable);
        }
Esempio n. 16
0
        AnimationMixerPlayable Setup2()
        {
            animator = GetComponent <Animator>();
            //animator.playableGraph.Destroy();

            playableGraph = PlayableGraph.Create(nameof(PlayableComponent));
            var playableOutput = AnimationPlayableOutput.Create(playableGraph, $"Animation Output", animator);

            // Animator controller
            var controllerPlayable = AnimatorControllerPlayable.Create(playableGraph, animator.runtimeAnimatorController);

            // Clip
            var clipPlayable = AnimationClipPlayable.Create(playableGraph, animationClips[0]);

            clipPlayable.Play();

            // Mixer
            var mixer = AnimationMixerPlayable.Create(playableGraph, 2, true);

            playableGraph.Connect(controllerPlayable, 0, mixer, 0);
            mixer.SetInputWeight(0, 1);
            playableGraph.Connect(clipPlayable, 0, mixer, 1);
            mixer.SetInputWeight(1, 0);

            // Setup output
            playableOutput.SetSourcePlayable(mixer);

            playableGraph.Play();
            return(mixer);
        }
Esempio n. 17
0
            public Instance(AnimStateController controller, PlayableGraph graph, AnimGraphJump settings)
            {
                m_AnimState = controller.GetComponent <AnimStateData>();

                m_Mixer = AnimationLayerMixerPlayable.Create(graph, 2);

                m_AnimJump = AnimationClipPlayable.Create(graph, settings.animJump);
                m_AnimJump.SetApplyFootIK(true);
                m_AnimJump.SetDuration(settings.animJump.length);
                m_AnimJump.Pause();
                graph.Connect(m_AnimJump, 0, m_Mixer, 0);
                m_Mixer.SetInputWeight(0, 1);

                var gameJumpHeight   = 1.0f;
                var gameJumpDuration = 0.3f;
                var animJumpVel      = settings.jumpHeight / settings.animJump.length;
                var characterJumpVel = gameJumpHeight / gameJumpDuration;

                m_PlaySpeed = characterJumpVel / animJumpVel;

                m_AnimAim = AnimationClipPlayable.Create(graph, settings.animAim);
                m_AnimAim.SetApplyFootIK(false);
                m_AnimAim.Pause();
                graph.Connect(m_AnimAim, 0, m_Mixer, 1);
                m_Mixer.SetInputWeight(1, 1);
                m_Mixer.SetLayerAdditive(1, true);

                m_AimTimeFactor = settings.animAim.length / 180.0f;
            }
Esempio n. 18
0
    PlayableGraph CreatePlayableGraph()
    {
        // Create a Mixer.
        PlayableGraph g = animator.playableGraph;

        //var playableOutput = AnimationPlayableOutput.Create(g, "AnimationOutput", animator);

        mixerPlayable = AnimationMixerPlayable.Create(g, AnimationMapping.Length + 1);

        // Create a 'neutral' playable with low weight
        var neutral = AnimationClipPlayable.Create(g, NeutralAnimation);

        g.Connect(neutral, 0, mixerPlayable, 0);
        // Create a playable for every AffdexPlayable and connect inputs to the Mixer
        for (int i = 0; i < AnimationMapping.Length; i++)
        {
            var playable = AnimationClipPlayable.Create(g, AnimationMapping[i].CubismExpression);
            Debug.Log("Connection: " + i + 1);
            g.Connect(playable, 0, mixerPlayable, i + 1);
        }

        if (AttemptLayerMix)
        {
            AttachMixerToLayerMixer(mixerPlayable, g);
        }
        else
        {
            AttachMixerToAnimationPlayableOutput(mixerPlayable, g);
        }
        g.Play();
        GraphVisualizerClient.Show(g, "Affdex");
        rawWeights = new float[AnimationMapping.Length];
        return(g);
    }
        /// <summary>
        /// Use this for initialization
        /// </summary>
        private void Awake()
        {
            // Create playable graph.
            playableGraph = PlayableGraph.Create();

            // Create playable output node.
            var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>());

            // Create animation mixer playerable node.
            int animationClipsLength = animationClips == null ? 0 : animationClips.Length;

            animationMixer = AnimationMixerPlayable.Create(playableGraph, animationClipsLength);

            // Connect the mixer to an output.
            playableOutput.SetSourcePlayable(animationMixer);

            // Create clip playable node for all animations.
            for (int i = 0; i < animationClipsLength; i++)
            {
                // Wrap the clip in a playable.
                var clipPlayable = AnimationClipPlayable.Create(playableGraph, animationClips[i]);

                playableGraph.Connect(clipPlayable, 0, animationMixer, i);
                animationMixer.SetInputWeight(i, 0.0f);
            }

            // Create audio output node.
            var audioOutput = AudioPlayableOutput.Create(playableGraph, "Audio", GetComponent <AudioSource>());

            // Create audio mixer playerable node.
            int audioClipsLength = audioClips == null ? 0 : audioClips.Length;

            audioMixer = AudioMixerPlayable.Create(playableGraph, audioClipsLength);

            // Connect the mixer to an output.
            audioOutput.SetSourcePlayable(audioMixer);

            // Create clip playable node for all audios.
            for (int i = 0; i < audioClipsLength; i++)
            {
                // Wrap the clip in a playable.
                var clipPlayable = AudioClipPlayable.Create(playableGraph, audioClips[i], false);

                playableGraph.Connect(clipPlayable, 0, audioMixer, i);
                audioMixer.SetInputWeight(i, 0.0f);
            }

            // Init the animation component list.
            currentAnimationList = new List <AnimationComponent>();

            // Plays the playable graph.
            playableGraph.Play();

            // Register graph visual client to show debug messages.
            GraphVisualizerClient.Show(playableGraph, "Animation Engine Graph");
        }
Esempio n. 20
0
        // Creates a layer mixer containing default blends
        // the base layer is a default clip of all driven properties
        // the next layer is optionally the desired default pose (in the case of humanoid, the tpose
        private Playable CreateDefaultBlend(PlayableGraph graph, GameObject go, Playable mixer, bool requireOffset)
        {
#if  UNITY_EDITOR
            if (Application.isPlaying)
            {
                return(mixer);
            }

            int inputs = 1 + ((m_CachedPropertiesClip != null) ? 1 : 0) + ((m_DefaultPoseClip != null) ? 1 : 0);
            if (inputs == 1)
            {
                return(mixer);
            }

            var defaultPoseMixer = AnimationLayerMixerPlayable.Create(graph, inputs);

            int mixerInput = 0;
            if (m_CachedPropertiesClip)
            {
                var cachedPropertiesClip = AnimationClipPlayable.Create(graph, m_CachedPropertiesClip);
                cachedPropertiesClip.SetApplyFootIK(false);
                var defaults = (Playable)cachedPropertiesClip;
                if (requireOffset)
                {
                    defaults = AttachOffsetPlayable(graph, defaults, m_SceneOffsetPosition, Quaternion.Euler(m_SceneOffsetRotation));
                }
                graph.Connect(defaults, 0, defaultPoseMixer, mixerInput);
                defaultPoseMixer.SetInputWeight(mixerInput, 1.0f);
                mixerInput++;
            }

            if (m_DefaultPoseClip)
            {
                var defaultPose = AnimationClipPlayable.Create(graph, m_DefaultPoseClip);
                defaultPose.SetApplyFootIK(false);
                var blendDefault = (Playable)defaultPose;
                if (requireOffset)
                {
                    blendDefault = AttachOffsetPlayable(graph, blendDefault, m_SceneOffsetPosition, Quaternion.Euler(m_SceneOffsetRotation));
                }

                graph.Connect(blendDefault, 0, defaultPoseMixer, mixerInput);
                defaultPoseMixer.SetInputWeight(mixerInput, 1.0f);
                mixerInput++;
            }


            graph.Connect(mixer, 0, defaultPoseMixer, mixerInput);
            defaultPoseMixer.SetInputWeight(mixerInput, 1.0f);

            return(defaultPoseMixer);
#else
            return(mixer);
#endif
        }
Esempio n. 21
0
        public void Init()
        {
            InitializeTweener();
            if (handData)
            {
                graph = PlayableGraph.Create("Hand Animation Controller graph");

                fingers = new Finger[5];
                var fingerMixer = AnimationLayerMixerPlayable.Create(graph, fingers.Length);
                for (uint i = 0; i < fingers.Length; i++)
                {
                    fingers[i] = new Finger(graph, handData.closed, handData.opened, handData[(int)i], lerper);
                    fingerMixer.SetLayerAdditive(i, false);
                    fingerMixer.SetLayerMaskFromAvatarMask(i, handData[(int)i]);
                    graph.Connect(fingers[i].Mixer, 0, fingerMixer, (int)i);
                    fingerMixer.SetInputWeight((int)i, 1);
                }
                handMixer = AnimationMixerPlayable.Create(graph, 2);
                graph.Connect(fingerMixer, 0, handMixer, 0);
                handMixer.SetInputWeight(0, 1);
                if (handData.poses.Count > 0)
                {
                    poseMixer = AnimationMixerPlayable.Create(graph, handData.poses.Count);
                    poses     = new List <Pose>();
                    for (int i = 0; i < handData.poses.Count; i++)
                    {
                        var poseClip = handData.poses[i];
                        if (poseClip)
                        {
                            var pose = new Pose(lerper);
                            pose.playable = AnimationClipPlayable.Create(graph, handData.poses[i]);
                            pose.clip     = handData.poses[i];
                            poses.Add(pose);
                            graph.Connect(pose.playable, 0, poseMixer, i);
                            poseMixer.SetInputWeight(i, 0);
                        }
                        poseMixer.SetInputWeight(pose, 1);
                    }
                    if (poses.Count > 0)
                    {
                        graph.Connect(poseMixer, 0, handMixer, 1);
                        handMixer.SetInputWeight(1, 0);
                    }
                }
                var playableOutput = AnimationPlayableOutput.Create(graph, "Hand Controller", GetComponentInChildren <Animator>());
                playableOutput.SetSourcePlayable(handMixer);
                initialized = true;
                graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
                graph.Play();
            }
            else
            {
                initialized = false;
            }
        }
 public void Init(AnimationClip[] clipsToPlay, Playable owner, PlayableGraph graph)
 {
     owner.SetInputCount(1);
     mixer = AnimationMixerPlayable.Create(graph, clipsToPlay.Length);
     graph.Connect(mixer, 0, owner, 0);
     owner.SetInputWeight(0, 1);
     for (int clipIndex = 0; clipIndex < mixer.GetInputCount(); clipIndex++)
     {
         graph.Connect(AnimationClipPlayable.Create(graph, clipsToPlay[clipIndex]), 0, mixer, clipIndex);
         mixer.SetInputWeight(clipIndex, 1f);
     }
 }
    public void Initialize(AnimationClip[] clipArray, Playable owner, PlayableGraph graph)
    {
        owner.SetInputCount(1);
        m_mixerPlayable = AnimationMixerPlayable.Create(graph, clipArray.Length);
        graph.Connect(m_mixerPlayable, 0, owner, 0);
        owner.SetInputWeight(0, 1);

        //根据clipArray创建AnimationClipPlayable并连接
        for (int clipIndex = 0; clipIndex < m_mixerPlayable.GetInputCount(); ++clipIndex)
        {
            graph.Connect(AnimationClipPlayable.Create(graph, clipArray[clipIndex]), 0, m_mixerPlayable, clipIndex);
        }
    }
Esempio n. 24
0
    //private AnimatorController animController;

    void Start()
    {
        playableGraph = PlayableGraph.Create("ClairePlayableGraph");

        playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

        var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>());

        // Create a Mixer
        AnimationLayerMixerPlayable mixerLayerPlayable = AnimationLayerMixerPlayable.Create(playableGraph, 2);


        playableOutput.SetSourcePlayable(mixerLayerPlayable);

        // Wrap the clip in a playable

        var clipPlayable = AnimationClipPlayable.Create(playableGraph, clip);

        //var clipPlayable1 = AnimationClipPlayable.Create(playableGraph, clip1);


        // Wrap AnimController

        runtimeAnimController = GetComponent <Animator>().runtimeAnimatorController;
        //animController = (AnimatorController)animator.runtimeAnimatorController;
        var runtimeAnimControllerPlayable = AnimatorControllerPlayable.Create(playableGraph, runtimeAnimController);


        // Connect to Mixer

        playableGraph.Connect(runtimeAnimControllerPlayable, 0, mixerLayerPlayable, 1);
        playableGraph.Connect(clipPlayable, 0, mixerLayerPlayable, 0);

        mixerLayerPlayable.SetInputWeight(0, 1.0f);
        mixerLayerPlayable.SetInputWeight(1, 1.0f);

        //mixerLayerPlayable.SetLayerAdditive(0, true);
        mixerLayerPlayable.SetLayerAdditive(1, true);
        Debug.Log("Is layer 0 additive: " + mixerLayerPlayable.IsLayerAdditive(0));
        Debug.Log("Is layer 1 additive: " + mixerLayerPlayable.IsLayerAdditive(1));

        //mixerLayerPlayable.SetLayerMaskFromAvatarMask(1, headMask);

        // Connect the Playable to an output

        //playableOutput.SetSourcePlayable(clipPlayable);

        // Plays the Graph.

        playableGraph.Play();
    }
Esempio n. 25
0
        void Start()
        {
            playableGraph = PlayableGraph.Create();
            var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>());

            mixerPlayable = AnimationMixerPlayable.Create(playableGraph, 2);
            playableOutput.SetSourcePlayable(mixerPlayable);
            var clipPlayable0 = AnimationClipPlayable.Create(playableGraph, clip0);
            var clipPlayable1 = AnimationClipPlayable.Create(playableGraph, clip1);

            playableGraph.Connect(clipPlayable0, 0, mixerPlayable, 0);
            playableGraph.Connect(clipPlayable1, 0, mixerPlayable, 1);
            playableGraph.Play();
        }
Esempio n. 26
0
        private void Start()
        {
            playableGraph = PlayableGraph.Create();
            var playableOutPut = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>());

            mixerPlayable = AnimationMixerPlayable.Create(playableGraph, 2);
            playableOutPut.SetSourcePlayable(mixerPlayable);
            var clipPlayable = AnimationClipPlayable.Create(playableGraph, clip);
            var ctrlPlayable = AnimatorControllerPlayable.Create(playableGraph, controller);

            playableGraph.Connect(clipPlayable, 0, mixerPlayable, 0);
            playableGraph.Connect(ctrlPlayable, 0, mixerPlayable, 1);
            playableGraph.Play();
        }
Esempio n. 27
0
    void Start()
    {
        graph = PlayableGraph.Create("BlendController");
        AnimationPlayableOutput output = AnimationPlayableOutput.Create(graph, "Animation", GetComponent <Animator>());

        mixer = AnimationMixerPlayable.Create(graph, 2);
        output.SetSourcePlayable(mixer);
        AnimationClipPlayable      clipP = AnimationClipPlayable.Create(graph, clip);
        AnimatorControllerPlayable ctrlP = AnimatorControllerPlayable.Create(graph, controller);

        graph.Connect(clipP, 0, mixer, 0);
        graph.Connect(ctrlP, 0, mixer, 1);
        graph.Play();
    }
            public override void OnPlayableCreate(Playable playable)
            {
                m_ActualPlayable = playable;

                var mixer = AnimationMixerPlayable.Create(graph, 1, true);

                m_Mixer = mixer;

                self.SetInputCount(1);
                self.SetInputWeight(0, 1);

                m_Mixer.SetInputWeight(0, 1);
                graph.Connect(m_Mixer, 0, self, 0);
            }
Esempio n. 29
0
 public void Load(MusicClip musicClip, Playable owner, PlayableGraph graph)
 {
     Clip = musicClip;
     owner.SetInputCount(1);
     mixer = AudioMixerPlayable.Create(graph, musicClip.ClipLayers.Length);
     graph.Connect(mixer, 0, owner, 0);
     owner.SetInputWeight(0, 1);
     inputPlayables = new AudioClipPlayable[musicClip.ClipLayers.Length];
     for (int i = 0; i < musicClip.ClipLayers.Length; i++)
     {
         inputPlayables[i] = AudioClipPlayable.Create(graph, musicClip.ClipLayers[i].Clip, false);
         graph.Connect(inputPlayables[i], 0, mixer, i);
         mixer.SetInputWeight(i, i == 0 ? 1f : 0f);
     }
 }
    // Start is called before the first frame update
    void Start()
    {
        animator = GetComponent <Animator>();
        //smr = childwithSkinnedMeshRenderer.GetComponent<SkinnedMeshRenderer>();
        //blendShapeCount = smr.sharedMesh.blendShapeCount;

        playableGraph = PlayableGraph.Create("ClairePlayableGraph");
        playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
        var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", animator);

        // Create Top Level Layer Mixer
        AnimationLayerMixerPlayable mixerLayerPlayable = AnimationLayerMixerPlayable.Create(playableGraph, 2);

        playableOutput.SetSourcePlayable(mixerLayerPlayable);

        // Wrap AnimController
        runtimeAnimController = animator.runtimeAnimatorController;
        var runtimeAnimControllerPlayable = AnimatorControllerPlayable.Create(playableGraph, runtimeAnimController);

        // Create an Emotion Mixer
        mixerEmotionPlayable = AnimationMixerPlayable.Create(playableGraph, 10, true);
        //playableOutput.SetSourcePlayable(mixerEmotionPlayable);

        // Connect to Top Level Layer Mixer
        playableGraph.Connect(runtimeAnimControllerPlayable, 0, mixerLayerPlayable, 0);
        playableGraph.Connect(mixerEmotionPlayable, 0, mixerLayerPlayable, 1);
        mixerLayerPlayable.SetInputWeight(0, 1.0f);
        mixerLayerPlayable.SetInputWeight(1, 1.0f);
        mixerLayerPlayable.SetLayerMaskFromAvatarMask(1, headMask);

        // Wrap the clips in a playable
        pInterested    = AnimationClipPlayable.Create(playableGraph, interested);
        pInterested2   = AnimationClipPlayable.Create(playableGraph, interested2);
        pEntertained   = AnimationClipPlayable.Create(playableGraph, entertained);
        pUncomfortable = AnimationClipPlayable.Create(playableGraph, uncomfortable);
        pConfused      = AnimationClipPlayable.Create(playableGraph, confused);
        pBored         = AnimationClipPlayable.Create(playableGraph, bored);
        pNeutral       = AnimationClipPlayable.Create(playableGraph, neutral);

        // Connect to Emotion Mixer
        //mixerEmotionPlayable.SetInputCount(5); // InputCount needs to be == to the number of connected clips (for normalization purposes)
        playableGraph.Connect(pInterested, 0, mixerEmotionPlayable, 0);
        playableGraph.Connect(pInterested2, 0, mixerEmotionPlayable, 1);
        playableGraph.Connect(pEntertained, 0, mixerEmotionPlayable, 2);
        playableGraph.Connect(pUncomfortable, 0, mixerEmotionPlayable, 3);
        playableGraph.Connect(pConfused, 0, mixerEmotionPlayable, 4);
        playableGraph.Connect(pBored, 0, mixerEmotionPlayable, 5);
        playableGraph.Connect(pNeutral, 0, mixerEmotionPlayable, 6);


        // Plays the Graph
        playableGraph.Play();
    }