当前位置:网站首页>關於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;
边栏推荐
- [try to hack] John hash cracking tool
- Scala function advanced
- 驱动开发——HelloWDM驱动
- Vulnerability discovery - vulnerability probe type utilization and repair of web applications
- 也算是學習中的小總結
- Upload nestjs configuration files, configure the use of middleware and pipelines
- Visio draws Tai Chi
- Visio draw fan
- IPv6 comprehensive experiment
- Postman测试报告
猜你喜欢
ETCD数据库源码分析——etcdserver bootstrap初始化存储
Yolov5 tensorrt acceleration
Crazy God said redis notes
麥斯克電子IPO被終止:曾擬募資8億 河南資產是股東
Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
Etcd database source code analysis -- etcdserver bootstrap initialization storage
Ue5 small knowledge points to enable the setting of lumen
MPLS experiment
Fuzzy -- basic application method of AFL
IPv6 comprehensive experiment
随机推荐
Request (request object) and response (response object)
RTP GB28181 文件测试工具
Postman测试报告
程序员在互联网行业的地位 | 每日趣闻
DMA use of stm32
JS quick start (II)
驱动开发——第一个HelloDDK
Redis —— Redis In Action —— Redis 实战—— 实战篇一 —— 基于 Redis 的短信登录功能 —— Redis + Token 的共享 session 应用— 有代码
Basic explanation of turtle module - draw curve
【LGR-109】洛谷 5 月月赛 II & Windy Round 6
I'd like to ask about the current MySQL CDC design. In the full volume phase, if a chunk's binlog backfill phase,
Flody的应用
关于es8316的音频爆破音的解决
Biscuits (examination version)
Introduction of several RS485 isolated communication schemes
word封面下划线
The kernel determines whether peripherals are attached to the I2C address
饼干(考试版)
[detailed steps of FreeRTOS shift value for the first time]
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder