private void Awake()
        {
            this.SafeGetComponent(ref _animator);

            // for objects in bundles, it'll be pre-scrubbed out
            #if UNITY_EDITOR
            _animator.runtimeAnimatorController = null;
            #endif

            _graph = PlayableGraph.Create();

            _playSelectorOwner = ScriptPlayable <PlaySelectorPlayable> .Create(_graph);

            _playSelector = _playSelectorOwner.GetBehaviour();
            _playSelector.Initialize(_playSelectorOwner, _graph);

            var playableOutput = AnimationPlayableOutput.Create(_graph, "Animation", _animator);
            playableOutput.SetSourcePlayable(_playSelectorOwner);
            playableOutput.SetSourceInputPort(0);

            #if UNITY_EDITOR
            GraphVisualizerClient.Show(_graph, string.Format("{0}.PlayObjectAnimations", gameObject.name));
            #endif

            _graph.Play();
            _playSelectorOwner.Pause();
        }
Пример #2
0
 internal ImmediateAnimation(Animator animator, bool unscaledTime = false)
 {
     graph     = PlayableGraph.Create();
     timeScale = unscaledTime ? DirectorUpdateMode.UnscaledGameTime : DirectorUpdateMode.GameTime;
     graph.SetTimeUpdateMode(timeScale);
     output = AnimationPlayableOutput.Create(graph, "ImmediateAnimation", animator);
 }
Пример #3
0
        // PRIVATE METHODS: -----------------------------------------------------------------------

        private void Setup()
        {
            if (!this.runtimeController)
            {
                throw new Exception(ERR_NORTC);
            }

            if (this.characterAnimator.animator.playableGraph.IsValid())
            {
                this.characterAnimator.animator.playableGraph.Destroy();
            }

            if (this.graph.IsValid())
            {
                this.graph.Destroy();
            }

            this.graph = PlayableGraph.Create(GRAPH_NAME);
            this.graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

            AnimationPlayableOutput output = AnimationPlayableOutput.Create(
                this.graph, GRAPH_NAME,
                this.characterAnimator.animator
                );

            this.SetupSectionDefaultStates();
            this.SetupSectionStates();
            this.SetupSectionGestures();

            output.SetSourcePlayable(this.mixerGesturesOutput);
            output.SetSourceOutputPort(0);

            this.graph.Play();
        }
Пример #4
0
    void OnEnable()
    {
        Transform midJoint = endJoint.parent;

        if (midJoint == null)
        {
            return;
        }
        Transform topJoint = midJoint.parent;

        if (topJoint == null)
        {
            return;
        }

        graph = PlayableGraph.Create("TwoBoneIK");
        graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
        var output = AnimationPlayableOutput.Create(graph, "ouput", animator);

        //animator.fireEvents = false;

        var twoBoneIKJob = new TwoBoneIKJob();

        twoBoneIKJob.Setup(animator, topJoint, midJoint, endJoint, targetTransform);

        playable = AnimationScriptPlayable.Create(graph, twoBoneIKJob);
        //m_LookAtPlayable.AddInput(AnimationClipPlayable.Create(m_Graph, idleClip), 0, 1.0f);

        output.SetSourcePlayable(playable);
        graph.Play();
    }
Пример #5
0
    public void Configure(Animator animator, EnemyAnimationConfig config)
    {
        graph = PlayableGraph.Create();
        graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
        mixer = AnimationMixerPlayable.Create(graph, 4);

        var clip = AnimationClipPlayable.Create(graph, config.Move);

        clip.Pause();
        mixer.ConnectInput((int)Clip.Move, clip, 0);

        clip = AnimationClipPlayable.Create(graph, config.Intro);
        clip.SetDuration(config.Intro.length);
        clip.Pause();
        mixer.ConnectInput((int)Clip.Intro, clip, 0);

        clip = AnimationClipPlayable.Create(graph, config.Outro);
        clip.SetDuration(config.Outro.length);
        clip.Pause();
        mixer.ConnectInput((int)Clip.Outro, clip, 0);

        clip = AnimationClipPlayable.Create(graph, config.Dying);
        clip.SetDuration(config.Dying.length);
        clip.Pause();
        mixer.ConnectInput((int)Clip.Dying, clip, 0);

        var output = AnimationPlayableOutput.Create(graph, "Enemy", animator);

        output.SetSourcePlayable(mixer);
    }
