ScriptableObject 在游戏中的使用实例
ScriptableObject 使用指南
Unity 存储游戏数据的几种方法
Unity ScriptableObject实例
创建一个物品管理的ScriptableObject
- ItemScriptableObject
目的:在 project 面板中添加 Item Scriptable Object 的实例文件。

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu]
public class ItemScriptObject : ScriptableObject
{
public int id;
public new string name;
public ItemType itemType;
public string descirption;
public List<Property> propertyList;
public Sprite icon;
public GameObject prefab;
}
public enum ItemType
{
Weapon,
Consumable
}
[Serializable]
public class Property
{
public PropertyType proPertyType;
public int value;
public Property()
{
}
public Property(PropertyType proPertyType, int value)
{
this.proPertyType = proPertyType;
this.value = value;
}
}
public enum PropertyType
{
HPVValue,
EnergyValue,
MentalValue,
SpeedValue,
AttackValue
}
- 最终效果:

创建一个管理所有 ScriptableObject 的数据库(ItemDBSO)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu()]
public class ItemDBSO : ScriptableObject
{
public List<ItemScriptObject> itemList;
}
- 最终效果
