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;
}
}

AddComponentRecursively的更多相关文章

随机推荐

  1. 【转】MySQL分库分表数据迁移工具的设计与实现

    一.背景 MySQL作为最流行的关系型数据库产品之一,当数据规模增大遭遇性能瓶颈时,最容易想到的解决方案就是分库分表.无论是进行水平拆分还是垂直拆分,第一步必然需要数据迁移与同步.由此可以衍生出一系列 ...

  2. Android  <meta-data>

    在AndroidManifest.xml中,<meta-data>元素可以作为子元素,被包含在<activity>.<application>.<servic ...

  3. Tensorboard on Server

    ssh -L 6006:localhost:5001 username@ml.cs.tsinghua.edu.cn -p 4513 6006是本地端口 5001是远程tensorboard绑定的端口

  4. python 按照自然数排序遍历文件 python os.listdir sort by natural sorting

    import os import re def sorted_aphanumeric(data): convert = lambda text: int(text) if text.isdigit() ...

  5. java中String new和直接赋值的区别

        Java中String new和直接赋值的区别     对于字符串:其对象的引用都是存储在栈中的,如果是编译期已经创建好(直接用双引号定义的)的就存储在常量池中,如果是运行期(new出来的)才 ...

  6. Ubuntu -- 安装、卸载程序的命令

    通过sudo apt-get install xxxx 安装软件后,总是无法卸载干净,这里以Apache 为例,提供方法:首先sudo apt-get remove apache2再sudo apt- ...

  7. 图解DHCP的4步租约过程

    图解DHCP的4步租约过程   DHCP租约过程就是DHCP客户机动态获取IP地址的过程. DHCP租约过程分为4步: ①客户机请求IP(客户机发DHCPDISCOVER广播包): ②server响应 ...

  8. jQuery Validation让验证变得如此easy(二)

    上一个样例我们是统一引用jquery.validate.js这样全部必填字段的提示信息都将是This field is required. 如今要改成动态提示,比方姓名假设为空则提示姓名不能为空,密码 ...

  9. 基于redis集群实现的分布式锁,可用于秒杀,定时器。

    在分布式系统中,经常会出现需要竞争同一资源的情况,使用redis可以实现分布式锁. 前提:redis集群已经整合项目,并且可以直接注入JedisCluster使用: @Autowired privat ...

  10. ubuntu下gedit和vim输入中文和中文显示

    安装和配置VIM,参考   http://jingyan.baidu.com/album/046a7b3efd165bf9c27fa915.html?picindex=4 在home/你的用户名 这个 ...