1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-02-06 07:14:56 +08:00

Added a virtual OnRename function to base nodes, triggered when a node gets renamed. (#225)

This commit is contained in:
Lumos 2020-01-02 19:48:36 +01:00 committed by Thor Brigsted
parent e98bd85531
commit b526092341
2 changed files with 8 additions and 1 deletions

View File

@ -129,9 +129,14 @@ namespace XNodeEditor {
public void Rename(string newName) {
if (newName == null || newName.Trim() == "") newName = NodeEditorUtilities.NodeDefaultName(target.GetType());
target.name = newName;
OnRename();
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
}
/// <summary> Called after this node's name has changed. </summary>
public virtual void OnRename() { }
[AttributeUsage(AttributeTargets.Class)]
public class CustomNodeEditorAttribute : Attribute,
XNodeEditor.Internal.NodeEditorBase<NodeEditor, NodeEditor.CustomNodeEditorAttribute, XNode.Node>.INodeEditorAttrib {

View File

@ -49,6 +49,7 @@ namespace XNodeEditor {
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();
@ -58,6 +59,7 @@ namespace XNodeEditor {
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();