AddComponentRecursively
2024-09-30 07:50:44
class AddComponentRecursively extends ScriptableWizard { var componentName : String = ""; @MenuItem ("GameObject/Add Component Recursively...") static function AddComponentsRecursivelyItem() {
ScriptableWizard.DisplayWizard("Add Component Recursively", AddComponentRecursively, "Add", "");
} //Main function
function OnWizardCreate() {
var total : int = ;
for (var currentTransform : Transform in Selection.transforms) {
total += RecurseAndAdd(currentTransform, componentName);
}
if (total == )
Debug.Log("No components added.");
else
Debug.Log(total + " components of type \"" + componentName + "\" created.");
} function RecurseAndAdd(parent : Transform, componentToAdd : String) : int {
//keep count
var total : int = ;
//add components to children
for (var child : Transform in parent) {
total += RecurseAndAdd(child, componentToAdd);
}
//add component to parent
var existingComponent : Component = parent.GetComponent(componentToAdd);
if (!existingComponent) {
parent.gameObject.AddComponent(componentToAdd);
total++;
} return total;
}
//Set the help string
function OnWizardUpdate () {
helpString = "Specify the exact name of the component you wish to add:";
} // The menu item will be disabled if no transform is selected.
@MenuItem ("GameObject/Add Component Recursively...", true) static function ValidateMenuItem() : boolean {
return Selection.activeTransform;
}
}
最新文章
- Jsoup提取文本时保留标签
- 转载:移动前端开发之viewport的深入理解
- Apache查看并发及TIME_WAIT过多的解决
- sqlplus命令大全
- drupal里面的ajax最粗浅的理解-流程
- NodeJS记录
- android ListView进阶
- [r]How To Use Git To Create A Key
- 新版福昕阅读器(Foxit Reader)启动速度慢解决办法
- response的contentType 几种类型
- NSConditionLock
- 将UTF8编码转化为中文 - NSString方法
- Python hashlib 无法打印
- 134、直接拿来用,Android界最火的开源项目
- 图片缓存:浏览器刷新 和 304 Not Modified 与 If-Modified-Since 及 Cache-Control
- poj 1184
- [C#]读取不同版本的excel文件的方法
- Java数据结构和算法(一)散列表
- AdvStringGrid 复选框、goRowSelect
- 用Keras 和 DDPG play TORCS(1)