1、ScriptableObject的创建(一):
using System.Collections;
using System.Collections.Generic;
using UnityEngine; [CreateAssetMenu(menuName = "MySubMenue/Create MyScriptableObject")]
public class TestScriptableObject : ScriptableObject
{
public int someVariable;
}
2、ScriptableObject的创建(二),运行时候在内存中创建:
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class Test : MonoBehaviour
{
void Start()
{
//脚本中动态创建一个ScriptableObject,创建于内存
//这里是泛型方法的一个使用实例,自行脑补
TestScriptableObject variable = ScriptableObject.CreateInstance<TestScriptableObject>();
variable.someVariable = ;
}
}
3、ScriptableObject的简单使用:
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class Test : MonoBehaviour
{
[SerializeField]
TestScriptableObject test; void Start()
{
Debug.Log(test.someVariable); //
test.someVariable = ; //改变初始存储的值为 14
}
}