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

rename on create

This commit is contained in:
Joram 2018-05-12 14:37:45 +02:00
parent 75795c59b0
commit f7bfe3e694
2 changed files with 15 additions and 1 deletions

View File

@ -301,7 +301,19 @@ namespace XNodeEditor {
public void CreateNode(Type type, Vector2 position) { public void CreateNode(Type type, Vector2 position) {
XNode.Node node = graph.AddNode(type); XNode.Node node = graph.AddNode(type);
node.position = position; node.position = position;
node.name = UnityEditor.ObjectNames.NicifyVariableName(type.ToString()); node.name = UnityEditor.ObjectNames.NicifyVariableName(type.ToString());
XNode.Node.CreateNodeMenuAttribute attrib;
if (NodeEditorUtilities.GetAttrib(type, out attrib))
{
if (attrib.UseLastAsName)
{
var subPaths = attrib.menuName.Split('/');
node.name = subPaths[subPaths.Length - 1];
}
}
AssetDatabase.AddObjectToAsset(node, graph); AssetDatabase.AddObjectToAsset(node, graph);
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets(); if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
Repaint(); Repaint();

View File

@ -239,10 +239,12 @@ namespace XNode {
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class CreateNodeMenuAttribute : Attribute { public class CreateNodeMenuAttribute : Attribute {
public string menuName; public string menuName;
public bool UseLastAsName;
/// <summary> Manually supply node class with a context menu path </summary> /// <summary> Manually supply node class with a context menu path </summary>
/// <param name="menuName"> Path to this node in the context menu </param> /// <param name="menuName"> Path to this node in the context menu </param>
public CreateNodeMenuAttribute(string menuName) { public CreateNodeMenuAttribute(string menuName, bool useLastAsName = false) {
this.menuName = menuName; this.menuName = menuName;
this.UseLastAsName = useLastAsName;
} }
} }