-
Notifications
You must be signed in to change notification settings - Fork 0
/
TilemapTransparency.cs
40 lines (34 loc) · 1.15 KB
/
TilemapTransparency.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
// **************************************************************** //
//
// Copyright (c) RimuruDev. All rights reserved.
// Contact me:
// - Gmail: rimuru.dev@gmail.com
// - LinkedIn: https://www.linkedin.com/in/rimuru/
// - GitHub: https://github.com/RimuruDev
//
// **************************************************************** //
using UnityEngine;
using UnityEngine.Tilemaps;
namespace AbyssMoth
{
[SelectionBase]
[DisallowMultipleComponent]
[RequireComponent(typeof(Tilemap))]
[HelpURL("https://github.com/RimuruDev/Unity-TilemapTransparency")]
public sealed class TilemapTransparency : MonoBehaviour
{
[field: SerializeField, Range(0f, 1f)] public float Transparency { get; private set; } = 0.5f;
private void OnValidate() =>
UpdateTransparency();
private void UpdateTransparency()
{
var tilemap = GetComponent<Tilemap>();
if (tilemap != null)
tilemap.color = new Color(1f, 1f, 1f, Transparency);
}
#if UNITY_EDITOR
private void OnDrawGizmos() =>
UpdateTransparency();
#endif
}
}