forked from autocore-ai/MapToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IconManager.cs
68 lines (63 loc) · 2.05 KB
/
IconManager.cs
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
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace Packages.MapToolbox
{
/// <summary>
/// https://github.com/Thundernerd/Unity3D-IconManager
/// MIT License
/// </summary>
static class IconManager
{
private static MethodInfo setIconForObjectMethodInfo;
public enum LabelIcon
{
Gray,
Blue,
Teal,
Green,
Yellow,
Orange,
Red,
Purple
}
public enum ShapeIcon
{
CircleGray,
CircleBlue,
CircleTeal,
CircleGreen,
CircleYellow,
CircleOrange,
CircleRed,
CirclePurple,
DiamondGray,
DiamondBlue,
DiamondTeal,
DiamondGreen,
DiamondYellow,
DiamondOrange,
DiamondRed,
DiamondPurple
}
public static void SetIcon(this GameObject gameObject, LabelIcon labelIcon) => SetIcon(gameObject, $"sv_label_{(int)labelIcon}");
public static void SetIcon(this GameObject gameObject, ShapeIcon shapeIcon) => SetIcon(gameObject, $"sv_icon_dot{(int)shapeIcon}_pix16_gizmo");
private static void SetIcon(this GameObject gameObject, string contentName)
{
GUIContent iconContent = EditorGUIUtility.IconContent(contentName);
SetIconForObject(gameObject, (Texture2D)iconContent.image);
}
public static void RemoveIcon(this GameObject gameObject) => SetIconForObject(gameObject, null);
public static void SetIconForObject(this GameObject obj, Texture2D icon)
{
if (setIconForObjectMethodInfo == null)
{
Type type = typeof(EditorGUIUtility);
setIconForObjectMethodInfo =
type.GetMethod("SetIconForObject", BindingFlags.Static | BindingFlags.NonPublic);
}
setIconForObjectMethodInfo.Invoke(null, new object[] { obj, icon });
}
}
}