コード例 #1
0
 /// <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.OnCreated();
     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);
     }
     AssetDatabase.AddObjectToAsset(node, target);
     if (NodeEditorPreferences.GetSettings().autoSave)
     {
         AssetDatabase.SaveAssets();
     }
     NodeEditorWindow.RepaintAll();
 }