I'm assuming you can not simply use a VideoPlayer
component instead and rather load a video than a PNG file for each frame for the same reason I once did: The Alpha Channel.
Anyway importing every frame as PNG file and switching the sprite every frame is very unefficient!
So if it isn't about the alpha chanel anyway just use a VideoPlayer with a video clip and jump to step 3.2. down here using the video file instead of single frames/WebM file.
If the issue is the alpha chanel:
I have found a solution once for having a GIF-like texture but maintaining transparency
requires Adobe MediaEncoder (can be tested free for 30 days).
1. Somewhere get the single images from as PNG
I rendered mine using Blender3D but you can ofcourse use any PNG frames with (or without) transparency.
You seem to have those already anyway. However, the frame files should have a consequent numbered naming like e.g. frame_001.png
, frame_002.png
, etc.
2. Encode the PNG files to a WebM
video format
Install the WebM codec for Adobe Premiere and MediaEncoder
Open the Adobe MediaEncoder
Go to File
->AddSource...

Select the first frame of your animation and make sure PNG file sequence
is enabled.

In the Queue
view click on the current target codec

As format select WebM
(only available after installing the plug-in in step 1.)

in the Image Settings
section you can either adjust the settings or simply click on Match Source

In the Codec Settings
switch to VP8
since Unity doesn't support VP9
(yet?)

You might want to make further adjustments but the most important: Enable Include Alpha Channel

When you think you are done hit Ok
at the bottom of the window

Back in the Queue
view click on the play symbol to start encoding

after finishing and closing Adobe MediaEncoder you will find the result in the same folder your source frames where in

3. Finally use the WebM "GIF" with transparency in Unity
Import the two result files into your Unity Project.
In the Assets
do right-click -> Create -> RenderTexture

Name it and change the size maybe (the rest should be fine.)
Somewhere in you Scene on a manager GameObject have a VideoPlayer
component. You need only one (per gif texture). Here use the imported WebM
file as VideoClip
and the created RenderTexture from step 2. as Target Texture
.
Enable Loop
and (if you want) Play On Awake
(otherwise you'll have to call Play manually.)
Instead of the Image
component use the RawImage
component and as Texture
reference the created RenderTexture
from step 2.

Now you have a transparent GIF animation using your original PNG frames within Unity

Just for the file size difference:
- The single PNG files (I used 24) for me have about 4.5 mb in total
- the WebM file has about 0.5 mb. So this makes it more or less a factor 10 smaller.
Imagine now how much space you might save if you use this instead of 500 PNG files!