Пример #6
0
 public void SetAnimation(AnimationClip clip)
 {
     _clip   = AnimationClipPlayable.Create(_graph, clip);
     _output = AnimationPlayableOutput.Create(_graph, "output", _animator);
     _output.SetSourcePlayable(_clip);
     _clipTotalTime = (int)clip.length;
 }
        //============================================================================================

        /**
         *  @brief Starts pose debugging in editor and creates the playable graph.
         *
         *********************************************************************************************/
        public void StartPoseDebug(int a_animDataId)
        {
            if (m_animData.Length > 0 && a_animDataId < m_animData.Length)
            {
                CurrentAnimData = m_animData[a_animDataId];
            }

            if (CurrentAnimData != null)
            {
                p_animator = GetComponent <Animator>();

                m_animationStates = new MxMPlayableState[1];

                if (p_animator)
                {
                    MxMPlayableGraph = PlayableGraph.Create();
                    MxMPlayableGraph.SetTimeUpdateMode(DirectorUpdateMode.Manual);

                    var playableOutput = AnimationPlayableOutput.Create(MxMPlayableGraph, "Animation", p_animator);
                    m_animationMixer = AnimationMixerPlayable.Create(MxMPlayableGraph, 1, true);
                    playableOutput.SetSourcePlayable(m_animationMixer);
                    m_animationMixer.SetInputWeight(0, 1f);

                    basePosition = transform.position;
                    baseRotation = transform.rotation;

                    m_debugPosesActive = true;
                }
                else
                {
                    m_debugPoses       = false;
                    m_debugPosesActive = false;
                }
            }
        }
    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);
        }
    }
Пример #9
0
        public static AnimationController Create(GameObject go)
        {
            var animator = go.GetComponent <Animator>();

            if (animator == null)
            {
                animator             = go.AddComponent <Animator>();
                animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
            }
            var graph    = PlayableGraph.Create("Action");
            var playable = ScriptPlayable <AnimationController> .Create(graph);

            var animOut = AnimationPlayableOutput.Create(graph, "Animation", animator);

            animOut.SetSourcePlayable(playable, 0);

            var mixer = AnimationMixerPlayable.Create(graph);

            playable.AddInput(mixer, 0, 1);

            var behaviour = playable.GetBehaviour();

            behaviour.mGraph = graph;
            behaviour.mMixer = mixer;
            return(behaviour);
        }
Пример #10
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);
        });
    }
Пример #11
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);
        }
Пример #12
0
    private void Start()
    {
        // AnimationClipPlayableを構築

        var clip1Playable = AnimationClipPlayable.Create(graph, Clip1);
        var clip2Playable = AnimationClipPlayable.Create(graph, Clip2);
        var clip3Playable = AnimationClipPlayable.Create(graph, Clip3);



        // ミキサーを生成して、Clip1とClip2を登録
        // (代わりにAnimatorControllerPlayableとかでも可能)

        mixer = AnimationMixerPlayable.Create(graph, 2, true);
        mixer.ConnectInput(0, clip1Playable, 0);
        mixer.ConnectInput(1, clip2Playable, 0);


        // outputを生成して、出力先を自身のAnimatorに設定

        var output = AnimationPlayableOutput.Create(graph, "output", GetComponent <Animator>());


        // playableをoutputに流し込む

        output.SetSourcePlayable(mixer);


        graph.Play();
    }
Пример #13
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);
        }
Пример #14
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;
    }
Пример #15
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();
    }
        public void Play()
        {
            if (clipPlayable.IsValid() && clipPlayable.GetPlayState() == PlayState.Paused)
            {
                clipPlayable.Play();
            }
            else if (!IsPlaying)
            {
                IsPlaying        = true;
                animator.enabled = true;
                graph            = PlayableGraph.Create(graphName);
                var animOutput = AnimationPlayableOutput.Create(graph, outputName, animator);
                clipPlayable = AnimationClipPlayable.Create(graph, clip != null ? clip : new AnimationClip());
                clipPlayable.SetDuration(clip.length);

                animOutput.SetSourcePlayable(clipPlayable);

                graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
                graph.Play();
            }
            else
            {
                clipPlayable.SetTime(0);
            }
        }
