当前位置:网站首页>关于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;
边栏推荐
- [Chongqing Guangdong education] Suzhou University English film and Television Appreciation reference materials
- Postman test report
- The most detailed and comprehensive update content and all functions of guitar pro 8.0
- Dynamic programming (tree DP)
- Postman manage test cases
- [NOIP2008 提高组] 笨小猴
- [NOIP2009 普及组] 分数线划定
- 树莓派3.5寸屏幕白屏显示连接
- Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
- Redis —— Redis In Action —— Redis 实战—— 实战篇一 —— 基于 Redis 的短信登录功能 —— Redis + Token 的共享 session 应用— 有代码
猜你喜欢

麦斯克电子IPO被终止:曾拟募资8亿 河南资产是股东

Coreldraw2022 new version new function introduction cdr2022

Introduction of several RS485 isolated communication schemes

Ue5 small knowledge points to enable the setting of lumen

8. Static file

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

行业专网对比公网,优势在哪儿?能满足什么特定要求?

Acwing week 58

RTP GB28181 文件测试工具

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
随机推荐
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems
Orm-f & Q object
Is the mode of education together - on campus + off campus reliable
Programmers' position in the Internet industry | daily anecdotes
ISP学习(2)
也算是学习中的小总结
The video in win10 computer system does not display thumbnails
2021 RoboCom 世界机器人开发者大赛-本科组(复赛)
MySQL reported an error datetime (0) null
MIT CMS. 300 session 8 – immersion / immersion
Selection of slow motion function
How to estimate the population with samples? (mean, variance, standard deviation)
8. Static file
11. Intranet penetration and automatic refresh
[noip2008 improvement group] stupid monkey
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Crazy God said redis notes
Visio draws Tai Chi
NPM command -- install dependent packages -- Usage / explanation
Coreldraw2022 new version new function introduction cdr2022