public static void AutoFillAnimation(SimpleAnimation anim, bool reverse = false, bool clean = true)
    {
        if (anim.allowAutoUpdate)
        {
          string path = AssetDatabase.GetAssetPath(anim.GetInstanceID());

          // Get the directory
          string dir = Path.GetDirectoryName(path);

          if (Directory.Exists(dir))
          {
        // List all sprites from the dir
        List<Texture> sprites = new List<Texture>();

        if(clean == false)
        {
          sprites.AddRange(anim.frames);
        }

        foreach (string file in Directory.GetFiles(dir))
        {
          foreach (var asset in AssetDatabase.LoadAllAssetsAtPath(file))
          {
            if (asset is Texture)
            {
              // Add them to the anim
              sprites.Add(asset as Texture);
            }
          }
        }

        if(reverse == false)
        {
          anim.frames = sprites.ToArray();
        }
        else
        {
          sprites.Reverse();
          anim.frames = sprites.ToArray();
        }

        EditorUtility.SetDirty(anim);

        AssetDatabase.SaveAssets();
        sprites = null;
          }
        }
    }
    void Awake()
    {
        render = GetComponent<Renderer>();

        defaultAnimationSaved = defaultAnimation;
    }
    /// <summary>
    /// Change the default animation
    /// </summary>
    /// <param name="p"></param>
    public void SetDefault(string name)
    {
        defaultAnimationSaved = defaultAnimation;

        var anims = Find(name);
        if (anims.Length > 0)
        {
          defaultAnimation = anims[Random.Range(0, anims.Length)]; ;

          if (debugMode)
          {
        Debug.Log("ANIMATION - New default: " + name + " " + defaultAnimation);
          }
        }
        else
        {
          Debug.LogError("Missing animation \"" + name + "\", can't set as default! " + this);
        }
    }
    /// <summary>
    /// Set the default animation back
    /// </summary>
    public void RestoreDefault()
    {
        defaultAnimation = defaultAnimationSaved;

        if (debugMode)
        {
          Debug.Log("ANIMATION - Restore default: " + defaultAnimation.name + " " + defaultAnimation);
        }
    }
    /// <summary>
    /// Play animation
    /// </summary>
    /// <param name="anim"></param>
    public void Play(SimpleAnimation anim, bool reset)
    {
        if (this.enabled == false) return;

        if (currentAnimation != anim)
        {
          currentAnimation = anim;
          Reset();
        }
        else if (currentAnimation == anim && reset)
        {
          Reset();
        }
        else
        {
          // Already playing the right animation
          return;
        }

        if (debugMode)
        {
          Debug.Log("ANIMATION - Playing animation \"" + currentAnimation + "\" (" + currentAnimation.Duration + " sec)");
        }

        if (currentAnimation.frames.Length == 0)
        {
          Debug.LogWarning("Empty animation (no frames): " + anim.name + " " + anim);
          currentAnimation = null;
        }
    }
 void OnEnable()
 {
     anim = target as SimpleAnimation;
 }