public enum CardMaterialGroupNameDefine { Bag, DeckGroup, DeckList, Max } public class CardMaterialGroup { private CardMaterialGroupNameDefine m_Define; private Dictionary<string, Material> m_Materials = new Dictionary<string, Material>(); public CardMaterialGroup(CardMaterialGroupNameDefine define) { m_Define = define; } public Material GetMaterial(bool isAi, bool isDark) { string name = (isAi ? "AI" : "Normal") + "_" + (isDark ? "Dard" : "NoDard"); if (m_Materials.TryGetValue(name, out var mat)) { return mat; } var originMat = RK.Mat.GetMaterialInstance(isAi ? AddressablePath.Material.AICardKuangMaterial : AddressablePath.Material.NormalCardKuangMaterial); mat = GameObject.Instantiate(originMat); mat.name = $"{mat.name}_{m_Define.ToString()}_{name}"; m_Materials.Add(name, mat); return mat; } } public class CardMaterialMgr : RK_Singleton<CardMaterialMgr> { private Dictionary<CardMaterialGroupNameDefine, CardMaterialGroup> m_CardMaterialGroupMap = new Dictionary<CardMaterialGroupNameDefine, CardMaterialGroup>(); public CardMaterialMgr() { for (int i = 0; i < (int)CardMaterialGroupNameDefine.Max; i++) { var define = (CardMaterialGroupNameDefine)i; var group = new CardMaterialGroup(define); m_CardMaterialGroupMap.Add(define, group); } } public CardMaterialGroup GetCardMaterialGroup(CardMaterialGroupNameDefine define) { if (m_CardMaterialGroupMap.TryGetValue(define, out var group)) { return group; } return null; } }
通过材质管理 使同一类型状态使用同一个材质,使其符合合批条件或则GUP Instance条件