备份CatanBuilding瘦身独立工程
This commit is contained in:
100
Assets/Scripts/UIRedPoint/RedPointManager.cs
Normal file
100
Assets/Scripts/UIRedPoint/RedPointManager.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
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<string, IUIRedPoint> redPointDic = new Dictionary<string, IUIRedPoint>();
|
||||
Dictionary<string, Dictionary<string, bool>> redPointStateDic = new Dictionary<string, Dictionary<string, bool>>();
|
||||
Dictionary<string, int> redPointCountDic = new Dictionary<string, int>();
|
||||
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<string, bool>();
|
||||
}
|
||||
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<string, bool>();
|
||||
}
|
||||
redPointStateDic[parentKey][parentKey] = state;
|
||||
redPointStateDic[parentKey][parentKey + "." + keys[i + 1]] = state;
|
||||
|
||||
if (redPointDic.ContainsKey(parentKey))
|
||||
{
|
||||
redPointDic[parentKey].SetRedPointState(GetRedPointState(parentKey));
|
||||
}
|
||||
parentKey += "." + keys[i + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user