当前位置:网站首页>关于Unity Inspector上的一些常用技巧,一般用于编辑器扩展或者其他
关于Unity Inspector上的一些常用技巧,一般用于编辑器扩展或者其他
2022-07-06 04:49:00 【charlsdm】
RequireComponent
RequireComponent用于给Object添加必要的组件,也可以理解为通过代码代替“Add Component”的操作,能够有效避免由于忘记添加必要的组件而造成的报错,同时也适用于为多个Object添加相同组件的场景,省去了重复操作。
另外RequireComponent代码需要放在类的前面
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(AudioSource))]
需要注意的是,当要移除通过RequireComponent添加的组件时,需要先移除脚本,否则产生如下警告。
Range
Range为变量限定取值范围,但仅限于在Inspector窗口中,也就是说,通过代码改变变量的值是不受Range约束的
[Range(1, 5)]
public int Speed;
[Range(0,1)]
public float Time;
Space
Space使Inspector窗口中字段之间的间隔增大
public float Max;
public float Min;
[Space()]
public float Speed;
SerializeField
一般来说,只有public的变量才会显示在Inspector窗口中,但SerializeField可以忽略访问修饰符,使private的变量也能显示
private bool NotInInspector;
[SerializeField] private bool InInspector;
HideInInspector
使public的字段不显示在Inspector窗口中
[HideInInspector]
public float Hide;
public float notHide;
Tooltip
为Inspcetor窗口中的字段附加一段文字说明
[Tooltip("Health value between 0 and 100.")]
public int Health = 100;
Header
给Inspector字段加标题,实现分组
[Header(“Text”)]
public Text hp;
public Text mp;
public Text power;
public Text defense;
边栏推荐
- word封面下划线
- Sentinel sliding window traffic statistics
- Visio draws Tai Chi
- 图论的扩展
- Sqlserver query results are not displayed in tabular form. How to modify them
- Tengine kernel parameters
- web工程导入了mysql驱动jar包却无法加载到驱动的问题
- Digital children < daily question> (Digital DP)
- Fuzzy -- basic application method of AFL
- Vulnerability discovery - vulnerability probe type utilization and repair of web applications
猜你喜欢

【LGR-109】洛谷 5 月月赛 II & Windy Round 6

Digital children < daily question> (Digital DP)

Sqlserver query results are not displayed in tabular form. How to modify them

你需要知道的 TCP 三次握手

Is the mode of education together - on campus + off campus reliable

The underlying structure of five data types in redis

Ue5 small knowledge points to enable the setting of lumen

Database - MySQL storage engine (deadlock)

ISP学习(2)

Postman前置脚本-全局变量和环境变量
随机推荐
Zynq learning notes (3) - partial reconfiguration
内核判断i2c地址上是否挂载外设
[noip2009 popularization group] score line delimitation
最高法院,离婚案件判决标准
集合详解之 Map + 面试题
Lagrange polynomial
Scala function advanced
Fuzzy -- basic application method of AFL
ISP学习(2)
Excellent PM must experience these three levels of transformation!
2021 robocom world robot developer competition - undergraduate group (semi-finals)
Introduction of several RS485 isolated communication schemes
ue5 小知识 FreezeRendering 查看视锥内渲染的物体
Summary of three log knowledge points of MySQL
Meet diverse needs: jetmade creates three one-stop development packages to help efficient development
比尔·盖茨晒18岁个人简历,48年前期望年薪1.2万美元
Ue5 small knowledge points to enable the setting of lumen
程序员在互联网行业的地位 | 每日趣闻
优秀PM必须经历这3层蜕变!
Flink kakfa data read and write to Hudi