【SCRIPTABLE OBJECTS in Unity】笔记
2019-07-23 本文已影响0人
zitaoye
Scriptable Objects 就是 data containers
- 创建一个template that defines what information each object should hold
- 创建object from that template
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//可以在右键菜单中创建了
[CreateAssetMenu(fileName="New Card",menuName="Card/Minion")]
public class Card : ScriptableObject {
public new string name;
public string description;
public sprite artwork;
public int manaCost;
public int attack;
public int health;
public void Print()
{
Debug.Log(name+": "+ description+"The Card Cost: "+namaCost);
}
}
然后可以直接在其他脚本中进行调用以及使用
using UnityEngine.UI;
public class CardDisplay : MonoBehaviour {
public Card myCard;
....
}
用法并不难,并且scriptableObject的占用空间非常小;