private static void DrawAddStateButtons(AnimationPlayer animationPlayer, PersistedInt selectedState, AnimationPlayerEditor editor, AnimationLayer layer) { if (GUILayout.Button("Single Clip", buttonWidth)) { EditorUtilities.RecordUndo(animationPlayer, "Add state to animation player"); layer.states.Add(SingleClip.Create(GetUniqueStateName(SingleClip.DefaultName, layer.states))); selectedState.SetTo(layer.states.Count - 1); editor.MarkDirty(); } if (GUILayout.Button("Play Random Clip", buttonWidth)) { EditorUtilities.RecordUndo(animationPlayer, "Add random state to animation player"); layer.states.Add(PlayRandomClip.Create(GetUniqueStateName(PlayRandomClip.DefaultName, layer.states))); selectedState.SetTo(layer.states.Count - 1); editor.MarkDirty(); } if (GUILayout.Button("Sequence", buttonWidth)) { EditorUtilities.RecordUndo(animationPlayer, "Add sequence to animation player"); layer.states.Add(Sequence.Create(GetUniqueStateName(Sequence.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 PlayAtTimeInstructionQueue(AnimationLayer animationLayer) { this.animationLayer = animationLayer; }
private void HandleInitialization(bool isGUICall) { if (scriptReloadChecker == null) { // Unity persists some objects through reload, and fails to persist others. This makes it hard to figure out if // something needs to be re-cached. This solves that - we know that Unity can't persist a raw object, so if it's null, a reload is neccessary. scriptReloadChecker = new object(); metaDataDrawer = new MetaDataDrawer(animationPlayer); stylesCreated = false; transitionsNeedsUpdate = true; MarkDirty(); } if (isGUICall && !stylesCreated) { var backgroundTex = EditorUtilities.MakeTex(1, 1, new Color(1.0f, 1.0f, 1.0f, .1f)); editLayerStyle = new GUIStyle { normal = { background = backgroundTex } }; var buttonBackgroundTex = EditorUtilities.MakeTex(1, 1, new Color(1.0f, 1.0f, 1.0f, 0.05f)); var buttonSelectedTex = EditorUtilities.MakeTex(1, 1, new Color(1.0f, 1.0f, 1.0f, 0.05f)); var buttonNotSelectedText = EditorUtilities.MakeTex(1, 1, new Color(1.0f, 1.0f, 1.0f, 0.2f)); editLayerButton_Background = new GUIStyle { normal = { background = buttonBackgroundTex } }; editLayerButton_NotSelected = new GUIStyle(GUI.skin.label) { normal = { background = buttonNotSelectedText }, alignment = TextAnchor.MiddleCenter }; editLayerButton_Selected = new GUIStyle(GUI.skin.label) { normal = { background = buttonSelectedTex }, alignment = TextAnchor.MiddleCenter }; stylesCreated = true; } if (animationPlayer.layers == null || animationPlayer.layers.Length == 0) { animationPlayer.layers = new AnimationLayer[1]; animationPlayer.layers[0] = AnimationLayer.CreateLayer(); if (animationPlayer.defaultTransition == default(TransitionData)) { animationPlayer.defaultTransition = TransitionData.Linear(.1f); //default shouldn't be snap } return; } if (stateNamesNeedsUpdate) { stateNamesNeedsUpdate = false; allStateNames = new string[animationPlayer.layers.Length][]; for (int i = 0; i < animationPlayer.layers.Length; i++) { var states = animationPlayer.layers[i].states; allStateNames[i] = new string[states.Count]; for (int j = 0; j < states.Count; j++) { allStateNames[i][j] = states[j].Name; } } } if (transitionsNeedsUpdate) { transitionsNeedsUpdate = false; foreach (var layer in animationPlayer.layers) { foreach (var transition in layer.transitions) { transition.FetchStates(layer.states); } } } if (previewer == null) { previewer = new AnimationStatePreviewer(animationPlayer); } }
private static void DrawCreateNewTransition(AnimationPlayer animationPlayer, Action <StateTransition> SetSelectedTransition, string[] stateNamesInLayer, string fromStateName, string toStateName, AnimationPlayerState selectedState, AnimationLayer layer) { using (new EditorGUILayout.HorizontalScope()) { GUILayout.FlexibleSpace(); if (GUILayout.Button($"Create new transition from {fromStateName}")) { GenericMenu menu = new GenericMenu(); foreach (var state in stateNamesInLayer) { menu.AddItem(new GUIContent($"Transition from {fromStateName} to {state}"), false, () => { //@TODO: If this is the first transition between the states, it should be set as default. EditorUtilities.RecordUndo(animationPlayer, $"Adding transition from {fromStateName} to {toStateName}"); var newState = new StateTransition { FromState = selectedState, ToState = layer.states.Find(s => s.Name == state), transitionData = TransitionData.Linear(.2f) }; layer.transitions.Add(newState); SetSelectedTransition(newState); }); } menu.ShowAsContext(); } } }