Beispiel #1
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();
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
 public void SetAnimation(AnimationClip clip)
 {
     _clip   = AnimationClipPlayable.Create(_graph, clip);
     _output = AnimationPlayableOutput.Create(_graph, "output", _animator);
     _output.SetSourcePlayable(_clip);
     _clipTotalTime = (int)clip.length;
 }
        //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 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);
        }
Beispiel #6
0
        AnimationScriptPlayable[] BuildRigPlayables(PlayableGraph graph, Rig rig, ref AnimationPlayableOutput output)
        {
            if (rig == null || rig.jobs == null || rig.jobs.Length == 0)
            {
                return(null);
            }

            var count     = rig.jobs.Length;
            var playables = new AnimationScriptPlayable[count];

            for (int i = 0; i < count; ++i)
            {
                var binder = rig.constraints[i].binder;
                playables[i] = binder.CreatePlayable(graph, rig.jobs[i]);
            }

            // Set null input on first rig playable in order to use inputWeight
            // to set job constraint weight
            playables[0].AddInput(Playable.Null, 0, 1);

            // Connect rest of rig playables serially
            for (int i = 1; i < count; ++i)
            {
                playables[i].AddInput(playables[i - 1], 0, 1);
            }

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

            return(playables);
        }
Beispiel #7
0
    private void PlayAnimation()
    {
        AnimationClip cur = idleClip;

        switch (curState)
        {
        case PlayerState.Idle:
        {
            cur = idleClip;
        }
        break;

        case PlayerState.Jump:
        {
            cur = jumpClip;
        }
        break;

        case PlayerState.Run:
        {
            cur = runClip;
        }
        break;
        }
        AnimationClipPlayable animationClip1 = AnimationClipPlayable.Create(playableGraph, cur);

        //playableGraph.Connect(animationClip1,0, animationLayerMixerPlayable, 0);
        //animationLayerMixerPlayable.SetLayerMaskFromAvatarMask(1, bbb);
        animationPlayableOutput.SetSourcePlayable(animationClip1);
        //Debug.Log("f**k");
        playableGraph.Play();
    }
Beispiel #8
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");
            }
        }
    }
        /// <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);
        }
Beispiel #10
0
        static public void Play(Animator animator, Playable playable, PlayableGraph graph)
        {
            AnimationPlayableOutput playableOutput = AnimationPlayableOutput.Create(graph, "AnimationClip", animator);

            playableOutput.SetSourcePlayable(playable, 0);
            graph.SyncUpdateAndTimeMode(animator);
            graph.Play();
        }
    public void ConnectTracksToPlayableGraph(AnimationClip clip, Animator anim)
    {
        AnimationPlayableOutput playableOutput = AnimationPlayableOutput.Create(timeline.pg, "Animation", anim);

        var clipPlayable = AnimationClipPlayable.Create(timeline.pg, clip);

        playableOutput.SetSourcePlayable(clipPlayable);
        playableOutput.SetSourceInputPort(0);
    }
Beispiel #12
0
        public void CreatePlayable(Animator animator = null)
        {
            m_PlayableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
            m_PlayableGraph.Play();
            m_Playable = ScriptPlayable <VisualAnimationPlayable> .Create(m_PlayableGraph).GetBehaviour();

            m_AnimationPlayableOutput = AnimationPlayableOutput.Create(m_PlayableGraph, "Output", animator);
            m_AnimationPlayableOutput.SetSourcePlayable(m_Playable.Playable, 0);
        }
Beispiel #13
0
 public void Initialize(GameObject go)
 {
     this.go         = go;
     graph           = PlayableGraph.Create("Preapare Data Graph");
     mixer           = AnimationMixerPlayable.Create(graph, 0, false);
     animationOutput = AnimationPlayableOutput.Create(graph, "Animation Output", go.GetComponent <Animator>());
     animationOutput.SetSourcePlayable(mixer);
     graph.SetTimeUpdateMode(DirectorUpdateMode.Manual);
 }
        public void Blend(AnimationScriptPlayable playable, float duration, AnimationCurve transitionCurve)
        {
            if (tweening && lastTween != null)
            {
                lastTween.callOnCompletes();
                lastTween.setOnUpdate((float value) => { });
                lastTween.setOnComplete(() => { });
                // LeanTween.pause(lastTween.id);
            }

            // tweenPlayable = AnimatorControllerPlayable.Create(playableGraph, ac);
            tweenPlayable = playable;
            mixerPlayable = AnimationMixerPlayable.Create(playableGraph, 2);

            mixerPlayable.ConnectInput(0, activePlayable, 0);
            mixerPlayable.ConnectInput(1, tweenPlayable, 0);

            // Plays the Graph.
            mixerPlayable.SetInputWeight(0, 1);
            playableOutput.SetSourcePlayable(mixerPlayable);

            lastTween = LeanTween
                        .value(playerController.gameObject, 0f, 1f, duration)
                        .setEase(transitionCurve)
                        .setOnUpdate((float value) =>
            {
                mixerPlayable.SetInputWeight(0, 1f - value);
                mixerPlayable.SetInputWeight(1, value);
            })
                        .setOnComplete(() =>
            {
                tweening = false;

                playableGraph.Disconnect(mixerPlayable, 0);
                playableGraph.Disconnect(mixerPlayable, 1);
                playableOutput.SetSourcePlayable(tweenPlayable);
                var prevActive = activePlayable;
                activePlayable = tweenPlayable;
                // prevActive.Destroy();
                mixerPlayable.Destroy();
            });

            tweening = true;
        }
        public EvaluationGraph(Animator animator, AnimationClip clip)
        {
            m_Graph = PlayableGraph.Create("Evaluation-Graph");
            m_Graph.SetTimeUpdateMode(DirectorUpdateMode.Manual);

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

            m_Output = AnimationPlayableOutput.Create(m_Graph, "Evaluation-Graph-Output", animator);
            m_Output.SetSourcePlayable(clipPlayable);
        }
