Files
2026-02-21 16:45:37 +08:00

52 lines
1.3 KiB
C#

using System.Collections.Generic;
using UnityEngine;
namespace UltimateWater.Internal
{
public class DefaultTextures : ApplicationSingleton<DefaultTextures>
{
private static readonly Dictionary<Color, Texture2D> _Cache = new Dictionary<Color, Texture2D>();
public static Texture2D Get(Color color)
{
DefaultTextures instance = ApplicationSingleton<DefaultTextures>.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<Color, Texture2D> 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;
}
}
}