首先需要创建一个类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "testAsset",menuName = "createAsset",order = 100)]//菜单按钮 第二个参数是菜单的名字 第三个是菜单上的顺序
public class assetSerialize : ScriptableObject {//这个类需要继承ScriptableObject
public int ID;
public string name;
public List<int> list;
}
这个类写完之后呢 会出现

点击之后就可以创建Asset

如何读取呢
void readAsset()
{
assetSerialize assets = UnityEditor.AssetDatabase.LoadAssetAtPath(“Assets/testAsset.asset”);//读取所创建的路径
Debug.Log(assets.ID);
Debug.Log(assets.name);
foreach (var item in assets.list)
{
Debug.Log(item);
}
}

本文介绍如何在Unity中使用ScriptableObject创建可编辑的Asset,包括创建自定义类、通过菜单创建Asset实例及读取Asset数据的方法。通过示例代码展示了如何在编辑器中创建和读取包含整型ID、字符串名称和整型列表的Asset。
779

被折叠的 条评论
为什么被折叠?



