From d69611d66431e28ea35477c6781a00d57ae04fa3 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 7 Apr 2021 21:13:03 +0800 Subject: =?UTF-8?q?*=E5=9B=A0=E4=B8=BA=E6=B2=A1=E6=9C=89meta=EF=BC=8C?= =?UTF-8?q?=E5=AF=BC=E8=87=B4missing=EF=BC=8C=E5=88=A0=E9=99=A4UIEffect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Test/UIEffect/Program/Common/MaterialCache.cs | 77 ---------------------- 1 file changed, 77 deletions(-) delete mode 100644 Assets/Test/UIEffect/Program/Common/MaterialCache.cs (limited to 'Assets/Test/UIEffect/Program/Common/MaterialCache.cs') diff --git a/Assets/Test/UIEffect/Program/Common/MaterialCache.cs b/Assets/Test/UIEffect/Program/Common/MaterialCache.cs deleted file mode 100644 index 8d8ed93..0000000 --- a/Assets/Test/UIEffect/Program/Common/MaterialCache.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System; -using UnityEngine; -using System.Text; -using UnityEngine.UI; - -namespace Coffee.UIEffects -{ - public class MaterialCache - { - static Dictionary materialMap = new Dictionary(); - - private class MaterialEntry - { - public Material material; - public int referenceCount; - - public void Release() - { - if (material) - { - UnityEngine.Object.DestroyImmediate(material, false); - } - - material = null; - } - } - -#if UNITY_EDITOR - [UnityEditor.InitializeOnLoadMethod] - private static void ClearCache() - { - foreach (var entry in materialMap.Values) - { - entry.Release(); - } - - materialMap.Clear(); - } -#endif - - public static Material Register(Material baseMaterial, Hash128 hash, - System.Action onModifyMaterial, Graphic graphic) - { - if (!hash.isValid) return null; - - MaterialEntry entry; - if (!materialMap.TryGetValue(hash, out entry)) - { - entry = new MaterialEntry() - { - material = new Material(baseMaterial) - { - hideFlags = HideFlags.HideAndDontSave, - }, - }; - - onModifyMaterial(entry.material, graphic); - materialMap.Add(hash, entry); - } - - entry.referenceCount++; - return entry.material; - } - - public static void Unregister(Hash128 hash) - { - MaterialEntry entry; - if (!hash.isValid || !materialMap.TryGetValue(hash, out entry)) return; - if (--entry.referenceCount > 0) return; - - entry.Release(); - materialMap.Remove(hash); - } - } -} -- cgit v1.1-26-g67d0