using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; namespace Raindrop.Render { //manages a pool of images :) public static class TempImageManager { static List tempObjects; static TempImageManager() { tempObjects = new List(); } /// /// Call this from some MonoBehaviour in OnDisable to destroy all objects. /// public static void OnDisable() { Clear(); } public static void Clear() { // Destroy all temp objects in the manager for (int i = 0; i < tempObjects.Count; i++) { if (tempObjects[i] == null) continue; Texture2D.Destroy(tempObjects[i]); } tempObjects.Clear(); // clear the list } /// /// Adds a temp object to the manager. /// /// Texture public static void Add(Texture2D obj) { if (obj == null) return; if (tempObjects.Contains(obj)) return; // already in the list tempObjects.Add(obj); // add to list } /// /// Destroys the object and removes it from the manager. /// /// Object public static void Destroy(Texture2D obj) { if (obj == null) return; tempObjects.Remove(obj); // remove from list Texture2D.Destroy(obj); // destroy the object } /// /// Creates a temporary texture and stores it in the manager. /// /// Width of the texture /// Height of the texture /// Texture2D public static Texture2D CreateTexture2D(int width, int height) { Texture2D tex = new Texture2D(width, height); tex.hideFlags = HideFlags.HideAndDontSave; tempObjects.Add(tex); return tex; } } }