Beispiel #16
0
    private void Start()
    {
        m_graph = PlayableGraph.Create();
        m_graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

        m_mixer  = AnimationMixerPlayable.Create(m_graph, 2);
        m_output = AnimationPlayableOutput.Create(m_graph, "Animation", GetComponent <Animator>());
        m_output.SetSourcePlayable(m_mixer);
        m_graph.Play();
    }
        public static AnimatorControllerPlayable PlayAnimatorController(Animator animator, RuntimeAnimatorController controller, out PlayableGraph graph)
        {
            graph = PlayableGraph.Create();
            AnimationPlayableOutput    output = AnimationPlayableOutput.Create(graph, "AnimatorControllerPlayable", animator);
            AnimatorControllerPlayable animatorControllerPlayable = AnimatorControllerPlayable.Create(graph, controller);

            output.SetSourcePlayable(animatorControllerPlayable);
            graph.SyncUpdateAndTimeMode(animator);
            graph.Play();
            return(animatorControllerPlayable);
        }
        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);
        }
Beispiel #19
0
    void CreateGraph()
    {
        m_PlayableGraph = PlayableGraph.Create(name);
        m_PlayableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

        m_PlayableOutput    = AnimationPlayableOutput.Create(m_PlayableGraph, "Animation", animator);
        m_RootMixerPlayable = AnimationMixerPlayable.Create(m_PlayableGraph, 1);
        m_PlayableOutput.SetSourcePlayable(m_RootMixerPlayable);

        m_PlayableGraph.Play();
    }
Beispiel #20
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);
        }
Beispiel #21
0
    private void InitializeAnimations()
    {
        npcData.Animator = gameObject.AddComponent <Animator>();

        PlayableGraph           playableGraph  = PlayableGraph.Create();
        AnimationClipPlayable   clipPlayable   = AnimationClipPlayable.Create(playableGraph, npcData.IdleFront);
        AnimationPlayableOutput playableOutput = AnimationPlayableOutput.Create(playableGraph, "idleFront", npcData.Animator);

        playableOutput.SetSourcePlayable(clipPlayable);
        playableGraph.Play();
    }
        public static AnimationClipPlayable PlayClip(Animator animator, AnimationClip clip, out PlayableGraph graph)
        {
            graph = PlayableGraph.Create();
            AnimationPlayableOutput output = AnimationPlayableOutput.Create(graph, "AnimationClip", animator);
            AnimationClipPlayable   animationClipPlayable = AnimationClipPlayable.Create(graph, clip);

            output.SetSourcePlayable(animationClipPlayable);
            graph.SyncUpdateAndTimeMode(animator);
            graph.Play();
            return(animationClipPlayable);
        }
        static public AnimationMixerPlayable PlayMixer(Animator animator, int inputCount, out PlayableGraph graph)
        {
            graph = PlayableGraph.Create();
            AnimationPlayableOutput playableOutput = AnimationPlayableOutput.Create(graph, "Mixer", animator);
            var mixer = AnimationMixerPlayable.Create(graph, inputCount);

            playableOutput.SetSourcePlayable(mixer);
            graph.SyncUpdateAndTimeMode(animator);
            graph.Play();

            return(mixer);
        }
        public void Play(AnimationClip animationClip)
        {
            var animationClipPlayable = AnimationClipPlayable.Create(playableGraph, animationClip);
            var prePlayable           = animationPlayableOutput.GetSourcePlayable();

            if (prePlayable.IsValid())
            {
                prePlayable.Destroy();
            }
            animationPlayableOutput.SetSourcePlayable(animationClipPlayable);
            playableGraph.Play();
        }
    void Start()
    {
        graph = PlayableGraph.Create("RotateCube");
        AnimationPlayableOutput animOutput = AnimationPlayableOutput.Create(graph, "Animation", GetComponent <Animator>());
        AnimationClipPlayable   clipPlay   = AnimationClipPlayable.Create(graph, clip);

        animOutput.SetSourcePlayable(clipPlay);
        graph.Play();

        // 另一种写法,更方便的接口
        //AnimationPlayableUtilities.PlayClip(GetComponent<Animator>(), clip, out graph);
    }
Beispiel #26
0
    // Start is called before the first frame update
    void Start()
    {
        playableGraph           = PlayableGraph.Create();
        animationPlayableOutput = AnimationPlayableOutput.Create(playableGraph, "", GetComponent <Animator>());
        AnimationClipPlayable animationClip1 = AnimationClipPlayable.Create(playableGraph, runClip);

        //playableGraph.Connect(animationClip1,0, animationLayerMixerPlayable, 0);
        //animationLayerMixerPlayable.SetLayerMaskFromAvatarMask(1, bbb);
        animationPlayableOutput.SetSourcePlayable(animationClip1);
        //Debug.Log("f**k");
        playableGraph.Play();
    }
Beispiel #27
0
    //Use this instead of the MonoBehaviour Start Function
    protected override void Init()
    {
        animator = GetComponent <Animator>();

        playableGraph = PlayableGraph.Create();
        //playableGraph.SetTimeUpdateMode(DirectorUpdateMode.Manual);

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

        playableClip = AnimationClipPlayable.Create(playableGraph, clip);

        playableOutput.SetSourcePlayable(playableClip);
    }
/*        public void UpdateHandPositions()
 *      {
 *          setEdit();
 *          editHandCoord();
 *          printHandCoord();
 *          //logAnimations();
 *
 *          MainCameraControl.main.viewModel.localScale = scale;
 *
 *          XRInputManager xrInput = XRInputManager.GetXRInputManager();
 *          Vector3 leftHandPos = xrInput.Get(Controller.Left, CommonUsages.devicePosition);
 *          Quaternion leftHandRot = xrInput.Get(Controller.Left, CommonUsages.deviceRotation);
 *          Vector3 rightHandPos = xrInput.Get(Controller.Right, CommonUsages.devicePosition);
 *          Quaternion rightHandRot = xrInput.Get(Controller.Right, CommonUsages.deviceRotation);
 *
 *          Transform rightHand = xrInput.GetGameTransform(Controller.Right);
 *          rightHand.localPosition += new Vector3(rightPosX, rightPosY, rightPosZ);
 *          rightHand.localRotation *= Quaternion.Euler(rightRotX, rightRotY, rightRotZ);
 *          ik.solver.rightHandEffector.target = rightHand;
 *          ik.solver.rightHandEffector.positionWeight = 1f;
 *
 *          Transform leftHand = xrInput.GetGameTransform(Controller.Left);
 *          leftHand.localPosition += new Vector3(leftPosX, leftPosY, leftPosZ);
 *          leftHand.localRotation *= Quaternion.Euler(leftRotX, leftRotY, leftRotZ);
 *          ik.references.leftHand.localRotation = leftHand.localRotation;
 *          ik.references.leftHand.localPosition = leftHand.localPosition;
 *//*            ik.solver.leftHandEffector.target = leftHand;
 *          ik.solver.leftHandEffector.positionWeight = 1f;*//*
 *
 *      }*/

        public void disableArmAnimations()
        {
            Animator   anim         = player.playerAnimator;
            Transform  leftLowerArm = ik.references.leftForearm;
            AvatarMask mask         = new AvatarMask();

            mask.AddTransformPath(leftLowerArm);
            PlayableGraph           graph          = player.playerAnimator.playableGraph;
            AnimationPlayableOutput playableOutput = AnimationPlayableOutput.Create(graph, "LayerMixer", anim);
            AnimationMixerPlayable  mixer          = AnimationMixerPlayable.Create(graph, 2);

            playableOutput.SetSourcePlayable(mixer);
        }
Beispiel #29
0
    public void Awake()
    {
        graph = PlayableGraph.Create();
        graph.SetTimeUpdateMode(mode);

        playableOutput = AnimationPlayableOutput.Create(graph, "EthanWithPlayable", GetComponent <Animator>());

        var runClip = AnimationClipPlayable.Create(graph, run);

        playableOutput.SetSourcePlayable(runClip);

        graph.Play();
    }
Beispiel #30
0
        public void Play(AnimationClip clip = null, float time = 0, float speed = 0)
        {
            if (clip == null && this.clip == null)
            {
                throw new Exception("An AnimationClip must be set at least once to play.");
            }

            if (clip != null)
            {
                playable  = AnimationClipPlayable.Create(graph, clip);
                this.clip = clip;
                output.SetSourcePlayable(playable);
            }

            if (speed == 0f)
            {
                speed = clip.apparentSpeed;
            }
            playable.SetSpeed(speed);
            playable.SetTime(time);
            playable.SetDuration(clip.averageDuration);
            graph.Play();
        }