zoukankan      html  css  js  c++  java
  • AddComponentRecursively

    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 = 0;
            for (var currentTransform : Transform in Selection.transforms) { 
              total += RecurseAndAdd(currentTransform, componentName);
            }
            if (total == 0)
                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 = 0;
            //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; 
        }
    }
  • 相关阅读:
    border-radius:50%和100%究竟有什么区别
    GoLang几种读文件方式的比较
    Golang Import使用入门
    golang: 常用数据类型底层结构分析
    Python--字典操作
    Python--字符串操作
    Python split 分割中文
    LR(逻辑回归)
    Python--列表操作
    Eclipse 使用Anaconda python 解释器
  • 原文地址:https://www.cnblogs.com/softimagewht/p/3765408.html
Copyright © 2011-2022 走看看