Beispiel #1
0
        private static void DrawAddStateButtons(AnimationPlayer animationPlayer, PersistedInt selectedState, AnimationPlayerEditor editor, AnimationLayer layer)
        {
            if (GUILayout.Button("Single Clip State", buttonWidth))
            {
                EditorUtilities.RecordUndo(animationPlayer, "Add state to animation player");
                layer.states.Add(SingleClipState.Create(GetUniqueStateName(SingleClipState.DefaultName, layer.states)));
                selectedState.SetTo(layer.states.Count - 1);
                editor.MarkDirty();
            }

            if (GUILayout.Button("1D Blend Tree", buttonWidth))
            {
                EditorUtilities.RecordUndo(animationPlayer, "Add blend tree to animation player");
                layer.states.Add(BlendTree1D.Create(GetUniqueStateName(BlendTree1D.DefaultName, layer.states)));
                selectedState.SetTo(layer.states.Count - 1);
                editor.MarkDirty();
            }

            if (GUILayout.Button("2D Blend Tree", buttonWidth))
            {
                EditorUtilities.RecordUndo(animationPlayer, "Add 2D blend tree to animation player");
                layer.states.Add(BlendTree2D.Create(GetUniqueStateName(BlendTree2D.DefaultName, layer.states)));
                selectedState.SetTo(layer.states.Count - 1);
                editor.MarkDirty();
            }
        }
        public static BlendTree2D Create(string name)
        {
            var blendTree = new BlendTree2D();

            blendTree.Initialize(name, DefaultName);
            blendTree.blendVariable  = "blend1";
            blendTree.blendVariable2 = "blend2";
            blendTree.blendTree      = new List <BlendTreeEntry2D>();
            return(blendTree);
        }
Beispiel #3
0
        private static void Draw2DBlendTree(BlendTree2D state, ref bool markDirty)
        {
            state.blendVariable  = EditorUtilities.TextField("First blend variable", state.blendVariable, 120f);
            state.blendVariable2 = EditorUtilities.TextField("Second blend variable", state.blendVariable2, 120f);
            EditorGUI.indentLevel++;

            if (state.blendTree == null)
            {
                state.blendTree = new System.Collections.Generic.List <BlendTreeEntry2D>();
            }

            int swapIndex = -1;

            for (var i = 0; i < state.blendTree.Count; i++)
            {
                var blendTreeEntry = state.blendTree[i];

                var oldClip = blendTreeEntry.clip;
                blendTreeEntry.clip = EditorUtilities.ObjectField("Clip", blendTreeEntry.clip, 150f, 200f);
                if (blendTreeEntry.clip != oldClip && blendTreeEntry.clip != null)
                {
                    markDirty |= state.OnClipAssigned(blendTreeEntry.clip);
                }

                EditorGUILayout.BeginHorizontal();
                {
                    blendTreeEntry.threshold1 = EditorUtilities.FloatField($"When '{state.blendVariable}' =", blendTreeEntry.threshold1, 150f, 200f);
                    EditorGUI.BeginDisabledGroup(i == 0);
                    if (GUILayout.Button("\u2191", upDownButtonStyle, upDownButtonOptions))
                    {
                        swapIndex = i;
                    }
                    EditorGUI.EndDisabledGroup();
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                {
                    blendTreeEntry.threshold2 = EditorUtilities.FloatField($"When '{state.blendVariable2}' =", blendTreeEntry.threshold2, 150f, 200f);

                    EditorGUI.BeginDisabledGroup(i == state.blendTree.Count - 1);
                    if (GUILayout.Button("\u2193", upDownButtonStyle, upDownButtonOptions))
                    {
                        swapIndex = i + 1;
                    }
                    EditorGUI.EndDisabledGroup();

                    // Remove 2D blend tree entry
                    if (GUILayout.Button("Remove", GUILayout.Width(70f)))
                    {
                        state.blendTree.RemoveAt(i);
                    }
                }
                EditorGUILayout.EndHorizontal();

                if (i != state.blendTree.Count - 1)
                {
                    EditorUtilities.Splitter(width: 350f);
                }
            }

            if (swapIndex != -1)
            {
                markDirty = true;
                state.blendTree.Swap(swapIndex, swapIndex - 1);
            }

            EditorGUI.indentLevel--;

            GUILayout.Space(10f);
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Add blend tree entry", GUILayout.Width(150f)))
            {
                state.blendTree.Add(new BlendTreeEntry2D());
                markDirty = true;
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }