-
Notifications
You must be signed in to change notification settings - Fork 0
/
Colorize Object (EditorWindow).cs
68 lines (61 loc) · 1.2 KB
/
Colorize Object (EditorWindow).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 UnityEngine;
using UnityEditor;
public class Colorizer : EditorWindow
{
Color color;
[MenuItem("Window/Colorizer")]
public static void ShowWindow()
{
GetWindow<Colorizer>("Colorizer");
}
void OnGUI()
{
GUILayout.Label("Color the selected objects!", EditorStyles.boldLabel);
color = EditorGUILayout.ColorField("Color", color);
if (GUILayout.Button("COLORIZE!"))
{
Colorize();
}
if (GUILayout.Button("RANDOM COLORIZE!"))
{
GenerateColor();
}
if (GUILayout.Button("RESET COLORIZE!"))
{
Reset();
}
}
void Colorize()
{
foreach (GameObject obj in Selection.gameObjects)
{
Renderer renderer = obj.GetComponent<Renderer>();
if (renderer != null)
{
renderer.sharedMaterial.color = color;
}
}
}
public void GenerateColor()
{
foreach (GameObject obj in Selection.gameObjects)
{
Renderer renderer = obj.GetComponent<Renderer>();
if (renderer != null)
{
renderer.sharedMaterial.color = Random.ColorHSV();
}
}
}
public void Reset()
{
foreach (GameObject obj in Selection.gameObjects)
{
Renderer renderer = obj.GetComponent<Renderer>();
if (renderer != null)
{
renderer.sharedMaterial.color = Color.white;
}
}
}
}