コード例 #1
0
    void Awake()
    {
        animator.updateMode = AnimatorUpdateMode.UnscaledTime;
        playableGraph       = PlayableGraph.Create(GetType().ToString());
        playableGraph.SetTimeUpdateMode(DirectorUpdateMode.UnscaledGameTime);
        var animationLayerMixerPlayable = AnimationLayerMixerPlayable.Create(playableGraph, resources.Count);
        var animationPlayableOutput     = AnimationPlayableOutput.Create(playableGraph, GetType().ToString() + "Output", animator);

        animationPlayableOutput.SetSourcePlayable(animationLayerMixerPlayable);

        var ui     = Instantiate(uiPrerab);
        var layout = Instantiate(layoutPrerab, ui.transform);

        resources.ForEach(resource =>
        {
            var animationClips = Resources.LoadAll <AnimationClip>(resource).ToList();
            var mixier         = new Mixer(playableGraph, ref animationLayerMixerPlayable, blendingCurve, animationClips);
            var grid           = Instantiate(gridPrerab, layout.transform);
            var toggleGroup    = grid.GetComponent <ToggleGroup>();

            animationClips.ForEach(animationClip =>
            {
                var button = Instantiate(buttonPrerab, grid.transform);
                button.GetComponentInChildren <Text>().text = animationClip.name;
                var toggle   = button.GetComponent <Toggle>();
                toggle.group = toggleGroup;
                toggle
                .OnValueChangedAsObservable()
                .Where(_ => _)
                .Subscribe(_ => mixier.Play(animationClip.name));
            });
            mixers.Add(mixier);
        });
    }
コード例 #2
0
        //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);
        }
コード例 #3
0
    private PlayableGraph graph;                    //PlayAbleとの接続


    private void Awake()
    {
        graph = PlayableGraph.Create();
        var anim = GetComponent <Animator>();

        var defo = new List <AnimationClip>();

        //全レイヤーの初期アニメを取得し、デフォルトアニメとしてコンバータにセット
        foreach (var i in Enumerable.Range(0, anim.layerCount))
        {
            var temp = anim.GetCurrentAnimatorClipInfo(i)[0].clip;
            converters.Add(new Converter(graph, temp));
            defo.Add(temp);
            Debug.Log("Layer num " + i + ",defoult anim " + temp.name);
        }

        //LayerMask情報をコンバータにセット
        layerMixer = AnimationLayerMixerPlayable.Create(graph, anim.layerCount);
        foreach (var item in maskBoxs)
        {
            layerMixer.SetLayerMaskFromAvatarMask(item.numberToMask, item.layerMask);
        }

        var output = AnimationPlayableOutput.Create(graph, "output", anim);         //自身のAnimatorを出力先に決定

        output.SetSourcePlayable(layerMixer);
        graph.Play();
    }
コード例 #4
0
ファイル: RandomAnim.cs プロジェクト: studentutu/coreutils
        private void Play(AnimationClip animClip)
        {
            m_Graph = PlayableGraph.Create(name + " Character Anims");
            m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

            // Create the starting animation clip.
            AnimationClipPlayable animPlayable = AnimationClipPlayable.Create(m_Graph, animClip);

            // Create the transition mixer for changing animations over time.
            AnimationMixerPlayable transitionMixer = AnimationMixerPlayable.Create(m_Graph, 2);

            // Connect the base clip to the transition mixer.
            m_Graph.Connect(animPlayable, 0, transitionMixer, 1);

            transitionMixer.SetInputWeight(0, 0);
            transitionMixer.SetInputWeight(1, 1);

            // Create the layer output to handle 'heels'/'barefoot' options.
            AnimationPlayableOutput     playableOutput = AnimationPlayableOutput.Create(m_Graph, "LayerMixer", m_Animator);
            AnimationLayerMixerPlayable layerMixer     = AnimationLayerMixerPlayable.Create(m_Graph, 2);

            // Set the 'heels' layer to additive.
            layerMixer.SetLayerAdditive(1, true);
            playableOutput.SetSourcePlayable(layerMixer);

            layerMixer.ConnectInput(0, transitionMixer, 0, 1);

            m_Graph.Play();
        }
コード例 #5
0
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_Move8Dir settings)
        {
            m_settings        = settings;
            m_EntityManager   = entityManager;
            m_Owner           = owner;
            m_AnimStateOwner  = animStateOwner;
            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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
            /************************************************************************************************************************/

            /// <summary>[Internal] Creates a new <see cref="LayerList"/>.</summary>
            internal LayerList(AnimancerPlayable root, out Playable layerMixer)
            {
                Root       = root;
                _Layers    = new AnimancerLayer[DefaultCapacity];
                layerMixer = LayerMixer = AnimationLayerMixerPlayable.Create(root._Graph, 1);
                Root._Graph.Connect(layerMixer, 0, Root._RootPlayable, 0);
            }
コード例 #8
0
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_InAir settings)
        {
            m_settings       = settings;
            m_EntityManager  = entityManager;
            m_Owner          = owner;
            m_AnimStateOwner = animStateOwner;

            GameDebug.Assert(entityManager.HasComponent <Character>(m_AnimStateOwner), "Owner has no Character component");
            m_character = entityManager.GetComponentObject <Character>(m_AnimStateOwner);

            m_mainMixer = AnimationMixerPlayable.Create(graph);

            m_animInAir = AnimationClipPlayable.Create(graph, settings.animInAir);
            m_animInAir.Play();
            m_animInAir.SetApplyFootIK(false);
            inAirPort = m_mainMixer.AddInput(m_animInAir, 0);

            m_animLandAntic = AnimationClipPlayable.Create(graph, settings.animLandAntic);
            m_animInAir.Play();
            m_animLandAntic.SetApplyFootIK(false);
            landAnticPort = m_mainMixer.AddInput(m_animLandAntic, 0);

            m_layerMixer = AnimationLayerMixerPlayable.Create(graph);
            var port = m_layerMixer.AddInput(m_mainMixer, 0);

            m_layerMixer.SetInputWeight(port, 1);

            // Aim
            //if (settings.animAimDownToUp != null)
            //    m_aimHandler = new AimVerticalHandler(m_layerMixer, settings.animAimDownToUp);

            // Actions
            m_actionAnimationHandler = new ActionAnimationHandler(m_layerMixer, settings.actionAnimations);
        }
コード例 #9
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;
            }
コード例 #10
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);
            }
コード例 #11
0
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, AnimGraph_Simple settings)
        {
            m_EntityManager = entityManager;
            m_Owner         = owner;

            m_layerMixer = AnimationLayerMixerPlayable.Create(graph);
            int port;

            // Idle
            m_animIdle = AnimationClipPlayable.Create(graph, settings.animIdle);
            m_animIdle.SetApplyFootIK(settings.idleFootIKActive);
            port = m_layerMixer.AddInput(m_animIdle, 0);
            m_layerMixer.SetInputWeight(port, 1.0f);

            // Aim
            if (settings.animAimDownToUp != null)
            {
                m_aimHandler = new AimVerticalHandler(m_layerMixer, settings.animAimDownToUp);
            }

            // Actions
            m_actionMixer = AnimationLayerMixerPlayable.Create(graph);
            port          = m_actionMixer.AddInput(m_layerMixer, 0);
            m_actionMixer.SetInputWeight(port, 1);
            m_actionAnimationHandler = new ActionAnimationHandler(m_actionMixer, settings.actionAnimations);
        }
コード例 #12
0
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_Jump settings)
        {
            m_EntityManager  = entityManager;
            m_Owner          = owner;
            m_AnimStateOwner = animStateOwner;

            m_additiveMixer = AnimationLayerMixerPlayable.Create(graph);

            m_animJump = AnimationClipPlayable.Create(graph, settings.animJump);
            m_animJump.SetApplyFootIK(true);
            m_animJump.SetDuration(settings.animJump.length);
            m_animJump.Pause();
            int port = m_additiveMixer.AddInput(m_animJump, 0);

            m_additiveMixer.SetLayerAdditive((uint)port, false);
            m_additiveMixer.SetInputWeight(port, 1);

            // Adjust play speed so vertical velocity in animation is matched with character velocity (so feet doesnt penetrate ground)
            var animJumpVel      = settings.jumpHeight / settings.animJump.length;
            var characterJumpVel = Game.config != null ? Game.config.jumpAscentHeight / Game.config.jumpAscentDuration : animJumpVel;

            playSpeed = characterJumpVel / animJumpVel;


            // Aim
            //m_aimHandler = new AimVerticalHandler(m_additiveMixer, settings.animAimDownToUp);
        }
コード例 #13
0
    void Start()
    {
        var animator = this.GetComponent <Animator>();

        this.PlayableGraph = PlayableGraph.Create("Test");

        this.AnimationLayerMixerPlayable = AnimationLayerMixerPlayable.Create(this.PlayableGraph, 0);
        this.AnimationLayerMixerPlayable.SetInputCount(0);
        var playableOutput = AnimationPlayableOutput.Create(this.PlayableGraph, "Animation", animator);

        playableOutput.SetSourcePlayable(this.AnimationLayerMixerPlayable);

        this.Layers.Add(AnimationMixerPlayable.Create(this.PlayableGraph));
        ((AnimationMixerPlayable)this.Layers[0]).AddInput(AnimationClipPlayable.Create(this.PlayableGraph, this.FakeClip), 0);
        ((AnimationMixerPlayable)this.Layers[0]).AddInput(AnimationClipPlayable.Create(this.PlayableGraph, this.FakeClip), 0);

        this.Layers.Add(AnimationClipPlayable.Create(this.PlayableGraph, this.FakeClip));


        this.Layers.Add(AnimationMixerPlayable.Create(this.PlayableGraph));
        ((AnimationMixerPlayable)this.Layers[2]).AddInput(AnimationClipPlayable.Create(this.PlayableGraph, this.FakeClip), 0);

        this.AnimationLayerMixerPlayable.AddInput((Playable)this.Layers[0], 0);
        this.AnimationLayerMixerPlayable.AddInput((Playable)this.Layers[1], 0);
        this.AnimationLayerMixerPlayable.AddInput((Playable)this.Layers[2], 0);

        this.PlayableGraph.Play();
    }
コード例 #14
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;
    }
コード例 #15
0
    private void Awake()
    {
        Animator animator = GetComponent <Animator>();

        animator.updateMode  = m_AnimatorUpdateMode;
        animator.cullingMode = m_CullingMode;

#if !UNITY_2018_2_OR_NEWER
        Debug.LogError("Only support 2018.2 or newer!");
#else
#if UNITY_2018_2
        m_Graph = animator.playableGraph;
#else
        m_Graph = PlayableGraph.Create(this.name);
        AnimationPlayableOutput.Create(m_Graph, "ani", animator);
        m_Graph.Play();
#endif
#endif
        m_LayerManager = AnimationLayerMixerPlayable.Create(m_Graph, 2);
        m_Graph.GetOutput(0).SetSourcePlayable(m_LayerManager);

        m_Layer = new SAnimationLayer[m_LayerCount];
        for (int i = 0; i < m_LayerCount; i++)
        {
            m_Layer[i] = new SAnimationLayer(animator, m_LayerManager, i);
        }
    }
コード例 #16
0
        /// <summary>
        /// Called by Unity.
        /// </summary>
        private void OnEnable()
        {
            _cubismFadeMotionList = GetComponent <CubismFadeController>().CubismFadeMotionList;

            // Fail silently...
            if (_cubismFadeMotionList == null)
            {
                Debug.LogError("CubismMotionController : CubismFadeMotionList doesn't set in CubismFadeController.");
                return;
            }

            // Get Animator.
            var animator = GetComponent <Animator>();

            if (animator.runtimeAnimatorController != null)
            {
                Debug.LogWarning("Animator Controller was set in Animator component.");
                return;
            }

            _isActive = true;

            // Disabble animator's playablegrap.
            var graph = animator.playableGraph;

            if (graph.IsValid())
            {
                graph.GetOutput(0).SetWeight(0);
            }

            // Create Playable Graph.
            _playableGrap = PlayableGraph.Create("Playable Graph : " + this.FindCubismModel().name);
            _playableGrap.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

            // Create Playable Output.
            _playableOutput = AnimationPlayableOutput.Create(_playableGrap, "Animation", animator);
            _playableOutput.SetWeight(1);

            // Create animation layer mixer.
            _layerMixer = AnimationLayerMixerPlayable.Create(_playableGrap, LayerCount);

            // Create cubism motion layers.
            if (_motionLayers == null)
            {
                LayerCount    = (LayerCount < 1) ? 1 : LayerCount;
                _motionLayers = new CubismMotionLayer[LayerCount];
            }

            for (var i = 0; i < LayerCount; ++i)
            {
                _motionLayers[i] = CubismMotionLayer.CreateCubismMotionLayer(_playableGrap, _cubismFadeMotionList);
                _motionLayers[i].AnimationEndHandler += OnAnimationEnd;
                _layerMixer.ConnectInput(i, _motionLayers[i].PlayableOutput, 0);
                _layerMixer.SetInputWeight(i, 1.0f);
            }

            // Set Playable Output.
            _playableOutput.SetSourcePlayable(_layerMixer);
        }