Пример #17
0
        public SelectionWheelObjectAnimation(SelectionWheelGameObject SelectionWheelGameObject, AnimationClip enterTransitionAnimationClip, Action OnExitAnimationCompleted)
        {
            SelectionWheelObjectAnimationVariables = new Dictionary <SelectionWheelObjectAnimationVarableType, BoolVariable>()
            {
                { SelectionWheelObjectAnimationVarableType.OpenAnimation, new BoolVariable(false, OnOpenAnimationStarted) },
                {
                    SelectionWheelObjectAnimationVarableType.CloseAnimation, new BoolVariable(false, OnCloseAnimationStarted, () =>
                    {
                        OnCloseAnimationFinished();
                        OnExitAnimationCompleted.Invoke();
                    })
                }
            };

            AnimationGraph = PlayableGraph.Create(GetType().Name);
            AnimationGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

            EnterTransitionAnimationClipPlayable = AnimationClipPlayable.Create(AnimationGraph, enterTransitionAnimationClip);
            EnterTransitionAnimationClipPlayable.SetApplyFootIK(false);
            EnterTransitionAnimationClipPlayable.Pause();
            var animationGraphPlayableOutput = AnimationPlayableOutput.Create(AnimationGraph, "Animation", SelectionWheelGameObject.Animator);

            animationGraphPlayableOutput.SetSourcePlayable(EnterTransitionAnimationClipPlayable);

            AnimationGraph.Play();
        }
Пример #18
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;
    }
Пример #19
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;
    }
Пример #20
0
        public static PlayableGraph BuildPlayableGraph(Animator animator, IList <IRigLayer> layers, SyncSceneToStreamLayer syncSceneToStreamLayer)
        {
            string        graphName = animator.gameObject.transform.name + "_Rigs";
            PlayableGraph graph     = PlayableGraph.Create(graphName);

            graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

            IEnumerable <PlayableChain> playableChains = BuildPlayables(animator, graph, layers, syncSceneToStreamLayer);

            foreach (var chain in playableChains)
            {
                if (!chain.IsValid())
                {
                    continue;
                }

                AnimationPlayableOutput output = AnimationPlayableOutput.Create(graph, String.Format("%1-Output", chain.name), animator);
                output.SetAnimationStreamSource(AnimationStreamSource.PreviousInputs);
                output.SetSortingOrder(k_AnimationOutputPriority);

                // Connect last rig playable to output
                output.SetSourcePlayable(chain.playables[chain.playables.Length - 1]);
            }

            return(graph);
        }
Пример #21
0
    private void BuildOutput()
    {
        PlayableDirector.Evaluate();

        if (PlayableDirector.playableGraph.IsValid())
        {
            _outputTrackIndex       = 0;
            _trackAsset             = (PlayableDirector.playableAsset as TimelineAsset)?.GetOutputTrack(_outputTrackIndex);
            _originalOutput         = (AnimationPlayableOutput)PlayableDirector.playableGraph.GetOutputByType <AnimationPlayableOutput>(_outputTrackIndex);
            _originalSourcePlayable = _originalOutput.GetSourcePlayable();
            _clone         = PlayableDirector.playableAsset.CreatePlayable(PlayableDirector.playableGraph, PlayableDirector.gameObject);
            _mixer         = AnimationMixerPlayable.Create(PlayableDirector.playableGraph, 2);
            _cloneIndex    = _mixer.AddInput(_clone, 0);
            _originalIndex = _mixer.AddInput(_originalSourcePlayable, 0, 1f);

            if (_originalOutput.IsOutputValid() && _originalOutput.GetTarget() != null)
            {
                _output = AnimationPlayableOutput.Create(PlayableDirector.playableGraph, "OverridedDirectorOutput" + GetInstanceID(), _originalOutput.GetTarget());
                _output.SetSourcePlayable(_mixer);
                _output.SetSourceOutputPort(_originalOutput.GetSourceOutputPort());
                _output.SetWeight(1f);
                _originalOutput.SetTarget(null);
            }
            else
            {
                Debug.Log("Original Director Output is invalid");
            }
        }
    }
Пример #22
0
    private void Start()
    {
        playableGraph = PlayableGraph.Create();

        // Create the outputs.

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

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

        // Create the playables.

        var animationClipPlayable = AnimationClipPlayable.Create(playableGraph, animationClip);

        var audioClipPlayable = AudioClipPlayable.Create(playableGraph, audioClip, true);

        // Connect the playables to an output

        animationOutput.SetSourcePlayable(animationClipPlayable);

        audioOutput.SetSourcePlayable(audioClipPlayable);

        // Plays the Graph.

        playableGraph.Play();
    }
Пример #23
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();
        }
Пример #24
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();
    }
