AddSelectedAnimationsToRig

From Unify Community Wiki
Jump to: navigation, search

Author: Jeff Murray (psychicparrot)

Description

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

Usage

1. Place this script in YourProject/Assets/Editor and a menu item will automatically appear in the Custom menu after it is compiled.

2. First, make sure that your rig has no animations applied to it already (that was the part I couldn't figure out how to automate- if anyone finds out how to do this please let me know!)

3. Select all your animations in the project pane.

4. Open this wizard from the Custom menu.

5. Select a rig to apply them to from the drop down or drag and drop it in.

6. Hit the button.

7. Boom! You're done!

C# - AddSelectedAnimationsToRig.cs

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)
        {			
			rig.animation.AddClip(an.clip,an.clip.name);        
        }
 
        Selection.activeObject=rig;
 
        // bit of clean up
        objs=null;
        rig=null;   
    }   
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Tools