当前位置:网站首页>關於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;
边栏推荐
猜你喜欢

Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code

Postman pre script - global variables and environment variables

Weng Kai C language third week 3.1 punch in

The underlying structure of five data types in redis

Postman Association

L'introduction en bourse de MSK Electronics a pris fin: 800 millions de RMB d'actifs de Henan étaient des actionnaires

8. Static file

ETCD数据库源码分析——etcdserver bootstrap初始化存储
![[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity](/img/ac/93a64e59592e3d083a771b993d6884.jpg)
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity

Postman assertion
随机推荐
[buuctf.reverse] 159_ [watevrCTF 2019]Watshell
[lgr-109] Luogu may race II & windy round 6
Vulnerability discovery - vulnerability probe type utilization and repair of web applications
Acwing week 58
Luogu deep foundation part 1 Introduction to language Chapter 2 sequential structure programming
Embedded development program framework
JS quick start (II)
Ue5 small knowledge points to enable the setting of lumen
Codeforces Round #804 (Div. 2)
项目经理,你会画原型嘛?项目经理需要做产品设计了?
Word cover underline
Introduction of several RS485 isolated communication schemes
集合详解之 Collection + 面试题
团队协作出了问题,项目经理怎么办?
ORM aggregate query and native database operation
[Chongqing Guangdong education] Suzhou University English film and Television Appreciation reference materials
Use sentinel to interface locally
Postman test report
[05-1, 05-02, 05-03] network protocol
Postman关联