Skip to content

Commit c0a2a6f

Browse files
authored
Create TilemapTransparency.cs
1 parent 8597d01 commit c0a2a6f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

TilemapTransparency.cs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// **************************************************************** //
2+
//
3+
// Copyright (c) RimuruDev. All rights reserved.
4+
// Contact me:
5+
// - Gmail: [email protected]
6+
// - LinkedIn: https://www.linkedin.com/in/rimuru/
7+
// - GitHub: https://github.com/RimuruDev
8+
//
9+
// **************************************************************** //
10+
11+
using UnityEngine;
12+
using UnityEngine.Tilemaps;
13+
14+
namespace AbyssMoth
15+
{
16+
[SelectionBase]
17+
[DisallowMultipleComponent]
18+
[RequireComponent(typeof(Tilemap))]
19+
[HelpURL("https://github.com/RimuruDev/Unity-TilemapTransparency")]
20+
public sealed class TilemapTransparency : MonoBehaviour
21+
{
22+
[field: SerializeField, Range(0f, 1f)] public float Transparency { get; private set; } = 0.5f;
23+
24+
private void OnValidate() =>
25+
UpdateTransparency();
26+
27+
private void UpdateTransparency()
28+
{
29+
var tilemap = GetComponent<Tilemap>();
30+
31+
if (tilemap != null)
32+
tilemap.color = new Color(1f, 1f, 1f, Transparency);
33+
}
34+
35+
#if UNITY_EDITOR
36+
private void OnDrawGizmos() =>
37+
UpdateTransparency();
38+
#endif
39+
}
40+
}

0 commit comments

Comments
 (0)