public override void OnInspectorGUI() { GUI.color = new Color(1, 0.75f, 0.5f); if (GUILayout.Button("Open Editor", GUILayout.Height(40))) { DashEditorWindow.InitEditorWindow(null); DashEditorCore.EditGraph((DashGraph)target); } }
static void ConnectSelectionAsInput(object p_node) { foreach (int nodeIndex in SelectionManager.selectedNodes) { NodeBase node = Graph.Nodes[nodeIndex]; Graph.Connect((NodeBase)p_node, 0, node, 0); } DashEditorCore.SetDirty(); }
public static DashEditorWindow InitEditorWindow(DashController p_dashController) { DashEditorCore.EditController(p_dashController); Instance = GetWindow <DashEditorWindow>(); Instance.titleContent = new GUIContent("Dash Editor"); Instance.minSize = new Vector2(800, 400); return(Instance); }
void BindGraph(DashGraph p_graph) { bool editing = DashEditorCore.EditorConfig.editingGraph == p_graph; Controller.BindGraph(p_graph); // If we are currently editing this controller refresh if (editing) { DashEditorCore.EditController(Controller); } }
void OnAddVariable(DashVariables p_variables, Type p_type) { string name = "new" + p_type.ToString().Substring(p_type.ToString().LastIndexOf(".") + 1); int index = 0; while (p_variables.HasVariable(name + index)) { index++; } p_variables.AddVariableByType((Type)p_type, name + index, null); DashEditorCore.SetDirty(); }
public static bool OpenDashGraphEditor(int p_instanceID, int p_line) { Object asset = EditorUtility.InstanceIDToObject(p_instanceID); if (asset.GetType() == typeof(DashGraph)) { string path = AssetDatabase.GetAssetPath(asset); DashEditorWindow.InitEditorWindow(null); DashEditorCore.EditGraph((DashGraph)AssetDatabase.LoadAssetAtPath <DashGraph>(path)); return(true); } return(false); }
void DrawControllerInfo(Rect p_rect) { if (Graph == null) { return; } GUI.color = Color.white; GUIStyle style = new GUIStyle(); style.normal.textColor = Color.white; style.fontSize = 24; style.fontStyle = FontStyle.Bold; GUI.color = new Color(1, 1, 1, 0.25f); if (Controller != null && Controller.HasBoundGraph) { GUI.Label(new Rect(p_rect.x + 16, p_rect.height - 40, 200, 40), "Bound", style); } else { GUI.Label(new Rect(p_rect.x + 16, p_rect.height - 40, 200, 40), "Asset", style); } if (Controller != null) { style.normal.textColor = Color.yellow; style.fontSize = 18; GUI.Label(new Rect(p_rect.x + 16, p_rect.height - 58, 200, 40), Controller.name, style); } if (GraphUtils.IsSubGraph(DashEditorCore.EditorConfig.editingGraphPath)) { if (GUI.Button(new Rect(p_rect.x + 16, p_rect.height - (Controller == null ? 80 : 98), 100, 32), "GO TO PARENT")) { if (Controller != null) { DashEditorCore.EditController(Controller, GraphUtils.GetParentPath(DashEditorCore.EditorConfig.editingGraphPath)); } else { DashEditorCore.EditGraph(DashEditorCore.EditorConfig.editingRootGraph, GraphUtils.GetParentPath(DashEditorCore.EditorConfig.editingGraphPath)); } } } }
static void SetAsPreview(object p_node) { Graph.previewNode = (NodeBase)p_node; DashEditorCore.SetDirty(); }
void OnPrefabStageOpened(UnityEditor.Experimental.SceneManagement.PrefabStage p_stage) { //when exiting prefab state we are left with a floating graph instance which can creat confusion DashEditorCore.EditController(null); }
void ProcessLeftClick(Event p_event, Rect p_rect) { if (p_event.button != 0) { return; } if (p_event.type == EventType.MouseDown) { GUI.FocusControl(""); } // Select if (p_event.type == EventType.MouseDown && !p_event.alt && Graph != null && !p_event.control) { DashEditorWindow.SetDirty(true); NodeBase hitNode = Graph.HitsNode(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y)); int hitNodeIndex = Graph.Nodes.IndexOf(hitNode); if (!SelectionManager.IsSelected(hitNodeIndex) && (!p_event.shift || hitNodeIndex == 0)) { SelectionManager.ClearSelection(); } if (hitNodeIndex >= 0) { AddSelectedNode(hitNodeIndex); dragging = DraggingType.NODE_DRAG; } else { GraphBox box = Graph.HitsBoxDrag(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y)); if (box != null) { DashEditorCore.selectedBox = box; DashEditorCore.selectedBox.StartDrag(); dragging = DraggingType.BOX_DRAG; } else { box = Graph.HitsBoxResize(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y)); if (box != null) { DashEditorCore.selectedBox = box; DashEditorCore.selectedBox.StartResize(); dragging = DraggingType.BOX_RESIZE; } else { dragging = DraggingType.SELECTION; DashEditorCore.selectedBox = null; Graph.connectingNode = null; selectedRegion = new Rect(p_event.mousePosition.x, p_event.mousePosition.y, 0, 0); } } } } // Dragging if (p_event.type == EventType.MouseDrag) { switch (dragging) { case DraggingType.NODE_DRAG: Vector2 delta = p_event.alt ? Snapping.Snap(p_event.delta, new Vector2(10, 10)): p_event.delta; SelectionManager.DragSelectedNodes(delta, Graph); break; case DraggingType.BOX_DRAG: DashEditorCore.selectedBox.Drag(new Vector2(p_event.delta.x * Zoom, p_event.delta.y * Zoom)); break; case DraggingType.BOX_RESIZE: DashEditorCore.selectedBox.Resize(new Vector2(p_event.delta.x * Zoom, p_event.delta.y * Zoom)); break; case DraggingType.SELECTION: selectedRegion.width += p_event.delta.x; selectedRegion.height += p_event.delta.y; Rect fixedRect = FixRect(selectedRegion); SelectionManager.SelectingNodes(Graph.Nodes.FindAll(n => n.IsInsideRect(fixedRect)).Select(n => n.Index).ToList()); break; } DashEditorWindow.SetDirty(true); } if (p_event.type == EventType.MouseUp) { if (dragging == DraggingType.SELECTION) { SelectionManager.SelectingToSelected(); } if (dragging == DraggingType.NODE_DRAG || dragging == DraggingType.BOX_DRAG || dragging == DraggingType.BOX_RESIZE) { DashEditorCore.SetDirty(); } dragging = DraggingType.NONE; selectedRegion = Rect.zero; DashEditorWindow.SetDirty(true); } }
public override void OnInspectorGUI() { if (DashEditorCore.EditorConfig.settingsShowInspectorLogo) { GUILayout.BeginHorizontal(); GUILayout.Box(Resources.Load <Texture>("Textures/dash"), GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); } if (EditorUtility.IsPersistent(target)) { GUI.enabled = false; } EditorGUI.BeginChangeCheck(); if (((IEditorControllerAccess)Controller).graphAsset == null && !Controller.HasBoundGraph) { GUILayout.BeginVertical(); var oldColor = GUI.color; GUI.color = new Color(1, 0.75f, 0.5f); if (GUILayout.Button("Create Graph", GUILayout.Height(40))) { if (EditorUtility.DisplayDialog("Create Graph", "Create Bound or Asset Graph?", "Bound", "Asset")) { BindGraph(GraphUtils.CreateEmptyGraph()); } else { ((IEditorControllerAccess)Controller).graphAsset = GraphUtils.CreateGraphAsAssetFile(); } } GUI.color = oldColor; ((IEditorControllerAccess)Controller).graphAsset = (DashGraph)EditorGUILayout.ObjectField(((IEditorControllerAccess)Controller).graphAsset, typeof(DashGraph), true); } else { GUILayout.BeginVertical(); var oldColor = GUI.color; GUI.color = new Color(1, 0.75f, 0.5f); if (GUILayout.Button("Open Editor", GUILayout.Height(40))) { OpenEditor(); } GUI.color = oldColor; if (!Controller.HasBoundGraph) { EditorGUI.BeginChangeCheck(); ((IEditorControllerAccess)Controller).graphAsset = (DashGraph)EditorGUILayout.ObjectField(((IEditorControllerAccess)Controller).graphAsset, typeof(DashGraph), true); if (EditorGUI.EndChangeCheck()) { DashEditorCore.EditController(Controller); } if (GUILayout.Button("Bind Graph")) { BindGraph(Controller.Graph); } } else { if (GUILayout.Button("Save to Asset")) { DashGraph graph = GraphUtils.CreateGraphAsAssetFile(Controller.Graph); if (graph != null) { Controller.BindGraph(null); ((IEditorControllerAccess)Controller).graphAsset = graph; } } if (GUILayout.Button("Remove Graph")) { if (DashEditorCore.EditorConfig.editingGraph == Controller.Graph) { DashEditorCore.UnloadGraph(); } Controller.BindGraph(null); } } } Controller.useCustomTarget = EditorGUILayout.Toggle( new GUIContent("Use Custom Target", "Customize target which is this gameobject transform by default."), Controller.useCustomTarget); if (Controller.useCustomTarget == true) { Controller.customTarget = (Transform)EditorGUILayout.ObjectField("Custom Target", Controller.customTarget, typeof(Transform), true); } else { Controller.customTarget = null; } Controller.autoStart = EditorGUILayout.Toggle( new GUIContent("Auto Start", "Automatically call an input on a graph when controller is started."), Controller.autoStart); if (Controller.autoStart) { Controller.autoStartInput = EditorGUILayout.TextField("Auto Start Input", Controller.autoStartInput); } Controller.autoOnEnable = EditorGUILayout.Toggle( new GUIContent("Auto OnEnable", "Automatically call an input on a graph when controller is enabled."), Controller.autoOnEnable); if (Controller.autoOnEnable) { Controller.autoOnEnableInput = EditorGUILayout.TextField("Auto OnEnable Input", Controller.autoOnEnableInput); } GUILayout.EndVertical(); if (Controller.Graph != null) { if (Controller.HasBoundGraph) { GUIVariableUtils.DrawVariablesInspector("Graph Variables", Controller.Graph.variables, Controller.gameObject); } else { Controller.showGraphVariables = EditorGUILayout.Toggle("Show Graph Variables", Controller.showGraphVariables); if (Controller.showGraphVariables) { GUIStyle style = new GUIStyle(); style.fontStyle = FontStyle.Italic; style.normal.textColor = Color.yellow; style.alignment = TextAnchor.MiddleCenter; EditorGUILayout.LabelField("Warning these are not bound to instance.", style); GUIVariableUtils.DrawVariablesInspector("Graph Variables", Controller.Graph.variables, Controller.gameObject); } } } Controller.advancedInspector = EditorGUILayout.Toggle(new GUIContent("Show Advanced Inspector", ""), Controller.advancedInspector); if (Controller.advancedInspector) { DrawExposedPropertiesInspector(); } if (Controller.advancedInspector && Controller.Graph != null) { GUILayout.Space(16); DrawGraphStructureInspector(); } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(target); } serializedObject.ApplyModifiedProperties(); }
static void ActivateConnection(object p_connection) { ((NodeConnection)p_connection).active = true; DashEditorCore.SetDirty(); }
static void DeleteConnection(object p_connection) { Undo.RegisterCompleteObjectUndo(Graph, "Delete Connection"); Graph.Disconnect((NodeConnection)p_connection); DashEditorCore.SetDirty(); }
protected void DrawVariablesGUI(Vector2 p_position, bool p_global, Color p_color, DashVariables p_variables, ref bool p_minimized, GameObject p_boundObject) { Rect rect = new Rect(p_position.x, p_position.y, 380, p_minimized ? 32 : 200); DrawBoxGUI(rect, p_global ? "Global Variables" : "Graph Variables", TextAnchor.UpperCenter, p_color); var minStyle = new GUIStyle(); minStyle.normal.textColor = Color.white; minStyle.fontStyle = FontStyle.Bold; minStyle.fontSize = 20; if (GUI.Button(new Rect(rect.x + rect.width - 20 + (p_minimized ? 0 : 2), rect.y + 2, 20, 20), p_minimized ? "+" : "-", minStyle)) { p_minimized = !p_minimized; GUI.FocusControl(""); } if (p_minimized) { return; } if (p_global && PrefabUtility.GetPrefabInstanceStatus(p_boundObject) != PrefabInstanceStatus.NotAPrefab) { var style = new GUIStyle(); style.alignment = TextAnchor.MiddleCenter; style.normal.textColor = Color.white; style.fontSize = 20; style.wordWrap = true; EditorGUI.TextArea(new Rect(rect.x + 5, rect.y + 30, rect.width - 10, rect.height - 30), "Global variables on prefab instances are not supported!", style); return; } GUILayout.BeginArea(new Rect(rect.x + 5, rect.y + 30, rect.width - 10, rect.height - 79)); scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false); EditorGUI.BeginChangeCheck(); if (p_variables != null) { int index = 0; foreach (var variable in p_variables) { GUIVariableUtils.VariableField(p_variables, variable.Name, p_boundObject, rect.width - 10); EditorGUILayout.Space(4); index++; } } GUILayout.EndScrollView(); GUILayout.EndArea(); if (GUI.Button(new Rect(rect.x + 4, rect.y + rect.height - 48, rect.width - 8, 20), "Add Variable")) { TypesMenu.Show((type) => OnAddVariable(p_variables, type)); } if (GUI.Button(new Rect(rect.x + 4, rect.y + rect.height - 24, rect.width / 2 - 6, 20), "Copy Variables")) { VariableUtils.CopyVariables(p_variables); } if (GUI.Button(new Rect(rect.x + rect.width / 2 + 2, rect.y + rect.height - 24, rect.width / 2 - 6, 20), "Paste Variables")) { VariableUtils.PasteVariables(p_variables, p_boundObject); } if (EditorGUI.EndChangeCheck()) { DashEditorCore.SetDirty(); } UseEvent(new Rect(rect.x, rect.y, rect.width, rect.height)); }