private void OnGUI() { if (firstFrame) { UpdatePositionToMouse(); firstFrame = false; } input = EditorGUILayout.TextField(input); Event e = Event.current; // If input is empty, revert name to default instead if (input == null || input.Trim() == "") { if (GUILayout.Button("Revert to default") || (e.isKey && e.keyCode == KeyCode.Return)) { target.name = NodeEditorUtilities.NodeDefaultName(target.GetType()); NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename(); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); Close(); target.TriggerOnValidate(); } } // Rename asset to input text else { if (GUILayout.Button("Apply") || (e.isKey && e.keyCode == KeyCode.Return)) { target.name = input; NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename(); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); Close(); target.TriggerOnValidate(); } } }
/// <summary> Rename the node asset. This will trigger a reimport of the node. </summary> public void Rename(string newName) { if (newName == null || newName.Trim() == "") { newName = NodeEditorUtilities.NodeDefaultName(target.GetType()); } target.name = newName; AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); }
/// <summary> Create a node and save it in the graph asset </summary> public virtual XNode.Node CreateNode(Type type, Vector2 position) { Undo.RecordObject(target, "Create Node"); XNode.Node node = target.AddNode(type); Undo.RegisterCreatedObjectUndo(node, "Create Node"); node.position = position; if (node.name == null || node.name.Trim() == "") node.name = NodeEditorUtilities.NodeDefaultName(type); if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target))) AssetDatabase.AddObjectToAsset(node, target); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets(); NodeEditorWindow.RepaintAll(); return node; }
/// <summary> Create a node and save it in the graph asset </summary> public virtual void CreateNode(Type type, Vector2 position) { XNode.Node node = target.AddNode(type); node.position = position; if (node.name == null || node.name.Trim() == "") { node.name = NodeEditorUtilities.NodeDefaultName(type); } AssetDatabase.AddObjectToAsset(node, target); if (NodeEditorPreferences.GetSettings().autoSave) { AssetDatabase.SaveAssets(); } NodeEditorWindow.RepaintAll(); }
private static void AddRequired(NodeGraph graph, Type type, ref Vector2 position) { if (!graph.nodes.Any(x => x.GetType() == type)) { xNode.Node node = graph.AddNode(type); node.position = position; position.x += 200; if (node.name == null || node.name.Trim() == "") { node.name = NodeEditorUtilities.NodeDefaultName(type); } if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(graph))) { AssetDatabase.AddObjectToAsset(node, graph); } } }
private static void OnPostprocessAllAssets( string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { for (int i = 0; i < movedAssets.Length; i++) { Node nodeAsset = AssetDatabase.LoadMainAssetAtPath(movedAssets[i]) as Node; // If the renamed asset is a node graph, but the v2 AssetDatabase has swapped a sub-asset node to be its // main asset, reset the node graph to be the main asset and rename the node asset back to its default // name. if (nodeAsset != null && AssetDatabase.IsMainAsset(nodeAsset)) { AssetDatabase.SetMainObject(nodeAsset.graph, movedAssets[i]); AssetDatabase.ImportAsset(movedAssets[i]); nodeAsset.name = NodeEditorUtilities.NodeDefaultName(nodeAsset.GetType()); EditorUtility.SetDirty(nodeAsset); } } }