mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-04 06:14:54 +08:00
Unified all functions that set the default node name (#161)
This commit is contained in:
parent
0553dc8894
commit
5d45300935
@ -86,9 +86,9 @@ namespace XNodeEditor {
|
||||
|
||||
/// <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 = UnityEditor.ObjectNames.NicifyVariableName(target.GetType().Name);
|
||||
if (newName == null || newName.Trim() == "") newName = NodeEditorUtilities.NodeDefaultName(target.GetType());
|
||||
target.name = newName;
|
||||
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
|
||||
AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(target), target.name);
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
|
||||
@ -133,6 +133,15 @@ namespace XNodeEditor {
|
||||
} else return type.ToString();
|
||||
}
|
||||
|
||||
/// <summary> Returns the default name for the node type. </summary>
|
||||
public static string NodeDefaultName(Type type) {
|
||||
string typeName = type.Name;
|
||||
// Automatically remove redundant 'Node' postfix
|
||||
if (typeName.EndsWith("Node")) typeName = typeName.Substring(0, typeName.LastIndexOf("Node"));
|
||||
typeName = UnityEditor.ObjectNames.NicifyVariableName(typeName);
|
||||
return typeName;
|
||||
}
|
||||
|
||||
/// <summary>Creates a new C# Class.</summary>
|
||||
[MenuItem("Assets/Create/xNode/Node C# Script", false, 89)]
|
||||
private static void CreateNode() {
|
||||
|
||||
@ -74,12 +74,7 @@ namespace XNodeEditor {
|
||||
public virtual void CreateNode(Type type, Vector2 position) {
|
||||
XNode.Node node = target.AddNode(type);
|
||||
node.position = position;
|
||||
if (string.IsNullOrEmpty(node.name)) {
|
||||
// Automatically remove redundant 'Node' postfix
|
||||
string typeName = type.Name;
|
||||
if (typeName.EndsWith("Node")) typeName = typeName.Substring(0, typeName.LastIndexOf("Node"));
|
||||
node.name = UnityEditor.ObjectNames.NicifyVariableName(typeName);
|
||||
}
|
||||
if (node.name == null || node.name.Trim() == "") node.name = NodeEditorUtilities.NodeDefaultName(type);
|
||||
AssetDatabase.AddObjectToAsset(node, target);
|
||||
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||
NodeEditorWindow.RepaintAll();
|
||||
|
||||
@ -48,8 +48,8 @@ namespace XNodeEditor {
|
||||
// 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 = UnityEditor.ObjectNames.NicifyVariableName(target.GetType().Name);
|
||||
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
|
||||
target.name = NodeEditorUtilities.NodeDefaultName(target.GetType());
|
||||
AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(target), target.name);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
@ -57,7 +57,7 @@ namespace XNodeEditor {
|
||||
else {
|
||||
if (GUILayout.Button("Apply") || (e.isKey && e.keyCode == KeyCode.Return)) {
|
||||
target.name = input;
|
||||
AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(target), input);
|
||||
AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(target), target.name);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user