This script was developed in 2021 during the Quadroom game development. It utilizes the Unity Addressables system to load sprites into a SpriteRenderer
from memory.
- Attach the
AddressableSpriteLoader
script to a GameObject in your Unity project. - Assign a sprite asset using the
loadableSpriteAsset
field in the inspector. - Attach a
SpriteRenderer
component to the same GameObject and assign it to thespriteRenderer
field in the inspector.
Make sure to mark the checkbox "Addressable" on the sprites you intend to load using this script.
This function initiates the loading of the sprite from memory. It checks if the necessary fields (loadableSpriteAsset
and spriteRenderer
) are assigned before starting the loading process.
This function unloads the sprite from memory by setting the sprite on the SpriteRenderer
to null
and releasing the handle obtained during loading.
This coroutine handles the asynchronous loading of the sprite asset using Unity's Addressables
system. Once loaded successfully, it sets the sprite on the SpriteRenderer
.