From 3493d0019a1bc27f700449da430561bda5fe56c5 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Sun, 18 Aug 2024 12:56:22 -0400 Subject: [PATCH] add a cache dictionary to ShaderID --- MiraAPI/Utilities/ShaderID.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/MiraAPI/Utilities/ShaderID.cs b/MiraAPI/Utilities/ShaderID.cs index 569215f..7b9fb86 100644 --- a/MiraAPI/Utilities/ShaderID.cs +++ b/MiraAPI/Utilities/ShaderID.cs @@ -1,9 +1,24 @@ -using UnityEngine; +using System.Collections.Generic; +using UnityEngine; namespace MiraAPI.Utilities; public static class ShaderID { + private static readonly Dictionary _cache = new(); + + public static int Get(string name) + { + if (_cache.TryGetValue(name, out var id)) + { + return id; + } + + id = Shader.PropertyToID(name); + _cache[name] = id; + return id; + } + // For player shader public static readonly int _BodyColor = Shader.PropertyToID("_BodyColor"); public static readonly int _BackColor = Shader.PropertyToID("_BackColor");