52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
public class TerrainShaderDebugGUI : MonoBehaviour
|
|
{
|
|
private const int GUIRectWidth = 500;
|
|
|
|
private bool _drawGUI;
|
|
|
|
public Texture2D BlockedTilesMaskTexture { get; set; }
|
|
|
|
public Texture2D CliffsMaskTexture { get; set; }
|
|
|
|
public static TerrainShaderDebugGUI Create()
|
|
{
|
|
return new GameObject(nameof(TerrainShaderDebugGUI)).AddComponent<TerrainShaderDebugGUI>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Keyboard.current.f1Key.wasPressedThisFrame) _drawGUI = !_drawGUI;
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
if (!_drawGUI) return;
|
|
|
|
GUI.color = new Color(1, 1, 1, 0.8f);
|
|
|
|
var x = 0;
|
|
DrawTexture(BlockedTilesMaskTexture, ref x);
|
|
DrawTexture(CliffsMaskTexture, ref x);
|
|
}
|
|
|
|
private void DrawTexture(Texture2D texture, ref int x)
|
|
{
|
|
const int spacing = 10;
|
|
|
|
var oldFilterMode = texture.filterMode;
|
|
texture.filterMode = FilterMode.Point;
|
|
|
|
var aspect = (float)texture.height / texture.width;
|
|
GUI.DrawTexture(new Rect(spacing + x, spacing, GUIRectWidth, GUIRectWidth * aspect), texture, ScaleMode.ScaleToFit, false);
|
|
|
|
texture.filterMode = oldFilterMode;
|
|
|
|
x += GUIRectWidth + spacing;
|
|
}
|
|
}
|
|
} |