unity inspector 自动装载Commont和Prefab属性

 

在使用unity的过程中,经常遇到这样的问题:每次都需要手动为序列化属性拖拽赋值。像这样:

 

 

试着找了找,真的找到了一份代码,但是缺少自动装载Prefab的功能。之后我花了点时间添加这个功能。

使用方法:

 1   [Autohook]
 2     public Button SendBtn;
 3     [Autohook]
 4     public Button StartBtn;
 5     [Autohook]
 6     public Button LeaveBtn;
 7     [Autohook]
 8     public Text RoomDateText;
 9     [Autohook]
10     public ScrollRect PlayerList;
11 
12     [Autohook]
13     public GameObject PlayerBarPrefab;
14     [Autohook]
15     public GameObject RoomBarPrefab;

Autohook会自动在子节点中寻找对应的名称。

如果要自动赋值Prefab,类型必须为GameObject,并且有Prefab后缀。

例如: [Autohook] public GameObject RoomBarPrefab; 

这一句会在Prefabs的目录下寻找RoomBar这个prefab,并赋值到此。

 

代码包:

链接: https://pan.baidu.com/s/1ITUicf2pbt9EoqWhgoCojg 提取码: hwvs

 

posted @ 2020-02-25 05:11  backinfile  阅读(410)  评论(0编辑  收藏  举报