-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObjectColorHex.cs
More file actions
83 lines (69 loc) · 2.06 KB
/
GameObjectColorHex.cs
File metadata and controls
83 lines (69 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using Il2Cpp;
using UnityEngine;
namespace FMF.HexLabelMod;
/// <summary>Shared hex resolution for <see cref="CableSpinner"/> and <see cref="Rack"/> (world + HUD).</summary>
internal static class GameObjectColorHex
{
public static bool TryGetSpinnerHex(CableSpinner spinner, out string hex)
{
hex = null;
var raw = spinner.rgbColor;
if (!string.IsNullOrWhiteSpace(raw) && HexColorUtil.TryNormalizeHex(raw, out hex))
return true;
var material = spinner.cableMaterial;
if (material == null)
return false;
try
{
if (material.HasProperty("_BaseColor"))
{
hex = HexColorUtil.ToHex(material.GetColor("_BaseColor"));
return true;
}
if (material.HasProperty("_Color"))
{
hex = HexColorUtil.ToHex(material.color);
return true;
}
}
catch
{
return false;
}
return false;
}
public static bool TryGetRackHex(Rack rack, out string hex)
{
hex = null;
try
{
var renderers = rack.GetComponentsInChildren<Renderer>(true);
if (renderers == null || renderers.Count == 0)
return false;
for (var i = 0; i < renderers.Count; i++)
{
var renderer = renderers[i];
if (renderer == null)
continue;
var mat = renderer.sharedMaterial;
if (mat == null)
continue;
if (mat.HasProperty("_BaseColor"))
{
hex = HexColorUtil.ToHex(mat.GetColor("_BaseColor"));
return true;
}
if (mat.HasProperty("_Color"))
{
hex = HexColorUtil.ToHex(mat.color);
return true;
}
}
}
catch
{
return false;
}
return false;
}
}