public T CreateNodeAsset <T>(VisualNodeRoot root) where T : ScriptableObject { var nodeNameTag = typeof(T).Name; var path = AssetDatabase.GetAssetPath(root); var directoryPath = Path.GetDirectoryName(path); var absolutePath = Path.GetDirectoryName(Application.dataPath) + "/"; int numberedSufix = -1; string nodeFinalPath; do { numberedSufix++; nodeFinalPath = directoryPath + "/" + nodeNameTag + numberedSufix + ".asset"; } while (File.Exists(absolutePath + nodeFinalPath)); var newNode = ScriptableObject.CreateInstance <T>(); try { AssetDatabase.CreateAsset(newNode, nodeFinalPath); } catch (Exception e) { Debug.LogError("Could not create Node asset at path " + nodeFinalPath); return(null); } return(newNode); }
public void DeleteNodes(VisualNodeBase node, VisualNodeRoot root) { if (node == root.root) { root.root = null; } //enter on children var childCount = node.children.Count(); for (int i = childCount - 1; i >= 0; i--) { if (node.children[i] != null) { node.children[i].parent = null; //DeleteNodesRecursive(node.children[i], root); } } //remove from parent if (node.parent != null) { var index = node.parent.children.IndexOf(node); node.parent.children.RemoveAt(index); node.parent.children.Insert(index, null); } root.nodes.Remove(node); EditorUtility.SetDirty(root); //delete asset UnityEngine.Object.DestroyImmediate(node, true); AssetDatabase.SaveAssets(); }
private void OnGUI() { GUI.Box(new Rect(0, 0, position.width, 20), ""); _currentRoot = (VisualNodeRoot)EditorGUILayout.ObjectField(_currentRoot, typeof(VisualNodeRoot)); if (_currentRoot == null) { GUILayout.Label("There is no VisualNodeRoot selected."); return; } if (_currentRoot.root == null) { if (GUI.Button(new Rect(0, 20, 100, 16), "Add root node")) { new VisualNodeEditorContextMenu(AddNodeToRoot).ShowMenu(); } return; } if (Event.current.isScrollWheel) { zoomScale += Event.current.delta.y / 100; if (zoomScale <= .1f) { zoomScale = .1f; } } if (Event.current.keyCode == KeyCode.R) { editorZoomArea.ResetZoom(); Event.current.Use(); } //Begin scroll view fullEditorSize.width += 50; fullEditorSize.height += 50; editorZoomArea.Begin(new Rect(0, 20, position.width, position.height), fullEditorSize); fullEditorSize.xMax = 0; fullEditorSize.yMax = 0; DrawNodesConnections(); DrawNodeWindows(); editorZoomArea.End(); ConnectingToParentEventCheck(); HandleContextClick(); HandleScrollDrag(); }
private void OnSelectionChange() { if (Selection.activeObject is VisualNodeRoot) { _currentRoot = Selection.activeObject as VisualNodeRoot; _currentRoot.nodes.RemoveAll((o) => o == null); } zoomScale = 1f; scrollPos = Vector2.zero; Repaint(); }
public static void OpenInVisualNodeEditor() { ShowWindow(); _currentRoot = Selection.activeObject as VisualNodeRoot; }