private OrderedDictionary <Guid, FRVariable> BuildParameterList(OrderedDictionary <Guid, FRVariable> parameterDefinitions, object[] parameterValues) { OrderedDictionary <Guid, FRVariable> result = new OrderedDictionary <Guid, FRVariable>(); int parameterValueIndex = 0; foreach (Guid key in parameterDefinitions.Keys) { Type parameterType = parameterDefinitions[key].GetType(); FRVariable variable = (FRVariable)Activator.CreateInstance(parameterType); PropertyInfo valuePropertyInfo = parameterType.GetProperty("Value"); if (valuePropertyInfo != null) { if (parameterValueIndex < parameterValues.Length) { valuePropertyInfo.SetValue(variable, parameterValues[parameterValueIndex]); } else { valuePropertyInfo.SetValue(variable, null); } } result.Add(key, variable); ++parameterValueIndex; } return(result); }
public VariableFieldPopup(Rect _dropdownRect, Graph _rootGraph, Node _node, FRVariable _variable, string _variableName) { dropdownRect = _dropdownRect; rootGraph = _rootGraph; node = _node; variable = _variable; variableName = _variableName; }
//public static void DrawVariableW(FieldInfo _field, FRVariable _variable, FlowReactor.Nodes.Node _node, GUISkin _editorSkin) //{ // var _rootGraph = _node.rootGraph; // if (_variable.type == FRVariable.VariableType.local) // { // GUI.color = new Color(100f / 255f, 140f / 255f, 120f / 255f); // using (new GUILayout.HorizontalScope(_editorSkin.GetStyle("FRVariable"))) // { // GUI.color = Color.white; // _variable.Draw(false, null); // var _dropdownRect = GUILayoutUtility.GetLastRect(); // var field = _field; // GUI.enabled = _rootGraph.blackboards.Keys.Count > 0 ? true : false; // GUI.enabled = !Application.isPlaying; // if (EditorGUILayout.DropdownButton(new GUIContent("Blackboard"), FocusType.Keyboard, "miniButton", GUILayout.Width(80))) // { // selectedFieldName = _variable.name; // FieldInfo fieldSelectedBlackboardGuid = typeof(FRVariableGUIUtility).GetField("selectedBlackboardGuid"); // FieldInfo fieldSelectedVariableGuid = typeof(FRVariableGUIUtility).GetField("selectedVariableGuid"); // FieldInfo fieldSelectedName = typeof(FRVariableGUIUtility).GetField("selectedFieldName"); // if (fieldSelectedVariableGuid != null && fieldSelectedName != null && fieldSelectedBlackboardGuid != null) // { // PopupWindow.Show(_dropdownRect, new PopUps.PopupShowPossibleBlackboardVariables(_rootGraph.blackboards, _dropdownRect, typeof(FlowReactor.Editor.FRVariableGUIUtility), field, fieldSelectedBlackboardGuid, fieldSelectedVariableGuid, fieldSelectedName)); // } // } // GUI.enabled = true; // if ( !string.IsNullOrEmpty(selectedBlackboardGuid.ToString()) && !string.IsNullOrEmpty(selectedVariableGuid.ToString())) // && field.Name == selectedFieldName) // { // FRVariable _selectedVar = null; // if (_rootGraph.blackboards.ContainsKey(selectedBlackboardGuid)) // { // if(_rootGraph.blackboards[selectedBlackboardGuid].blackboard.variables.TryGetValue(selectedVariableGuid, out _selectedVar)) // { // if (_rootGraph.blackboards[selectedBlackboardGuid].blackboard.variables[selectedVariableGuid].connectedNodes == null) // { // _rootGraph.blackboards[selectedBlackboardGuid].blackboard.variables[selectedVariableGuid].connectedNodes = new List<FlowReactor.Nodes.Node>(); // } // _rootGraph.blackboards[selectedBlackboardGuid].blackboard.variables[selectedVariableGuid].connectedNodes.Add(_node); // _variable.type = FRVariable.VariableType.blackboard; // _variable.blackboardGuid = selectedBlackboardGuid.ToString(); // _variable.variableGuid = selectedVariableGuid.ToString(); // _variable.assignedBlackboard = _rootGraph.blackboards[selectedBlackboardGuid].blackboard; // _variable.graph = _rootGraph; // } // } // selectedBlackboardGuid = Guid.Empty; // selectedVariableGuid = Guid.Empty; // selectedFieldName = "-"; // } // } // } // else if(_variable.type == FRVariable.VariableType.blackboard) // { // GUI.color = Color.black; // using (new GUILayout.HorizontalScope(_editorSkin.GetStyle("FRVariable"))) // { // GUI.color = Color.white; // if (_rootGraph.blackboards.ContainsKey(Guid.Parse((_variable.blackboardGuid)))) // { // GUILayout.Label(_rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.name + " / " + _rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].name); // } // else // { // GUI.color = Color.red; // GUILayout.Label("Blackboard id does not exist"); // GUI.color = Color.white; // } // GUI.enabled = !Application.isPlaying; // // or else show button to switch back to local node variable // if (GUILayout.Button("Disconnect", "miniButton", GUILayout.Width(80))) // { // // remove connection from blackboard // if (_rootGraph.blackboards.ContainsKey(Guid.Parse(_variable.blackboardGuid))) // { // if (_rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables.ContainsKey(Guid.Parse(_variable.variableGuid))) // { // if (_rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].connectedNodes != null) // { // _rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].connectedNodes.Remove(_node); // } // } // } // _rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].sceneReferenceOnly = false; // _variable.type = FRVariable.VariableType.local; // _variable.blackboardGuid = ""; // _variable.variableGuid = ""; // _variable.assignedBlackboard = null; // _variable.graph = null; // } // } // GUI.enabled = true; // } //} public static void DrawVariableNodeInput(string _variableName, FRVariable _variable, FlowReactor.Nodes.Node _node, bool _onlyBlackboard, GUISkin _editorSkin) { using (new GUILayout.HorizontalScope()) { if (GUILayout.Button("o", GUILayout.Width(20))) { } GUILayout.Label(_variableName); } }
void DragItem(int _itemIndex, Rect _rect, FRVariable _variable, Guid _bbVariableGuid, Event _event) { if (globalDragLocked && _event.type != EventType.MouseUp) { return; } Rect _dragRect = new Rect(_rect.x, _rect.y, 20, 20); if (_dragRect.Contains(Event.current.mousePosition)) { if (_event.type == EventType.MouseDrag) { isDragging = true; dragItemIndex = _itemIndex; BlackBoardVariableDragProperties.eventType = EventType.MouseDrag; BlackBoardVariableDragProperties.variable = _variable; BlackBoardVariableDragProperties.isDragging = true; BlackBoardVariableDragProperties.blackboardGuid = blackboardGuid; BlackBoardVariableDragProperties.startDragPosition = new Vector2(_rect.x, _rect.y); BlackBoardVariableDragProperties.blackboardVariableGuid = _bbVariableGuid; BlackBoardVariableDragProperties.editor = this; reorderableList.draggable = false; Repaint(); _event.Use(); } } if (isDragging && dragItemIndex == _itemIndex) { BlackBoardVariableDragProperties.mousePosition = _event.mousePosition; } if (_event.type == EventType.MouseUp && isDragging) { dragItemIndex = -1; isDragging = false; BlackBoardVariableDragProperties.isDragging = false; BlackBoardVariableDragProperties.eventType = EventType.MouseUp; } if (!BlackBoardVariableDragProperties.isDragging) { reorderableList.draggable = true; } // GUI.Box(_dragRect, new GUIContent(dragIcon, "Drag variable to node variable field")); }
public PopupShowPossibleBlackboardVariables(Dictionary <Guid, Graph.Blackboards> _blackboards, Rect _rect, object _targetObject, FRVariable _variable, FlowReactor.Nodes.Node _node, FieldInfo _selectedBlackboardGuid, FieldInfo _selectedVariableGuid, FieldInfo _selectedName) { //Debug.Log("open " + _variable.name + " " + _node.nodeData.title); blackboards = _blackboards; rect = _rect; variable = _variable; selectedBlackboardGuid = _selectedBlackboardGuid; selectedVariableGuid = _selectedVariableGuid; selectedName = _selectedName; field2Value = _selectedName.GetValue(_targetObject) as string; targetObject = _targetObject; rootGraph = _node.rootGraph; node = _node; }
public static void UnExposeVariable(FRVariable _variable) { if (_variable.nodeOwner.rootGraph.exposedNodeVariables.ContainsKey(_variable.nodeOwner.nodeData.title)) { if (_variable.nodeOwner.rootGraph.exposedNodeVariables[_variable.nodeOwner.nodeData.title].variables.ContainsKey(_variable.exposedName)) { _variable.nodeOwner.rootGraph.exposedNodeVariables[_variable.nodeOwner.nodeData.title].variables.Remove(_variable.exposedName); if (_variable.nodeOwner.rootGraph.exposedNodeVariables[_variable.nodeOwner.nodeData.title].variables.Keys.Count == 0) { _variable.nodeOwner.rootGraph.exposedNodeVariables.Remove(_variable.nodeOwner.nodeData.title); } _variable.type = FRVariable.VariableType.local; _variable.graph = null; _variable.nodeOwner = null; } } }
public static void ExposeVariable(Graph _rootGraph, Node _node, FRVariable _variable, string _variableName) { _variable.type = FRVariable.VariableType.exposed; _variable.graph = _node.graphOwner; _variable.nodeOwner = _node; _variable.exposedNodeName = _node.nodeData.title; _variable.exposedName = _variableName; _variable.name = _variableName; //Debug.Log("expose variable node name: " + _node.nodeData.title); if (_rootGraph.exposedNodeVariables == null) { _rootGraph.exposedNodeVariables = new Dictionary <string, Graph.ExposedVariables>(); } if (!_rootGraph.exposedNodeVariables.ContainsKey(_node.nodeData.title)) { _rootGraph.exposedNodeVariables.Add(_node.nodeData.title, new Graph.ExposedVariables(_node, _variableName, _variable)); } else { if (_rootGraph.exposedNodeVariables[_node.nodeData.title].node != _node) { // is it the same node? var _newNodeName = ReturnNewNodeName(_rootGraph.exposedNodeVariables, _node.nodeData.title); _node.nodeData.title = _newNodeName; _variable.exposedNodeName = _newNodeName; _rootGraph.exposedNodeVariables.Add(_node.nodeData.title, new Graph.ExposedVariables(_node, _variableName, _variable)); } else { if (!_rootGraph.exposedNodeVariables[_node.nodeData.title].variables.ContainsKey(_variableName)) { _rootGraph.exposedNodeVariables[_node.nodeData.title].variables.Add(_variableName, _variable); // = Graph.AddToVariablesWithUniqueExposedName(variable, rootGraph.exposedNodeVariables[node].variables); } } } }
static void DropAreaGUI(Rect _rect, FRVariable _nodeVariable, Node _node, GUISkin _skin) { Rect _dropArea = new Rect(_rect.x - 2, _rect.y - 2, _rect.width + 4, _rect.height + 4); Event _evt = Event.current; if (_dropArea.Contains(_evt.mousePosition) && BlackBoardVariableDragProperties.isDragging) { if (BlackBoardVariableDragProperties.variable.GetType() == _nodeVariable.GetType()) { GUI.color = Color.green; } else { GUI.color = Color.red; } GUI.Box(_dropArea, "", _skin.GetStyle("FRVariable")); } GUI.color = Color.white; if (_evt.type == EventType.MouseUp && _dropArea.Contains(_evt.mousePosition)) { if (BlackBoardVariableDragProperties.variable != null && _nodeVariable != null) { if (BlackBoardVariableDragProperties.variable.GetType() == _nodeVariable.GetType()) { var bb = _node.graphOwner.blackboards.Keys.Select(x => x.ToString()).ToArray(); // Connect BB variable to node variable _nodeVariable.type = FRVariable.VariableType.blackboard; _nodeVariable.variableGuid = BlackBoardVariableDragProperties.blackboardVariableGuid.ToString(); _nodeVariable.blackboardGuid = BlackBoardVariableDragProperties.blackboardGuid.ToString(); _nodeVariable.assignedBlackboard = _node.rootGraph.blackboards[BlackBoardVariableDragProperties.blackboardGuid].blackboard; _nodeVariable.graph = _node.rootGraph; if (!_node.rootGraph.blackboards[Guid.Parse(_nodeVariable.blackboardGuid)].blackboard.variables[Guid.Parse(_nodeVariable.variableGuid)].sceneReferenceOnly && _nodeVariable.sceneReferenceOnly) { _node.rootGraph.blackboards[Guid.Parse(_nodeVariable.blackboardGuid)].blackboard.variables[Guid.Parse(_nodeVariable.variableGuid)].sceneReferenceOnly = true; } if (BlackBoardVariableDragProperties.variable.connectedNodes == null) { BlackBoardVariableDragProperties.variable.connectedNodes = new List <FlowReactor.Nodes.Node>(); } BlackBoardVariableDragProperties.variable.connectedNodes.Add(_node); BlackBoardVariableDragProperties.isDragging = false; GUI.FocusControl(""); BlackBoardVariableDragProperties.editor.SetupListWithoutResLoading(); } else { BlackBoardVariableDragProperties.isDragging = false; } } else { BlackBoardVariableDragProperties.isDragging = false; } BlackBoardVariableDragProperties.variable = null; _evt.Use(); } }
public static void DrawVariable(string _variableName, FRVariable _variable, FlowReactor.Nodes.Node _node, bool _onlyBlackboard, GUISkin _editorSkin) { var _rootGraph = _node.rootGraph; //var _returnHeight = 22f; if (_variable == null) { return; } if (_variable.type == FRVariable.VariableType.local) { GUI.color = _node.color; using (new GUILayout.HorizontalScope()) //_editorSkin.GetStyle("FRVariable"))) { GUILayout.Label("", _editorSkin.GetStyle("LineVariables")); GUI.color = Color.white; if (!string.IsNullOrEmpty(_variableName)) { GUILayout.Label(_variableName); } if (!_onlyBlackboard) { // Get Custom attributes for FRVariables and pass them to the variable Draw() method FieldInfo[] _f = _node.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy); object[] _attributes = null; for (int f = 0; f < _f.Length; f++) { if (_f[f].GetValue(_node) == _variable) { _attributes = _f[f].GetCustomAttributes(false); //if (_attribute != null) //{ // Debug.Log("Found attribute " + _f[f].Name + " " + _attribute.Length); //} } } GUI.enabled = !sceneRefObjectDragging; if (_attributes != null) { var _att = _attributes.FirstOrDefault(x => x.GetType() == typeof(SceneObjectOnly)); if (_att != null) { _variable.sceneReferenceOnly = true; GUI.enabled = false; GUILayout.Label(new GUIContent("scene only", EditorGUIUtility.IconContent("d_SceneViewOrtho").image), "ObjectField"); GUI.enabled = true; } else { _variable.sceneReferenceOnly = false; _variable.Draw(false, _attributes); } } else { _variable.Draw(false, _attributes); } GUI.enabled = true; var _lr = GUILayoutUtility.GetLastRect(); // DropArea for when user drags a blackboard variable to this node variable field DropAreaGUI(_lr, _variable, _node, _editorSkin); } else { GUILayout.Label("", GUILayout.Width(100)); } var _dropdownRect = GUILayoutUtility.GetLastRect(); GUI.enabled = _rootGraph.blackboards.Keys.Count > 0 ? true : false; GUI.enabled = !Application.isPlaying; GUI.SetNextControlName("NodeClear"); //GUILayout.Label("F"); //var _dropdownRect = GUILayoutUtility.GetLastRect(); if (GUILayout.Button("", _editorSkin.GetStyle("VariableMenuButton"), GUILayout.Width(20))) { //VariableContextMenu(_dropdownRect, _rootGraph, _node, _variable); PopupWindow.Show(_dropdownRect, new VariableFieldPopup(_dropdownRect, _rootGraph, _node, _variable, _variableName)); } //if (EditorGUILayout.DropdownButton(new GUIContent("", "connect to blackboard"), FocusType.Keyboard, _editorSkin.GetStyle("ConnectBlackboardButton"), GUILayout.Width(20))) //{ // //selectedFieldName = _variable.name; // FieldInfo fieldSelectedBlackboardGuid = typeof(FRVariableGUIUtility).GetField("selectedBlackboardGuid"); // FieldInfo fieldSelectedVariableGuid = typeof(FRVariableGUIUtility).GetField("selectedVariableGuid"); // FieldInfo fieldSelectedName = typeof(FRVariableGUIUtility).GetField("selectedFieldName"); // if (fieldSelectedVariableGuid != null && fieldSelectedName != null && fieldSelectedBlackboardGuid != null) // { // PopupWindow.Show(_dropdownRect, new PopUps.PopupShowPossibleBlackboardVariables(_rootGraph.blackboards, _dropdownRect, typeof(FlowReactor.Editor.FRVariableGUIUtility), _variable, _node, fieldSelectedBlackboardGuid, fieldSelectedVariableGuid, fieldSelectedName)); // } //} GUI.enabled = true; } } else if (_variable.type == FRVariable.VariableType.blackboard) { GUI.color = Color.black; using (new GUILayout.HorizontalScope()) //_editorSkin.GetStyle("FRVariable"))) { if (!_rootGraph.blackboards.ContainsKey(Guid.Parse(_variable.blackboardGuid))) { // user has remove blackboard from graph // reset variable connection _variable.type = FRVariable.VariableType.local; _variable.blackboardGuid = ""; _variable.variableGuid = ""; _variable.assignedBlackboard = null; _variable.graph = null; } else { if (_rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables.ContainsKey(Guid.Parse(_variable.variableGuid))) { var _bbPath = _rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.name + " / " + _rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].name; var _bbVarName = _rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].name; GUILayout.Label("", _editorSkin.GetStyle("LineVariables")); GUI.color = Color.white; GUI.enabled = false; if (!string.IsNullOrEmpty(_variableName)) { GUILayout.Label(new GUIContent(_variableName, "connected to: " + _bbPath)); } if (_rootGraph.blackboards.ContainsKey(Guid.Parse(_variable.blackboardGuid))) { try { var _varName = _rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].name; GUILayout.FlexibleSpace(); var _var = _rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)]; //if (_var.GetType() == typeof(FRGameObject)) //{ //var _g = _var as FRGameObject; //if (_g.Value == null) //{ // GUILayout.Label(_bbPath); //} //else //{ if (_var.sceneReferenceOnly) { GUI.enabled = false; GUILayout.Label(" = " + _bbPath); //GUILayout.Label(new GUIContent("scene only", EditorGUIUtility.IconContent("d_SceneViewOrtho").image), "ObjectField"); GUI.enabled = true; } else { GUI.enabled = false; //!sceneRefObjectDragging; GUILayout.Label(" = " + _bbVarName); _var.Draw(false, null); GUI.enabled = true; } //} //else //{ // GUI.enabled = !sceneRefObjectDragging; // _var.Draw(false, null); // GUI.enabled = true; //} //GUILayout.Label(_rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.name + " / " + _rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].name); var _lrect = GUILayoutUtility.GetLastRect(); GUI.Label(_lrect, new GUIContent("", "connected to: " + _bbPath)); } catch { GUILayout.Label(_variable.name); GUI.color = Color.red; GUILayout.Label(" : (Variable id doesn't exist)"); GUI.color = Color.white; } } else { using (new GUILayout.HorizontalScope()) { GUILayout.Label(_variable.name); GUI.color = Color.red; GUILayout.Label(" : (Blackboard id doesn't exist)"); GUI.color = Color.white; } } GUILayout.FlexibleSpace(); GUI.enabled = true; // or else show button to switch back to local node variable if (GUILayout.Button(new GUIContent("", "Disconnect from blackboard"), _editorSkin.GetStyle("DisconnectBlackboardButton"), GUILayout.Width(20))) { // remove connection from blackboard if (_rootGraph.blackboards.ContainsKey(Guid.Parse(_variable.blackboardGuid))) { if (_rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables.ContainsKey(Guid.Parse(_variable.variableGuid))) { if (_rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].connectedNodes != null) { _rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].connectedNodes.Remove(_node); } } } if (_variable.sceneReferenceOnly) { bool _hasOtherSceneRefs = false; for (int n = 0; n < _rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].connectedNodes.Count; n++) { if (_rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].connectedNodes[n] != _node) { List <FRVariable> _allNodeVariables; FlowReactor.Editor.GetAvailableVariableTypes.GetAllFRVariablesOnNode(_rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].connectedNodes[n], out _allNodeVariables); for (int i = 0; i < _allNodeVariables.Count; i++) { if (_allNodeVariables[i].sceneReferenceOnly) { _hasOtherSceneRefs = true; } } } } if (!_hasOtherSceneRefs) { _rootGraph.blackboards[Guid.Parse(_variable.blackboardGuid)].blackboard.variables[Guid.Parse(_variable.variableGuid)].sceneReferenceOnly = false; } } _variable.type = FRVariable.VariableType.local; _variable.blackboardGuid = ""; _variable.variableGuid = ""; _variable.assignedBlackboard = null; _variable.graph = null; } } else { _variable.type = FRVariable.VariableType.local; _variable.blackboardGuid = ""; _variable.variableGuid = ""; _variable.assignedBlackboard = null; _variable.graph = null; } } } } else if (_variable.type == FRVariable.VariableType.exposed) { using (new GUILayout.HorizontalScope()) { GUI.color = colOrange; GUILayout.Label("", _editorSkin.GetStyle("LineVariables")); GUI.color = Color.white; if (!string.IsNullOrEmpty(_variableName)) { GUILayout.Label(new GUIContent(_variableName + " = " + _variable.exposedName, "exposed as: " + _variable.exposedName)); } if (GUILayout.Button("", _editorSkin.GetStyle("VariableExposedButton"), GUILayout.Width(20))) { UnExposeVariable(_variable); } } } }
public static void DrawVariable(FRVariable _variable, FlowReactor.Nodes.Node _node, bool _onlyBlackboard, GUISkin _editorSkin) { DrawVariable("", _variable, _node, _onlyBlackboard, _editorSkin); }
public void ValueChanged(FRVariable _var) { ExecuteNext(0, flowReactor); }
public PopupDataboxVariables(DataboxObjectManager _databoxManager, FRVariable _variable) //(FlowReactorDataboxAddon _addon, DataboxObjectManager _databoxManager, SONodeVariable _variable) { databoxManager = _databoxManager; variable = _variable; }
public override void OnInspectorGUI() { if (editorSkin == null) { editorSkin = EditorHelpers.LoadSkin(); editIcon = EditorHelpers.LoadIcon("editIcon.png"); refreshIcon = EditorHelpers.LoadIcon("refreshIcon.png"); okIcon = EditorHelpers.LoadIcon("checkmarkIcon.png"); cancelIcon = EditorHelpers.LoadIcon("cancelIcon.png"); } if (fr != null && fr.graph != null) { GUI.enabled = true; } else { GUI.enabled = false; } using (new GUILayout.HorizontalScope("Box")) { if (GUILayout.Button((Application.isPlaying && fr.runUniqueInstance) ? "Open instance" : "Open", GUILayout.Height(50))) { //var window = CreateInstance<GraphEditor>(); //window.Init(window, fr.graph); var _settings = (FREditorSettings)FREditorSettings.GetOrCreateSettings(); _settings.OpenGraphWindow(fr.graph); // Check if graph needs to be updated GraphUpdater.UpdateGraph(fr.graph); } if (Application.isPlaying && fr.runUniqueInstance) { if (GUILayout.Button("Open original", GUILayout.Height(50))) { //var window = CreateInstance<GraphEditor>(); //window.Init(window, fr.originalGraph); var _settings = (FREditorSettings)FREditorSettings.GetOrCreateSettings(); _settings.OpenGraphWindow(fr.originalGraph); } } } GUI.enabled = true; EditorGUI.BeginChangeCheck(); using (new GUILayout.HorizontalScope("Box")) { fr.graph = (Graph)EditorGUILayout.ObjectField(fr.graph, typeof(Graph), false); if (GUILayout.Button("New Graph")) { NodeCreator.CreateNewGraphWithDefaultNodes(fr); } } using (new GUILayout.VerticalScope(("Box"))) { using (new GUILayout.HorizontalScope()) { GUILayout.Label("Graph settings"); GUILayout.FlexibleSpace(); if (GUILayout.Button("?", GUILayout.Width(18))) { Application.OpenURL("https://flowreactor.io/documentation/flowreactor-component/"); } } fr.runUniqueInstance = GUILayout.Toggle(fr.runUniqueInstance, "unique instance"); fr.useGlobalUpdateLoop = GUILayout.Toggle(fr.useGlobalUpdateLoop, "global update loop"); } if (fr.graph == null) { return; } // cache keys which needs to be removed List <string> cleanupKeys = new List <string>(); EditorHelpers.DrawUILine(); #region nodecontrollables // NODE CONTROLLABLES //////////////////////////// using (new GUILayout.HorizontalScope("Toolbar")) { GUILayout.Label("Node controlled objects", "boldLabel"); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent(refreshIcon, "Collect all controllable nodes"), "toolbarButton")) { fr.graph.RegisterINodeControllables(fr); UpdateControllablesDictionary(); } if (GUILayout.Button("?", "toolbarButton")) { Application.OpenURL("https://flowreactor.io/documentation/frnodemodules/"); } } if (fr.nodeControllables != null && fr.nodeControllables.Count > 0) { EditorGUI.BeginChangeCheck(); using (new GUILayout.VerticalScope(editorSkin.GetStyle("BoxLine"))) { if (fr.nodeControllables != null) { foreach (Node node in fr.nodeControllables.Keys) { using (new GUILayout.VerticalScope("Box")) { using (new GUILayout.HorizontalScope("Toolbar")) { GUILayout.Label(node.nodeData.title); GUILayout.FlexibleSpace(); } Dictionary <string, INodeControllable> tempController = new Dictionary <string, INodeControllable>(); foreach (var faces in fr.nodeControllables[node].interfaces.Keys) { using (new GUILayout.HorizontalScope()) { GUILayout.Label(faces); var _lastRect = GUILayoutUtility.GetLastRect(); var _obj = EditorGUILayout.ObjectField((UnityEngine.Object)fr.nodeControllables[node].interfaces[faces], typeof(INodeControllable), true); if (GUILayout.Button("select")) { PopupWindow.Show(_lastRect, new PopupShowINodeControllableObjects(node, faces)); } //fr.gameControllerInterfaces[node].interfaces[faces] = _obj as INodeController; tempController.Add(faces, _obj as INodeControllable); } } foreach (var t in tempController.Keys) { fr.nodeControllables[node].interfaces[t] = tempController[t]; } } } } else { GUILayout.Label("null"); } } if (EditorGUI.EndChangeCheck()) { UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene()); } } EditorHelpers.DrawUILine(); //////////////////////////// #endregion #region exposedvariables // EXPOSED VARIABLES //////////////////////////// using (new GUILayout.HorizontalScope("Toolbar")) { GUILayout.Label("Exposed variables", "boldLabel"); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent(refreshIcon, "Manually collect and update exposed variables from nodes"), "ToolbarButton")) { fr.CollectAndUpdateAllExposedVariables(); } #if FLOWREACTOR_DEBUG GUI.color = Color.yellow; if (GUILayout.Button("Clear exposed variables", "ToolbarButton")) { fr.exposedNodeVariables = new Dictionary <string, Dictionary <string, FRVariable> >(); fr.graph.exposedNodeVariables = new Dictionary <string, Graph.ExposedVariables>(); } GUI.color = Color.white; #endif } if (fr.exposedNodeVariables != null) { if (fr.exposedNodeVariables.Keys.Count > 0) { var i = 0; using (new GUILayout.VerticalScope(editorSkin.GetStyle("BoxLine"))) { foreach (string exposedNodeKey in fr.exposedNodeVariables.Keys) { if (EditorGUIUtility.isProSkin) { GUI.color = colorsDarkSkin[i % 2]; } else { GUI.color = colorsLighSkin[i % 2]; } using (new GUILayout.VerticalScope(editorSkin.GetStyle("BoxWhite"))) { GUI.color = Color.white; GUILayout.Label(exposedNodeKey, "boldLabel"); List <string> _variableKeys = fr.exposedNodeVariables[exposedNodeKey].Keys.ToList(); for (int s = 0; s < _variableKeys.Count; s++) { using (new GUILayout.HorizontalScope()) { var _variableKey = _variableKeys[s]; var _exposedVariable = fr.exposedNodeVariables[exposedNodeKey][_variableKey]; var _varType = _exposedVariable.GetType().Name.ToString(); GUILayout.Label(new GUIContent(_varType, "GetExposedVariable<" + _varType + ">(" + "\"" + exposedNodeKey + "\"," + "\"" + _variableKey + "\");"), GUILayout.Width(80)); GUI.enabled = _exposedVariable.editExposedName; _exposedVariable.exposedName = GUILayout.TextField(_exposedVariable.exposedName, GUILayout.Width(100)); GUI.enabled = true; if (_exposedVariable.editExposedName) { if (string.IsNullOrEmpty(_exposedVariable.exposedName)) { GUI.enabled = false; } if (GUILayout.Button(okIcon, GUILayout.Width(20), GUILayout.Height(20))) { _exposedVariable.editExposedName = false; var _fromName = _variableKey; var _newName = _exposedVariable.exposedName; #if FLOWREACTOR_DEBUG Debug.Log("update key from: " + _fromName + " to: " + _newName); #endif // check if new name already exists bool _nameAlreadyExists = false; foreach (var variableKeyB in fr.exposedNodeVariables[exposedNodeKey].Keys) { if (variableKeyB.Equals(_newName)) { _nameAlreadyExists = true; } } if (!_nameAlreadyExists) { var _nodeVariableField = fr.graph.exposedNodeVariables[exposedNodeKey].variables[_fromName].nodeOwner.GetType().GetField(fr.graph.exposedNodeVariables[exposedNodeKey].variables[_fromName].name); var _nodeVariable = _nodeVariableField.GetValue(fr.graph.exposedNodeVariables[exposedNodeKey].variables[_fromName].nodeOwner) as FRVariable; _nodeVariable.exposedName = _newName; fr.exposedNodeVariables[exposedNodeKey].UpdateKey(_fromName, _newName); fr.graph.exposedNodeVariables[exposedNodeKey].variables.UpdateKey(_fromName, _newName); } else { _exposedVariable.exposedName = _fromName; } } GUI.enabled = true; if (GUILayout.Button(cancelIcon, GUILayout.Width(20), GUILayout.Height(20))) { fr.exposedNodeVariables[exposedNodeKey][_variableKey].exposedName = _variableKey; fr.exposedNodeVariables[exposedNodeKey][_variableKey].editExposedName = false; } } else { if (GUILayout.Button(editIcon, GUILayout.Width(20), GUILayout.Height(20))) { fr.exposedNodeVariables[exposedNodeKey][_variableKey].editExposedName = true; } } if (fr.exposedNodeVariables[exposedNodeKey].ContainsKey(_variableKey)) { GUILayout.Label("Value: ", GUILayout.Width(50)); fr.exposedNodeVariables[exposedNodeKey][_variableKey].Draw(true, null); } //GUILayout.Label("Runtime access: GetData<" + fr.exposedNodeVariables[exposed].variables[variableKeys[s]].GetType().ToString() + ">("); } } } i++; } } } } //////////////////////////// #endregion #region sceneoverrides // BLACKBOARD SCENE OVERRIDES //////////////////////////// if (fr.graph.blackboards != null && fr.graph.blackboards.Keys.Count > 0) { EditorHelpers.DrawUILine(); using (new GUILayout.HorizontalScope("Toolbar")) { GUILayout.Label("Blackboard scene overrides", "boldLabel"); } using (new GUILayout.VerticalScope(editorSkin.GetStyle("BoxLine"))) { foreach (var bb in fr.graph.blackboards.Keys) { if (fr.graph.blackboards[bb].blackboard == null) { EditorGUILayout.HelpBox("Blackboard is empty, please assign a blackboard asset to the graph", MessageType.Warning); continue; } using (new GUILayout.HorizontalScope(FlowReactorEditorStyles.overflowButton)) { fr.graph.blackboards[bb].foldout = EditorGUILayout.Foldout(fr.graph.blackboards[bb].foldout, fr.graph.blackboards[bb].blackboard.name); } if (fr.graph.blackboards[bb].foldout) { foreach (var key in fr.graph.blackboards[bb].blackboard.variables.Keys) { FRVariable value = null; // object is in the scene but variable is not set as overridable if (fr.overrideSceneVariables.TryGetValue(key.ToString(), out value) && !IsObjectPrefabInProject()) { using (new GUILayout.HorizontalScope()) { EditorGUI.BeginChangeCheck(); if (fr.graph.blackboards[bb].blackboard.variables[key].sceneReferenceOnly) { GUI.enabled = false; value.overrideVariable = true; } value.overrideVariable = GUILayout.Toggle(value.overrideVariable, "Override", GUILayout.Width(100)); GUI.enabled = true; if (value.overrideVariable == false) { //fr.overrideSceneVariables.Remove(key.ToString()); GUI.enabled = false; GUILayout.Label(fr.graph.blackboards[bb].blackboard.variables[key].name); if (fr.graph.blackboards[bb].blackboard.variables[key].useDatabox) { GUILayout.Label(fr.graph.blackboards[bb].blackboard.variables[key].databoxID + " | " + fr.graph.blackboards[bb].blackboard.variables[key].tableID + " | " + fr.graph.blackboards[bb].blackboard.variables[key].entryID + " | " + fr.graph.blackboards[bb].blackboard.variables[key].tableID); } else { fr.graph.blackboards[bb].blackboard.variables[key].Draw(true, null); } GUI.enabled = true; } else { GUI.enabled = true; //GUILayout.Label(value.name); GUILayout.Label(fr.graph.blackboards[bb].blackboard.variables[key].name); value.Draw(true, null); } GUI.enabled = true; if (EditorGUI.EndChangeCheck() && !Application.isPlaying) { UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene()); } } } // object lives in the scene else { using (new GUILayout.HorizontalScope()) { var v = fr.graph.blackboards[bb].blackboard.variables[key] as FRVariable; if (!IsObjectPrefabInProject()) { if (v.sceneReferenceOnly) { GUI.enabled = false; v.overrideVariable = true; } } else { GUI.enabled = false; } v.overrideVariable = GUILayout.Toggle(v.overrideVariable, "Override", GUILayout.Width(100)); GUI.enabled = true; if (v.overrideVariable) { // create new item and copy it to the override variables var _newOverrideVariable = (FRVariable)Activator.CreateInstance(fr.graph.blackboards[bb].blackboard.variables[key].GetType()); _newOverrideVariable.overrideVariable = true; _newOverrideVariable.name = v.name; fr.overrideSceneVariables.Add(key.ToString(), _newOverrideVariable); fr.overrideSceneVariables[key.ToString()].overrideVariable = true; fr.overrideSceneVariables[key.ToString()].name = v.name; v.overrideVariable = false; // blackboard is always false } GUI.enabled = false; GUILayout.Label(v.name); if (fr.graph.blackboards[bb].blackboard.variables[key].useDatabox) { GUILayout.Label(fr.graph.blackboards[bb].blackboard.variables[key].databoxID + " | " + fr.graph.blackboards[bb].blackboard.variables[key].tableID + " | " + fr.graph.blackboards[bb].blackboard.variables[key].entryID + " | " + fr.graph.blackboards[bb].blackboard.variables[key].tableID); } else { fr.graph.blackboards[bb].blackboard.variables[key].Draw(true, null); } GUI.enabled = true; } } } GUILayout.Space(10); EditorHelpers.DrawUILine(); } // cleanup override variables if they don't exist in the blackboard anymore foreach (var kc in fr.overrideSceneVariables.Keys) { bool _overrideVarExists = false; foreach (var bc in fr.graph.blackboards.Keys) { if (fr.graph.blackboards[bc].blackboard.variables.ContainsKey(Guid.Parse(kc))) { _overrideVarExists = true; } } if (!_overrideVarExists) { Debug.Log("cleanup"); cleanupKeys.Add(kc.ToString()); } } } } } for (int c = 0; c < cleanupKeys.Count; c++) { #if FLOWREACTOR_DEBUG Debug.Log("remove override variable " + cleanupKeys[c]); #endif Debug.Log("remove"); fr.overrideSceneVariables.Remove(cleanupKeys[c]); } // only for debug #if FLOWREACTOR_DEBUG DrawDefaultInspector(); #endif if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(target); } serializedObject.Update(); serializedObject.ApplyModifiedProperties(); }