mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2024-12-29 03:28:26 +00:00
41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace QSB.Utility;
|
|
|
|
[UsedInUnityProject]
|
|
public class ZOverride : MonoBehaviour
|
|
{
|
|
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();
|
|
|
|
protected virtual void Start()
|
|
{
|
|
uiElementsToApplyTo = gameObject.GetComponentsInChildren<Graphic>();
|
|
foreach (var graphic in uiElementsToApplyTo)
|
|
{
|
|
var material = graphic.materialForRendering;
|
|
if (material == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
Material materialCopy;
|
|
if (!materialMappings.ContainsKey(material))
|
|
{
|
|
materialCopy = new Material(material);
|
|
materialMappings.Add(material, materialCopy);
|
|
}
|
|
else
|
|
{
|
|
materialCopy = materialMappings[material];
|
|
}
|
|
|
|
materialCopy.SetInt(shaderTestMode, (int)desiredUIComparison);
|
|
graphic.material = materialCopy;
|
|
}
|
|
}
|
|
} |