1
1
using UnityEngine ;
2
2
using UnityEditor ;
3
- using System . Collections ;
4
- using System . Collections . Generic ;
5
3
6
- // TilemapLayerHelper (wip)
4
+ // TilemapLayerHelper
7
5
// Use PageDown/PageUp to select between tilemap layers
8
6
// First assign tileRoot into the editorwindow field and hit GetTileMaps button
9
7
@@ -13,6 +11,7 @@ public class TilemapLayerHelper : EditorWindow
13
11
Transform tileRoot ;
14
12
GameObject [ ] tilemapGos ;
15
13
14
+ bool fadeOtherLayers = false ;
16
15
int selectedLayer = 0 ;
17
16
string [ ] layerNames = new string [ ] { "" } ;
18
17
@@ -55,9 +54,19 @@ void OnGUI()
55
54
i ++ ;
56
55
}
57
56
}
57
+
58
+ GUI . changed = false ;
59
+ fadeOtherLayers = GUILayout . Toggle ( fadeOtherLayers , "Fade other layers" ) ;
60
+
61
+ if ( GUI . changed ) // reset tilemap layer colors
62
+ {
63
+ SetTileMapLayerColors ( ) ;
64
+ }
65
+
58
66
}
59
67
60
68
69
+
61
70
void OnSceneGUI ( SceneView sceneView )
62
71
{
63
72
Event e = Event . current ;
@@ -84,15 +93,35 @@ void OnSceneGUI(SceneView sceneView)
84
93
85
94
86
95
Handles . BeginGUI ( ) ;
96
+
87
97
selectedLayer = GUI . SelectionGrid ( new Rect ( 0 , 32 , 128 , 64 ) , selectedLayer , layerNames , 1 ) ;
98
+
99
+ if ( fadeOtherLayers )
100
+ {
101
+ SetTileMapLayerColors ( ) ;
102
+ }
103
+
88
104
Handles . EndGUI ( ) ;
89
105
}
90
106
107
+ // make non-selected layers semi-transparent
108
+ void SetTileMapLayerColors ( )
109
+ {
110
+ for ( int i = 0 ; i < layerNames . Length ; i ++ )
111
+ {
112
+ if ( i == selectedLayer || ! fadeOtherLayers )
113
+ {
114
+ tilemapGos [ i ] . GetComponent < TileMap > ( ) . color = Color . white ;
115
+ } else {
116
+ tilemapGos [ i ] . GetComponent < TileMap > ( ) . color = Color . white * 0.5f ;
117
+ }
118
+ }
119
+
120
+ }
91
121
92
122
// helpers
93
123
int Wrap ( int i , int i_max )
94
124
{
95
125
return ( ( i % i_max ) + i_max ) % i_max ;
96
126
}
97
-
98
127
}
0 commit comments