9 public static byte ReverseBits(
byte value)
11 return (
byte)((value * 0x0202020202 & 0x010884422010) % 1023);
14 public static int SparsifyBits(
byte value,
int sparse)
17 for (
int bits = 0; bits < 8; bits++, value >>= 1)
19 retVal |= (value & 1);
22 return retVal >> sparse;
25 public static Color EncodeIDAsColor(
int instanceId)
27 var uid = instanceId * 2;
32 (SparsifyBits((
byte)(uid >> 16), 3) << 2) |
33 (SparsifyBits((
byte)(uid >> 8), 3) << 1) |
34 SparsifyBits((
byte)(uid), 3);
37 var r = (byte)(sid >> 8);
38 var g = (byte)(sid >> 16);
42 return new Color32(r, g, b, 255);
45 public static Color EncodeTagAsColor(
string tag)
47 var hash = tag.GetHashCode();
48 var a = (byte)(hash >> 24);
49 var r = (byte)(hash >> 16);
50 var g = (byte)(hash >> 8);
52 return new Color32(r, g, b, a);
55 public static Color EncodeLayerAsColor(
int layer)
65 var uniqueColors =
new Color[] {
66 new Color(1,1,1,1),
new Color(z,z,z,1),
67 new Color(1,1,z,1),
new Color(1,z,1,1),
new Color(z,1,1,1),
68 new Color(1,z,0,1),
new Color(z,0,1,1),
new Color(0,1,z,1),
70 new Color(1,0,0,1),
new Color(0,1,0,1),
new Color(0,0,1,1),
71 new Color(1,1,0,1),
new Color(1,0,1,1),
new Color(0,1,1,1),
72 new Color(1,z,z,1),
new Color(z,1,z,1)
77 var color = uniqueColors[layer % uniqueColors.Length];
78 var divider = 1.0f + Mathf.Floor(layer / uniqueColors.Length);