-
Notifications
You must be signed in to change notification settings - Fork 0
/
LayerFilter.cs
101 lines (88 loc) · 2.11 KB
/
LayerFilter.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class LayerFilter : EditorWindow
{
Color black = Color.black;
Color white = Color.white;
List<string> layers = new List<string>();
List<Color> colors = new List<Color>();
[MenuItem("Window/LayerFilter")]
static void Init ()
{
LayerFilter window = (LayerFilter)EditorWindow.GetWindow (typeof (LayerFilter));
}
void Awake()
{
for( int i = 0; i < 32; ++i )
{
string layerName = LayerMask.LayerToName(i);
layers.Add(layerName);
colors.Add(Color.white);
}
for( int i = 0; i < 32; i++)
{
Color color = new Color(
EditorPrefs.GetFloat(i + "r", 1.0f),
EditorPrefs.GetFloat(i + "g", 1.0f),
EditorPrefs.GetFloat(i + "b", 1.0f),
EditorPrefs.GetFloat(i + "a", 1.0f));
colors[i] = color;
}
}
void OnDestroy()
{
for( int i = 0; i < 32; i++)
{
Color myColor = colors[i];
EditorPrefs.SetFloat(i + "r", myColor.r);
EditorPrefs.SetFloat(i + "g", myColor.g);
EditorPrefs.SetFloat(i + "b", myColor.b);
EditorPrefs.SetFloat(i + "a", myColor.a);
}
}
void OnGUI()
{
for(int i = 0; i < colors.Count; i++)
{
if(layers[i].Length > 0)
colors[i] = EditorGUILayout.ColorField (layers[i], colors[i]);
}
if(GUILayout.Button("Apply"))
{
Object[] objects = GameObject.FindObjectsOfType(typeof (GameObject));
foreach(Object o in objects)
{
GameObject g = (GameObject) o;
if (g != null)
{
SpriteRenderer sp = (SpriteRenderer) g.GetComponent(typeof(SpriteRenderer));
if(sp)
{
Debug.Log(g);
Debug.Log (g.layer);
Debug.Log(colors[g.layer]);
sp.color = colors[g.layer];
}
}
}
}
if(GUILayout.Button("Clear"))
{
Object[] objects = GameObject.FindObjectsOfType(typeof (GameObject));
foreach(Object o in objects)
{
GameObject g = (GameObject) o;
if (g != null)
{
SpriteRenderer sp = (SpriteRenderer) g.GetComponent(typeof(SpriteRenderer));
if(sp)
{
sp.color = Color.white;
}
}
}
}
}
}