Unity+Code Learning

【SCRIPTABLE OBJECTS in Unity】笔记

2019-07-23  本文已影响0人  zitaoye

Scriptable Objects 就是 data containers

  1. 创建一个template that defines what information each object should hold
  2. 创建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的占用空间非常小;

上一篇下一篇

猜你喜欢

热点阅读