当前位置:网站首页>關於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;
边栏推荐
- [HBZ share] reasons for slow addition and deletion of ArrayList and fast query
- Etcd database source code analysis -- etcdserver bootstrap initialization storage
- What are the advantages of the industry private network over the public network? What specific requirements can be met?
- 几种RS485隔离通讯的方案介绍
- Postman关联
- Quatre méthodes de redis pour dépanner les grandes clés sont nécessaires pour optimiser
- [buuctf.reverse] 159_[watevrCTF 2019]Watshell
- SQL injection vulnerability (MSSQL injection)
- Pagoda configuration mongodb
- yolov5 tensorrt加速
猜你喜欢
![[detailed steps of FreeRTOS shift value for the first time]](/img/73/a469eb2465bb2c5acaa4d018d3edd3.jpg)
[detailed steps of FreeRTOS shift value for the first time]

Flink kakfa data read and write to Hudi

English Vocabulary - life scene memory method

acwing周赛58

几种RS485隔离通讯的方案介绍

Introduction of several RS485 isolated communication schemes

A blog to achieve embedded entry

Yolov5 tensorrt acceleration

Postman断言

Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
随机推荐
SQL注入漏洞(MSSQL注入)
Distributed transaction solution
Excellent PM must experience these three levels of transformation!
Use sentinel to interface locally
8. Static file
Finance online homework
团队协作出了问题,项目经理怎么办?
Quatre méthodes de redis pour dépanner les grandes clés sont nécessaires pour optimiser
Visio draw fan
Summary of three log knowledge points of MySQL
Etcd database source code analysis -- etcdserver bootstrap initialization storage
Pagoda configuration mongodb
C'est un petit résumé de l'étude.
newton interpolation
MIT CMS. 300 session 8 – immersion / immersion
[HBZ sharing] how to locate slow queries in cloud database
Bubble sort
Dry goods collection | Vulkan game engine video tutorial
Postman前置脚本-全局变量和环境变量
Basic explanation of turtle module - draw curve