BattleFlyWordMgr.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System;
  5. public enum FONT_TYPE
  6. {
  7. GREEN_FONT = 1, //绿色数值
  8. RED_FONT = 2, //红色数值
  9. WHITE_FONT = 3, //白色数值
  10. YELLOW_FONT = 4, //黄色数值
  11. SP_FONT = 5, //蓝量颜色
  12. }
  13. //数字飘字类型
  14. public enum DIGIT_TYPE
  15. {
  16. Invalid,
  17. AttackHurt, //普通伤害
  18. CritHurt, //暴击伤害
  19. MultiSkillHurtMerge, //多段伤害的技能的累积伤害
  20. Heal, //治疗
  21. PlayerHurt, //玩家伤害
  22. PlayerMultiSkillHurtMerget, //玩家多段伤害的技能的累积伤害
  23. ChangeSP, //蓝量变化
  24. };
  25. //其他文本飘字内容
  26. public enum enOtherFloatTextContent
  27. {
  28. Absorb, //吸收
  29. Missing, //被致盲,普攻miss
  30. AdditiveEffect, //增益效果
  31. NegativeEffect, //减益效果
  32. };
  33. public enum RESTRICT_TYPE
  34. {
  35. None = 0, // 无
  36. Dizzy = 1,
  37. SlowDown = 2,
  38. Taunt = 3,
  39. Fear = 4,
  40. Frozen = 5,
  41. Floating = 6,
  42. Slient = 7,
  43. Stone = 8,
  44. }
  45. //飘字信息
  46. public struct stFloatText
  47. {
  48. public int m_floatTextSequence;
  49. public Vector3 m_worldPosition;
  50. };
  51. public struct FloatDigitInfo
  52. {
  53. public Fighter attacker;
  54. public Fighter target;
  55. public DIGIT_TYPE digitType;
  56. public int value;
  57. public int buffId;
  58. public float showTime;
  59. public bool tweenAlpha;
  60. public bool lastHurt;
  61. public FloatDigitInfo(Fighter attacker, Fighter target, int buffId, DIGIT_TYPE digitType, int value, float showTime,bool tweenAlpha,bool lastHurt)
  62. {
  63. this.attacker = attacker;
  64. this.target = target;
  65. this.buffId = buffId;
  66. this.digitType = digitType;
  67. this.value = value;
  68. this.showTime = showTime;
  69. this.tweenAlpha = tweenAlpha;
  70. this.lastHurt = lastHurt;
  71. }
  72. public void Dispose()
  73. {
  74. this.attacker = null;
  75. this.target = null;
  76. }
  77. }
  78. //延迟飘字 角色ID(角色唯一ID * 10 + 敌我方)
  79. public class DelayFlyWord
  80. {
  81. public const float m_c_fDelayTime = 0.5f;
  82. private long m_nId = 0;
  83. private float m_fCurTime = 0.0f;
  84. private enOtherFloatTextContent m_enTextCon;
  85. private Queue<string> mQueueDelayShowWord = new Queue<string>();
  86. private void RefreshTime()
  87. {
  88. if (mQueueDelayShowWord.Count <= 0)
  89. m_fCurTime = 0.0f;
  90. }
  91. //添加
  92. public void AddDelayShowWord(long nId,enOtherFloatTextContent EnTextContent,string strinfo)
  93. {
  94. m_nId = nId;
  95. m_enTextCon = EnTextContent;
  96. if (null == mQueueDelayShowWord)
  97. mQueueDelayShowWord = new Queue<string>();
  98. //RefreshTime(); 初次 没有延迟
  99. mQueueDelayShowWord.Enqueue(strinfo);
  100. }
  101. //处理
  102. public bool ProcessDelayShowWord(out long nID,out enOtherFloatTextContent enContent,out string strInfo)
  103. {
  104. strInfo = string.Empty;
  105. nID = m_nId;
  106. enContent = m_enTextCon;
  107. m_fCurTime -= Time.deltaTime;
  108. if (m_fCurTime <= 0)
  109. {
  110. m_fCurTime = 0.0f;
  111. }
  112. if (null != mQueueDelayShowWord && mQueueDelayShowWord.Count > 0)
  113. {
  114. if(m_fCurTime <= 0)
  115. {
  116. strInfo = mQueueDelayShowWord.Dequeue();
  117. m_fCurTime = m_c_fDelayTime;
  118. return true;
  119. }
  120. }
  121. return false;
  122. }
  123. public void ClearDelayShowWord()
  124. {
  125. m_nId = 0;
  126. if (null != mQueueDelayShowWord)
  127. {
  128. mQueueDelayShowWord.Clear();
  129. mQueueDelayShowWord = null;
  130. }
  131. }
  132. }
  133. public class BattleFlyWordMgr : SingletonMono<BattleFlyWordMgr>
  134. {
  135. public const int c_max_battleFlyWordNum = 50;
  136. public const string white_font_prefix = "number_w_";
  137. public const string yellow_font_prefix = "number_y_";
  138. public const string red_font_prefix = "number_r_";
  139. public const string green_font_prefix = "number_g_";
  140. const string FLOAT_TEXT_PREFAB = "Battle/FloatText";
  141. const string FLOAT_BUFF_TEXT_PREFAB = "Battle/FloatBuffText";
  142. const uint DEFAULT_FONT_SIZE = 6;
  143. private static string[][] s_battleFloatDigitAnimatorStates = new string[][]
  144. {
  145. new string[]{""},
  146. new string[]{ "Hurt_Left", "Hurt_Right"},
  147. new string[]{ "Hurt_Left", "Hurt_Right"},
  148. new string[]{ "SkillMergeHurt01","SkillMergeHurt01" },
  149. new string[]{ "Heal_Up","Heal_Up" },
  150. new string[]{ "HurtPlayer_Left", "HurtPlayer_Right" },
  151. new string[]{ "SkillMergeHurtPlayer01","SkillMergeHurtPlayer01" },
  152. new string[]{ "Heal_Up","Heal_Up" },
  153. };
  154. bool bLoaded = false;
  155. bool bLoaded3d = false;
  156. private List<FloatDigitInfo> mFloatDigitInfoList;
  157. private List<BattleFloatTextComponent> mFloatTextComList = new List<BattleFloatTextComponent>();
  158. private List<BattleFloatBuffText> mFloatBuffTextComList = new List<BattleFloatBuffText>();
  159. private Dictionary<long, DelayFlyWord> mDicDelayShowWord = new Dictionary<long, DelayFlyWord>();
  160. private GameObject mHud = null;
  161. private Canvas mHudCanvas = null;
  162. private GameObject mFloatTextRoot = null;
  163. public GameObject HudRoot
  164. {
  165. get { return mHud; }
  166. }
  167. public Transform HudRootTrans
  168. {
  169. get { return mHud!=null?mHud.transform:null; }
  170. }
  171. public bool Loaded
  172. {
  173. get { return bLoaded && bLoaded3d; }
  174. }
  175. public int FloatTextCnt
  176. {
  177. get { return mFloatTextComList.Count; }
  178. }
  179. public override void InitMgr()
  180. {
  181. base.InitMgr();
  182. Init();
  183. EventMgr.AddEventListener<UIEventParamFighterHurt>(ECoreEventType.EID_FIGHTER_HURT, OnFighterHurt);
  184. EventMgr.AddEventListener<object[]>(ECoreEventType.EID_FIGHTER_HEAL, OnFighterHeal);
  185. EventMgr.AddEventListener<Fighter>(ECoreEventType.EID_FIGHTER_DODGE, OnFighterMissing);
  186. EventMgr.AddEventListener<Fighter,int>(ECoreEventType.EID_SHIELD_ABSORT_HURT, OnShowShieldHurt);
  187. EventMgr.AddEventListener<Fighter,string>(ECoreEventType.EID_ADD_FUNCTION, OnAddFunction);
  188. EventMgr.AddEventListener<Fighter, string>(ECoreEventType.EID_NEGATIVE_FUNCTION, OnNegativeFunction);
  189. EventMgr.AddEventListener<Fighter,int>(ECoreEventType.EID_Fighter_AddSp, OnFighterChangeSp);
  190. }
  191. private void Init()
  192. {
  193. mHud = new GameObject("HudRoot");
  194. mHud.transform.SetParent(UIMgr.Instance.UIBattleRootTrans);
  195. RectTransform rt = mHud.AddComponent<RectTransform>();
  196. rt.anchorMin = Vector2.zero;
  197. rt.anchorMax = Vector2.one;
  198. rt.anchoredPosition3D = Vector3.zero;
  199. rt.offsetMin = rt.offsetMax = Vector2.zero;
  200. rt.localScale = Vector3.one;
  201. mHudCanvas = mHud.AddComponent<Canvas>();
  202. mHudCanvas.overrideSorting = true;
  203. mHudCanvas.sortingOrder = 0;
  204. mHud.layer = LayerMask.NameToLayer("UI");
  205. }
  206. protected override void Dispose()
  207. {
  208. EventMgr.RemoveEventListener<UIEventParamFighterHurt>(ECoreEventType.EID_FIGHTER_HURT, OnFighterHurt);
  209. EventMgr.RemoveEventListener<object[]>(ECoreEventType.EID_FIGHTER_HEAL, OnFighterHeal);
  210. EventMgr.RemoveEventListener<Fighter>(ECoreEventType.EID_FIGHTER_DODGE, OnFighterMissing);
  211. EventMgr.RemoveEventListener<Fighter, int>(ECoreEventType.EID_SHIELD_ABSORT_HURT, OnShowShieldHurt);
  212. EventMgr.RemoveEventListener<Fighter,string>(ECoreEventType.EID_ADD_FUNCTION, OnAddFunction);
  213. EventMgr.RemoveEventListener<Fighter, string>(ECoreEventType.EID_NEGATIVE_FUNCTION, OnNegativeFunction);
  214. EventMgr.RemoveEventListener<Fighter,int>(ECoreEventType.EID_Fighter_AddSp, OnFighterChangeSp);
  215. Clear();
  216. base.Dispose();
  217. }
  218. ///---------------------------------------------延迟显示
  219. private void AddDelayShowWord(long nFighterId, enOtherFloatTextContent EnTextContent, string strinfo)
  220. {
  221. if (null == mDicDelayShowWord)
  222. mDicDelayShowWord = new Dictionary<long, DelayFlyWord>();
  223. bool bIsFinde = mDicDelayShowWord.ContainsKey(nFighterId);
  224. if(!bIsFinde)
  225. {
  226. DelayFlyWord pDelayWord = new DelayFlyWord();
  227. mDicDelayShowWord.Add(nFighterId,pDelayWord);
  228. }
  229. mDicDelayShowWord[nFighterId].AddDelayShowWord(nFighterId, EnTextContent, strinfo);
  230. }
  231. private void ClearDelayShowWord()
  232. {
  233. if (null != mDicDelayShowWord)
  234. {
  235. var etr = mDicDelayShowWord.GetEnumerator();
  236. while (etr.MoveNext())
  237. {
  238. etr.Current.Value.ClearDelayShowWord();
  239. }
  240. mDicDelayShowWord.Clear();
  241. mDicDelayShowWord = null;
  242. }
  243. }
  244. private void ProcessDelayShowWord()
  245. {
  246. if (null != mDicDelayShowWord)
  247. {
  248. var etr = mDicDelayShowWord.GetEnumerator();
  249. while (etr.MoveNext())
  250. {
  251. long nFighterId = 0;
  252. string strInfo = string.Empty;
  253. enOtherFloatTextContent enContent;
  254. bool bIsProcess = etr.Current.Value.ProcessDelayShowWord(out nFighterId,out enContent,out strInfo);
  255. if(bIsProcess)
  256. {
  257. if(null != BattleMgr.Instance.Battle)
  258. {
  259. long nId = nFighterId / 10;
  260. long nSide = nFighterId - nId * 10;
  261. Fighter pFighter = BattleMgr.Instance.Battle.FighterMgr.GetFighterByID(nId, (eTeamType)nSide);
  262. if(null == pFighter)
  263. {
  264. continue;
  265. }
  266. CreateBattleFunctionText(pFighter, enContent, strInfo);
  267. }
  268. }
  269. }
  270. }
  271. }
  272. //-----------------------------------------延迟显示end
  273. public void StartLoad()
  274. {
  275. //
  276. bLoaded = false;
  277. bLoaded3d = true;
  278. string[] assetNames = new string[] { FighterHPBar.HUD_HERO_PREFAB, FLOAT_TEXT_PREFAB, FLOAT_BUFF_TEXT_PREFAB, SkillName2D.HUD_SKILLNAME_PREFAB, RageEffect2D.HUD_RAGE_PREFAB, BattleDropMgr.drop_gold_prefab_name,BattleDropMgr.drop_exp_prefab_name ,BattleDropMgr.drop_partnerexp_prefab_name,BattleDropMgr.drop_item_prefab_name,BattleDropMgr.drop_jobexp_prefab_name };
  279. ResourceMgr.Instance.LoadAsset<List<GameObject>>(OnLoadFlyWordCompleted, Constants.UIPath, assetNames);
  280. //string[] assetNamesFor3D = new string[] { BattleDropMgr.drop_prefab_name};
  281. //ResourceMgr.Instance.LoadAsset<List<GameObject>>(OnLoad3DFlyWordCompleted, Constants.ModelPath, assetNamesFor3D);
  282. }
  283. public void SetHudVisible(bool vis,int recoverTime = 0)
  284. {
  285. if(mHudCanvas != null)
  286. {
  287. mHudCanvas.enabled = vis;
  288. }
  289. if(recoverTime > 0 )
  290. {
  291. TimerManager.Instance.AddTimer(recoverTime, 1, OnRecoverVis);
  292. }
  293. }
  294. void OnRecoverVis(int seq)
  295. {
  296. if(mHudCanvas != null)
  297. {
  298. mHudCanvas.enabled = !mHudCanvas.enabled;
  299. }
  300. }
  301. public void Clear()
  302. {
  303. bLoaded = false;
  304. bLoaded3d = false;
  305. if (mFloatDigitInfoList != null)
  306. {
  307. for(int idx =0; idx < mFloatDigitInfoList.Count;idx++)
  308. {
  309. mFloatDigitInfoList[idx].Dispose();
  310. }
  311. mFloatDigitInfoList.Clear();
  312. }
  313. if(mFloatTextComList!=null)
  314. {
  315. for(int idx =0; idx < mFloatTextComList.Count;idx++)
  316. {
  317. BattleFloatTextComponent com = mFloatTextComList[idx];
  318. if (com == null) continue;
  319. ResourceMgr.Instance.RecycleGO(Constants.UIPath, FLOAT_TEXT_PREFAB, com.transform.parent.gameObject);
  320. com.Dispose();
  321. }
  322. mFloatTextComList.Clear();
  323. }
  324. if(removeList!=null)
  325. {
  326. for(int idx =0; idx < removeList.Count;idx++)
  327. {
  328. removeList[idx].Destroy();
  329. }
  330. removeList.Clear();
  331. }
  332. if(mFloatBuffTextComList!=null)
  333. {
  334. for (int idx = 0; idx < mFloatBuffTextComList.Count; idx++)
  335. {
  336. BattleFloatBuffText com = mFloatBuffTextComList[idx];
  337. if (com == null) continue;
  338. ResourceMgr.Instance.RecycleGO(Constants.UIPath, FLOAT_BUFF_TEXT_PREFAB, com.transform.parent.gameObject);
  339. com.Dispose();
  340. }
  341. mFloatBuffTextComList.Clear();
  342. }
  343. ClearDelayShowWord();
  344. }
  345. void OnLoadFlyWordCompleted(List<GameObject> prefabs, string assetPath, params string[] assetName)
  346. {
  347. bLoaded = true;
  348. PrecacheGo();
  349. }
  350. void OnLoad3DFlyWordCompleted(List<GameObject> prefabs, string assetPath, params string[] assetName)
  351. {
  352. bLoaded3d = true;
  353. }
  354. void PrecacheGo()
  355. {
  356. ResourceMgr.Instance.SetGoPoolMaxCacheNum(Constants.UIPath, FLOAT_TEXT_PREFAB, c_max_battleFlyWordNum);
  357. ResourceMgr.Instance.SetGoPoolMaxCacheNum(Constants.UIPath, FLOAT_BUFF_TEXT_PREFAB, c_max_battleFlyWordNum);
  358. for (int idx = 0; idx < c_max_battleFlyWordNum; idx++)
  359. {
  360. GameObject go = ResourceMgr.Instance.GetGoFromPool(Constants.UIPath, FLOAT_TEXT_PREFAB);
  361. if (go != null)
  362. {
  363. ResourceMgr.Instance.RecycleGO(Constants.UIPath, FLOAT_TEXT_PREFAB, go);
  364. }
  365. }
  366. for (int idx = 0; idx < c_max_battleFlyWordNum; idx++)
  367. {
  368. GameObject go = ResourceMgr.Instance.GetGoFromPool(Constants.UIPath, FLOAT_BUFF_TEXT_PREFAB);
  369. if (go != null)
  370. {
  371. ResourceMgr.Instance.RecycleGO(Constants.UIPath, FLOAT_BUFF_TEXT_PREFAB, go);
  372. }
  373. }
  374. BattleDropMgr.Instance.PrecacheGo();
  375. }
  376. private void OnFighterMissing(CoreEvent<Fighter> ce)
  377. {
  378. CreateBattleFunctionText(ce.Data, enOtherFloatTextContent.Missing);
  379. }
  380. private void OnShowShieldHurt(CoreEvent<Fighter,int> ce)
  381. {
  382. CreateBattleFunctionText(ce.Data, enOtherFloatTextContent.Absorb,"",ce.Data1);
  383. }
  384. private void OnAddFunction(CoreEvent<Fighter,string> ce)
  385. {
  386. long nId = ce.Data.Id * 10 + (int)ce.Data.TeamSide;
  387. AddDelayShowWord(nId, enOtherFloatTextContent.AdditiveEffect, ce.Data1);
  388. //CreateBattleFunctionText(ce.Data, enOtherFloatTextContent.AdditiveEffect,ce.Data1);
  389. }
  390. private void OnNegativeFunction(CoreEvent<Fighter,string> ce)
  391. {
  392. long nId = ce.Data.Id * 10 + (int)ce.Data.TeamSide;
  393. AddDelayShowWord(nId, enOtherFloatTextContent.NegativeEffect, ce.Data1);
  394. //CreateBattleFunctionText(ce.Data, enOtherFloatTextContent.NegativeEffect, ce.Data1);
  395. }
  396. private void OnFighterHeal(CoreEvent<object[]> ce)
  397. {
  398. object[] data = ce.Data;
  399. Fighter fighter = (Fighter)data[0];
  400. int healVal = (int)data[1];
  401. DIGIT_TYPE digitType = DIGIT_TYPE.Heal;
  402. CollectFloatDigitInSingleFrame(fighter, fighter, 0, digitType, healVal, 1.0f,true);
  403. }
  404. private void OnFighterChangeSp(CoreEvent<Fighter,int> ce)
  405. {
  406. Fighter f = ce.Data;
  407. CollectFloatDigitInSingleFrame(f, f, 0, DIGIT_TYPE.ChangeSP, ce.Data1, 1.0f, true);
  408. }
  409. private void OnFighterHurt(CoreEvent<UIEventParamFighterHurt> ce)
  410. {
  411. UIEventParamFighterHurt param = ce.Data;
  412. Fighter caster = param.mCaster;
  413. Fighter target = param.mTarget;
  414. bool isCrit = param.mIsCrit;
  415. int isMultiSkill = param.mMultiSkillNum;
  416. int buffId = param.mBuffId;
  417. int killSeq = param.mAttackSeq;
  418. int lastDamage = param.mLastDamage;
  419. DIGIT_TYPE digitType = DIGIT_TYPE.AttackHurt;
  420. bool createMulitiSkillHurt = false;
  421. if(isCrit && (isMultiSkill<=1) && target.Actor.IsNpc)
  422. {
  423. digitType = DIGIT_TYPE.CritHurt;
  424. }else if (isMultiSkill>1) {
  425. createMulitiSkillHurt = true;
  426. }
  427. if((digitType == DIGIT_TYPE.AttackHurt || digitType == DIGIT_TYPE.CritHurt) && target!=null && target.IsPlayer)
  428. {
  429. digitType = DIGIT_TYPE.PlayerHurt;
  430. }
  431. CollectFloatDigitInSingleFrame(caster,target, buffId, digitType, param.mHurtVal,1.0f,true);
  432. if (createMulitiSkillHurt)
  433. {
  434. //DebugHelper.LogError("killSeq:" + killSeq + " multiSkill:" + isMultiSkill);
  435. float showTime = (killSeq == isMultiSkill)? 2: param.mMultiKillInterval;
  436. if(target.TeamSide == 0)
  437. {
  438. CollectFloatDigitInSingleFrame(caster, target, buffId, DIGIT_TYPE.PlayerMultiSkillHurtMerget, param.mHurtVal + lastDamage, showTime, killSeq == isMultiSkill, killSeq == isMultiSkill);
  439. }
  440. else
  441. {
  442. CollectFloatDigitInSingleFrame(caster, target, buffId, DIGIT_TYPE.MultiSkillHurtMerge, param.mHurtVal + lastDamage, showTime, killSeq == isMultiSkill, killSeq == isMultiSkill);
  443. }
  444. }
  445. }
  446. /// <summary>
  447. /// 用于判断两个飘字类型是否可以合并为一个暴击的飘字类型
  448. /// </summary>
  449. /// <param name="type1"></param>
  450. /// <param name="type2"></param>
  451. /// <returns></returns>
  452. private bool CanMergeToCritText(ref DIGIT_TYPE type1, DIGIT_TYPE type2)
  453. {
  454. if (type1 == DIGIT_TYPE.AttackHurt && type2 == DIGIT_TYPE.AttackHurt)
  455. {
  456. if (type1 < type2)
  457. {
  458. type1 = type2;
  459. }
  460. return true;
  461. }
  462. else
  463. {
  464. return false;
  465. }
  466. }
  467. /// <summary>
  468. /// 合并同一帧中的伤害飘字
  469. /// </summary>
  470. /// <param name="attacker">攻击者</param>
  471. /// <param name="target">受击目标</param>
  472. /// <param name="digitType">飘字类型</param>
  473. /// <param name="value">飘字数值</param>
  474. public void CollectFloatDigitInSingleFrame(Fighter attacker, Fighter target, int buffId, DIGIT_TYPE digitType, int value, float showTime, bool lastHurt, bool tweenAlpha=true)
  475. {
  476. if (mFloatDigitInfoList == null)
  477. {
  478. mFloatDigitInfoList = new List<FloatDigitInfo>();
  479. }
  480. //低端机
  481. if (FloatTextCnt>= c_max_battleFlyWordNum)
  482. {
  483. return;
  484. }
  485. FloatDigitInfo tempInfo = new FloatDigitInfo(attacker, target, buffId, digitType, value,showTime, tweenAlpha, lastHurt);
  486. mFloatDigitInfoList.Add(tempInfo);
  487. }
  488. /// <summary>
  489. /// 显示上一帧合并起来的伤害飘字
  490. /// </summary>
  491. private void updateFloatDigitInLastFrame()
  492. {
  493. if (mFloatDigitInfoList == null || mFloatDigitInfoList.Count == 0)
  494. {
  495. return;
  496. }
  497. for (int i = 0; i < mFloatDigitInfoList.Count; i++)
  498. {
  499. FloatDigitInfo infoNode = mFloatDigitInfoList[i];
  500. if (infoNode.attacker == null || infoNode.target == null)
  501. {
  502. continue;
  503. }
  504. Vector3 targetPos = infoNode.target.Position;
  505. Vector3 attackerPos = infoNode.attacker.Position;
  506. //往左飘
  507. if (Vector3.Cross(targetPos, attackerPos).y > 0)
  508. {
  509. CreateBattleFloatDigit(infoNode, 1);
  510. }
  511. else
  512. {
  513. CreateBattleFloatDigit(infoNode, 0);
  514. }
  515. }
  516. mFloatDigitInfoList.Clear();
  517. }
  518. BattleFloatTextComponent FindFloatTextCom(FloatDigitInfo info)
  519. {
  520. for(int idx =0; idx < mFloatTextComList.Count; idx++)
  521. {
  522. BattleFloatTextComponent com = mFloatTextComList[idx];
  523. if (com.CanMerge(info))
  524. return com;
  525. }
  526. return null;
  527. }
  528. //--------------------------------------------------
  529. /// 创建数字飘字
  530. /// @digitValue
  531. /// @digitType
  532. /// @worldPosition
  533. /// @animatIndex 动画数组下标
  534. //--------------------------------------------------
  535. public void CreateBattleFloatDigit(FloatDigitInfo info,int animatIndex)
  536. {
  537. // Fighter caster, Fighter target,int skillId, int digitValue, DIGIT_TYPE digitType,
  538. string[] animatorStates = s_battleFloatDigitAnimatorStates[(int)info.digitType];
  539. if (animatorStates.Length <= 0 || animatIndex < 0 || animatIndex >= animatorStates.Length)
  540. {
  541. return;
  542. }
  543. string animName = animatorStates[animatIndex];
  544. if(info.digitType == DIGIT_TYPE.MultiSkillHurtMerge && info.lastHurt)
  545. {
  546. animName = "SkillMergeHurt_Up";
  547. }else if(info.digitType == DIGIT_TYPE.PlayerMultiSkillHurtMerget && info.lastHurt)
  548. {
  549. animName = "SkillMergeHurtPlayer_Up";
  550. }
  551. CreateBattleFloatText(info, animName );
  552. }
  553. //--------------------------------------------------
  554. /// 创建战斗飘字
  555. /// @digitObject
  556. /// @worldPosition
  557. //--------------------------------------------------
  558. private void CreateBattleFloatText(FloatDigitInfo info,string animatorState)
  559. {
  560. if (string.IsNullOrEmpty(animatorState))
  561. {
  562. return;
  563. }
  564. GameObject digit = ResourceMgr.Instance.GetGoFromPool(Constants.UIPath, FLOAT_TEXT_PREFAB);
  565. if (digit == null) return;
  566. //digit.name = info.target!=null?"floattext_"+info.target.Name+"_"+info.digitType: "floattext_unknown";
  567. BattleFloatTextComponent component = digit.GetComponentInChildren<BattleFloatTextComponent>();
  568. if (digit == null)
  569. {
  570. return;
  571. }
  572. if (null == CameraMgr.Instance.UICamera)
  573. {
  574. ResourceMgr.Instance.RecycleGO(Constants.UIPath, FLOAT_TEXT_PREFAB, digit);
  575. return;
  576. }
  577. digit.transform.SetParent(HudRootTrans);
  578. digit.transform.localScale = Vector3.one;
  579. digit.transform.localRotation = Quaternion.identity;
  580. RectTransform rt = digit.GetComponent<RectTransform>();
  581. rt.anchorMin = Vector2.zero;
  582. rt.anchorMax = Vector2.one;
  583. rt.anchoredPosition3D = Vector3.zero;
  584. rt.offsetMin = rt.offsetMax = Vector2.zero;
  585. //Canvas hudCanvas = digit.GetComponent<Canvas>();
  586. //hudCanvas.overrideSorting = true;
  587. //hudCanvas.sortingOrder = 0;
  588. FONT_TYPE fontType = FONT_TYPE.WHITE_FONT;
  589. if(info.digitType == DIGIT_TYPE.Heal)
  590. {
  591. fontType = FONT_TYPE.GREEN_FONT;
  592. }else if(info.digitType == DIGIT_TYPE.ChangeSP)
  593. {
  594. fontType = FONT_TYPE.SP_FONT;
  595. }
  596. else
  597. {
  598. if (info.target!=null && info.target.IsTeamMember)
  599. {
  600. fontType = FONT_TYPE.RED_FONT;
  601. }
  602. else
  603. {
  604. if (info.digitType == DIGIT_TYPE.CritHurt ||
  605. info.digitType == DIGIT_TYPE.MultiSkillHurtMerge ||
  606. info.digitType == DIGIT_TYPE.PlayerMultiSkillHurtMerget)
  607. {
  608. fontType = FONT_TYPE.YELLOW_FONT;
  609. }
  610. }
  611. }
  612. component.ShowHurt(info.attacker,info.target,info.buffId, info.value, info.digitType,fontType, info.showTime,info.tweenAlpha);
  613. Animator animator = component.anim;
  614. if (animator != null && animator.gameObject.activeInHierarchy)
  615. {
  616. animator.Play(animatorState);
  617. }
  618. mFloatTextComList.Add(component);
  619. }
  620. private void CreateBattleFunctionText(Fighter target, enOtherFloatTextContent type, string icon = "",float hurt = 0)
  621. {
  622. //if (!target.IsHero) return;
  623. GameObject digit = ResourceMgr.Instance.GetGoFromPool(Constants.UIPath, FLOAT_BUFF_TEXT_PREFAB);
  624. if (digit == null)
  625. {
  626. return;
  627. }
  628. digit.name = target != null ? GetFloatTextName(type) +"_"+ target.Name : "floattext_unknown";
  629. BattleFloatBuffText component = digit.GetComponentInChildren<BattleFloatBuffText>();
  630. if (null == CameraMgr.Instance.UICamera)
  631. {
  632. ResourceMgr.Instance.RecycleGO(Constants.UIPath, FLOAT_TEXT_PREFAB, digit);
  633. return;
  634. }
  635. digit.transform.SetParent(mHud.transform);
  636. digit.transform.localScale = Vector3.one;
  637. digit.transform.localRotation = Quaternion.identity;
  638. RectTransform rt = digit.GetComponent<RectTransform>();
  639. rt.anchorMin = Vector2.zero;
  640. rt.anchorMax = Vector2.one;
  641. rt.anchoredPosition3D = Vector3.zero;
  642. rt.offsetMin = rt.offsetMax = Vector2.zero;
  643. //Canvas hudCanvas = digit.GetComponent<Canvas>();
  644. //hudCanvas.overrideSorting = true;
  645. //hudCanvas.sortingOrder = 0;
  646. if(type == enOtherFloatTextContent.Absorb)
  647. {
  648. component.ShowShield(target,hurt);
  649. }else if(type == enOtherFloatTextContent.Missing)
  650. {
  651. component.ShowMissing(target);
  652. }
  653. else
  654. {
  655. component.ShowBuffText(target,icon, type == enOtherFloatTextContent.AdditiveEffect);
  656. }
  657. mFloatBuffTextComList.Add(component);
  658. }
  659. private string GetFloatTextName(enOtherFloatTextContent type)
  660. {
  661. switch(type)
  662. {
  663. case enOtherFloatTextContent.Absorb:
  664. return "Shield";
  665. case enOtherFloatTextContent.Missing:
  666. return "Missing";
  667. case enOtherFloatTextContent.AdditiveEffect:
  668. case enOtherFloatTextContent.NegativeEffect:
  669. return "Function";
  670. }
  671. return "";
  672. }
  673. //--------------------------------------------------
  674. /// 清理所有飘字
  675. //--------------------------------------------------
  676. public void ClearAllBattleFloatText()
  677. {
  678. if (mFloatDigitInfoList != null)
  679. {
  680. mFloatDigitInfoList.Clear();
  681. }
  682. if(mFloatBuffTextComList != null)
  683. {
  684. mFloatBuffTextComList.Clear();
  685. }
  686. }
  687. public void LateUpdate()
  688. {
  689. ProcessDelayShowWord();//延迟飘字
  690. updateFloatDigitInLastFrame();
  691. checkFloatCompleted();
  692. UpdateBufffFloat();
  693. }
  694. List<BattleFloatTextComponent> removeList = new List<BattleFloatTextComponent>();
  695. void checkFloatCompleted()
  696. {
  697. for(int idx =0; idx < mFloatTextComList.Count;idx++)
  698. {
  699. BattleFloatTextComponent com = mFloatTextComList[idx];
  700. if (com.CheckTime())
  701. {
  702. removeList.Add(com);
  703. }
  704. }
  705. for(int idx =0; idx < removeList.Count; idx++)
  706. {
  707. BattleFloatTextComponent com = removeList[idx];
  708. ResourceMgr.Instance.RecycleGO(Constants.UIPath, FLOAT_TEXT_PREFAB, com.transform.parent.gameObject);
  709. mFloatTextComList.Remove(com);
  710. com.Dispose();
  711. }
  712. removeList.Clear();
  713. }
  714. void UpdateBufffFloat()
  715. {
  716. for(int idx = mFloatBuffTextComList.Count-1; idx>=0;idx--)
  717. {
  718. var com = mFloatBuffTextComList[idx];
  719. if (com.Finished)
  720. {
  721. ResourceMgr.Instance.RecycleGO(Constants.UIPath, FLOAT_BUFF_TEXT_PREFAB, com.transform.parent.gameObject);
  722. mFloatBuffTextComList.Remove(com);
  723. com.Dispose();
  724. }
  725. }
  726. }
  727. }