1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00

Moved method to editor and removed the global notification.

This commit is contained in:
Lumos 2020-01-01 19:24:14 +01:00
parent a68ec65e6c
commit 0fcde9d33b
3 changed files with 9 additions and 29 deletions

View File

@ -129,33 +129,14 @@ namespace XNodeEditor {
public void Rename(string newName) { public void Rename(string newName) {
if (newName == null || newName.Trim() == "") newName = NodeEditorUtilities.NodeDefaultName(target.GetType()); if (newName == null || newName.Trim() == "") newName = NodeEditorUtilities.NodeDefaultName(target.GetType());
target.name = newName; target.name = newName;
TriggerRenameNotifications(target); OnRename();
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
} }
/// <summary> /// <summary> Called after this node's name has changed. </summary>
/// Triggers OnRename on all nodes in the graph after a node's name changes, public virtual void OnRename() { }
/// reimporting asset files for all subsequently renamed nodes.
/// </summary>
public static void TriggerRenameNotifications(XNode.Node renamedNode) {
List<XNode.Node> graphNodes = renamedNode.graph.nodes;
string[] oldNodeNames = new string[graphNodes.Count];
// Notify all nodes, allow them to further change names accordingly
for (int i = 0; i < graphNodes.Count; i++) {
XNode.Node node = graphNodes[i];
oldNodeNames[i] = node.name;
node.OnRename(renamedNode);
}
// After all user-driven modifications have been resolved, update all assets whose node names have changed
// (And always reimport the node which got renamed in the first place)
for (int i = 0; i < graphNodes.Count; i++) {
if (graphNodes[i] == renamedNode || graphNodes[i].name != oldNodeNames[i]) {
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graphNodes[i]));
}
}
}
[AttributeUsage(AttributeTargets.Class)] [AttributeUsage(AttributeTargets.Class)]
public class CustomNodeEditorAttribute : Attribute, public class CustomNodeEditorAttribute : Attribute,
XNodeEditor.Internal.NodeEditorBase<NodeEditor, NodeEditor.CustomNodeEditorAttribute, XNode.Node>.INodeEditorAttrib { XNodeEditor.Internal.NodeEditorBase<NodeEditor, NodeEditor.CustomNodeEditorAttribute, XNode.Node>.INodeEditorAttrib {

View File

@ -49,7 +49,8 @@ namespace XNodeEditor {
if (input == null || input.Trim() == "") { if (input == null || input.Trim() == "") {
if (GUILayout.Button("Revert to default") || (e.isKey && e.keyCode == KeyCode.Return)) { if (GUILayout.Button("Revert to default") || (e.isKey && e.keyCode == KeyCode.Return)) {
target.name = NodeEditorUtilities.NodeDefaultName(target.GetType()); target.name = NodeEditorUtilities.NodeDefaultName(target.GetType());
NodeEditor.TriggerRenameNotifications((XNode.Node)target); NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename();
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
Close(); Close();
target.TriggerOnValidate(); target.TriggerOnValidate();
} }
@ -58,7 +59,8 @@ namespace XNodeEditor {
else { else {
if (GUILayout.Button("Apply") || (e.isKey && e.keyCode == KeyCode.Return)) { if (GUILayout.Button("Apply") || (e.isKey && e.keyCode == KeyCode.Return)) {
target.name = input; target.name = input;
NodeEditor.TriggerRenameNotifications((XNode.Node)target); NodeEditor.GetEditor((XNode.Node)target, NodeEditorWindow.current).OnRename();
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
Close(); Close();
target.TriggerOnValidate(); target.TriggerOnValidate();
} }

View File

@ -254,9 +254,6 @@ namespace XNode {
/// <summary> Called after a connection is removed from this port </summary> /// <summary> Called after a connection is removed from this port </summary>
/// <param name="port">Output or Input</param> /// <param name="port">Output or Input</param>
public virtual void OnRemoveConnection(NodePort port) { } public virtual void OnRemoveConnection(NodePort port) { }
/// <summary> Called after a node's name has changed. </summary>
public virtual void OnRename(Node node) { }
/// <summary> Disconnect everything from this node </summary> /// <summary> Disconnect everything from this node </summary>
public void ClearConnections() { public void ClearConnections() {