美文网首页unity编辑器扩展
Unity编辑器扩展(三)删除以及添加组件(物体)

Unity编辑器扩展(三)删除以及添加组件(物体)

作者: 哈莉波特大 | 来源:发表于2020-02-18 15:11 被阅读0次

常用方法:

删除:

添加:

AddComponentMenu

给物体添加一个脚本

例如:

RequireComponent

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

例如:

GetComponent

获取组件

AddComponent

添加组件

上面的编辑器模式下面也可以用,需要继承于MonoBehaviour

例如:

BuildinGrowthGroup buildinGrowthGroup = obj.GetComponent<BuildinGrowthGroup>() ?? obj.AddComponent<BuildinGrowthGroup>();

buildinGrowthGroup = obj.GetComponent<BuildinGrowthGroup>();

(判断一个物体是否有BuildinGrowthGroup这个脚本,如果没有则添加上,添加之后如果需要获取的话,还需要再次GetComponent)

Instantiate

添加一个物体

例如:

相关文章

网友评论

    本文标题:Unity编辑器扩展(三)删除以及添加组件(物体)

    本文链接:https://www.haomeiwen.com/subject/snkgfhtx.html