当前位置:网站首页>关于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;
边栏推荐
- Dynamic programming (tree DP)
- English Vocabulary - life scene memory method
- canal同步mysql数据变化到kafka(centos部署)
- Leetcode 186 Flip the word II in the string (2022.07.05)
- Postman测试报告
- RTP gb28181 document testing tool
- ORM aggregate query and native database operation
- SQL注入漏洞(MSSQL注入)
- newton interpolation
- 也算是學習中的小總結
猜你喜欢
MPLS experiment
Postman前置脚本-全局变量和环境变量
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
Digital children < daily question> (Digital DP)
几种RS485隔离通讯的方案介绍
Selection of slow motion function
Visio draws Tai Chi
Postman关联
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems
行业专网对比公网,优势在哪儿?能满足什么特定要求?
随机推荐
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder
Postman pre script - global variables and environment variables
Orm-f & Q object
Meet diverse needs: jetmade creates three one-stop development packages to help efficient development
Postman前置脚本-全局变量和环境变量
Basic knowledge and examples of binary tree
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
MIT CMS. 300 session 8 – immersion / immersion
yolov5 tensorrt加速
word封面下划线
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
Ue5 small knowledge points to enable the setting of lumen
Why does MySQL need two-phase commit
驱动开发——第一个HelloDDK
[HBZ sharing] how to locate slow queries in cloud database
Postman test report
Yyds dry goods inventory OSI & tcp/ip
Flink kakfa data read and write to Hudi
Postman assertion
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity