/// <summary> /// Gets the type data with the specified identifier or, if not declared and checked, creates a new one when a valid type name with namespace is passed /// </summary> public static TypeData GetTypeData(string typeName, bool createIfNotDeclared) { if (types == null || types.Count == 0) { NodeEditor.ReInit(false); } TypeData typeData; if (!types.TryGetValue(typeName, out typeData)) { if (createIfNotDeclared) { Type type = Type.GetType(typeName); if (type == null) { typeData = types.First().Value; Debug.LogError("No TypeData defined for: " + typeName + " and type could not be found either!"); } else { typeData = new TypeData(type); types.Add(typeName, typeData); } } else { typeData = types.First().Value; Debug.LogError("No TypeData defined for: " + typeName + "!"); } } return(typeData); }
public static void StartNodeGUI(bool IsEditorWindow) { NodeEditor.checkInit(true); // Required for gamemode switch // Also for EditorWindow+RTNodeEditor in parallel where RTNodeEditor GUISkin setup would not be enough for the editor window as it's missing the editor styles if (nodeSkin == null || (IsEditorWindow && nodeSkin.FindStyle("ObjectField") == null)) { NodeEditor.ReInit(true); } isEditorWindow = IsEditorWindow; unitySkin = GUI.skin; GUI.skin = nodeSkin; #if UNITY_EDITOR unityTextColor = UnityEditor.EditorStyles.label.normal.textColor; UnityEditor.EditorStyles.label.normal.textColor = NE_TextColor; unityHoverTextColor = UnityEditor.EditorStyles.label.hover.textColor; UnityEditor.EditorStyles.label.hover.textColor = NE_TextColor; unityActiveTextColor = UnityEditor.EditorStyles.label.active.textColor; UnityEditor.EditorStyles.label.active.textColor = NE_TextColorSelected; unityFocusedTextColor = UnityEditor.EditorStyles.label.focused.textColor; UnityEditor.EditorStyles.label.focused.textColor = NE_TextColorSelected; #endif }
private void DrawSideWindow() { GUILayout.Label(new GUIContent("Node Editor (" + mainNodeCanvas.name + ")", "Opened Canvas path: " + openedCanvasPath), NodeEditorGUI.nodeLabelBold); if (GUILayout.Button(new GUIContent("Save Canvas", "Saves the Canvas to a Canvas Save File in the Assets Folder"))) { string path = EditorUtility.SaveFilePanelInProject("Save Node Canvas", "Node Canvas", "asset", "", NodeEditor.editorPath + "Resources/Saves/"); if (!string.IsNullOrEmpty(path)) { SaveNodeCanvas(path); } } if (GUILayout.Button(new GUIContent("Load Canvas", "Loads the Canvas from a Canvas Save File in the Assets Folder"))) { string path = EditorUtility.OpenFilePanel("Load Node Canvas", NodeEditor.editorPath + "Resources/Saves/", "asset"); if (!path.Contains(Application.dataPath)) { if (!string.IsNullOrEmpty(path)) { ShowNotification(new GUIContent("You should select an asset inside your project folder!")); } } else { path = path.Replace(Application.dataPath, "Assets"); LoadNodeCanvas(path); } } if (GUILayout.Button(new GUIContent("New Canvas", "Loads an empty Canvas"))) { NewNodeCanvas(); } if (GUILayout.Button(new GUIContent("Recalculate All", "Initiates complete recalculate. Usually does not need to be triggered manually."))) { NodeEditor.RecalculateAll(mainNodeCanvas); } if (GUILayout.Button("Force Re-Init")) { NodeEditor.ReInit(true); } if (NodeEditor.isTransitioning(mainNodeCanvas) && GUILayout.Button("Stop Transitioning")) { NodeEditor.StopTransitioning(mainNodeCanvas); } NodeEditorGUI.knobSize = EditorGUILayout.IntSlider(new GUIContent("Handle Size", "The size of the Node Input/Output handles"), NodeEditorGUI.knobSize, 12, 20); mainEditorState.zoom = EditorGUILayout.Slider(new GUIContent("Zoom", "Use the Mousewheel. Seriously."), mainEditorState.zoom, 0.6f, 2); if (mainEditorState.selectedNode != null && Event.current.type != EventType.Ignore) { mainEditorState.selectedNode.DrawNodePropertyEditor(); } }
private void OnGUI() { // Initiation NodeEditor.checkInit(); if (NodeEditor.InitiationError) { GUILayout.Label("Node Editor Initiation failed! Check console for more information!"); return; } AssureEditor(); AssureCanvas(); // Specify the Canvas rect in the EditorState mainEditorState.canvasRect = canvasWindowRect; // If you want to use GetRect: // Rect canvasRect = GUILayoutUtility.GetRect (600, 600); // if (Event.current.type != EventType.Layout) // mainEditorState.canvasRect = canvasRect; // Perform drawing with error-handling try { NodeEditor.DrawCanvas(mainNodeCanvas, mainEditorState); } catch (UnityException e) { // on exceptions in drawing flush the canvas to avoid locking the ui. NewNodeCanvas(); NodeEditor.ReInit(true); Debug.LogError("Unloaded Canvas due to exception when drawing!"); Debug.LogException(e); } // Draw Side Window sideWindowWidth = Math.Min(600, Math.Max(200, (int)(position.width / 5))); NodeEditorGUI.StartNodeGUI(); GUILayout.BeginArea(sideWindowRect, GUI.skin.box); DrawSideWindow(); GUILayout.EndArea(); NodeEditorGUI.EndNodeGUI(); UpdatePreviewTextures(); }
public void DrawSideWindow() { GUILayout.Label(new GUIContent("Node Editor (" + mainNodeCanvas.name + ")", "Opened Canvas path: " + openedCanvasPath), NodeEditorGUI.nodeLabelBold); if (GUILayout.Button(new GUIContent("Save Canvas", "Saves the Canvas to a Canvas Save File in the Assets Folder"))) { SaveNodeCanvas(EditorUtility.SaveFilePanelInProject("Save Node Canvas", "Node Canvas", "asset", "", ResourceManager.resourcePath + "Saves/")); } if (GUILayout.Button(new GUIContent("Load Canvas", "Loads the Canvas from a Canvas Save File in the Assets Folder"))) { string path = EditorUtility.OpenFilePanel("Load Node Canvas", ResourceManager.resourcePath + "Saves/", "asset"); if (!path.Contains(Application.dataPath)) { if (path != String.Empty) { ShowNotification(new GUIContent("You should select an asset inside your project folder!")); } return; } path = path.Replace(Application.dataPath, "Assets"); LoadNodeCanvas(path); } if (GUILayout.Button(new GUIContent("New Canvas", "Loads an empty Canvas"))) { NewNodeCanvas(); } if (GUILayout.Button(new GUIContent("Recalculate All", "Initiates complete recalculate. Usually does not need to be triggered manually."))) { NodeEditor.RecalculateAll(mainNodeCanvas); } if (GUILayout.Button("Force Re-Init")) { NodeEditor.ReInit(true); } NodeEditorGUI.knobSize = EditorGUILayout.IntSlider(new GUIContent("Handle Size", "The size of the Node Input/Output handles"), NodeEditorGUI.knobSize, 12, 20); mainEditorState.zoom = EditorGUILayout.Slider(new GUIContent("Zoom", "Use the Mousewheel. Seriously."), mainEditorState.zoom, 0.6f, 2); }
/// <summary> /// Gets the type data for the specified type name, if declared /// </summary> public static TypeData GetTypeData(string typeName) { if (types == null || types.Count == 0) { NodeEditor.ReInit(false); } TypeData typeData; if (!types.TryGetValue(typeName, out typeData)) { Debug.LogError("No TypeData defined for: " + typeName); typeData = types.First().Value; } if (typeData.declaration == null || typeData.InputKnob == null || typeData.OutputKnob == null) { NodeEditor.ReInit(false); typeData = GetTypeData(typeName); } return(typeData); }
/// <summary> /// Gets the type data for the specified type or, if not declared and checked, creates a new one for that type /// </summary> public static TypeData GetTypeData(Type type, bool createIfNotDeclared) { if (types == null || types.Count == 0) { NodeEditor.ReInit(false); } TypeData typeData = types.Values.First((TypeData tData) => tData.Type == type); if (typeData == null) { if (createIfNotDeclared) { typeData = new TypeData(type); types.Add(type.FullName, typeData); } else { typeData = types.First().Value; Debug.LogError("No TypeData defined for: " + type.FullName + "!"); } } return(typeData); }