Skip to content

Commit ea545d8

Browse files
authored
Update TilemapLayerHelper.cs
1 parent af0656e commit ea545d8

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

Scripts/2D/Tilemaps/Editor/TilemapLayerHelper.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using UnityEngine;
22
using UnityEditor;
3-
using System.Collections;
4-
using System.Collections.Generic;
53

6-
// TilemapLayerHelper (wip)
4+
// TilemapLayerHelper
75
// Use PageDown/PageUp to select between tilemap layers
86
// First assign tileRoot into the editorwindow field and hit GetTileMaps button
97

@@ -13,6 +11,7 @@ public class TilemapLayerHelper : EditorWindow
1311
Transform tileRoot;
1412
GameObject[] tilemapGos;
1513

14+
bool fadeOtherLayers = false;
1615
int selectedLayer = 0;
1716
string[] layerNames = new string[] { "" };
1817

@@ -55,9 +54,19 @@ void OnGUI()
5554
i++;
5655
}
5756
}
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+
5866
}
5967

6068

69+
6170
void OnSceneGUI(SceneView sceneView)
6271
{
6372
Event e = Event.current;
@@ -84,15 +93,35 @@ void OnSceneGUI(SceneView sceneView)
8493

8594

8695
Handles.BeginGUI();
96+
8797
selectedLayer = GUI.SelectionGrid(new Rect(0, 32, 128, 64), selectedLayer, layerNames, 1);
98+
99+
if (fadeOtherLayers)
100+
{
101+
SetTileMapLayerColors();
102+
}
103+
88104
Handles.EndGUI();
89105
}
90106

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+
}
91121

92122
// helpers
93123
int Wrap(int i, int i_max)
94124
{
95125
return ((i % i_max) + i_max) % i_max;
96126
}
97-
98127
}

0 commit comments

Comments
 (0)