其他分享
首页 > 其他分享> > Unity创建配置文件

Unity创建配置文件

作者:互联网

1.新建脚本继承ScriptableObject,添加[CreateAssetMenu]特性在Create下创建GameCreateAsset类文件

1 [CreateAssetMenu]
2 public class GameAssets : ScriptableObject
3 {
4     //具体的配置信息  
5 }

2.在指定文件夹下生成NewCreateAsset.asset文件

 1 [MenuItem("Assets/GameAssets/CreateAssets")]
 2 public static void CreateAssets()
 3 {
 4   CreateScriptable<GameAssets>("GameConfig", "GameAsset");
 5 }
 6 
 7 static void CreateScriptable<T>(string route, string className) where T : ScriptableObject
 8 {
 9   T createAsset = (T)ScriptableObject.CreateInstance(className);
10   AssetDatabase.CreateAsset(createAsset, "Assets/Resources/" + route + "/NewCreateAsset.asset");
11   AssetDatabase.SaveAssets();
12   AssetDatabase.Refresh();
13 }

 

标签:ScriptableObject,string,配置文件,创建,AssetDatabase,Unity,CreateAssets,static,NewCreat
来源: https://www.cnblogs.com/New-FaXiaoyou/p/15791990.html