/// <summary> /// Called upon every frame. /// </summary> /// <param name="m">The local FSM</param> public abstract void OnStateUpdate(BaseStateMachine m);
/// <summary> /// Called when moving to another state. Used for clean up e.g. speed variables. /// </summary> /// <param name="m">The local FSM</param> public abstract void OnStateExit(BaseStateMachine m);
/// <summary> /// Called once to load all the necessary components. It is recommended to cache m to localFSM. /// </summary> /// <param name="m">The local FSM</param> public abstract void Initialize(BaseStateMachine m);
/// <summary> /// Called upon entering a state. /// </summary> /// <param name="m">The local FSM</param> public abstract void OnStateEnter(BaseStateMachine m);
public override void Initialize(BaseStateMachine m) { //throw new System.NotImplementedException(); }
//public override void OnStateUpdate(StateMachine m) //{ // Debug.Log(name + " UPDATE"); //} public override void OnStateUpdate(BaseStateMachine m) { Debug.Log("UPDATE " + name); }
//public override void OnStateExit(StateMachine m) //{ // Debug.Log(name + " EXIT"); //} public override void OnStateExit(BaseStateMachine m) { Debug.Log("EXIT " + name); }
//public override void OnStateEnter(StateMachine m) //{ // Debug.Log(name + " ENTER"); //} public override void OnStateEnter(BaseStateMachine m) { Debug.Log("ENTER " + name); }
void OnGUI() { Handles.DrawAAPolyLine(new Vector3(50, 100), new Vector3(100, 100), new Vector3(100, 150), new Vector3(50, 100)); //Texture2D t = Texture2D.whiteTexture; //GUI.color = Color.blue; //GUI.DrawTexture(new Rect(0, 0, maxSize.x, maxSize.y), Texture2D.whiteTexture, ScaleMode.StretchToFill); //GUI.Label(new Rect(200, 200, 100, 100), "A label"); //GUI.TextField(new Rect(20, 20, 70, 30), ""); //Debug.Log(Selection.activeObject.GetType()); GUIStyle style = new GUIStyle(GUI.skin.box); style.normal.background = Texture2D.whiteTexture; //style.normal.background. if (Selection.activeGameObject.GetComponent <MyStateMachine.BaseStateMachine>()) { fsm = Selection.activeGameObject.GetComponent <MyStateMachine.BaseStateMachine>(); if (!loaded) { int i = 0; nodes.Clear(); mahdic.Clear(); foreach (MyStateMachine.State s in fsm.states) { Node n = new Node(new Vector2(100 * i, 100 * i), 50, 50); n.color = Color.white; n.name = s.name; n.state = s; //Debug.Log("TEST:"+s.uiPosition); //Load state in cached position if (s.uiPosition == Vector2.zero) { Debug.Log("A"); n.posAndSize = new Vector4(100 * i, 100 * i, 50, 50); } else { Debug.Log("B:" + n.state.uiPosition); n.posAndSize = new Vector4(s.uiPosition.x, s.uiPosition.y, 50, 50); n.rect.position = new Vector2(s.uiPosition.x, s.uiPosition.y); } n.ID = s.ID; nodes.Add(n); //Debug.Log(n.ID); mahdic.Add(n.ID, n); //GUI.backgroundColor = Color.white; //GUI.Box(new Rect(100, 100*i, 50, 50), s.name,style); //GUI.color = Color.white; i++; } foreach (MyStateMachine.State s in fsm.states) { //Debug.Log("SSSSS"); Node n = mahdic[s.ID]; foreach (MyStateMachine.Transition t in s.transitions) { Connection c = new Connection(); c.n = mahdic[t.nextState.ID]; n.connections.Add(c); } } //foreach (Node n in nodes) //{ // foreach (MyStateMachine.StateMachine.State s in fsm.states) // { // if(s.ID==n.ID) // { // foreach(MyStateMachine.StateMachine.Transition t in s.transitions) // { // } // break; // } // } //} loaded = true; } Handles.color = Color.green; //Handles.ArrowHandleCap(0, new Vector2(200,200), Quaternion.LookRotation(Vector3.down), HandleUtility.GetHandleSize(new Vector2(200, 200)), EventType.Repaint); foreach (Node n in nodes) { //if(fsm.currentState.ID==n.ID) //{ // GUI.backgroundColor = Color.yellow; //} //else //{ // GUI.backgroundColor = Color.white; //} GUI.backgroundColor = n.color; GUI.Box(n.rect, n.name, style); //Handles.DrawAAConvexPolygon(new Vector3(0, 100), new Vector3(1, 100), new Vector3(0, 150)); foreach (Connection c in n.connections) { Debug.Log("CONNE"); Handles.color = Color.white; //Handles.DrawLine(new Vector2(0,0), new Vector3(100,100)); Handles.DrawLine(new Vector2(n.rect.x + (n.rect.width / 2), n.rect.y + (n.rect.height / 2)), new Vector2(c.n.rect.x + (c.n.rect.width / 2), c.n.rect.y + (c.n.rect.height / 2))); Vector2 d = new Vector2(n.rect.x, n.rect.y) - new Vector2(c.n.rect.x, c.n.rect.y); //EditorGUIUtility.RotateAroundPivot(Mathf.Atan2(d.y, d.x) * Mathf.Rad2Deg, Vector2.Lerp(new Vector2(n.rect.x, n.rect.y), new Vector2(c.n.rect.x, c.n.rect.y), 0.5f)); GUI.Box(new Rect(Vector2.Lerp(new Vector2(n.rect.x, n.rect.y), new Vector2(c.n.rect.x, c.n.rect.y), 0.5f), Vector2.one), "", style); //EditorGUIUtility.RotateAroundPivot(0,Vector2.zero); //Handles.ArrowHandleCap(0, new Vector2(n.rect.x, n.rect.y), Quaternion.LookRotation(d.normalized), 1, EventType.Repaint); } //GUI.color = Color.white; } Debug.Log("OBJECT HAS STATE MACHINE"); } ProcessNodeEvents(Event.current); //Selection.activeGameObject.GetC //Handles.DrawBezier(new Vector3(100, 100), new Vector3(100, 200), new Vector3(100, 150), new Vector3(50, 100), Color.blue, null, 2F); //for(int i=0;i<10;i++) //{ // Handles.DrawLine(new Vector2(20 * i, 0), new Vector2(20 * i, position.height)); //} ////EditorGUILayout.RectField("TEST", new Rect(0, 0, 50, 50)); //GUILayout.Label("Base Settings", EditorStyles.boldLabel); //myString = EditorGUILayout.TextField("Text Field", myString); //groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Settings", groupEnabled); //myBool = EditorGUILayout.Toggle("Toggle", myBool); //myFloat = EditorGUILayout.Slider("Slider", myFloat, -3, 3); //EditorGUILayout.EndToggleGroup(); //GUI.color = new Color(1, 0, 0, 1); //GUI.Box(new Rect(100, 100, 50, 50), "Test"); }