///<summary>Returns all transitions of the state</summary> public FSMConnection[] GetTransitions() { var result = new FSMConnection[outConnections.Count]; for (var i = 0; i < outConnections.Count; i++) { result[i] = (FSMConnection)outConnections[i]; } return(result); }
void ShowBaseFSMInspectorGUI() { EditorUtils.CoolLabel("Transitions"); if (outConnections.Count == 0) { GUI.backgroundColor = new Color(1, 1, 1, 0.5f); GUILayout.BeginHorizontal("box"); GUILayout.Label("No Transitions"); GUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; } var onFinishExists = false; EditorUtils.ReorderableList(outConnections, delegate(int i){ FSMConnection connection = (FSMConnection)outConnections[i]; GUI.backgroundColor = new Color(1, 1, 1, 0.5f); GUILayout.BeginHorizontal("box"); if (connection.condition) { GUILayout.Label(connection.condition.summaryInfo); } else { GUILayout.Label("OnFinish" + (onFinishExists? " (exists)" : "")); onFinishExists = true; } GUILayout.FlexibleSpace(); GUILayout.Label("--> '" + connection.targetNode.nodeName + "'"); if (GUILayout.Button(">")) { Graph.currentSelection = connection; } GUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; }); if (this.GetType() != typeof(FSMAnyState)) { transitionEvaluation = (TransitionEvaluation)EditorGUILayout.EnumPopup(transitionEvaluation); } EditorUtils.BoldSeparator(); }
sealed public override void DrawNodeConnections() { var e = Event.current; if (maxOutConnections == 0) { if (e.type == EventType.MouseUp && ID == graph.allNodes.Count) { clickedPort = null; //e.Use(); } return; } var portRectLeft = new Rect(0, 0, 20, 20); var portRectRight = new Rect(0, 0, 20, 20); var portRectBottom = new Rect(0, 0, 20, 20); portRectLeft.center = new Vector2(nodeRect.x - 11, nodeRect.yMax - 10); portRectRight.center = new Vector2(nodeRect.xMax + 11, nodeRect.yMax - 10); portRectBottom.center = new Vector2(nodeRect.center.x, nodeRect.yMax + 11); EditorGUIUtility.AddCursorRect(portRectLeft, MouseCursor.ArrowPlus); EditorGUIUtility.AddCursorRect(portRectRight, MouseCursor.ArrowPlus); EditorGUIUtility.AddCursorRect(portRectBottom, MouseCursor.ArrowPlus); GUI.color = new Color(1, 1, 1, 0.3f); GUI.Box(portRectLeft, "", "arrowLeft"); GUI.Box(portRectRight, "", "arrowRight"); if (maxInConnections == 0) { GUI.Box(portRectBottom, "", "arrowBottom"); } GUI.color = Color.white; if (e.button == 0 && e.type == EventType.MouseDown) { if (portRectLeft.Contains(e.mousePosition)) { clickedPort = new Port(this, portRectLeft.center); e.Use(); } if (portRectRight.Contains(e.mousePosition)) { clickedPort = new Port(this, portRectRight.center); e.Use(); } if (maxInConnections == 0 && portRectBottom.Contains(e.mousePosition)) { clickedPort = new Port(this, portRectBottom.center); e.Use(); } } if (clickedPort != null && clickedPort.parent == this) { Handles.DrawBezier(clickedPort.pos, e.mousePosition, clickedPort.pos, e.mousePosition, new Color(0.5f, 0.5f, 0.8f, 0.8f), null, 2); } if (clickedPort != null && e.type == EventType.MouseUp) { var port = clickedPort; if (ID == graph.allNodes.Count) { clickedPort = null; e.Use(); } if (nodeRect.Contains(e.mousePosition)) { foreach (FSMConnection connection in inConnections) { if (connection.sourceNode == port.parent) { Debug.LogWarning("State is already connected to target state. Consider using a 'ConditionList' on the existing transition if you want to check multiple conditions"); clickedPort = null; e.Use(); return; } } graph.ConnectNode(port.parent, this); clickedPort = null; e.Use(); } } for (int i = 0; i < outConnections.Count; i++) { FSMConnection connection = outConnections[i] as FSMConnection; var targetPos = (connection.targetNode as FSMState).GetConnectedInPortPosition(connection); var sourcePos = Vector2.zero; if (nodeRect.center.x <= targetPos.x) { sourcePos = portRectRight.center; } if (nodeRect.center.x > targetPos.x) { sourcePos = portRectLeft.center; } if (maxInConnections == 0 && nodeRect.center.y < targetPos.y - 50 && Mathf.Abs(nodeRect.center.x - targetPos.x) < 200) { sourcePos = portRectBottom.center; } connection.DrawConnectionGUI(sourcePos, targetPos); } }