/// <summary>Initialize node for execution.</summary> protected override void Init() { base.Init(); // Init connected. _exit = new FSMConnection(this, "_exit"); _exit.Init(); _isConnected = _exit.Connected; // Cache type checks. _variablePort = GetInputPort("_variable"); _isValidVariable = _variablePort.Connection != null && _expectedType.IsAssignableFrom(_variablePort.Connection.node.GetType()); }
/// <summary>Draw transition ports.</summary> protected virtual void OnTransitionsGUI() { _state = target as FSMStateNode; // Only work the GUI for the current exits and entries. int exitCount = _state.ExitsCount; int entryCount = _state.EntriesCount; // Check if we need to create new entry. _entry = target.GetInputPort("entry"); if (_entry == null) { _entry = target.AddInstanceInput(typeof(FSMConnection), Node.ConnectionType.Override, Node.TypeConstraint.Inherited, "entry"); } // If entry connection is not empty create new entry. if (_entry.Connection != null) { _state.AddEntryConnection(_entry.Connection); _entry.Disconnect(_entry.Connection); } // Check if we need to create new exit. _exit = target.GetOutputPort("exit"); if (_exit == null) { _exit = target.AddInstanceOutput(typeof(FSMConnection), Node.ConnectionType.Override, Node.TypeConstraint.Inherited, "exit"); } // If exit connection is not empty create new exit. if (_exit.Connection != null) { _state.AddExitConnection(_exit.Connection); _exit.Disconnect(_exit.Connection); } GUILayout.BeginHorizontal(); NodeEditorGUILayout.PortField(_entry, GUILayout.Width(50)); EditorGUILayout.Space(); NodeEditorGUILayout.PortField(_exit, GUILayout.Width(50)); GUILayout.EndHorizontal(); EditorGUILayout.Space(); for (int i = 0; i < entryCount; i++) { FSMConnection connection = _state.GetEntryConnection(i); NodePort port = target.GetInputPort(connection.PortName); NodePort connected = port.Connection; if (connected == null) { _state.RemoveEntryConnection(i); i--; entryCount--; } else { GUILayout.BeginHorizontal(); NodeEditorGUILayout.PortField(new GUIContent(), port, GUILayout.Width(-4)); EditorGUILayout.LabelField(string.Format("> {0}", connected.node.name)); GUILayout.EndHorizontal(); } } EditorGUILayout.Space(); for (int i = 0; i < exitCount; i++) { FSMConnection connection = _state.GetExitConnection(i); NodePort port = target.GetOutputPort(connection.PortName); NodePort connected = port.Connection; if (connected == null) { _state.RemoveExitConnection(i); i--; exitCount--; } else { GUILayout.BeginHorizontal(); EditorGUILayout.Space(); NodeEditorGUILayout.PortField(new GUIContent(), port, GUILayout.Width(50)); GUILayout.EndHorizontal(); } } }