コード例 #17
0
        public void Start()
        {
            graph = PlayableGraph.Create(name);

            layerMixer = AnimationLayerMixerPlayable.Create(graph, 0);

            AnimationPlayableUtilities.Play(animator, layerMixer, graph);
        }
コード例 #18
0
    // Use this for initialization
    void Start()
    {
        animator = GetComponent <Animator>();

        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);

        // Create an Emotion Mixer
        mixerEmotionPlayable = AnimationMixerPlayable.Create(playableGraph, 4);

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

        // 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
        pHappy             = AnimationClipPlayable.Create(playableGraph, happy);
        pHappyTransitionIn = AnimationClipPlayable.Create(playableGraph, happyTransitionIn);
        pAngry             = AnimationClipPlayable.Create(playableGraph, angry);
        pAngryTransitionIn = AnimationClipPlayable.Create(playableGraph, angryTransitionIn);
        pTPose             = AnimationClipPlayable.Create(playableGraph, tPose);

        // Setup Durations for IsDone Checks
        pHappyTransitionIn.SetDuration(happyTransitionIn.length);
        pAngryTransitionIn.SetDuration(angryTransitionIn.length);

        // Connect to Emotion Mixer
        mixerEmotionPlayable.SetInputCount(5); // InputCount needs to be == to the number of connected clips (for normalization purposes)
        playableGraph.Connect(pHappy, 0, mixerEmotionPlayable, 0);
        playableGraph.Connect(pHappyTransitionIn, 0, mixerEmotionPlayable, 1);
        playableGraph.Connect(pAngry, 0, mixerEmotionPlayable, 2);
        playableGraph.Connect(pAngryTransitionIn, 0, mixerEmotionPlayable, 3);
        playableGraph.Connect(pTPose, 0, mixerEmotionPlayable, 4);

        Debug.Log("INputLength: " + mixerEmotionPlayable.GetInputCount());



        // Activate T Pose
        mixerEmotionPlayable.SetInputWeight(4, 1.0f);

        Debug.Log("Happy Transition Time: " + pHappyTransitionIn.GetDuration());

        // Plays the Graph
        playableGraph.Play();
    }
コード例 #19
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
        }
コード例 #20
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;
            }
        }
コード例 #21
0
        public static AnimationLayerMixerPlayable PlayLayerMixer(Animator animator, int inputCount, out PlayableGraph graph)
        {
            graph = PlayableGraph.Create();
            AnimationPlayableOutput     output = AnimationPlayableOutput.Create(graph, "Mixer", animator);
            AnimationLayerMixerPlayable animationLayerMixerPlayable = AnimationLayerMixerPlayable.Create(graph, inputCount);

            output.SetSourcePlayable(animationLayerMixerPlayable);
            graph.SyncUpdateAndTimeMode(animator);
            graph.Play();
            return(animationLayerMixerPlayable);
        }
コード例 #22
0
        public void Create(Animator animator)
        {
            string name = animator.gameObject.name;

            _graph = PlayableGraph.Create(name);
            _graph.SetTimeUpdateMode(DirectorUpdateMode.Manual);

            _mixerRoot = AnimationLayerMixerPlayable.Create(_graph);
            _output    = AnimationPlayableOutput.Create(_graph, name, animator);
            _output.SetSourcePlayable(_mixerRoot);
        }
