Пример #1
0
        public static void DrawTreesElements(DataCreator creator, EditorWindow editor)
        {
            if (creator.selectedBlendTree == -1 || creator.blendTrees.Count == 0 || creator.selectedBlendTree >= creator.blendTrees.Count)
            {
                creator.selectedBlendTree = -1;
                GUILayout.Label("No blend tree item is selected");
                return;
            }

            BlendTreeInfo blendTree = creator.blendTrees[creator.selectedBlendTree];

            GUILayoutElements.DrawHeader(blendTree.name, GUIResources.GetLightHeaderStyle_MD());
            blendTree.name = EditorGUILayout.TextField(
                new GUIContent("Blend Tree name"),
                blendTree.name
                );

            blendTree.findInYourself  = EditorGUILayout.Toggle(new GUIContent("Find in yourself"), blendTree.findInYourself);
            blendTree.blendToYourself = EditorGUILayout.Toggle(new GUIContent("Blend to yourself"), blendTree.blendToYourself);

            blendTree.useSpaces = EditorGUILayout.Toggle(new GUIContent("Use spaces"), blendTree.useSpaces);
            if (blendTree.useSpaces)
            {
                if (blendTree.clips.Count == 2)
                {
                    blendTree.spaces = EditorGUILayout.IntField(new GUIContent("Spaces"), blendTree.spaces);
                }
                else
                {
                    GUILayout.Label("You can use \"Spaces\" with only 2 animations!");
                }
            }

            DrawElement(blendTree, creator.selectedBlendTree);
        }
Пример #2
0
        private static void DrawElement(BlendTreeInfo element, int elementIndex)
        {
            GUILayout.Space(5);

            GUILayoutElements.DrawHeader(
                "Animation clips",
                GUIResources.GetLightHeaderStyle_MD()
                );

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Add Clip", GUILayout.Width(100)))
            {
                element.AddClip(null);
            }
            if (GUILayout.Button("Clear clips", GUILayout.Width(100)))
            {
                element.ClearClips();
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(5);
            for (int i = 0; i < element.clips.Count; i++)
            {
                GUILayout.BeginHorizontal();
                element.clips[i] = (AnimationClip)EditorGUILayout.ObjectField(element.clips[i], typeof(AnimationClip), true);
                if (GUILayout.Button("X", GUILayout.Width(20)))
                {
                    element.RemoveClip(i);
                    i--;
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.Space(5);

            GUILayoutElements.DrawHeader(
                "Clips weights",
                GUIResources.GetLightHeaderStyle_MD()
                );
            GUILayout.Space(5);
            for (int weightIndex = 0; weightIndex < element.clipsWeights.Count; weightIndex++)
            {
                if (element.clips[weightIndex] != null)
                {
                    GUILayout.Label(new GUIContent(element.clips[weightIndex].name + " weight"));
                    element.clipsWeights[weightIndex] = EditorGUILayout.Slider(
                        element.clipsWeights[weightIndex],
                        0,
                        1f
                        );
                }
            }
            GUILayout.Space(10);
        }
Пример #3
0
        private void UpdateAnimator(float deltaTime)
        {
            if (this.graph == null || !this.graph.IsValid())
            {
                return;
            }
            sliderTimeBuffor = sliderTime;

            sliderTime %= maxSliderTime;

            previewTime = Time.realtimeSinceStartup;

            if (isSequencePlaying)
            {
                creator.sequences[creator.selectedSequence].CalculateLength();
                graph.Evaluate(deltaTime);
                creator.sequences[creator.selectedSequence].Update(graph, deltaTime);
                if (creator.sequences[creator.selectedSequence].currentPlayingTime >= creator.sequences[creator.selectedSequence].length)
                {
                    //PreviewButtonAction();
                }
            }
            else
            {
                BlendTreeInfo element   = creator.blendTrees[creator.selectedBlendTree];
                float         weightSum = 0f;
                float[]       weights   = new float[element.clips.Count];
                if (weights.Length == graph.GetMixerInputCount())
                {
                    for (int i = 0; i < element.clips.Count; i++)
                    {
                        weightSum += element.clipsWeights[i];
                    }
                    for (int i = 0; i < element.clips.Count; i++)
                    {
                        weights[i] = element.clipsWeights[i] / weightSum;
                    }

                    for (int i = 0; i < element.clips.Count; i++)
                    {
                        graph.SetMixerInputWeight(i, weights[i]);
                    }
                }
                graph.Evaluate(deltaTime);
            }

            this.Repaint();
        }
Пример #4
0
        private void PreviewButtonAction()
        {
            creator.gameObjectTransform.position = pos;
            creator.gameObjectTransform.rotation = rot;

            sliderTime       = 0f;
            sliderTimeBuffor = sliderTime;

            if (graph == null)
            {
                graph = new PreparingDataPlayableGraph();
                graph.Initialize(creator.gameObjectTransform.gameObject);
            }
            else if (!graph.IsValid())
            {
                graph.Initialize(creator.gameObjectTransform.gameObject);
            }

            graph.ClearMainMixerInput();

            switch (selectedCreator)
            {
            case 1:
                BlendTreeInfo blendTree = creator.blendTrees[creator.selectedBlendTree];
                if (blendTree.IsValid())
                {
                    blendTree.CreateGraphFor(
                        creator.gameObjectTransform.gameObject,
                        graph
                        );
                    isSequencePlaying = false;

                    maxSliderTime = blendTree.GetLength();
                }
                break;

            case 2:
                AnimationsSequence seq = creator.sequences[creator.selectedSequence];
                if (seq.IsValid())
                {
                    seq.CreateAnimationsInTime(0f, graph);
                    isSequencePlaying = true;
                    maxSliderTime     = seq.length;
                }
                break;
            }
        }