其中[CreateAssetMenu]属性可以在Create里点击对应名称创建asset文件。如下图
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu]
public class ChatConfig : ScriptableObject
{
[SerializeField]
public List<string> ChatContent;
}
使用Resources Load类型为ChatConfig的对象就可以加载到所有数据,例如文章来源:https://www.toymoban.com/news/detail-613097.html
var content = Resources.Load<ChatConfig>("ChatConfig");
代码创建文章来源地址https://www.toymoban.com/news/detail-613097.html
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();
}
}
到了这里,关于Unity创建asset文件的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!