举个例子
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "ScriptableObject/Weapon")]
public class Weapon : ScriptableObject {
public string weaponName;
public Sprite sprite;
public Color color = Color.white;
public ColliderType colliderType = ColliderType.None;
public enum ColliderType {
None = 0,
Sprite = 1,
Grid = 2
}
}
  这就是创建出来的对象 查看属性  然后
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponTest : MonoBehaviour
{
public Weapon weapon;
void Start()
{
}
void Update()
{
}
}
你会发现  可以把那个对象拖进来
你也可以用代码创建对象
Weapon w = ScriptableObject.CreateInstance<Weapon>();
AssetDatabase.CreateAsset(w, "Assets/aaa.asset");
AssetDatabase.SaveAssets();
这个相当于 提供了一种可视化的 unity独特的数据存储方式
|