using asap.core; using System.Collections.Generic; using System.Linq; public class RedPointManager { private static RedPointManager instance; public static RedPointManager Instance { get { if (instance == null) { instance = new RedPointManager(); } return instance; } } public void Init() { redPointDic.Clear(); redPointStateDic.Clear(); redPointCountDic.Clear(); } Dictionary redPointDic = new Dictionary(); Dictionary> redPointStateDic = new Dictionary>(); Dictionary redPointCountDic = new Dictionary(); public void AddRedPoint(string key, IUIRedPoint uiRedPoint) { if (redPointDic.ContainsKey(key)) { GameDebug.LogWarning("key is already exist"); } redPointDic[key] = uiRedPoint; } public void RemoveRedPoint(string key) { if (!redPointDic.ContainsKey(key)) { GameDebug.LogWarning("key is not exist"); return; } redPointDic.Remove(key); } public bool GetRedPointState(string key) { if (!redPointStateDic.ContainsKey(key)) { return false; } return redPointStateDic[key].Values.Contains(true); } public int GetRedPointCount(string key) { if (!redPointCountDic.ContainsKey(key)) { return 0; } return redPointCountDic[key]; } public void SetRedPointState(string key, bool state, int count = 0) { if (string.IsNullOrEmpty(key)) { GameDebug.LogError("key is null"); return; } redPointCountDic[key] = count; if (!redPointStateDic.ContainsKey(key)) { redPointStateDic[key] = new Dictionary(); } redPointStateDic[key][key] = state; if (redPointDic.ContainsKey(key)) { redPointDic[key].SetRedPointState(GetRedPointState(key)); } string[] keys = key.Split('.'); if (keys.Length > 1) { string parentKey = keys[0]; for (int i = 0; i < keys.Length - 1; i++) { if (!redPointStateDic.ContainsKey(parentKey)) { redPointStateDic[parentKey] = new Dictionary(); } redPointStateDic[parentKey][parentKey] = state; redPointStateDic[parentKey][parentKey + "." + keys[i + 1]] = state; if (redPointDic.ContainsKey(parentKey)) { redPointDic[parentKey].SetRedPointState(GetRedPointState(parentKey)); } parentKey += "." + keys[i + 1]; } } } }