/// <summary> /// Requests to reload the knobTexture and adapts it to the position and orientation /// </summary> protected void UpdateKnobTexture() { ReloadTexture(); if (knobTexture == null) { throw new UnityException("Knob texture of " + name + " could not be loaded!"); } if (side != defaultSide) { // Rotate Knob texture according to the side it's used on int rotationSteps = getRotationStepsAntiCW(defaultSide, side); string[] mods = new string[] { "Rotation:" + rotationSteps }; Texture2D modKnobTex = null; // Try to get standard texture in memory NodeResourceManager.MemoryTexture memoryTex = NodeResourceManager.FindInMemory(knobTexture); if (memoryTex != null) { // Texture does exist in memory, so built a mod including rotation and try to find it again mods = NodeResourceManager.AppendMod(memoryTex.modifications, "Rotation:" + rotationSteps); NodeResourceManager.TryGetTexture(memoryTex.path, ref modKnobTex, mods); } if (modKnobTex == null) { // Rotated version does not exist yet, so create and record it modKnobTex = RTEditorGUI.RotateTextureCCW(knobTexture, rotationSteps); NodeResourceManager.AddTextureToMemory(memoryTex.path, modKnobTex, mods); } knobTexture = modKnobTex; } }
/// <summary> /// Setup of the base framework. Enough to manage and calculate canvases. /// </summary> private static void setupBaseFramework() { CheckEditorPath(); // Init Resource system. Can be called anywhere else, too, if it's needed before. NodeResourceManager.SetDefaultResourcePath(editorPath + "GameResources/"); // Run fetching algorithms searching the script assemblies for Custom Nodes / Connection Types / NodeCanvas Types ConnectionPortStyles.FetchConnectionPortStyles(); NodeTypes.FetchNodeTypes(); NodeCanvasManager.FetchCanvasTypes(); ConnectionPortManager.FetchNodeConnectionDeclarations(); ImportExportManager.FetchIOFormats(); // Setup Callback system NodeEditorCallbacks.SetupReceivers(); NodeEditorCallbacks.IssueOnEditorStartUp(); // Init input NodeEditorInputSystem.SetupInput(); #if UNITY_EDITOR UnityEditor.EditorApplication.update -= Update; UnityEditor.EditorApplication.update += Update; #endif initiatedBase = true; }
public static NodeEditorWindow OpenNodeEditor() { _editor = GetWindow <NodeEditorWindow>(); _editor.minSize = new Vector2(400, 200); NodeEditor.ReInit(false); Texture iconTexture = NodeResourceManager.LoadTexture(EditorGUIUtility.isProSkin? "Textures/Icon_Dark.png" : "Textures/Icon_Light.png"); _editor.titleContent = new GUIContent("Node Editor", iconTexture); return(_editor); }
protected void LoadKnobTextures() { #if UNITY_EDITOR if (NodeEditorInterface.GetInstance().isOpenedWindows) { #endif _inKnobTex = NodeResourceManager.GetTintedTexture(InKnobTexPath, Color); _outKnobTex = NodeResourceManager.GetTintedTexture(OutKnobTexPath, Color); if (InKnobTex == null || OutKnobTex == null) { LogMgr.LogError("Invalid style '" + Identifier + "': Could not load knob textures from '" + InKnobTexPath + "' and '" + OutKnobTexPath + "'!"); } #if UNITY_EDITOR } #endif }
/// <summary> /// Loads the NodeCanvas from the asset file at path and optionally creates a working copy of it before returning /// </summary> public static NodeCanvas LoadNodeCanvas(string path, bool createWorkingCopy) { #if !UNITY_EDITOR throw new System.NotImplementedException(); #else if (string.IsNullOrEmpty(path)) { throw new System.ArgumentNullException("Cannot load Canvas: No path specified!"); } path = NodeResourceManager.PreparePath(path); // Load only the NodeCanvas from the save file NodeCanvas nodeCanvas = NodeResourceManager.LoadResource <NodeCanvas> (path); if (nodeCanvas == null) { throw new UnityException("Cannot load NodeCanvas: The file at the specified path '" + path + "' is no valid save file as it does not contain a NodeCanvas!"); } if (!Application.isPlaying && (nodeCanvas.editorStates == null || nodeCanvas.editorStates.Length == 0)) { // Try to load any contained editorStates, as the canvas did not reference any nodeCanvas.editorStates = NodeResourceManager.LoadResources <NodeEditorState> (path); } // Set the path as the new source of the canvas nodeCanvas.UpdateSource(path); // Postprocess the loaded canvas nodeCanvas.Validate(); if (createWorkingCopy) { nodeCanvas = CreateWorkingCopy(nodeCanvas); } NodeEditorCallbacks.IssueOnLoadCanvas(nodeCanvas); return(nodeCanvas); #endif }
public static bool Init() { // Textures Background = NodeResourceManager.LoadTexture("Textures/background.png"); AALineTex = NodeResourceManager.LoadTexture("Textures/AALine.png"); GUIBox = NodeResourceManager.LoadTexture("Textures/NE_Box.png"); GUIButton = NodeResourceManager.LoadTexture("Textures/NE_Button.png"); GUIBoxSelection = NodeResourceManager.LoadTexture("Textures/BoxSelection.png"); GUIToolbar = NodeResourceManager.LoadTexture("Textures/NE_Toolbar.png"); GUIToolbarButton = NodeResourceManager.LoadTexture("Textures/NE_ToolbarButton.png"); if (!Background || !AALineTex || !GUIBox || !GUIButton || !GUIToolbar || !GUIToolbarButton) { return(false); } // Skin & Styles nodeSkin = Object.Instantiate(GUI.skin); GUI.skin = nodeSkin; foreach (GUIStyle style in GUI.skin) { style.fontSize = 11; //style.normal.textColor = style.active.textColor = style.focused.textColor = style.hover.textColor = NE_TextColor; } // Label nodeSkin.label.normal.textColor = NE_TextColor; nodeLabel = nodeSkin.label; nodeLabelBold = new GUIStyle(nodeLabel) { fontStyle = FontStyle.Bold }; nodeLabelSelected = new GUIStyle(nodeLabel); nodeLabelSelected.normal.background = RTEditorGUI.ColorToTex(1, NE_LightColor); nodeLabelCentered = new GUIStyle(nodeLabel) { alignment = TextAnchor.MiddleCenter }; nodeLabelBoldCentered = new GUIStyle(nodeLabelBold) { alignment = TextAnchor.MiddleCenter }; nodeLabelLeft = new GUIStyle(nodeLabel) { alignment = TextAnchor.MiddleLeft }; nodeLabelRight = new GUIStyle(nodeLabel) { alignment = TextAnchor.MiddleRight }; // Box nodeSkin.box.normal.background = GUIBox; nodeSkin.box.normal.textColor = NE_TextColor; nodeSkin.box.active.textColor = NE_TextColor; nodeBox = nodeSkin.box; nodeBoxBold = new GUIStyle(nodeBox) { fontStyle = FontStyle.Bold }; // Button nodeSkin.button.normal.textColor = NE_TextColor; nodeSkin.button.normal.background = GUIButton; // Toolbar toolbar = GUI.skin.FindStyle("toolbar"); toolbarButton = GUI.skin.FindStyle("toolbarButton"); toolbarLabel = GUI.skin.FindStyle("toolbarButton"); toolbarDropdown = GUI.skin.FindStyle("toolbarDropdown"); if (toolbar == null || toolbarButton == null || toolbarLabel == null || toolbarDropdown == null) { // No editor styles available - use custom skin toolbar = new GUIStyle(nodeSkin.box); toolbar.normal.background = GUIToolbar; toolbar.active.background = GUIToolbar; toolbar.border = new RectOffset(0, 0, 1, 1); toolbar.margin = new RectOffset(0, 0, 0, 0); toolbar.padding = new RectOffset(10, 10, 1, 1); toolbarLabel = new GUIStyle(nodeSkin.box); toolbarLabel.normal.background = GUIToolbarButton; toolbarLabel.border = new RectOffset(2, 2, 0, 0); toolbarLabel.margin = new RectOffset(-2, -2, 0, 0); toolbarLabel.padding = new RectOffset(6, 6, 4, 4); toolbarButton = new GUIStyle(toolbarLabel); toolbarButton.active.background = RTEditorGUI.ColorToTex(1, NE_LightColor); toolbarDropdown = new GUIStyle(toolbarButton); } GUI.skin = null; return(true); }
/// <summary> /// Saves the the specified NodeCanvas as a new asset at path, optionally as a working copy and overwriting any existing save at path /// </summary> public static void SaveNodeCanvas(string path, ref NodeCanvas nodeCanvas, bool createWorkingCopy, bool safeOverwrite = true) { #if !UNITY_EDITOR throw new System.NotImplementedException(); #else if (string.IsNullOrEmpty(path)) { throw new System.ArgumentNullException("Cannot save NodeCanvas: No path specified!"); } if (nodeCanvas == null) { throw new System.ArgumentNullException("Cannot save NodeCanvas: The specified NodeCanvas that should be saved to path '" + path + "' is null!"); } if (nodeCanvas.GetType() == typeof(NodeCanvas)) { throw new System.ArgumentException("Cannot save NodeCanvas: The NodeCanvas has no explicit type! Please convert it to a valid sub-type of NodeCanvas!"); } nodeCanvas.Validate(); if (nodeCanvas.livesInScene) { LogMgr.LogWarning("Attempting to save scene canvas '" + nodeCanvas.name + "' to an asset, references to scene object may be broken!" + (!createWorkingCopy? " Forcing creation of working copy!" : "")); createWorkingCopy = true; } if (UnityEditor.AssetDatabase.Contains(nodeCanvas) && UnityEditor.AssetDatabase.GetAssetPath(nodeCanvas) != path) { LogMgr.LogWarning("Trying to create a duplicate save file for '" + nodeCanvas.name + "'! Forcing creation of working copy!"); nodeCanvas = CreateWorkingCopy(nodeCanvas); } // Prepare and update source path of the canvas path = NodeResourceManager.PreparePath(path); nodeCanvas.UpdateSource(path); // Preprocess the canvas NodeCanvas processedCanvas = nodeCanvas; processedCanvas.OnBeforeSavingCanvas(); if (createWorkingCopy) { processedCanvas = CreateWorkingCopy(processedCanvas); } // Differenciate canvasSave as the canvas asset and nodeCanvas as the source incase an existing save has been overwritten NodeCanvas canvasSave = processedCanvas; NodeCanvas prevSave; if (safeOverwrite && (prevSave = NodeResourceManager.LoadResource <NodeCanvas> (path)) != null && prevSave.GetType() == canvasSave.GetType()) { // OVERWRITE: Delete contents of old save for (int nodeCnt = 0; nodeCnt < prevSave.nodes.Count; nodeCnt++) { Node node = prevSave.nodes[nodeCnt]; // Make sure all node ports are included in the representative connectionPorts list ConnectionPortManager.UpdatePortLists(node); for (int k = 0; k < node.connectionPorts.Count; k++) { Object.DestroyImmediate(node.connectionPorts[k], true); } Object.DestroyImmediate(node, true); } for (int i = 0; i < prevSave.editorStates.Length; i++) { if (prevSave.editorStates[i] != null) { Object.DestroyImmediate(prevSave.editorStates[i], true); } } // Overwrite main canvas OverwriteCanvas(ref prevSave, processedCanvas); canvasSave = prevSave; } else { // Write main canvas UnityEditor.AssetDatabase.CreateAsset(processedCanvas, path); } // Write editorStates AddSubAssets(processedCanvas.editorStates, canvasSave); // Write nodes + contents foreach (Node node in processedCanvas.nodes) { // Write node and additional scriptable objects AddSubAsset(node, canvasSave); AddSubAssets(node.GetScriptableObjects(), node); // Make sure all node ports are included in the representative connectionPorts list ConnectionPortManager.UpdatePortLists(node); foreach (ConnectionPort port in node.connectionPorts) { AddSubAsset(port, node); } } UnityEditor.AssetDatabase.SaveAssets(); UnityEditor.AssetDatabase.Refresh(); NodeEditorCallbacks.IssueOnSaveCanvas(canvasSave); #endif }