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;
          }
        }
    }
Ejemplo n.º 2
0
        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 <Sprite> sprites = new List <Sprite>();

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

                    if (reverse)
                    {
                        sprites.Reverse();
                    }

                    if (clean == false)
                    {
                        sprites.InsertRange(0, anim.frames);
                    }

                    anim.frames = sprites.ToArray();

                    EditorUtility.SetDirty(anim);

                    AssetDatabase.SaveAssets();
                    sprites = null;
                }
            }
        }