Scriptable Object没有继承自MonoBehavior,而是继承自Scriptable Object,所以Scriptable Object不能当脚本挂载到GameObject上,也不能进行GetComponent等对GameObject的操作,同时Scriptable Object以Asset文件存储,但不论是MonoBehavior还是Scriptable Object最终都继承自Unity Object。 但要注意的是,虽然Scriptable Object没有继承自Mo...
ScriptableObject是一个Unity中的object,不是GameObject的实例。你可以使用它来创建一个具有自己的变量和方法的类,其开销会比MonoBehaviour更小。 Unity的GameObject会默认包含一个Transform组件,体现为:1、在Inspector中可以看到Transform组件;2、继承了MonoBehaviour的类中可以直接调用transform参数。 SO不包含Transform并且存在...
false, 1)] [MenuItem("GameObject/测试/测试0", false, 0)] static void CreateCustomGameObject0(MenuCommand conmand) { GameObject go = new GameObject("Custom Game Object1"); //设置新建物体未选中物体的子节点 GameObjectUtility.SetParentAndAlign(go, conmand.context as GameObject); Undo.RegisterCreat...
Scriptable Object什么是Scriptable Object首先看看官方文档中的描述: 一个类,如果需要创建无需附加到游戏对象的对象时,可从该类派生。 它对仅用于存储数据的资源最有用。简单来说,我们平时写的游戏脚本,都会挂载到相应的游戏对象中,比如PlayerController之类的,而ScriptableObject就是不用挂载到游戏对象的脚本,这个类的...
在Unity中使用Scriptable Object可以快速编出一堆具有相似性的物体类型,比如说我想用Scriptable Object来管理不同类型的子弹,子弹具有: 初速度 float bulletSpeed 威力float damage 生命周期 int lifeSpan 或者 float lifeSpan 子弹种类 BulletType bulletType
強化數據類型 (Extensible Enum) 最後,講者介紹了用Scriptable Object代替enum,其實這個做法,以前也有這個講者提及; 這是一些使用Scriptable Object代替enum的好處: 可以繼承 可以附加一些相關資料,例如範例中,類型附加了相關圖像和顯示名字 應用範例:類似Minecraft掘礦的mechanics ...
public enum ItemType { COIN,HEALTH } //使⽤枚举创建名为itemType的属性 public ItemType itemType;} 中介——⼀个继承⾃MonoBehaviour的脚本,这样就能使得Scriptable Objec挂载到GameObject上了 using System.Collections;using System.Collections.Generic;using UnityEngine;public class Consumable : MonoBehaviour...
OnDisable This function is called when the scriptable object goes out of scope. OnEnable This function is called when the object is loaded. OnValidate Editor-only function that Unity calls when the script is loaded or a value changes in the Inspector. Reset Reset to default values. Inherited ...
这种比较简便,在project文件内,点击加号就能看到,这种方法需要继承ScripteableObject类 2、 在顶部菜单栏创建,自主传入类名,指定生成位置 使用方法 1、直接声明一个资源类,然后在inspector,直接将asset拖上去 2、放到能加载到的文件夹内,直接加载 3、通过单例模式去加载,这样不用去动态加载和手动拖取 ...
Just like MonoBehaviours, ScriptableObjects derive from the baseUnityEngine.Objectbut, unlike MonoBehaviours, you can’t attach a ScriptableObject to aGameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s function...