赞
踩
其中[CreateAssetMenu]属性可以在Create里点击对应名称创建asset文件。如下图
- using System.Collections.Generic;
- using UnityEngine;
-
- [CreateAssetMenu]
- public class ChatConfig : ScriptableObject
- {
- [SerializeField]
- public List<string> ChatContent;
- }
使用Resources Load类型为ChatConfig的对象就可以加载到所有数据,例如
var content = Resources.Load<ChatConfig>("ChatConfig");
代码创建
- using UnityEditor;
- using UnityEngine;
- public class CreateAssetEditor
- {
- [MenuItem("Assets/Create ScriptObject")]
- static void CreateScriptObject()
- {
- ChatConfig config = ScriptableObject.CreateInstance<ChatConfig>();
- config.ChatContent = new System.Collections.Generic.List<string>
- {
- "A",
- "B"
- };
-
- AssetDatabase.CreateAsset(config, "Assets/Resources/NewChatConfig.asset");
- AssetDatabase.SaveAssets();
- AssetDatabase.Refresh();
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。