/// <summary> /// Draw popup window /// </summary> private void OnGUI() { GUILayout.Space(20); GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.BeginVertical(); EditorGUILayout.LabelField("Create New Graph:", EditorStyles.boldLabel); //name = EditorGUILayout.TextField("Enter Name: ", name); model = (ActorModel)EditorGUILayout.ObjectField("Model", model, typeof(ActorModel), true); GUILayout.Space(10); GUILayout.BeginHorizontal(); if (GUILayout.Button("Create Graph", GUILayout.Height(40))) { if (model != null) { ChainEditorUtilities.CreateNewGraph(model); popup.Close(); } else { EditorUtility.DisplayDialog("Node Message:", "Please select a valid ActorModel!", "OK"); } } if (GUILayout.Button("Cancel", GUILayout.Height(40))) { popup.Close(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.Space(20); GUILayout.EndHorizontal(); GUILayout.Space(20); }
/// <summary> /// Constructor /// </summary> public View_Property() : base("Property View") { _redStyle = new GUIStyle("Button"); _redStyle.onNormal.background = ChainEditorUtilities.MakeTex(2, 2, new Color(0f, 1f, 0f, 0.5f)); _buttonOffsetStyle = new GUIStyle("Button"); _buttonOffsetStyle.margin = new RectOffset(0, 0, 0, -1); }
/// <summary> /// A method to draw everything in Graph /// </summary> /// <param name="e"></param> /// <param name="graph"></param> void DrawZoomableGraph(Event e, ChainGraph graph) { ChainEditorUtilities.BeginZoomArea(zoom, viewRect); viewRect.size /= zoom; graph.UpdateGraphGUI(e, viewRect, skin); ChainEditorUtilities.EndZoomArea(); }
/// <summary> /// Remove the connection between two nodes /// </summary> void RemoveConnection() { if (input.node != null) { if (input.node.output.nodes.Contains(this)) { input.node.output.nodes.Remove(this); } } input.node = parentGraph.connectedNode; ChainEditorUtilities.UpdateFollowUps(parentGraph); }
/// <summary> /// Add Connection between two nodes /// </summary> void AddConnection() { input.node = parentGraph.connectedNode; if (input.node != null) { if (input.node.output.nodes != null) { if (!input.node.output.nodes.Contains(this)) { input.node.output.nodes.Add(this); } } } ChainEditorUtilities.UpdateFollowUps(parentGraph); }
/// <summary> /// A method to zoom in/out graph /// </summary> void ZoomEvent() { // Allow adjusting the zoom with the mouse wheel as well. In this case, use the mouse coordinates // as the zoom center instead of the top left corner of the zoom area. This is achieved by // maintaining an origin that is used as offset when drawing any GUI elements in the zoom area. if (Event.current.type == EventType.ScrollWheel) { Vector2 screenCoordsMousePos = Event.current.mousePosition; Vector2 delta = Event.current.delta; Vector2 zoomCoordsMousePos = ChainEditorUtilities.ConvertScreenCoordsToZoomCoords(screenCoordsMousePos, viewRect, zoom, ZoomPivot); float zoomDelta = -delta.y / 150.0f; float oldZoom = zoom; zoom += zoomDelta; zoom = Mathf.Clamp(zoom, ZOOM_MIN, ZOOM_MAX); ZoomPivot += (zoomCoordsMousePos - ZoomPivot) - (oldZoom / zoom) * (zoomCoordsMousePos - ZoomPivot); } }
/// <summary> /// A method to update the the view aspect of the /// </summary> /// <param name="editorRect"></param> /// <param name="percentageRect"></param> /// <param name="e"></param> /// <param name="graph"></param> public override void UpdateView(Rect editorRect, Rect percentageRect, Event e, ChainGraph graph) { base.UpdateView(editorRect, percentageRect, e, graph); // Draw the Node workspace background GUI.Box(viewRect, "", skin.GetStyle("ViewBG")); ChainEditorUtilities.DrawGrid(viewRect, 50f, 0.25f, Color.white); ChainEditorUtilities.DrawGrid(viewRect, 10f, 0.15f, Color.white); if (graph != null) { DrawZoomableGraph(e, graph); GUILayout.BeginArea(new Rect(viewRect.x, viewRect.y, viewRect.width * zoom, viewRect.height)); DrawStateToolBar(graph); GUILayout.EndArea(); } // Update mouse and keyboard event ProcessEvent(e); }
/// <summary> /// A callback method to call the elements inside context menu /// </summary> /// <param name="obj"></param> void ContextCallback(object obj) { switch (obj.ToString()) { case "0": //Debug.Log("Created a new graph"); //ChainEditorUtilities.CreateNewGraph(); GraphCreationPopUp.Open(); break; case "1": //Debug.Log("Loaded a graph"); ChainEditorUtilities.LoadGraph(); break; case "2": //Debug.Log("Unloaded a graph"); ChainEditorUtilities.UnloadGraph(); break; case "3": ChainEditorUtilities.CreateNode(graph, NodeType.ChainBehaviorNode, _mousePos); break; case "4": ChainEditorUtilities.CreateNode(graph, NodeType.RootBehaviorNode, _mousePos); break; case "5": ChainEditorUtilities.DeleteNode(_deleteNodeIndex, graph); break; case "6": ChainEditorUtilities.UpdateGraphToModel(graph); break; } }
private void OnFile_SaveGraph() { ChainEditorUtilities.UpdateGraphToModel(graph); }
private void OnCreate_ChainNode() { ChainEditorUtilities.CreateNode(graph, NodeType.ChainBehaviorNode, new Vector2(Screen.width / 3, Screen.height / 3)); }
private void OnFile_LoadGraph() { ChainEditorUtilities.LoadGraph(); }