当前位置:网站首页>關於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;
边栏推荐
- Finance online homework
- Supreme Court, judgment standard of divorce cases
- 你需要知道的 TCP 三次握手
- 最高法院,离婚案件判决标准
- The video in win10 computer system does not display thumbnails
- Pagoda configuration mongodb
- Yyds dry goods inventory OSI & tcp/ip
- Digital children < daily question> (Digital DP)
- Postman测试报告
- Scala function advanced
猜你喜欢
随机推荐
Redis 排查大 key 的4种方法,优化必备
SharedPreferences source code analysis
Pagoda configuration mongodb
Extension of graph theory
Vulnerability discovery - vulnerability probe type utilization and repair of web applications
Summary of three log knowledge points of MySQL
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
A little knowledge of CPU, disk and memory
Postman断言
Microservice resource address
[buuctf.reverse] 159_ [watevrCTF 2019]Watshell
Excellent PM must experience these three levels of transformation!
最高法院,离婚案件判决标准
Postman test report
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
[lgr-109] Luogu may race II & windy round 6
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
集合详解之 Map + 面试题
图论的扩展
The underlying structure of five data types in redis