定义存储数据的类
[CreateAssetMenu(menuName = "MyDemo/Create MyScriptableObject")]
public class Demo : ScriptableObject
{
public int First;
public int Second;
public int Three;
}
创建测试脚本
public class DemoTest : MonoBehaviour
{
private Demo _demoTest;
public Text Text;
void Start()
{
if (_demoTest==null)
{
_demoTest=Resources.Load<Demo>("Demo/MyDemo");
}
Text.text = string.Format($"_demoTest.First={_demoTest.First}+_demoTest.Second={_demoTest.Second}+_demoTest.Three={_demoTest.Three}");
}
}
输出结果: