using UnityEngine; namespace BlockSpace.Voxels { public static class Palette { public const int ColorCount = 64; public static readonly Color32[] palette = BuildPalette(); private static readonly Color32 InvisibleCreatorPreviewColor = new Color32(64, 160, byte.MaxValue, 96); public static Color32 GetColor(byte index) { return palette[index & 0x3F]; } public static Color32 GetPreviewColor(byte index, VoxelMaterial material) { return material switch { VoxelMaterial.Transparent => WithAlpha(GetRenderColor(index), 112), VoxelMaterial.Invisible => InvisibleCreatorPreviewColor, _ => WithAlpha(GetRenderColor(index), byte.MaxValue), }; } public static Color32 GetMaterialPreviewColor(byte index, VoxelMaterial material) { return material switch { VoxelMaterial.Transparent => WithAlpha(GetColor(index), 112), VoxelMaterial.Invisible => InvisibleCreatorPreviewColor, _ => WithAlpha(GetColor(index), byte.MaxValue), }; } public static Color32 GetRenderColor(byte index) { return ToRenderColor(GetColor(index)); } private static Color32 WithAlpha(Color32 color, byte alpha) { return new Color32(color.r, color.g, color.b, alpha); } private static Color32 ToRenderColor(Color32 color) { Color linear = ((Color)color).linear; linear.a = (float)(int)color.a / 255f; return linear; } private static Color32[] BuildPalette() { return new Color32[64] { new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue), new Color32(217, 217, 217, byte.MaxValue), new Color32(179, 179, 179, byte.MaxValue), new Color32(140, 140, 140, byte.MaxValue), new Color32(102, 102, 102, byte.MaxValue), new Color32(64, 64, 64, byte.MaxValue), new Color32(31, 31, 31, byte.MaxValue), new Color32(0, 0, 0, byte.MaxValue), new Color32(byte.MaxValue, 225, 225, byte.MaxValue), new Color32(byte.MaxValue, 154, 154, byte.MaxValue), new Color32(byte.MaxValue, 79, 79, byte.MaxValue), new Color32(201, 47, 47, byte.MaxValue), new Color32(122, 31, 31, byte.MaxValue), new Color32(byte.MaxValue, 107, 138, byte.MaxValue), new Color32(217, 58, 99, byte.MaxValue), new Color32(122, 18, 52, byte.MaxValue), new Color32(byte.MaxValue, 224, 184, byte.MaxValue), new Color32(byte.MaxValue, 180, 92, byte.MaxValue), new Color32(240, 122, 36, byte.MaxValue), new Color32(184, 74, 27, byte.MaxValue), new Color32(122, 52, 24, byte.MaxValue), new Color32(201, 138, 74, byte.MaxValue), new Color32(138, 90, 50, byte.MaxValue), new Color32(74, 42, 24, byte.MaxValue), new Color32(byte.MaxValue, 244, 184, byte.MaxValue), new Color32(byte.MaxValue, 224, 102, byte.MaxValue), new Color32(byte.MaxValue, 208, 46, byte.MaxValue), new Color32(201, 154, 22, byte.MaxValue), new Color32(122, 90, 10, byte.MaxValue), new Color32(230, 210, 138, byte.MaxValue), new Color32(184, 164, 90, byte.MaxValue), new Color32(107, 98, 50, byte.MaxValue), new Color32(216, byte.MaxValue, 200, byte.MaxValue), new Color32(157, byte.MaxValue, 122, byte.MaxValue), new Color32(82, 217, 79, byte.MaxValue), new Color32(47, 158, 68, byte.MaxValue), new Color32(31, 95, 42, byte.MaxValue), new Color32(122, 214, 109, byte.MaxValue), new Color32(79, 143, 58, byte.MaxValue), new Color32(42, 74, 31, byte.MaxValue), new Color32(200, byte.MaxValue, byte.MaxValue, byte.MaxValue), new Color32(122, byte.MaxValue, byte.MaxValue, byte.MaxValue), new Color32(54, 207, 224, byte.MaxValue), new Color32(31, 143, 163, byte.MaxValue), new Color32(20, 88, 102, byte.MaxValue), new Color32(138, 199, byte.MaxValue, byte.MaxValue), new Color32(58, 141, byte.MaxValue, byte.MaxValue), new Color32(30, 63, 153, byte.MaxValue), new Color32(230, 209, byte.MaxValue, byte.MaxValue), new Color32(185, 138, byte.MaxValue, byte.MaxValue), new Color32(138, 77, byte.MaxValue, byte.MaxValue), new Color32(90, 43, 184, byte.MaxValue), new Color32(48, 26, 107, byte.MaxValue), new Color32(byte.MaxValue, 184, 240, byte.MaxValue), new Color32(byte.MaxValue, 95, 210, byte.MaxValue), new Color32(158, 38, 122, byte.MaxValue), new Color32(244, 240, 216, byte.MaxValue), new Color32(200, 191, 160, byte.MaxValue), new Color32(143, 130, 102, byte.MaxValue), new Color32(94, 85, 72, byte.MaxValue), new Color32(139, 184, 200, byte.MaxValue), new Color32(95, 120, 144, byte.MaxValue), new Color32(62, 74, 89, byte.MaxValue), new Color32(184, 115, 51, byte.MaxValue) }; } } }