Unity3d创建asset配置文件
创建脚本AndroidBuildConfigAsset > 继承ScriptableObject > 添加CreateAssetMenu特性;
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| using System.Collections; using System.Collections.Generic; using UnityEngine;
[CreateAssetMenu] public class AndroidBuildConfigAsset : ScriptableObject { public string android_name; public string android_version; public string android_keystone_path; public string android_keystone_alias; public string android_keystone_password; }
|
在Editor文件夹下创建CreateAssetEditor脚本 > 添加MenuItem特性
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| using UnityEditor; using UnityEngine;
public class CreateAssetEditor { [MenuItem("Tools/Create/Android Config")] static void CreateScriptObject() { AndroidBuildConfigAsset createAsset = ScriptableObject.CreateInstance<AndroidBuildConfigAsset>(); AssetDatabase.CreateAsset(createAsset, "Assets/Config/Build/AndroidBuildConfig.asset"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }
|
使用[MenuItem(“Tools/Create/Android Config”)] 特性来扩展编辑器, 作用是在 Assets菜单栏中添加了一个Android Config 的下拉菜单选项;
点击Android Config就会出现下图中新建的Asset配置文件;
**注意:**用来加载Asset配置中的数据;
1
| CreateAsset createAsset = Resources.Load<CreateAsset>("CreateAsset");
|
ref: https://blog.csdn.net/qq_34853692/article/details/98753947