コード例 #23
0
        public AnimatorPlayableObject(string graphName, Animator animator)
        {
            this.Animator            = animator;
            this.GlobalPlayableGraph = PlayableGraph.Create(graphName);
            this.GlobalPlayableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
            var playableOutput = AnimationPlayableOutput.Create(this.GlobalPlayableGraph, "Animation", animator);

            this.AnimationLayerMixerPlayable = AnimationLayerMixerPlayable.Create(this.GlobalPlayableGraph);
            PlayableOutputExtensions.SetSourcePlayable(playableOutput, this.AnimationLayerMixerPlayable);
            this.GlobalPlayableGraph.Play();
        }
コード例 #24
0
 public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, AnimGraph_AdditiveAnimation settings)
 {
     m_Settings = settings;
     m_graph    = graph;
     m_Mixer    = AnimationLayerMixerPlayable.Create(m_graph, 2);
     m_Mixer.SetInputWeight(0, 1f);
     m_Mixer.SetInputWeight(1, 1f);
     m_Mixer.SetLayerAdditive(1, true);
     m_AdditiveClip = AnimationClipPlayable.Create(m_graph, m_Settings.clip);
     m_AdditiveClip.SetApplyFootIK(false);
     m_graph.Connect(m_AdditiveClip, 0, m_Mixer, 1);
 }
コード例 #25
0
    // 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();
    }
コード例 #26
0
    // INITIALIZERS: ------------------------------------------------------------------------------

    public Playable Setup(PlayableGraph graph, Playable input)
    {
        this.graph = graph;

        this.mixer = AnimationLayerMixerPlayable.Create(this.graph, 2);
        this.mixer.ConnectInput(0, input, 0);
        this.mixer.ConnectInput(1, Playable.Null, 0);

        mixer.SetInputWeight(0, 1.0f);
        mixer.SetInputWeight(1, 0.0f);

        return(this.mixer);
    }
コード例 #27
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();
    }
コード例 #28
0
        public static AnimatorPlayable alloc(string p_graphName, Animator p_animator)
        {
            AnimatorPlayable l_instance = new AnimatorPlayable();

            l_instance.Animator            = p_animator;
            l_instance.GlobalPlayableGraph = PlayableGraph.Create(p_graphName);
            l_instance.GlobalPlayableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
            var playableOutput = AnimationPlayableOutput.Create(l_instance.GlobalPlayableGraph, "Animation", p_animator);

            l_instance.AnimationLayerMixerPlayable = AnimationLayerMixerPlayable.Create(l_instance.GlobalPlayableGraph);
            PlayableOutputExtensions.SetSourcePlayable(playableOutput, l_instance.AnimationLayerMixerPlayable);
            l_instance.GlobalPlayableGraph.Play();
            return(l_instance);
        }
コード例 #29
0
        private void Awake()
        {
            EnsureVersionUpgraded();
            hasAwoken = true;

            if (layers.Length == 0)
            {
                return;
            }

            //The playable graph is a directed graph of Playables.
            graph = PlayableGraph.Create();

            // The AnimationPlayableOutput links the graph with an animator that plays the graph.
            // I think we can ditch the animator, but the documentation is kinda sparse!
            outputAnimator = gameObject.EnsureComponent <Animator>();
            AnimationPlayableOutput animOutput = AnimationPlayableOutput.Create(graph, $"{name}_animation_player", outputAnimator);

            for (var i = 0; i < layers.Length; i++)
            {
                layers[i].InitializeSelf(graph);
            }

            if (layers.Length <= 1)
            {
                rootPlayable = layers[0].stateMixer;
            }
            else
            {
                var layerMixer = AnimationLayerMixerPlayable.Create(graph, layers.Length);

                for (var i = 0; i < layers.Length; i++)
                {
                    layers[i].InitializeLayerBlending(graph, i, layerMixer);
                }

                rootPlayable = layerMixer;
            }

            animOutput.SetSourcePlayable(rootPlayable);

            //fun fact: default is DSPClock!
            graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
            graph.Play();

            visualizerClientName = name + " AnimationPlayer";
            GraphVisualizerClient.Show(graph, visualizerClientName);
        }
        public PlayableStateController(PlayableGraph graph)
        {
            m_Params = new PlayableAnimatorParameter();

            m_StateLayers = new List <StateLayer>();

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

            var layer = new StateLayer(0, graph, m_Params);

            layer.SetPlayableOutput(0, layer.layerIndex, m_LayerMixer);
            m_StateLayers.Add(layer);     // 添加默认层

            m_Graph = graph;
        }