コード例 #1
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");
            }
        }
    }
コード例 #2
0
    public void SetAnimationClip(AnimationClip clip, AnimationClip endClip)
    {
        clipPlayable    = AnimationClipPlayable.Create(playableGraph, clip);
        endClipPlayable = AnimationClipPlayable.Create(playableGraph, endClip);

        inputIndex    = animMixer.AddInput(clipPlayable, 0, 0);
        inputIndexEnd = animMixer.AddInput(endClipPlayable, 0, 0);
        animMixer.SetInputWeight(inputIndex, 0);
        animMixer.SetInputWeight(inputIndexEnd, 0);
    }
コード例 #3
0
        public void CreateSingleAnimation(
            MotionMatchingData data,
            AnimationMixerPlayable stateMixer,
            double localTime,
            float newInputStartWeight,
            List <LogicAnimationsSequence> animationsSequences,
            bool passIK,
            bool passFootIK,
            float speedMulti = 1f
            )
        {
            switch (data.dataType)
            {
            case AnimationDataType.SingleAnimation:
                AnimationClipPlayable playable_1 = AnimationClipPlayable.Create(graph, data.clips[0]);
                playable_1.SetApplyPlayableIK(passIK);
                playable_1.SetApplyFootIK(passIK);
                playable_1.SetTime(localTime - Time.deltaTime);
                playable_1.SetTime(localTime);
                playable_1.SetSpeed(speedMulti);
                stateMixer.AddInput(playable_1, 0, newInputStartWeight);
                break;

            case AnimationDataType.BlendTree:
                AnimationMixerPlayable mixerPlayable = AnimationMixerPlayable.Create(this.graph);
                stateMixer.AddInput(mixerPlayable, 0, newInputStartWeight);
                for (int i = 0; i < data.clips.Count; i++)
                {
                    AnimationClipPlayable playable_2 = AnimationClipPlayable.Create(this.graph, data.clips[i]);
                    playable_2.SetApplyPlayableIK(passIK);
                    playable_2.SetApplyFootIK(passIK);
                    playable_2.SetTime(localTime - Time.deltaTime);
                    playable_2.SetTime(localTime);
                    playable_2.SetSpeed(speedMulti);
                    mixerPlayable.AddInput(playable_2, 0, data.blendTreeWeights[i]);
                }
                break;

            case AnimationDataType.AnimationSequence:
                animationsSequences.Add(new LogicAnimationsSequence(data, -1));
                int new_ASIndex = animationsSequences.Count - 1;
                animationsSequences[new_ASIndex].mixer = AnimationMixerPlayable.Create(this.graph);
                stateMixer.AddInput(animationsSequences[new_ASIndex].mixer, 0, newInputStartWeight);
                animationsSequences[new_ASIndex].CreateAnimationsInTime((float)localTime, this, passIK, passFootIK);
                break;
            }
        }
コード例 #4
0
        public void AddClip(PlayableGraph graph, AnimationClip clip)
        {
            if (_clipData.Any(cd => cd.Clip == clip))
            {
                return;
            }

            var clipPlayable = AnimationClipPlayable.Create(graph, clip);
            var mixerIndex   = Mixer.AddInput(clipPlayable, 0);

            _clipData.Add(new ClipData(mixerIndex, clipPlayable));
        }
コード例 #5
0
        public void Initialize(BaseAnimationSystem system, PlayableGraph graph, Playable self, int index, AnimationMixerPlayable rootMixer, TInit init)
        {
            SystemType = system.GetType();

            Self  = self;
            Root  = rootMixer;
            Graph = graph;

            Mixer = AnimationMixerPlayable.Create(graph, 0, true);
            Mixer.SetPropagateSetTime(true);
            OnInitialize(init);
            rootMixer.AddInput(self, 0);
            self.AddInput(Mixer, 0, 1);
        }
コード例 #6
0
        public void AddClipPlayable(
            AnimationMixerPlayable mixer,
            AnimationClip animation,
            bool passIK,
            bool passFootIK  = false,
            double localTime = 0d,
            float weight     = 0f
            )
        {
            AnimationClipPlayable playable = AnimationClipPlayable.Create(this.graph, animation);

            playable.SetApplyPlayableIK(passIK);
            playable.SetApplyFootIK(passFootIK);
            mixer.AddInput(playable, 0, weight);
            mixer.GetInput(mixer.GetInputCount() - 1).SetTime(localTime);
            mixer.GetInput(mixer.GetInputCount() - 1).SetTime(localTime);
        }
        public void CreateAnimationsInTime(float time, MotionMatchingPlayableGraph graph, bool passIK, bool passFootIK)
        {
            currentClipTime = time;
            //mixer = AnimationMixerPlayable.Create(graph.graph, 0);
            float seqLocalTime = GetLocalTime();

            for (int i = 0; i < data.clips.Count; i++)
            {
                AnimationClipPlayable playable = AnimationClipPlayable.Create(graph.graph, data.clips[i]);
                playable.SetApplyFootIK(passFootIK);
                playable.SetApplyPlayableIK(passIK);
                mixer.AddInput(playable, 0);

                float currentPlayableTime   = GetPlayableTimeInSequenceLocalTime(seqLocalTime, i);
                float currentplayableWeight = GetPlayableWeightInPlayableTime(currentPlayableTime, i);

                mixer.SetInputWeight(i, currentplayableWeight);
                mixer.GetInput(i).SetTime(currentPlayableTime - Time.deltaTime);
                mixer.GetInput(i).SetTime(currentPlayableTime);
            }
            NormalizeMixerInputWeights();
        }
コード例 #8
0
        public void AddClipPlayable(AnimationClip animation)
        {
            AnimationClipPlayable playable = AnimationClipPlayable.Create(this.graph, animation);

            mixer.AddInput(playable, 0, 0f);
        }
コード例 #9
0
        public void CreateBlendMotionMatchingAnimation(
            MotionMatchingData data,
            int dataIndex,
            AnimationMixerPlayable stateMixer,
            double localTime,
            float blendTime,
            List <float> blendingSpeeds,
            List <float> currentWeights,
            List <LogicAnimationsSequence> animationsSequences,
            bool passIK,
            bool passFootIK,
            float newInputStartWeight = 0f,
            float minWeightToAchive   = 0f,
            float speedMulti          = 1f
            )
        {
            if (stateMixer.GetInputCount() > 0)
            {
                if (currentWeights[currentWeights.Count - 1] >= minWeightToAchive)
                {
                    blendingSpeeds[blendingSpeeds.Count - 1] = -(stateMixer.GetInputWeight(stateMixer.GetInputCount() - 1) / blendTime);
                }
            }
            currentWeights.Add(newInputStartWeight);
            blendingSpeeds.Add(1f / blendTime);

            switch (data.dataType)
            {
            case AnimationDataType.SingleAnimation:
                AnimationClipPlayable playable_SA = AnimationClipPlayable.Create(graph, data.clips[0]);
                playable_SA.SetApplyPlayableIK(passIK);
                playable_SA.SetApplyFootIK(passFootIK);
                playable_SA.SetTime(localTime - Time.deltaTime);
                playable_SA.SetTime(localTime);
                playable_SA.SetSpeed(speedMulti);
                stateMixer.AddInput(playable_SA, 0, newInputStartWeight);
                break;

            case AnimationDataType.BlendTree:
                AnimationMixerPlayable mixerPlayable = AnimationMixerPlayable.Create(this.graph);
                stateMixer.AddInput(mixerPlayable, 0, newInputStartWeight);

                for (int i = 0; i < data.clips.Count; i++)
                {
                    AnimationClipPlayable playable_BT = AnimationClipPlayable.Create(this.graph, data.clips[i]);
                    playable_BT.SetApplyPlayableIK(passIK);
                    playable_BT.SetApplyFootIK(passFootIK);
                    playable_BT.SetTime(localTime - Time.deltaTime);
                    playable_BT.SetTime(localTime);
                    playable_BT.SetSpeed(speedMulti);
                    mixerPlayable.AddInput(playable_BT, 0, data.blendTreeWeights[i]);
                }
                break;

            case AnimationDataType.AnimationSequence:
                animationsSequences.Add(new LogicAnimationsSequence(data, dataIndex));
                int new_ASIndex = animationsSequences.Count - 1;
                animationsSequences[new_ASIndex].mixer = AnimationMixerPlayable.Create(this.graph);
                stateMixer.AddInput(animationsSequences[new_ASIndex].mixer, 0, newInputStartWeight);
                animationsSequences[new_ASIndex].CreateAnimationsInTime((float)localTime, this, passIK, passFootIK);
                break;
            }
        }
コード例 #10
0
            public Instance(AnimStateController animStateController, PlayableGraph graph, AnimGraphStateSelector settings)
            {
                m_AnimStateData = animStateController.GetComponent <AnimStateData>();

                m_Mixer = AnimationMixerPlayable.Create(graph, 0, true);

                m_AnimStates = new AnimationControllerEntry[(int)LocomotionState.MaxValue];

                var controllers          = new Dictionary <AnimGraphAsset, IAnimGraphInstance>();
                var controllerPorts      = new Dictionary <IAnimGraphInstance, int>();
                var stateTransitionPorts = new List <int>();
                var transitionTimes      = new Dictionary <IAnimGraphInstance, float[]>();

                foreach (var controllerDef in settings.controllers)
                {
                    if (controllerDef.template == null)
                    {
                        continue;
                    }
                    if (controllers.ContainsKey(controllerDef.template))
                    {
                        continue;
                    }

                    var controller = controllerDef.template.Instatiate(animStateController, graph);
                    controllers.Add(controllerDef.template, controller);

                    var outputPlayable = Playable.Null;
                    var outputPort     = 0;
                    controller.GetPlayableOutput(0, ref outputPlayable, ref outputPort);
                    var port = m_Mixer.AddInput(outputPlayable, outputPort);

                    controllerPorts.Add(controller, port);
                    stateTransitionPorts.Add(port);

                    var times = new float[(int)LocomotionState.MaxValue];
                    for (var i = 0; i < (int)LocomotionState.MaxValue; i++)
                    {
                        times[i] = controllerDef.transitionTime;
                    }

                    for (var i = 0; i < controllerDef.customTransitions.Length; i++)
                    {
                        var sourceStateIndex = (int)controllerDef.customTransitions[i].sourceState;
                        var time             = controllerDef.customTransitions[i].transtionTime;
                        times[sourceStateIndex] = time;
                    }

                    transitionTimes.Add(controller, times);
                }

                foreach (var controllerDef in settings.controllers)
                {
                    var animState = controllerDef.animationState;
                    if (m_AnimStates[(int)animState].controller != null)
                    {
                        continue;
                    }

                    var controller = controllers[controllerDef.template];
                    m_AnimStates[(int)animState].controller       = controller;
                    m_AnimStates[(int)animState].animStateUpdater = controller as IGraphState;
                    m_AnimStates[(int)animState].port             = controllerPorts[controller];
                    m_AnimStates[(int)animState].transitionTimes  = transitionTimes[controller];
                }

                m_StateTranstion = new SimpleTranstion <AnimationMixerPlayable>(m_Mixer, stateTransitionPorts.ToArray());
            }