-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRCC_LabelEditor.cs
More file actions
84 lines (70 loc) · 2.03 KB
/
Copy pathRCC_LabelEditor.cs
File metadata and controls
84 lines (70 loc) · 2.03 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
84
//----------------------------------------------
// Realistic Car Controller
//
// Copyright © 2014 - 2017 BoneCracker Games
// http://www.bonecrackergames.com
// Buğra Özdoğanlar
//
//----------------------------------------------
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
public class RCC_LabelEditor {
public enum LabelIcon {
Gray = 0,
Blue,
Teal,
Green,
Yellow,
Orange,
Red,
Purple
}
public enum Icon {
CircleGray = 0,
CircleBlue,
CircleTeal,
CircleGreen,
CircleYellow,
CircleOrange,
CircleRed,
CirclePurple,
DiamondGray,
DiamondBlue,
DiamondTeal,
DiamondGreen,
DiamondYellow,
DiamondOrange,
DiamondRed,
DiamondPurple
}
private static GUIContent[] labelIcons;
private static GUIContent[] largeIcons;
public static void SetIcon( GameObject gObj, LabelIcon icon ) {
if ( labelIcons == null ) {
labelIcons = GetTextures( "sv_label_", string.Empty, 0, 8 );
}
SetIcon( gObj, labelIcons[(int)icon].image as Texture2D );
}
public static void SetIcon( GameObject gObj, Icon icon ) {
if ( largeIcons == null ) {
largeIcons = GetTextures( "sv_icon_dot", "_pix16_gizmo", 0, 16 );
}
SetIcon( gObj, largeIcons[(int)icon].image as Texture2D );
}
private static void SetIcon( GameObject gObj, Texture2D texture ) {
var ty = typeof( EditorGUIUtility );
var mi = ty.GetMethod( "SetIconForObject", BindingFlags.NonPublic | BindingFlags.Static );
mi.Invoke( null, new object[] { gObj, texture } );
}
private static GUIContent[] GetTextures( string baseName, string postFix, int startIndex, int count ) {
GUIContent[] guiContentArray = new GUIContent[count];
var t = typeof( EditorGUIUtility );
var mi = t.GetMethod( "IconContent", BindingFlags.Public | BindingFlags.Static, null, new Type[] { typeof( string ) }, null );
for ( int index = 0; index < count; ++index ) {
guiContentArray[index] = mi.Invoke( null, new object[] { baseName + (object)(startIndex + index) + postFix } ) as GUIContent;
}
return guiContentArray;
}
}