Search Unity

Help needed in creating a custom tool

Discussion in 'Animation' started by Laamato, Feb 23, 2021.

  1. Laamato

    Laamato

    Joined:
    Aug 27, 2017
    Posts:
    6
    Hello everyone!

    I am creating a 2D game. I have hundreds of sprites. Processing everything manually is very time consuming. So I would like to automate this particular section of the workflow. The four steps I'd like to take are:


    1. On import create animation clips from pngs

    2. Create a new animation controller

    3. Assign new clips to this controller

    4. Loop through all of the clips and set the speed to .75f.

    I've done some research on these, but haven't yet been able to figure out the whole picture.

    Regarding 1:
    This is manually done by dragging a selection of sprites into the scene view, which then prompts whether I want to create an animation clip out of these. Am I somehow able to automatically skip this phase?

    I don't know if these help, but they could. I've found these from documentation: ModelImporter and AssetPostProcessor.

    I also found that I can construct an animation clip, but I'm stuck in how to add the sprites here.

    Regarding 2:
    Found this from docs:
    var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath("Assets/Mecanim/StateMachineTransitions.controller");

    Regarding 3:
    This is probably achieved via AddState/AddMotion method?

    Regarding 4:
    Found from docs:

    public class ExampleClass : MonoBehaviour
    {
    public Animation anim;

    void Start()
    {
    anim = GetComponent<Animation>();
    foreach (AnimationState state in anim)
    {
    state.speed = 0.5F;
    }
    }
    }


    Any help regarding to this much appreciated :) !
     
    Last edited: Feb 23, 2021