2020-12-24 15:57:25 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Utility
|
|
|
|
|
{
|
2021-05-02 08:09:37 +00:00
|
|
|
|
public class ZOverride : MonoBehaviour
|
2020-12-24 16:05:54 +00:00
|
|
|
|
{
|
|
|
|
|
private const string shaderTestMode = "unity_GUIZTestMode";
|
2020-12-24 15:57:25 +00:00
|
|
|
|
private readonly UnityEngine.Rendering.CompareFunction desiredUIComparison = UnityEngine.Rendering.CompareFunction.Always;
|
2020-12-24 16:05:54 +00:00
|
|
|
|
private Graphic[] uiElementsToApplyTo;
|
2021-11-20 19:49:50 +00:00
|
|
|
|
private readonly Dictionary<Material, Material> materialMappings = new();
|
2020-12-24 15:57:25 +00:00
|
|
|
|
|
2020-12-24 16:05:54 +00:00
|
|
|
|
protected virtual void Start()
|
|
|
|
|
{
|
|
|
|
|
uiElementsToApplyTo = gameObject.GetComponentsInChildren<Graphic>();
|
|
|
|
|
foreach (var graphic in uiElementsToApplyTo)
|
|
|
|
|
{
|
|
|
|
|
var material = graphic.materialForRendering;
|
|
|
|
|
if (material == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-06-18 21:38:32 +00:00
|
|
|
|
|
2020-12-24 15:57:25 +00:00
|
|
|
|
Material materialCopy;
|
|
|
|
|
if (!materialMappings.ContainsKey(material))
|
2020-12-24 16:05:54 +00:00
|
|
|
|
{
|
|
|
|
|
materialCopy = new Material(material);
|
|
|
|
|
materialMappings.Add(material, materialCopy);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
materialCopy = materialMappings[material];
|
|
|
|
|
}
|
2021-06-18 21:38:32 +00:00
|
|
|
|
|
2020-12-24 16:05:54 +00:00
|
|
|
|
materialCopy.SetInt(shaderTestMode, (int)desiredUIComparison);
|
|
|
|
|
graphic.material = materialCopy;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-24 15:57:25 +00:00
|
|
|
|
}
|