美文网首页Unity+Code Learning
【SCRIPTABLE OBJECTS in Unity】笔记

【SCRIPTABLE OBJECTS in Unity】笔记

作者: zitaoye | 来源:发表于2019-07-23 10:37 被阅读0次

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的占用空间非常小;

相关文章

网友评论

    本文标题:【SCRIPTABLE OBJECTS in Unity】笔记

    本文链接:https://www.haomeiwen.com/subject/adznlctx.html