private static void AddClipsAsBlendTree(AnimationPlayer animationPlayer, PersistedInt selectedLayer, PersistedInt selectedState, AnimationPlayerEditor editor, List <AnimationClip> animationClips) { EditorUtilities.RecordUndo(animationPlayer, "Added clip to Animation Player"); var layer = animationPlayer.layers[selectedLayer]; int numClipsBefore = layer.states.Count; var newStateName = GetUniqueStateName(BlendTree1D.DefaultName, layer.states); var newState = BlendTree1D.Create(newStateName); foreach (var clip in animationClips) { var newEntry = new BlendTreeEntry1D { clip = clip }; newState.blendTree.Add(newEntry); } layer.states.Add(newState); selectedState.SetTo(numClipsBefore); editor.MarkDirty(); }
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 BlendTree1D Create(string name) { var blendTree = new BlendTree1D(); blendTree.Initialize(name, DefaultName); blendTree.blendVariable = "blend"; blendTree.blendTree = new List <BlendTreeEntry1D>(); return(blendTree); }
private static void Draw1DBlendTree(BlendTree1D state, ref bool markDirty) { state.blendVariable = EditorUtilities.TextField("Blend with variable", state.blendVariable, 130f); EditorGUI.indentLevel++; int swapIndex = -1; if (state.blendTree == null) { state.blendTree = new System.Collections.Generic.List <BlendTreeEntry1D>(); } for (var i = 0; i < state.blendTree.Count; i++) { var blendTreeEntry = state.blendTree[i]; var whenLabel = $"When '{state.blendVariable}' ="; var whenLabelRequiredWidth = GUI.skin.label.CalcSize(new GUIContent(whenLabel)).x; var remainingAfterClipLabel = Screen.width - 30f - 70f - 25f - 100f; var remainingAfterWhenLabel = Screen.width - whenLabelRequiredWidth - 70f - 25f - 100f; EditorGUILayout.BeginHorizontal(); { var oldClip = blendTreeEntry.clip; blendTreeEntry.clip = EditorUtilities.ObjectField("Clip", blendTreeEntry.clip, 30f, remainingAfterClipLabel); if (blendTreeEntry.clip != oldClip) { if (blendTreeEntry.clip != null) { state.OnClipAssigned(blendTreeEntry.clip); } markDirty = true; } EditorGUI.BeginDisabledGroup(i == 0); if (GUILayout.Button("\u2191", upDownButtonStyle, upDownButtonOptions)) { swapIndex = i; } EditorGUI.EndDisabledGroup(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { blendTreeEntry.threshold = EditorUtilities.FloatField(whenLabel, blendTreeEntry.threshold, whenLabelRequiredWidth, remainingAfterWhenLabel); EditorGUI.BeginDisabledGroup(i == state.blendTree.Count - 1); if (GUILayout.Button("\u2193", upDownButtonStyle, upDownButtonOptions)) { swapIndex = i + 1; } EditorGUI.EndDisabledGroup(); // Remove 1D 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: Screen.width - 100f); } } 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 BlendTreeEntry1D()); markDirty = true; } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }
private static void Draw1DBlendTree(BlendTree1D state, ref bool markDirty) { state.blendVariable = EditorUtilities.TextField("Blend with variable", state.blendVariable, 130f); EditorGUI.indentLevel++; int swapIndex = -1; for (var i = 0; i < state.blendTree.Count; i++) { var blendTreeEntry = state.blendTree[i]; EditorGUILayout.BeginHorizontal(); { 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); } EditorGUI.BeginDisabledGroup(i == 0); if (GUILayout.Button("\u2191", upDownButtonStyle, upDownButtonOptions)) { swapIndex = i; } EditorGUI.EndDisabledGroup(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { blendTreeEntry.threshold = EditorUtilities.FloatField($"When '{state.blendVariable}' =", blendTreeEntry.threshold, 150f, 200f); EditorGUI.BeginDisabledGroup(i == state.blendTree.Count - 1); if (GUILayout.Button("\u2193", upDownButtonStyle, upDownButtonOptions)) { swapIndex = i + 1; } EditorGUI.EndDisabledGroup(); // Remove 1D 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 BlendTreeEntry1D()); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }