152 lines
4.6 KiB
C#
152 lines
4.6 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using GCGame.Table;
|
||
using UnityEngine;
|
||
|
||
// 注:保持这个类型作为数据接口,实际表现在WorldUiRoot中处理
|
||
public class DamageBoardManager : MonoBehaviour
|
||
{
|
||
public static DamageBoardManager damageBoardManager;
|
||
|
||
private readonly Dictionary<string, UIImgFont> _imgFonts = new Dictionary<string, UIImgFont>();
|
||
private readonly List<MyTuple<int, int>> _maxNumberList = new List<MyTuple<int, int>>();
|
||
private readonly Dictionary<int, string> _typeToFont = new Dictionary<int, string>();
|
||
private readonly Dictionary<int, int> m_TypeShowIndex = new Dictionary<int, int>();
|
||
|
||
private bool _init;
|
||
|
||
private void Awake()
|
||
{
|
||
damageBoardManager = this;
|
||
}
|
||
|
||
public static void PreloadDamageBoard()
|
||
{
|
||
if (damageBoardManager != null)
|
||
damageBoardManager.PreloadDamageBoardIns();
|
||
}
|
||
|
||
public UIImgFont GetImgFont(int type)
|
||
{
|
||
UIImgFont result = null;
|
||
string fontName;
|
||
if (_typeToFont.TryGetValue(type, out fontName))
|
||
_imgFonts.TryGetValue(fontName, out result);
|
||
return result;
|
||
}
|
||
|
||
public void AddFont(string assetName, Object resObj, Hashtable table)
|
||
{
|
||
var newObj = resObj as GameObject;
|
||
if (newObj != null)
|
||
{
|
||
var font = newObj.GetComponent<UIImgFont>();
|
||
if (font != null)
|
||
_imgFonts[assetName] = font;
|
||
}
|
||
}
|
||
|
||
private void LoadFont()
|
||
{
|
||
if (!_init)
|
||
{
|
||
_init = true;
|
||
var fontList = new HashSet<string>();
|
||
foreach (var damageTab in TableManager.GetDamageBoardType().Values)
|
||
{
|
||
var fontName = damageTab.FontName;
|
||
if (fontName.Length > 2)
|
||
{
|
||
_typeToFont.Add(damageTab.GetId(), fontName);
|
||
fontList.Add(fontName);
|
||
}
|
||
}
|
||
|
||
foreach (var fontName in fontList)
|
||
LoadAssetBundle.Instance.LoadGameObject(LoadAssetBundle.BUNDLE_PATH_Other,
|
||
fontName, AddFont, null, true);
|
||
}
|
||
}
|
||
|
||
//预加载一些伤害板
|
||
public void PreloadDamageBoardIns()
|
||
{
|
||
LoadFont();
|
||
}
|
||
|
||
public string GetTypeShowIndex(int nType, Tab_DamageBoardType tabDamageBoardType)
|
||
{
|
||
var motionName = string.Empty;
|
||
if (tabDamageBoardType != null)
|
||
{
|
||
int typeIndex;
|
||
var motionCount = tabDamageBoardType.getMotionNameCount();
|
||
if (!m_TypeShowIndex.TryGetValue(nType, out typeIndex))
|
||
typeIndex = 0;
|
||
// 维持原来的自修复逻辑 - typeIndex获取动画失败就自动试图拿下一个类型的动画
|
||
for (var i = 0; i < motionCount; i++)
|
||
{
|
||
var motionIndex = i + typeIndex;
|
||
if (motionIndex > motionCount - 1)
|
||
motionIndex -= motionCount;
|
||
motionName = tabDamageBoardType.GetMotionNamebyIndex(motionIndex);
|
||
if (!string.IsNullOrEmpty(motionName))
|
||
{
|
||
typeIndex = motionIndex;
|
||
break;
|
||
}
|
||
}
|
||
|
||
m_TypeShowIndex[nType] = typeIndex + 1;
|
||
}
|
||
|
||
return motionName;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得DamageBoard的表格数据,仅在所有检查成功才会返回
|
||
/// </summary>
|
||
public Tab_DamageBoardType TryAddDamageBoard(int nType)
|
||
{
|
||
if (damageBoardManager == null)
|
||
{
|
||
return null;
|
||
}
|
||
|
||
Tab_DamageBoardType damageBoardList;
|
||
Tab_DamageBoardType result;
|
||
var dictionary = TableManager.GetDamageBoardType();
|
||
result = dictionary.TryGetValue(nType, out damageBoardList) ? damageBoardList : dictionary[0];
|
||
var record = _maxNumberList.Find(a => a.first == nType);
|
||
if (record == null)
|
||
{
|
||
record = new MyTuple<int, int>(nType, 0);
|
||
_maxNumberList.Add(record);
|
||
}
|
||
|
||
if (record.second >= result.MaxNum)
|
||
result = null;
|
||
else
|
||
record.second++;
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 移除伤害面板最大数目
|
||
/// </summary>
|
||
public void RemoveDamageBoard(int nType)
|
||
{
|
||
var record = _maxNumberList.Find(a => a.first == nType);
|
||
if (record != null)
|
||
record.second = Mathf.Max(0, record.second - 1);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清除全部面板数量统计的记录
|
||
/// </summary>
|
||
public void ClearNumber()
|
||
{
|
||
for (var i = 0; i < _maxNumberList.Count; i++)
|
||
_maxNumberList[i].second = 0;
|
||
}
|
||
} |