public static TransitionEditor TransitionTo <TState>(this StateEditor <TState> editor, TState toState) where TState : struct { var transition = editor.Machine.CreateTransition(editor.State, toState); transition.Edit(); return(new TransitionEditor(transition, editor.Machine.TriggerScheduler, editor.Machine.Logger)); }
public void CreateStateEditorTest() { var element = StateEditor.CreateElement(new object(), BindingMode.Default); Assert.IsNotNull(element); Assert.IsTrue(BindingOperations.IsDataBound(element, Selector.SelectedValueProperty)); }
public static void AddDoBehavior <TState>(this StateEditor <TState> editor, string behaviorName, Action <IUnityContainer> behavior) where TState : struct { if (!editor.Machine.Editable) { throw new InvalidOperationException($"StateMachine {editor.Machine.Name} must be in editable in order to modify a state."); } var behavioralState = editor.Machine[editor.State] as BehavioralState; if (behavioralState == null) { throw new InvalidOperationException($"A Do behavior can only be added to a BehavioralState."); } behavioralState.AddDoBehavior(behaviorName, behavior); }
static void CreateStateEditor() { if (mInstance != null) { mInstance.Close(); mInstance = null; return; } mInstance = EditorWindow.GetWindow <StateEditor>(true, "状态编辑器"); mInstance.Show(); if (excel_state_group.excelView == null) { ExcelLoader.LoadSingleExcel("state_group"); } if (excel_state_effect.excelView == null) { ExcelLoader.LoadSingleExcel("state_effect"); } }
void Awake() { Target = (StateEditor)target; }
void OnStateGUI( StateEditor stateEditor ) { State state = stateEditor.state; SelectState( state ); EditorGUITools.StateTitlebar( state ); foreach( StateBehaviour behaviour in state.behaviours ) { //if( behaviour != null ) { Editor editor = stateEditor.GetBehaviourEditor( behaviour ); if( editor!=null ) { bool expanded = EditorGUITools.BehaviourTitlebar( behaviour.expanded,behaviour ); if( behaviour.expanded != expanded ) { behaviour.expanded = expanded; EditorUtility.SetDirty( behaviour ); } bool missing = IsMissingStateBehaviourTarget( behaviour ); if( expanded ) { if( missing ) { missing = MissingStateBehaviourGUI( state,editor.serializedObject ); } if( !missing ) { editor.OnInspectorGUI(); } } if( !missing ) { editor.serializedObject.Update(); SerializedProperty iterator = editor.serializedObject.GetIterator(); for( bool enterChildren=true;iterator.NextVisible(enterChildren);enterChildren=false ) { EditorGUITools.StateLinkField( ObjectNames.NicifyVariableName( iterator.name ),iterator ); } editor.serializedObject.ApplyModifiedProperties(); } } } } Event current = Event.current; switch( current.type ) { case EventType.DragUpdated: case EventType.DragPerform: DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if( current.type == EventType.DragPerform ) { bool findBehaviour = false; foreach( Object draggedObject in DragAndDrop.objectReferences ) { MonoScript script = draggedObject as MonoScript; if( script != null ) { System.Type classType = script.GetClass(); if( classType.IsSubclassOf(typeof(StateBehaviour)) ) { if( !findBehaviour ) { Undo.RecordObject( state.stateMachine,"Add State Behaviour" ); state.AddBehaviour( classType ); findBehaviour = true; EditorUtility.SetDirty( state.stateMachine ); DragAndDrop.AcceptDrag(); DragAndDrop.activeControlID = 0; current.Use(); } } else { Debug.LogError ( classType.Name + " is not support State Script." ); } } } } break; case EventType.Repaint: Rect lastRect = GUILayoutUtility.GetLastRect(); float height = lastRect.y + lastRect.height; if( height != state.position.height ) { state.position.height = height; EditorUtility.SetDirty( state.stateMachine ); Repaint(); } break; } DragStates(); //GUI.DragWindow(); }
StateEditor GetStateEditor( State state ) { StateEditor stateEditor = null; if( !_StateEditors.TryGetValue( state,out stateEditor ) ) { stateEditor = new StateEditor( state ); _StateEditors.Add( state,stateEditor ); } return stateEditor; }
public override void OnInspectorGUI() { DrawDefaultInspector (); if (GUILayout.Button ("Clean Map")) { cleanMap (); } if (GUILayout.Button ("Generate Backgrounds")) { var map = (TileMap)this.target; var backgrounds = new GameObject (map.nameForBgObject); backgrounds.tag = "Backgrounds"; backgrounds.transform.parent = map.transform; for (int i = 0; i < map.backgrounds.Count; i++) { var newBG = Instantiate (map.backgrounds [i]) as GameObject; newBG.transform.parent = backgrounds.transform; newBG.transform.position = backgrounds.transform.position; newBG.GetComponent<Renderer> ().sortingOrder = (i * -1) - 1; } } if (GUILayout.Button ("Delete Backgrounds")) { var map = (TileMap)this.target; foreach (Transform child in map.transform) { if (child.gameObject.tag == "Backgrounds") { DestroyImmediate (map.transform.Find ("Backgrounds").gameObject); } } } lastTileSize = EditorGUILayout.Vector2Field("Last Tile Size", lastTileSize); newTileSize = EditorGUILayout.Vector2Field("New Tile Size", newTileSize); if (GUILayout.Button("Re align map")) { ReAlignMap(); } enabledMode = (MapMode)EditorGUILayout.EnumPopup (enabledMode); isEditing = EditorGUILayout.Toggle ("Is Editing", isEditing); replaceTiles = EditorGUILayout.Toggle ("Should Replace Tiles", replaceTiles); if (isEditing) { OnEnable (); state = (StateEditor)EditorGUILayout.EnumPopup ("Editing Mode", state); if (state == StateEditor.Mutli) { overrideBottom = EditorGUILayout.Toggle ("Override Bottom", overrideBottom); } } // Tilesets DrawTilesetsPopup(); }