72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace Terkoiz.MapZoneHighlighter.BoundedBoxes
|
||
|
{
|
||
|
public class ColliderBoundsRenderer : MonoBehaviour
|
||
|
{
|
||
|
private static Material _lineMaterial;
|
||
|
private List<Vector3[,]> _outlines;
|
||
|
private List<Color> _colors;
|
||
|
|
||
|
private void Awake()
|
||
|
{
|
||
|
_outlines = new List<Vector3[,]>();
|
||
|
_colors = new List<Color>();
|
||
|
CreateLineMaterial();
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
_outlines = new List<Vector3[,]>();
|
||
|
_colors = new List<Color>();
|
||
|
}
|
||
|
|
||
|
private static void CreateLineMaterial()
|
||
|
{
|
||
|
if (!_lineMaterial)
|
||
|
{
|
||
|
// _lineMaterial = new Material(@"
|
||
|
// Shader ""Lines/Colored Blended"" {
|
||
|
// SubShader { Pass {
|
||
|
// Blend SrcAlpha OneMinusSrcAlpha
|
||
|
// ZWrite Off Cull Off Fog { Mode Off }
|
||
|
// BindChannels {
|
||
|
// Bind ""vertex"", vertex Bind ""color"", color }
|
||
|
// } } }
|
||
|
// ");
|
||
|
_lineMaterial = new Material(Shader.Find("Hidden/Internal-Colored"));
|
||
|
_lineMaterial.hideFlags = HideFlags.HideAndDontSave;
|
||
|
_lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void OnPostRender()
|
||
|
{
|
||
|
if (_outlines == null) return;
|
||
|
CreateLineMaterial();
|
||
|
_lineMaterial.SetPass(0);
|
||
|
GL.Begin(GL.LINES);
|
||
|
for (int j = 0; j < _outlines.Count; j++)
|
||
|
{
|
||
|
GL.Color(_colors[j]);
|
||
|
for (int i = 0; i < _outlines[j].GetLength(0); i++)
|
||
|
{
|
||
|
GL.Vertex(_outlines[j][i, 0]);
|
||
|
GL.Vertex(_outlines[j][i, 1]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
GL.End();
|
||
|
}
|
||
|
|
||
|
public void SetOutlines(Vector3[,] newOutlines, Color newcolor)
|
||
|
{
|
||
|
if (newOutlines.GetLength(0) > 0)
|
||
|
{
|
||
|
_outlines.Add(newOutlines);
|
||
|
_colors.Add(newcolor);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|