/// <summary> /// Returns whether to account for input in the given state using the mousePosition /// </summary> internal static bool shouldIgnoreInput(NodeEditorState state) { if (state == null) { return(true); } // Account for any opened popups if (OverlayGUI.HasPopupControl()) { return(true); } // Check if mouse is outside of canvas rect if (!state.canvasRect.Contains(Event.current.mousePosition)) { return(true); } // Check if mouse is inside an ignoreInput rect for (int ignoreCnt = 0; ignoreCnt < state.ignoreInput.Count; ignoreCnt++) { if (state.ignoreInput [ignoreCnt].Contains(Event.current.mousePosition)) { return(true); } } return(false); }
public static void EndNodeGUI() { OverlayGUI.EndOverlayGUI(); if ((Object)GUI.skin == (Object)defaultSkin) { GUI.skin = defaultSkin; } }
public override void OnInspectorGUI() { if (node == null) { node = (Node)target; } if (node == null) { return; } if (titleStyle == null) { titleStyle = new GUIStyle(GUI.skin.label); titleStyle.fontStyle = FontStyle.Bold; titleStyle.alignment = TextAnchor.MiddleCenter; titleStyle.fontSize = 16; } if (boldLabelStyle == null) { boldLabelStyle = new GUIStyle(GUI.skin.label); boldLabelStyle.fontStyle = FontStyle.Bold; } OverlayGUI.StartOverlayGUI("NodeInspector"); EditorGUI.BeginChangeCheck(); GUILayout.Space(10); GUILayout.Label(node.Title, titleStyle); GUILayout.Space(10); GUILayout.Label("Rect: " + node.rect.ToString()); node.backgroundColor = EditorGUILayout.ColorField("Color", node.backgroundColor); GUILayout.Space(10); GUILayout.Label("Connection Ports", boldLabelStyle); foreach (ConnectionPort port in node.connectionPorts) { string labelPrefix = port.direction == Direction.In ? "Input " : (port.direction == Direction.Out ? "Output " : ""); string label = labelPrefix + port.styleID + " '" + port.name + "'"; EditorGUILayout.ObjectField(label, port, port.GetType(), true); } GUILayout.Space(10); GUILayout.Label("Property Editor", boldLabelStyle); node.DrawNodePropertyEditor(); if (EditorGUI.EndChangeCheck()) { NodeEditor.RepaintClients(); } OverlayGUI.EndOverlayGUI(); }
private void OnGUI() { float inset = 0.0f; Vector3[] corners = new Vector3[4]; rt.GetWorldCorners(corners); Vector3 topLeft = corners[1]; topLeft.y = Screen.height - topLeft.y; rootRect = new Rect(topLeft.x, topLeft.y, corners[2].x - corners[0].x, corners[2].y - corners[0].y); canvasRect = new Rect(rootRect.x + inset, rootRect.y + inset, rootRect.width - inset * 2, rootRect.height - inset * 2); // Initiation NodeEditor.checkInit(true); if (NodeEditor.InitiationError) { GUILayout.Label("Node Editor Initiation failed! Check console for more information!"); return; } AssureSetup(); // ROOT: Start Overlay GUI for popups OverlayGUI.StartOverlayGUI("RTNodeEditor"); // Set various nested groups GUI.BeginGroup(rootRect, GUI.skin.box); // Begin Node Editor GUI and set canvas rect NodeEditorGUI.StartNodeGUI(false); canvasCache.editorState.canvasRect = new Rect(canvasRect.x, canvasRect.y + editorInterface.toolbarHeight, canvasRect.width, canvasRect.height - editorInterface.toolbarHeight); try { // Perform drawing with error-handling NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState); } catch (UnityException e) { // On exceptions in drawing flush the canvas to avoid locking the UI canvasCache.NewNodeCanvas(); NodeEditor.ReInit(true); Debug.LogError("Unloaded Canvas due to exception in Draw!"); Debug.LogException(e); } // Draw Interface editorInterface.DrawToolbarGUI(canvasRect); editorInterface.DrawModalPanel(); // End Node Editor GUI NodeEditorGUI.EndNodeGUI(); // End various nested groups GUI.EndGroup(); // END ROOT: End Overlay GUI and draw popups OverlayGUI.EndOverlayGUI(); }
public static void StartNodeGUI() { NodeEditor.checkInit(true); defaultSkin = GUI.skin; if (nodeSkin != null) { GUI.skin = nodeSkin; } OverlayGUI.StartOverlayGUI(); }
public static void StartNodeGUI() { if ((Object)GUI.skin != (Object)defaultSkin) { if ((Object)nodeSkin == (Object)null) { Init(true); } GUI.skin = nodeSkin; } OverlayGUI.StartOverlayGUI(); }
public static void StartNodeGUI() { if (GUI.skin != defaultSkin) { if (nodeSkin == null) { Init(true); } GUI.skin = nodeSkin; } OverlayGUI.StartOverlayGUI(); }
public static void StartNodeGUI(string editorUser, bool IsEditorWindow) { NodeEditor.checkInit(true); curEditorUser = editorUser; isEditorWindow = IsEditorWindow; defaultSkin = GUI.skin; if (nodeSkin != null) { GUI.skin = nodeSkin; } OverlayGUI.StartOverlayGUI(curEditorUser); }
/// <summary> /// Draws the Node Canvas on the screen in the rect specified by editorState /// </summary> public static void DrawCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState) { if (!editorState.drawing) { return; } checkInit(); NodeEditorGUI.StartNodeGUI(); OverlayGUI.StartOverlayGUI(); DrawSubCanvas(nodeCanvas, editorState); OverlayGUI.EndOverlayGUI(); NodeEditorGUI.EndNodeGUI(); }
private void OnGUI() { // Initiation NodeEditor.checkInit(true); if (NodeEditor.InitiationError) { GUILayout.Label("Node Editor Initiation failed! Check console for more information!"); return; } AssureSetup(); // Start Overlay GUI for popups (before any other GUI) OverlayGUI.StartOverlayGUI("RTNodeEditor"); // Set root rect (can be any number of arbitrary groups, e.g. a nested UI, but at least one) GUI.BeginGroup(new Rect(0, 0, Screen.width, Screen.height)); // Begin Node Editor GUI and set canvas rect NodeEditorGUI.StartNodeGUI(false); canvasCache.editorState.canvasRect = new Rect(rect.x, rect.y + editorInterface.toolbarHeight, rect.width, rect.height - editorInterface.toolbarHeight); try { // Perform drawing with error-handling NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState); } catch (UnityException e) { // On exceptions in drawing flush the canvas to avoid locking the UI canvasCache.NewNodeCanvas(); NodeEditor.ReInit(true); Debug.LogError("Unloaded Canvas due to exception in Draw!"); Debug.LogException(e); } // Draw Interface GUILayout.BeginArea(rect); editorInterface.DrawToolbarGUI(); GUILayout.EndArea(); editorInterface.DrawModalPanel(); // End Node Editor GUI NodeEditorGUI.EndNodeGUI(); // End root rect GUI.EndGroup(); // End Overlay GUI and draw popups OverlayGUI.EndOverlayGUI(); }
private void OnGUI() { // Initiation NodeEditor.checkInit(true); if (NodeEditor.InitiationError) { GUILayout.Label("Node Editor Initiation failed! Check console for more information!"); return; } AssureSetup(); // ROOT: Start Overlay GUI for popups OverlayGUI.StartOverlayGUI("RTNodeEditor"); // Set various nested groups GUI.BeginGroup(rootRect, GUI.skin.box); // Begin Node Editor GUI and set canvas rect NodeEditorGUI.StartNodeGUI(false); canvasCache.editorState.canvasRect = new Rect(canvasRect.x, canvasRect.y /* + editorInterface.toolbarHeight*/, canvasRect.width, canvasRect.height /* - editorInterface.toolbarHeight*/); try { // Perform drawing with error-handling NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState); } catch (UnityException e) { // On exceptions in drawing flush the canvas to avoid locking the UI canvasCache.NewNodeCanvas(); NodeEditor.ReInit(true); Debug.LogError("Unloaded Canvas due to exception in Draw!"); Debug.LogException(e); } //Debug.Log(Event.current.type); // Draw Interface editorInterface.DrawToolbarGUI(canvasRect); editorInterface.DrawModalPanel(); // End Node Editor GUI NodeEditorGUI.EndNodeGUI(); // End various nested groups GUI.EndGroup(); // END ROOT: End Overlay GUI and draw popups OverlayGUI.EndOverlayGUI(); }
private void OnGUI() { // Initiation NodeEditor.checkInit(true); if (NodeEditor.InitiationError) { GUILayout.Label("Node Editor Initiation failed! Check console for more information!"); return; } AssureEditor(); AssureSetup(); // ROOT: Start Overlay GUI for popups OverlayGUI.StartOverlayGUI("NodeEditorWindow"); // Begin Node Editor GUI and set canvas rect NodeEditorGUI.StartNodeGUI(true); canvasCache.editorState.canvasRect = canvasWindowRect; //EditorGUI.BeginChangeCheck(); try { // Perform drawing with error-handling NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState); } catch (UnityException e) { // On exceptions in drawing flush the canvas to avoid locking the UI canvasCache.NewNodeCanvas(); NodeEditor.ReInit(true); Debug.LogError("Unloaded Canvas due to an exception during the drawing phase!"); Debug.LogException(e); } //if (EditorGUI.EndChangeCheck()) //{ // Debug.Log("修改文件:" + canvasCache.nodeCanvas.saveName); //} // Draw Interface editorInterface.DrawToolbarGUI(new Rect(0, 0, Screen.width, 0)); editorInterface.DrawModalPanel(); // End Node Editor GUI NodeEditorGUI.EndNodeGUI(); // END ROOT: End Overlay GUI and draw popups OverlayGUI.EndOverlayGUI(); }
private void OnGUI() { // Initiation NodeEditor.checkInit(true); if (NodeEditor.InitiationError) { GUILayout.Label("Node Editor Initiation failed! Check console for more information!"); return; } AssureSetup(); // Start Overlay GUI for popups OverlayGUI.StartOverlayGUI("RTNodeEditor"); // Begin Node Editor GUI and set canvas rect NodeEditorGUI.StartNodeGUI(false); canvasCache.editorState.canvasRect = new Rect(rect.x, rect.y + editorInterface.toolbarHeight, rect.width, rect.height - editorInterface.toolbarHeight); // Access custom state variable whenever you need canvasCache.editorState.myCustomStateVariable = 0; try { // Perform drawing with error-handling NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState); } catch (UnityException e) { // On exceptions in drawing flush the canvas to avoid locking the UI canvasCache.NewNodeCanvas(); NodeEditor.ReInit(true); Debug.LogError("Unloaded Canvas due to exception in Draw!"); Debug.LogException(e); } // Draw Interface GUILayout.BeginArea(rect); editorInterface.DrawToolbarGUI(); GUILayout.EndArea(); editorInterface.DrawModalPanel(); // End Node Editor GUI NodeEditorGUI.EndNodeGUI(); // End Overlay GUI and draw popups OverlayGUI.EndOverlayGUI(); }
private void OnGUI() { // Initiation NodeEditor.checkInit(true); if (NodeEditor.InitiationError) { GUILayout.Label("Node Editor Initiation failed! Check console for more information!"); return; } AssureEditor(); AssureSetup(); // ROOT: Start Overlay GUI for popups OverlayGUI.StartOverlayGUI("NodeEditorWindow"); // Begin Node Editor GUI and set canvas rect NodeEditorGUI.StartNodeGUI(true); canvasCache.editorState.canvasRect = canvasWindowRect; try { // Perform drawing with error-handling NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState); } catch (UnityException e) { // On exceptions in drawing flush the canvas to avoid locking the UI canvasCache.NewNodeCanvas(); NodeEditor.ReInit(true); LogMgr.LogError("Unloaded Canvas due to an exception during the drawing phase!"); LogMgr.LogException(e); } // Draw Interface NodeEditorInterface.GetInstance().DrawToolbarGUI(new Rect(0, 0, Screen.width, 0)); ActionMenuTools.GetInstance().DrawGamesMenu(Math.Min(400, Math.Max(200, (int)(position.width / 5))), position.height); NodeEditorInterface.GetInstance().DrawModalPanel(); // End Node Editor GUI NodeEditorGUI.EndNodeGUI(); // END ROOT: End Overlay GUI and draw popups OverlayGUI.EndOverlayGUI(); }
internal static bool shouldIgnoreInput(NodeEditorState state) { if (OverlayGUI.HasPopupControl()) { return(true); } if (!state.canvasRect.Contains(Event.current.mousePosition)) { return(true); } for (int i = 0; i < state.ignoreInput.Count; i++) { if (state.ignoreInput[i].Contains(Event.current.mousePosition)) { return(true); } } return(false); }
protected override void OnGUI() { base.OnGUI(); // Initiation NodeEditor.checkInit(true); if (NodeEditor.InitiationError) { GUILayout.Label("Node Editor Initiation failed! Check console for more information!"); return; } AssureSetup(); // ROOT: Start Overlay GUI for popups OverlayGUI.StartOverlayGUI("ActorEditorWindow"); // Begin Node Editor GUI and set canvas rect NodeEditorGUI.StartNodeGUI(true); _canvasCache.editorState.canvasRect = CanvasWindowRect; try { // Perform drawing with error-handling NodeEditor.DrawCanvas(_canvasCache.nodeCanvas, _canvasCache.editorState); } catch (UnityException e) { // On exceptions in drawing flush the canvas to avoid locking the UI _canvasCache.NewNodeCanvas(); NodeEditor.ReInit(true); Debug.LogError("Unloaded Canvas due to an exception during the drawing phase!"); Debug.LogException(e); } // Draw Interface _editorInterface.DrawToolbarGUI(new Rect(MenuWidth - 5, 0, Screen.width - MenuWidth + 5, 30)); _editorInterface.DrawModalPanel(); // End Node Editor GUI NodeEditorGUI.EndNodeGUI(); // END ROOT: End Overlay GUI and draw popups OverlayGUI.EndOverlayGUI(); }
/// <summary> /// Returns whether to account for input in curEditorState /// </summary> private static bool ignoreInput(Vector2 mousePos) { // Account for any opened popups if (OverlayGUI.HasPopupControl()) { return(true); } // Mouse outside of canvas rect or inside an ignoreInput rect if (!curEditorState.canvasRect.Contains(mousePos)) { return(true); } foreach (Rect ignoreRect in curEditorState.ignoreInput) { if (ignoreRect.Contains(mousePos)) { return(true); } } return(false); }
private void OnGUI() { if (wwwShader1 != null) { if (wwwShader1.isDone) { string pathShader = "Assets/TextureWang/Shaders/TextureOps.shader"; pathShader = pathShader.Replace("/", "" + Path.DirectorySeparatorChar); File.WriteAllBytes(pathShader, wwwShader1.bytes); AssetDatabase.ImportAsset(pathShader, ImportAssetOptions.ForceSynchronousImport); wwwShader1 = null; } Repaint(); } if (m_ReplaceNode != null && !OverlayGUI.HasPopupControl() && ms_InputInfo != null) { NodeEditorInputSystem.ShowContextMenu(ms_InputInfo); ms_InputInfo = null; } /* * if (NodeEditor.curEditorState == null) * { * Debug.Log("OnGUI::TWWindow has no editor state " + NodeEditor.curEditorState+"actual editor state "+ canvasCache.editorState); * } * else if (NodeEditor.curEditorState.selectedNode == null) * { * Debug.Log("OnGUI::TWWindow has no Selected Node " + NodeEditor.curEditorState); * } * else * { * Debug.Log("OnGUI:: Selected Node " + NodeEditor.curEditorState.selectedNode); * } */ // Initiation NodeEditor.checkInit(true); if (NodeEditor.InitiationError) { GUILayout.Label("Node Editor Initiation failed! Check console for more information!"); return; } AssureEditor(); canvasCache.AssureCanvas(); // Specify the Canvas rect in the EditorState canvasCache.editorState.canvasRect = canvasWindowRect; // If you want to use GetRect: // Rect canvasRect = GUILayoutUtility.GetRect (600, 600); // if (Event.current.type != EventType.Layout) // mainEditorState.canvasRect = canvasRect; NodeEditorGUI.StartNodeGUI(); // Perform drawing with error-handling try { NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState); if (canvasCache.editorState.selectedNode != null) { if (canvasCache.editorState.selectedNode is TextureNode) { var tn = canvasCache.editorState.selectedNode as TextureNode; if (tn.m_RequestRepaint) { tn.m_RequestRepaint = false; Repaint(); m_InspectorWindow.Repaint(); } } } if (wwwShader1 != null) { GUI.Label(new Rect(100, 100, 500, 200), "One Time Shader Download in progress..."); } } catch (UnityException e) { // on exceptions in drawing flush the canvas to avoid locking the ui. canvasCache.NewNodeCanvas(); NodeEditor.ReInit(true); Debug.LogError("Unloaded Canvas due to an exception during the drawing phase!"); Debug.LogException(e); } if (m_PostOnLoadCanvasFixup != null) { // m_PostOnLoadCanvasFixup.PostOnLoadCanvasFixup(); m_PostOnLoadCanvasFixup = null; } // Draw Side Window //sideWindowWidth = Math.Min(600, Math.Max(200, (int)(position.width / 5))); //GUILayout.BeginArea(sideWindowRect, GUI.skin.box); //DrawSideWindow(); //GUILayout.EndArea(); NodeEditorGUI.EndNodeGUI(); // if (Event.current.type == EventType.Repaint) // m_InspectorWindow.Repaint(); /* * //if (Event.current.type == EventType.Repaint) * { * if (mainEditorState.selectedNode != mainEditorState.wantselectedNode) * { * mainEditorState.selectedNode = mainEditorState.wantselectedNode; * NodeEditor.RepaintClients(); * Repaint(); * } * * } */ if (!m_Docked && m_DockedRetry++ < 100 && m_InspectorWindow != null && m_NodeSelectionWindow != null) { try { m_DockedRetry++; Docker.Dock(this, m_InspectorWindow, Docker.DockPosition.Right); Docker.Dock(this, m_NodeSelectionWindow, Docker.DockPosition.Left); } catch (Exception ex) { Debug.LogError(" Dock failed " + ex); } m_Docked = true; } }
public static void EndNodeGUI() { OverlayGUI.EndOverlayGUI(); GUI.skin = defaultSkin; }
private void OnGUI() { if (wwwShader1 != null) { if (wwwShader1.isDone) { string pathShader = "Assets/TextureWang/Shaders/TextureOps.shader"; pathShader = pathShader.Replace("/", "" + Path.DirectorySeparatorChar); File.WriteAllBytes(pathShader, wwwShader1.bytes); AssetDatabase.ImportAsset(pathShader, ImportAssetOptions.ForceSynchronousImport); wwwShader1 = null; } Repaint(); Debug.Log("repaint 2"); } if (canvasCache.nodeCanvas.m_PreviewAnimation) { if (m_SW == null) { m_SW = Stopwatch.StartNew(); } m_AnimValue += (m_SW.ElapsedMilliseconds - m_LastTime) / 3000.0f; if (m_AnimValue < 0) { m_AnimValue = 0; } m_LastTime = m_SW.ElapsedMilliseconds; if (m_AnimValue > 1.0f) { m_AnimValue = 0.0f; } foreach (var x in canvasCache.nodeCanvas.nodes) { if (x is InputNodeAnimated) { var ina = x as InputNodeAnimated; ina.m_Value.Set(m_AnimValue); } } NodeEditor.RecalculateAll(canvasCache.nodeCanvas); Repaint(); Debug.Log("repaint 3"); } else { m_AnimValue = 0; } if (m_ReplaceNode != null && !OverlayGUI.HasPopupControl() && ms_InputInfo != null) { NodeEditorInputSystem.ShowContextMenu(ms_InputInfo); ms_InputInfo = null; } /* * if (NodeEditor.curEditorState == null) * { * Debug.Log("OnGUI::TWWindow has no editor state " + NodeEditor.curEditorState+"actual editor state "+ canvasCache.editorState); * } * else if (NodeEditor.curEditorState.selectedNode == null) * { * Debug.Log("OnGUI::TWWindow has no Selected Node " + NodeEditor.curEditorState); * } * else * { * Debug.Log("OnGUI:: Selected Node " + NodeEditor.curEditorState.selectedNode); * } */ // Initiation NodeEditor.checkInit(true); if (NodeEditor.InitiationError) { GUILayout.Label("Node Editor Initiation failed! Check console for more information!"); return; } AssureEditor(); canvasCache.AssureCanvas(); // Specify the Canvas rect in the EditorState canvasCache.editorState.canvasRect = canvasWindowRect; // If you want to use GetRect: // Rect canvasRect = GUILayoutUtility.GetRect (600, 600); // if (Event.current.type != EventType.Layout) // mainEditorState.canvasRect = canvasRect; NodeEditorGUI.StartNodeGUI(); // Perform drawing with error-handling try { if ((Event.current.keyCode >= KeyCode.A && Event.current.keyCode <= KeyCode.Z) || Event.current.keyCode == KeyCode.Escape) { if (Event.current.keyCode == KeyCode.Escape) { PopupMenu.m_NameFilter = ""; } else { int ascii = ((int)Event.current.keyCode - (int)KeyCode.A) + 65; string c = Char.ConvertFromUtf32(ascii); PopupMenu.m_NameFilter = c; } Debug.Log("m_NameFilter " + PopupMenu.m_NameFilter); OverlayGUI.currentPopup = null; NodeEditorInputInfo inputInfo = new NodeEditorInputInfo(canvasCache.editorState); NodeEditorInputSystem.ShowContextMenu(inputInfo); } NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState); if (canvasCache.editorState.selectedNode != null) { if (canvasCache.editorState.selectedNode is TextureNode) { var tn = canvasCache.editorState.selectedNode as TextureNode; if (tn.m_RequestRepaint) { tn.m_RequestRepaint = false; Debug.Log("repaint 1"); Repaint(); m_InspectorWindow.Repaint(); } } } if (wwwShader1 != null) { GUI.Label(new Rect(100, 100, 500, 200), "One Time Shader Download in progress..."); } } catch (UnityException e) { // on exceptions in drawing flush the canvas to avoid locking the ui. canvasCache.NewNodeCanvas(); NodeEditor.ReInit(true); Debug.LogError("Unloaded Canvas due to an exception during the drawing phase!"); Debug.LogException(e); } if (m_PostOnLoadCanvasFixup != null) { // m_PostOnLoadCanvasFixup.PostOnLoadCanvasFixup(); m_PostOnLoadCanvasFixup = null; } // Draw Side Window //sideWindowWidth = Math.Min(600, Math.Max(200, (int)(position.width / 5))); //GUILayout.BeginArea(sideWindowRect, GUI.skin.box); //DrawSideWindow(); //GUILayout.EndArea(); NodeEditorGUI.EndNodeGUI(); // if (Event.current.type == EventType.Repaint) // m_InspectorWindow.Repaint(); /* * //if (Event.current.type == EventType.Repaint) * { * if (mainEditorState.selectedNode != mainEditorState.wantselectedNode) * { * mainEditorState.selectedNode = mainEditorState.wantselectedNode; * NodeEditor.RepaintClients(); * Repaint(); * } * * } */ if (!m_Docked && m_DockedRetry++ < 100 && m_InspectorWindow != null && m_NodeSelectionWindow != null) { try { m_DockedRetry++; Docker.Dock(this, m_InspectorWindow, Docker.DockPosition.Right); Docker.Dock(this, m_NodeSelectionWindow, Docker.DockPosition.Left); } catch (Exception ex) { Debug.LogError(" Dock failed " + ex); } m_Docked = true; } }
private void CheckCacheUpdate() { //Debug.Log ("Checking for cache save!"); if (UnityEditor.EditorApplication.timeSinceStartup - lastCacheTime > cacheIntervalSec) { if (editorState.dragUserID == "" && editorState.connectOutput == null && GUIUtility.hotControl <= 0 && !OverlayGUI.HasPopupControl()) { // Only save when the user currently does not perform an action that could be interrupted by the save lastCacheTime = UnityEditor.EditorApplication.timeSinceStartup; SaveCache(); } } }
private void CheckCacheUpdate() { #if UNITY_EDITOR && CACHE if (UnityEditor.EditorApplication.timeSinceStartup - lastCacheTime > cacheIntervalSec) { AssureCanvas(); if (editorState.dragUserID == "" && editorState.connectKnob == null && GUIUtility.hotControl <= 0 && !OverlayGUI.HasPopupControl()) { // Only save when the user currently does not perform an action that could be interrupted by the save lastCacheTime = UnityEditor.EditorApplication.timeSinceStartup; SaveCache(); } } #endif }
/// <summary> /// Processes input events /// </summary> public static void InputEvents(List <Rect> ignoreInput) { Event e = Event.current; mousePos = e.mousePosition; if (OverlayGUI.HasPopupControl()) { return; } bool insideCanvas = curEditorState.canvasRect.Contains(e.mousePosition); for (int ignoreCnt = 0; ignoreCnt < ignoreInput.Count; ignoreCnt++) { if (ignoreInput [ignoreCnt].Contains(e.mousePosition)) { insideCanvas = false; break; } } if (!insideCanvas) { return; } curEditorState.focusedNode = null; if (insideCanvas && (e.type == EventType.MouseDown || e.type == EventType.MouseUp)) { curEditorState.focusedNode = NodeEditor.NodeAtPosition(e.mousePosition); if (e.button == 0) { curEditorState.activeNode = curEditorState.focusedNode; if (Repaint != null) { Repaint(); } } } #if UNITY_EDITOR if (curEditorState.focusedNode != null) { UnityEditor.Selection.activeObject = curEditorState.focusedNode; } #endif switch (e.type) { case EventType.MouseDown: curEditorState.dragNode = false; curEditorState.panWindow = false; if (curEditorState.focusedNode != null) { // A click on a node if (e.button == 1) { // Right click -> Node Context Click // TODO: Node Editor: Editor-Independancy - GenericMenu conversion // #if UNITY_EDITOR // UnityEditor.GenericMenu menu = new UnityEditor.GenericMenu (); // #else GenericMenu menu = new GenericMenu(); // #endif menu.AddItem(new GUIContent("Delete Node"), false, ContextCallback, new callbackObject("deleteNode", curNodeCanvas, curEditorState)); menu.AddItem(new GUIContent("Duplicate Node"), false, ContextCallback, new callbackObject("duplicateNode", curNodeCanvas, curEditorState)); if (NodeTypes.getNodeData(curEditorState.focusedNode).transitions) { menu.AddSeparator("Seperator"); menu.AddItem(new GUIContent("Make Transition"), false, ContextCallback, new callbackObject("startTransition", curNodeCanvas, curEditorState)); } menu.ShowAsContext(); e.Use(); } else if (e.button == 0) { if (!GUIToScreenRect(curEditorState.focusedNode.rect).Contains(e.mousePosition)) { // Left click at node edges -> Check for clicked connections to edit NodeOutput nodeOutput = curEditorState.focusedNode.GetOutputAtPos(e.mousePosition); if (nodeOutput != null) { // Output Node -> New Connection drawn from this curEditorState.connectOutput = nodeOutput; e.Use(); } else { // no output clicked, check input NodeInput nodeInput = curEditorState.focusedNode.GetInputAtPos(e.mousePosition); if (nodeInput != null && nodeInput.connection != null) { // Input node -> Loose and edit Connection curEditorState.connectOutput = nodeInput.connection; Node.RemoveConnection(nodeInput); e.Use(); } } } } } else { // A click on the empty canvas if (e.button == 2 || e.button == 0) { // Left/Middle Click -> Start scrolling curEditorState.panWindow = true; e.delta = Vector2.zero; } else if (e.button == 1) { // Right click -> Editor Context Click // TODO: Node Editor: Editor-Independancy - GenericMenu conversion if (curEditorState.connectOutput != null || curEditorState.makeTransition != null) { // #if UNITY_EDITOR // UnityEditor.GenericMenu menu = new UnityEditor.GenericMenu (); // #else GenericMenu menu = new GenericMenu(); // #endif // Iterate through all compatible nodes foreach (Node node in NodeTypes.nodes.Keys) { if (curEditorState.connectOutput != null) { foreach (var input in node.Inputs) { if (input.type == curEditorState.connectOutput.type) { menu.AddItem(new GUIContent("Add " + NodeTypes.nodes[node].adress), false, ContextCallback, new callbackObject(node.GetID, curNodeCanvas, curEditorState)); break; } } } else if (curEditorState.makeTransition != null && NodeTypes.nodes [node].transitions) { menu.AddItem(new GUIContent("Add " + NodeTypes.nodes[node].adress), false, ContextCallback, new callbackObject(node.GetID, curNodeCanvas, curEditorState)); } } menu.ShowAsContext(); } else { // #if UNITY_EDITOR // UnityEditor.GenericMenu menu = new UnityEditor.GenericMenu (); // #else GenericMenu menu = new GenericMenu(); // #endif foreach (Node node in NodeTypes.nodes.Keys) { menu.AddItem(new GUIContent("Add " + NodeTypes.nodes [node].adress), false, ContextCallback, new callbackObject(node.GetID, curNodeCanvas, curEditorState)); } menu.ShowAsContext(); } e.Use(); } } break; case EventType.MouseUp: if (curEditorState.focusedNode != null) { if (curEditorState.makeTransition != null) { Node.CreateTransition(curEditorState.makeTransition, curEditorState.focusedNode); } else if (curEditorState.connectOutput != null) { // Apply a connection if theres a clicked input if (!curEditorState.focusedNode.Outputs.Contains(curEditorState.connectOutput)) { // If an input was clicked, it'll will now be connected NodeInput clickedInput = curEditorState.focusedNode.GetInputAtPos(e.mousePosition); if (Node.CanApplyConnection(curEditorState.connectOutput, clickedInput)) { // If it can connect (type is equals, it does not cause recursion, ...) Node.ApplyConnection(curEditorState.connectOutput, clickedInput); } } e.Use(); } } curEditorState.makeTransition = null; curEditorState.connectOutput = null; curEditorState.dragNode = false; curEditorState.panWindow = false; break; case EventType.ScrollWheel: curEditorState.zoom = (float)Math.Round(Math.Min(2.0f, Math.Max(0.6f, curEditorState.zoom + e.delta.y / 15)), 2); if (Repaint != null) { Repaint(); } break; case EventType.KeyDown: // TODO: Node Editor: Shortcuts if (e.keyCode == KeyCode.N) // Start Navigating (curve to origin / active Node) { curEditorState.navigate = true; } if (e.keyCode == KeyCode.LeftControl && curEditorState.activeNode != null) // Snap { curEditorState.activeNode.rect.position = new Vector2(Mathf.RoundToInt((curEditorState.activeNode.rect.position.x - curEditorState.panOffset.x) / 10) * 10 + curEditorState.panOffset.x, Mathf.RoundToInt((curEditorState.activeNode.rect.position.y - curEditorState.panOffset.y) / 10) * 10 + curEditorState.panOffset.y); } if (Repaint != null) { Repaint(); } break; case EventType.KeyUp: if (e.keyCode == KeyCode.N) // Stop Navigating { curEditorState.navigate = false; } if (Repaint != null) { Repaint(); } break; case EventType.MouseDrag: if (curEditorState.panWindow) { // Scroll everything with the current mouse delta curEditorState.panOffset += e.delta * curEditorState.zoom; for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++) { curNodeCanvas.nodes [nodeCnt].rect.position += e.delta * curEditorState.zoom; } e.delta = Vector2.zero; if (Repaint != null) { Repaint(); } } else { curEditorState.panWindow = false; } if (curEditorState.dragNode && curEditorState.activeNode != null && GUIUtility.hotControl == 0) { // Drag the active node with the current mouse delta curEditorState.activeNode.rect.position += e.delta * curEditorState.zoom; NodeEditorCallbacks.IssueOnMoveNode(curEditorState.activeNode); e.delta = Vector2.zero; if (Repaint != null) { Repaint(); } } else { curEditorState.dragNode = false; } break; } }