编辑器的一些批处理脚本

// Automatically change the name of the selected object via a text field
class EditorGUILayoutTextField extends EditorWindow {
        //折叠页变量
        var tag_layer : boolean = true;
        var addCol : boolean = true;
        
        var selectedTag : String = "Untagged";   
        var selectedLayer : int = 0;
          
        var addToChild : boolean = false;
         
        @MenuItem("EditorTools/BeachTools")   
        static function beatchWorking() {
           /*
            var g:GameObject = GameObject.FindWithTag ("Finish");
            for(var i : GameObject in Selection.gameObjects){
                 
                 
               if(!i.GetComponent ("get")){
                 i.AddComponent ("get");
                 i.GetComponent("get").k = g;
                 i.transform.tag = "wwerwer";
              }else{
               
                i.transform.tag = "Player";
                i.GetComponent("get").k = g;
              }
             }
            
            */
                var window = GetWindow(EditorGUILayoutTextField);       
                window.Show();
        } 
         
        function OnGUI(){
                     
               tag_layer = EditorGUI.Foldout(Rect(3,3,position.width-6,15),tag_layer,"tag_layer");
               if(tag_layer){
              
                      selectedTag = EditorGUI.TagField(Rect(3,23,position.width/2-10, 50),"Tags:",selectedTag);                        
                      selectedLayer = EditorGUI.LayerField(Rect(position.width/2,23, position.width/2-5, 20),"Layers:",selectedLayer);
                                  
                    
                         
                      if(GUI.Button(Rect(6,45,190,25),"Change Tag")){
                         if(Selection.activeGameObject) {
                            if(addToChild){
                           
                                 var fu01 : Transform = Selection.activeTransform as Transform;
          for(var j=0;j<fu01.childCount;j++)
               fu01.GetChild(j).gameObject.tag = selectedTag;
                           
                            }else{              
                         for(var go : GameObject in Selection.gameObjects)                   
                         go.tag = selectedTag;
                       }
                       }
                      }
                                             
                      if(GUI.Button(Rect(position.width-196,45,190,25),"Change Layer")){
                          if(Selection.activeGameObject) {              
                        for(var go : GameObject in Selection.gameObjects)                   
                        go.layer = selectedLayer;
                    }
                      }       
               }
             
               addCol = EditorGUI.Foldout(Rect(3,80,position.width-6,15),addCol,"add_Collider");
               if(addCol){
                  
                    
                     if(GUI.Button(Rect(5,100,190,25),"Add Collider")){
                          if(Selection.activeGameObject){
                            if(addToChild){
                           
                              var fu : Transform = Selection.activeTransform as Transform;
            for(var i=0;i<fu.childCount;i++)
            fu.GetChild(i).gameObject.AddComponent("MeshCollider");
              
                         }else{
                        for(var z : GameObject in Selection.gameObjects)
                        z.AddComponent("MeshCollider");   
                         }
                     }
                     }
               
               }
               
               addToChild = EditorGUI.Toggle(Rect(0,270,position.width,20),"Add to Child",addToChild);
                //GUILayout.Label("Select an object in the hierarchy view");       
                //if(Selection.activeGameObject)           
                //Selection.activeGameObject.tag =          
                      //EditorGUILayout.TextField("Object Name: ", Selection.activeGameObject.tag);       
               this.Repaint();
 
          }  
}

posted @ 2012-07-29 08:19  softimagewht  阅读(273)  评论(0编辑  收藏  举报