数据库简单的储存方法ScriptableObject

一.简介

  1. ScriptableObject是一个特殊的类,它不需要挂载上任何的game object上。它可以不像model behavior需要一个物体才可以使 用,而ScriptableObject可以存在文件夹当中,而且他可以存储我的数据(store data)。
  2. ScriptableObject包含许多的方法:Destroy,Instantiate,Awake,OnDestroy等。
  3. ScriptableObject通常与CreateAssetMenuAttribute一起使用。
  4. model behavior需挂在一个物体上,物体上的数据可以通过代码的运行进行更改,但是当游戏停止运行时物体上的数据将恢复为原始数据。
  5. 在编写代码是需要将MonoBehaviour更改为ScriptableObjet后,在编写代码。

二. 实例

例如

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "New Item", menuName = "Inventory/New Item")]
public class Item : ScriptableObject {
    public string itemName;
    public Sprite itemImage;
    public int itemHeld;
    [TextArea]
    public string itemInfo;

    public bool equip;

}

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值