我们创建一个C#脚本然后做点修改: [CreateAssetMenu(fileName = "##创建Scriptable Obj时候默认的名字",menuName = "##右键菜单里的路径,比如Make a Bullet/Bullet")]//方便从菜单快速创建子弹副本publicclassBullets:ScriptableObject{publicfloatbulletSpeedpublicfloatdamagepublicintlifeSpanpublicBulletTypebulletType} ...
使用[CreateAssetMenu] 属性可以创建自定义菜单项,用于在编辑器中创建 ScriptableObject 对象。 警告:不建议在游戏运行时通过代码修改 ScriptableObject 中的字段,可能会导致编辑器中出现奇怪的行为。 2.3 创建对象数据:Scriptable Object Item.cs 脚本 ItemData 类继承自 ScriptableObject,并定义了四个属性:id、displayName...
your project’s memory usage by avoiding copies of values. This is useful if your project has aprefabAn asset type that allows you to store a GameObject complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene.More ...
以我现在做的项目为例简单介绍Scriptable Object的使用: 一,创建一个模板来定义每个对象包含的信息: 注意:此技能类是需要继承ScriptableObject,不需要挂载在任何gameobject上。因为是保存在文件夹当中,也可以利用此特性做到数据的储存。 using UnityEngine; [CreateAssetMenu(fileName ="New Skill",menuName ="Skills/Mi...
来自Unity官方开发者电子书《Create modular game architecture in unity with scriptableobjects》 前言 在unity官方文档的 Advanced best practice guides 中,提供了多本电子书,其中都包含许多有价值的信息。 本文将《Create modular game architecture in unity with scriptableobjects》翻译为中文版本供有需要的小伙伴参考...
写一个Scriptable Object案例: using System.Collections; using System.Collections.Generic; using UnityEngine; //在Creat菜单创建一个名为Item的条目(可以在资源文件夹下右键创建脚本化对象Item了) [CreateAssetMenu(menuName = "Item")] //继承自ScriptableObject而非MonoBehaviour,如此不能直接挂载到游戏对象上,得...
使用Scriptable需要在创建一个脚本并继承自ScriptableObject类,通过使用CreateAssetMenu属性来创建由自定义ScriptableObject类生成的资源。 ScriptableObject资源的创建: //方法1:在编辑器菜单中创建 [CreateAssetMenu(fileName = "NewScriptableObject", menuName = "CreateScriptableObject", order = 0)] ...
Scriptable Objects 就是 data containers 创建一个template that defines what information each object should hold 创建object from that template usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;//可以在右键菜单中创建了[CreateAssetMenu(fileName="New Card",menuName="Card/Minion")]public...
创建ScriptabelObjects 假设我们有一个角色对象具有移动、攻击、技能等要素,然后创建一个脚本用于生成ScriptableObject并管理该对象的Wwise事件。 usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;[CreateAssetMenu(menuName="Scriptable Object/Audio/Character",fileName="New Character Sheet")]public...
usingUnityEngine;usingUnityEditor;//新建一个Editor文件夹,放在里面publicclassMakeEnemyData{[MenuItem("Assets/Editor/Scriptable Object")]//定义了如何新建的路径publicstaticvoidCreateMyAsset(){//将EnemyData创建为assetEnemyDataasset=ScriptableObject.CreateInstance<EnemyData>();//设置新创建的NewScripableObject文...