Пример #25
0
 //次のアニメーションのプレイアブル作成
 private void SetNextAnimationPlayable()
 {
     if (setPlayAnimation != null && playableGraph.IsValid())
     {
         if (mixer.IsValid())
         {
             playableGraph.Disconnect(mixer, 0);
             playableGraph.Disconnect(mixer, 1);
         }
         else
         {
             mixer = AnimationMixerPlayable.Create(playableGraph, 2, true);
             var output = AnimationPlayableOutput.Create(playableGraph, "output", GetComponent <Animator>());
             output.SetSourcePlayable(mixer);
         }
         if (_beforePlayAnimation.IsValid())
         {
             _beforePlayAnimation.Destroy();
         }
         if (_nowPlayAnimation.IsValid())
         {
             _beforePlayAnimation = _nowPlayAnimation;
         }
         //今のアニメーションに設定
         nowPlayAnimation   = setPlayAnimation;
         _beforeNowPlayClip = nowPlayAnimation;
         setPlayAnimation   = null;
         //アニメーションプレイアブル作成
         _nowPlayAnimation = AnimationClipPlayable.Create(playableGraph, nowPlayAnimation);
         mixer.ConnectInput(0, _nowPlayAnimation, 0);
         mixer.ConnectInput(1, _beforePlayAnimation, 0);
     }
 }
Пример #26
0
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < clipBindings.Length; i++)
        {
            int indx = i;
            clipBindings[indx].binding.Init();
            clipBindings[indx].binding.Bind(() => StartClip(indx), (f) => UpdateClip(indx, f), () => EndClip(indx));
        }


        animator = GetComponent <Animator>();

        playableGraph = PlayableGraph.Create();


        var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Anim", animator);

        mixer = AnimationMixerPlayable.Create(playableGraph, clipBindings.Length);

        playableOutput.SetSourcePlayable(mixer);


        playableClips = new AnimationClipPlayable[clipBindings.Length];

        for (int i = 0; i < playableClips.Length; i++)
        {
            playableClips[i] = AnimationClipPlayable.Create(playableGraph, clipBindings[i].clip);

            playableGraph.Connect(playableClips[i], 0, mixer, i);
        }
    }
Пример #27
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();
    }
Пример #28
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();
    }
Пример #29
0
    public void Initialize(EntityManager entityManager, Entity owner, Entity character)
    {
        m_Animator = entityManager.GetComponentObject <Animator>(owner);

        m_Animator.fireEvents = fireAnimationEvents;

        GameDebug.Assert(animStateDefinition != null, "No animStateDefinition defined for AnimStateController:" + this.name);

        Profiler.BeginSample("Create graph");
        m_PlayableGraph = PlayableGraph.Create(name);
        Profiler.EndSample();

#if UNITY_EDITOR
        GraphVisualizerClient.Show(m_PlayableGraph);
#endif

        Profiler.BeginSample("Instantiate playables");
        m_animGraph = animStateDefinition.Instatiate(entityManager, owner, m_PlayableGraph, character);
        Profiler.EndSample();

        m_animGraphLogic = m_animGraph as IGraphLogic;

        m_PlayableGraph.Play();

        var outputPlayable = Playable.Null;
        var outputPort     = 0;
        m_animGraph.GetPlayableOutput(0, ref outputPlayable, ref outputPort);

        // Set graph output
        var animationOutput = AnimationPlayableOutput.Create(m_PlayableGraph, "Animator", m_Animator);
        animationOutput.SetSourcePlayable(outputPlayable);
        animationOutput.SetSourceOutputPort(outputPort);
    }
        bool CreatePlayableGraph()
        {
            var animator = GetComponent <Animator>();

            if (animator.avatar == null)
            {
                animator.avatar      = AvatarBuilder.BuildGenericAvatar(animator.gameObject, transform.name);
                animator.avatar.name = "Avatar";
            }

            var deltaTimeProperty = animator.BindSceneProperty(transform, typeof(Kinematica), "_deltaTime");

            job = new UpdateAnimationPoseJob();
            if (!job.Setup(animator,
                           GetComponentsInChildren <Transform>(), ref Synthesizer.Ref, deltaTimeProperty))
            {
                return(false);
            }

            playableGraph =
                PlayableGraph.Create(
                    $"Kinematica_{animator.transform.name}");

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

            var playable = AnimationScriptPlayable.Create(playableGraph, job);

            output.SetSourcePlayable(playable);

            playableGraph.Play();

            return(true);
        }