2020-12-24 15:57:25 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.Utility;
|
|
|
|
|
|
2022-10-09 22:33:51 +00:00
|
|
|
|
[UsedInUnityProject]
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public class ZOverride : MonoBehaviour
|
2020-12-24 15:57:25 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private const string shaderTestMode = "unity_GUIZTestMode";
|
|
|
|
|
private readonly UnityEngine.Rendering.CompareFunction desiredUIComparison = UnityEngine.Rendering.CompareFunction.Always;
|
|
|
|
|
private Graphic[] uiElementsToApplyTo;
|
|
|
|
|
private readonly Dictionary<Material, Material> materialMappings = new();
|
2022-02-27 12:40:44 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
protected virtual void Start()
|
|
|
|
|
{
|
|
|
|
|
uiElementsToApplyTo = gameObject.GetComponentsInChildren<Graphic>();
|
|
|
|
|
foreach (var graphic in uiElementsToApplyTo)
|
2020-12-24 16:05:54 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
var material = graphic.materialForRendering;
|
|
|
|
|
if (material == null)
|
2020-12-24 16:05:54 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
Material materialCopy;
|
|
|
|
|
if (!materialMappings.ContainsKey(material))
|
|
|
|
|
{
|
|
|
|
|
materialCopy = new Material(material);
|
|
|
|
|
materialMappings.Add(material, materialCopy);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
materialCopy = materialMappings[material];
|
2022-02-27 12:40:44 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
|
|
|
|
|
materialCopy.SetInt(shaderTestMode, (int)desiredUIComparison);
|
|
|
|
|
graphic.material = materialCopy;
|
2020-12-24 16:05:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|