Unity编辑器扩展(三)删除以及添加组件(物体)
2020-02-18 本文已影响0人
哈莉波特大
常用方法:
删除:
添加:
AddComponentMenu
给物体添加一个脚本
例如:

RequireComponent
自动帮你添加你需要的组件,而且删除组件的时候会有提示
例如:

GetComponent
获取组件
AddComponent
添加组件
上面的编辑器模式下面也可以用,需要继承于MonoBehaviour
例如:
BuildinGrowthGroup buildinGrowthGroup = obj.GetComponent<BuildinGrowthGroup>() ?? obj.AddComponent<BuildinGrowthGroup>();
buildinGrowthGroup = obj.GetComponent<BuildinGrowthGroup>();
(判断一个物体是否有BuildinGrowthGroup这个脚本,如果没有则添加上,添加之后如果需要获取的话,还需要再次GetComponent)
Instantiate
添加一个物体
例如:
