コード例 #1
0
        public override Playable GeneratePlayable(PlayableGraph graph, Dictionary <string, List <BlendTreeController1D> > varTo1DBlendControllers,
                                                  Dictionary <string, List <BlendTreeController2D> > varTo2DBlendControllers, Dictionary <string, float> blendVars)
        {
            var treeMixer = AnimationMixerPlayable.Create(graph, blendTree.Count, true);

            if (blendTree.Count == 0)
            {
                return(treeMixer);
            }

            float[] thresholds = new float[blendTree.Count];

            for (int j = 0; j < blendTree.Count; j++)
            {
                var blendTreeEntry = blendTree[j];
                var clipPlayable   = AnimationClipPlayable.Create(graph, blendTreeEntry.clip);
                clipPlayable.SetSpeed(speed);
                graph.Connect(clipPlayable, 0, treeMixer, j);
                thresholds[j] = blendTreeEntry.threshold;
            }

            treeMixer.SetInputWeight(0, 1f);
            var blendController = new BlendTreeController1D(treeMixer, thresholds, val => blendVars[blendVariable] = val);

            varTo1DBlendControllers.GetOrAdd(blendVariable).Add(blendController);
            blendVars[blendVariable] = 0;

            return(treeMixer);
        }
コード例 #2
0
        public override Playable GeneratePlayable(PlayableGraph graph, Dictionary <string, List <BlendTreeController1D> > varTo1DBlendControllers,
                                                  Dictionary <string, List <BlendTreeController2D> > varTo2DBlendControllers,
                                                  List <BlendTreeController2D> all2DControllers)
        {
            var treeMixer = AnimationMixerPlayable.Create(graph, blendTree.Count, true);

            treeMixer.SetSpeed(speed);
            treeMixer.SetPropagateSetTime(true);

            if (blendTree.Count == 0)
            {
                return(treeMixer);
            }


            float[] thresholds = new float[blendTree.Count];

            var innerPlayables = new AnimationClipPlayable[blendTree.Count];

            for (int i = 0; i < blendTree.Count; i++)
            {
                var blendTreeEntry = blendTree[i];
                var clip           = GetClipToUseFor(blendTreeEntry.clip);
                if (clip == null)
                {
                    clip = new AnimationClip();
                }
                var clipPlayable = AnimationClipPlayable.Create(graph, clip);
                clipPlayable.SetApplyFootIK(true);
                // clipPlayable.SetSpeed(speed);
                graph.Connect(clipPlayable, 0, treeMixer, i);
                thresholds[i]     = blendTreeEntry.threshold;
                innerPlayables[i] = clipPlayable;
            }

            controller = new BlendTreeController1D(treeMixer, innerPlayables, thresholds, compensateForDifferentDurations);
            varTo1DBlendControllers.GetOrAdd(blendVariable).Add(controller);
            controller.SetInitialValue(0);

            return(treeMixer);
        }