using System.Collections.Generic; using UnityEngine; namespace UltimateWater.Internal { public class DefaultTextures : ApplicationSingleton { private static readonly Dictionary _Cache = new Dictionary(); public static Texture2D Get(Color color) { DefaultTextures instance = ApplicationSingleton.Instance; if (instance == null) { return null; } Texture2D value; if (_Cache.TryGetValue(color, out value)) { return value; } value = CreateColorTexure(color, "[UWS] DefaultTextures - " + color); _Cache.Add(color, value); return value; } protected override void OnDestroy() { foreach (KeyValuePair item in _Cache) { item.Value.Destroy(); } _Cache.Clear(); base.OnDestroy(); } private static Texture2D CreateColorTexure(Color color, string name) { Texture2D texture2D = new Texture2D(2, 2, TextureFormat.ARGB32, false); texture2D.name = name; texture2D.hideFlags = HideFlags.DontSave; Texture2D texture2D2 = texture2D; texture2D2.SetPixel(0, 0, color); texture2D2.SetPixel(1, 0, color); texture2D2.SetPixel(0, 1, color); texture2D2.SetPixel(1, 1, color); texture2D2.Apply(false, true); return texture2D2; } } }