AddSelectedAnimationsToRig

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(C# - AddSelectedAnimationsToRig.cs)
(C# - AddSelectedAnimationsToRig.cs)
Line 19: Line 19:
 
     static void DoSet()
 
     static void DoSet()
 
     {
 
     {
         ScriptableWizard.DisplayWizard("Add selected animations to rig", typeof(AddSelectedAnimationsToRig), "Set animations...");
+
         ScriptableWizard.DisplayWizard("Add selected animations to rig", typeof(AddSelectedAnimationsToRig), "Set animations...");
 +
     
 
     }
 
     }
 
    
 
    
 
     void OnWizardUpdate()
 
     void OnWizardUpdate()
     {          
+
     {
      helpString = "Add selected animations to the rig...";    
+
       
 +
        if(!rig){
 +
        // Disable the wizard create button
 +
isValid = false;
 +
 +
// And tell the user why
 +
helpString = "Choose a rig with an animation component already attached to it.";
 +
        } else {
 +
        isValid = true;
 +
helpString = "Add selected animations to the rig...";
 +
        }
 +
       
 
     }
 
     }
 
    
 
    
Line 33: Line 45:
 
         foreach (Animation an in objs)
 
         foreach (Animation an in objs)
 
         {
 
         {
rig.animation.AddClip(an.clip,an.name);          
+
         
 +
            Debug.Log(an.name);
 +
rig.animation.AddClip(an.clip,an.name);
 +
           
 
         }
 
         }
 
          
 
          
Line 40: Line 55:
 
         // bit of clean up
 
         // bit of clean up
 
         objs=null;
 
         objs=null;
         rig=null;  
+
         rig=null;
 +
       
 
     }   
 
     }   
 
}</csharp>
 
}</csharp>

Revision as of 00:52, 7 May 2009

Author: Jeff Murray (psychicparrot)

Description

A wizard to add multiple animations to a rig in one go.

Usage

Place this script in YourProject/Assets/Editor and a menu item will automatically appear in the Custom menu after it is compiled. Select all your animations, open the wizard and select a rig to apply them to. Hit the button. Boom! You're done!

C# - AddSelectedAnimationsToRig.cs

<csharp>using UnityEngine; using UnityEditor;

public class AddSelectedAnimationsToRig : ScriptableWizard {

   public GameObject rig;
  
   [MenuItem ("Custom/Add selected animations to rig")]
   static void DoSet()
   {
       ScriptableWizard.DisplayWizard("Add selected animations to rig", typeof(AddSelectedAnimationsToRig), "Set animations...");
      
   }
  
   void OnWizardUpdate()
   {
   	    
       if(!rig){

// Disable the wizard create button isValid = false;

// And tell the user why helpString = "Choose a rig with an animation component already attached to it.";

       } else {
       	isValid = true;

helpString = "Add selected animations to the rig...";

       }
       
   }
  
   void OnWizardCreate()
   {
       Object[] objs = Selection.GetFiltered(typeof(Animation), SelectionMode.Unfiltered);
      
       foreach (Animation an in objs)
       {
          
           Debug.Log(an.name);

rig.animation.AddClip(an.clip,an.name);

       }
       
       Selection.activeObject=rig;
       
       // bit of clean up
       objs=null;
       rig=null;
       
   }   

}</csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox