DressUpObj.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using System;
  4. using System.Linq;
  5. using ET;
  6. using FairyGUI;
  7. using ProtoBuf.Meta;
  8. namespace GFGGame
  9. {
  10. public enum DressUpOption
  11. {
  12. Auto,
  13. Add,
  14. Remove
  15. }
  16. //用于换装对象的数据存储和方法封装
  17. public class DressUpObj
  18. {
  19. public int bgId
  20. {
  21. get
  22. {
  23. return _dressUpData.bgId;
  24. }
  25. }
  26. public int suitId
  27. {
  28. get
  29. {
  30. return _dressUpData.suitId;
  31. }
  32. }
  33. public int actionId
  34. {
  35. get
  36. {
  37. return _dressUpData.actionId;
  38. }
  39. }
  40. public bool IsAction
  41. {
  42. get
  43. {
  44. return _dressUpData.actionId > 0;
  45. }
  46. }
  47. public List<int> itemList
  48. {
  49. get
  50. {
  51. return _dressUpData.itemList.ToList();
  52. }
  53. }
  54. private Action onUpdateAction;
  55. /// <summary>
  56. ///
  57. /// </summary>
  58. /// <param name="sceneObj"></param>
  59. /// <param name="needSetMask"></param>
  60. /// <param name="showSceneType"></param>
  61. /// <param name="roleObj"></param>
  62. /// <param name="showBg"></param>
  63. /// <param name="resetData">是否重置装备数据</param>
  64. public void setSceneObj(GameObject sceneObj, bool needSetMask = false, bool showSceneType = true, GameObject roleObj = null, bool showBg = true, Action onUpdateAction = null)
  65. {
  66. if (_sceneObj != null && _sceneObj != sceneObj)
  67. {
  68. PrefabManager.Instance.Restore(_sceneObj);
  69. }
  70. _sceneObj = sceneObj;
  71. _needSetMask = needSetMask;
  72. _showSceneType = showSceneType;
  73. _showBg = showBg;
  74. _roleObj = roleObj;
  75. this.onUpdateAction = onUpdateAction;
  76. if (_dressUpData.IsNew)
  77. {
  78. PutOnDefaultDressUpData(_showBg);
  79. }
  80. else
  81. {
  82. var tempData = DressUpDataClone();
  83. TakeOffAll(false);
  84. PutOnDressUpData(tempData);
  85. }
  86. Timers.inst.AddUpdate(OnUpdate);
  87. }
  88. public DressUpData DressUpDataClone()
  89. {
  90. return _dressUpData.Clone();
  91. }
  92. public void Dispose()
  93. {
  94. _sceneObj = null;
  95. _dressUpData = null;
  96. Timers.inst.Remove(OnUpdate);
  97. foreach (var t in handlers)
  98. {
  99. t.Release();
  100. }
  101. onUpdateAction = null;
  102. }
  103. private void ClearView()
  104. {
  105. Timers.inst.Remove(OnUpdate);
  106. foreach (var t in handlers)
  107. {
  108. t.Cancel();
  109. t.Release();
  110. }
  111. }
  112. //传入一个服装部件Id,判断是否有与此部件同类型服装已穿着
  113. public bool CheckSameTypeIsOn(int itemId)
  114. {
  115. int subType = ItemUtilCS.GetItemSubType(itemId);
  116. for (int i = 0; i < _dressUpData.itemList.Count; i++)
  117. {
  118. int _subType = ItemUtilCS.GetItemSubType(_dressUpData.itemList[i]);
  119. if (subType == _subType) return true;
  120. }
  121. return false;
  122. }
  123. /// <summary>
  124. /// 仅判断换装部件是否已穿着
  125. /// </summary>
  126. /// <param name="itemId"></param>
  127. /// <returns></returns>
  128. public bool CheckDressUpItemIsOn(int itemId)
  129. {
  130. if (itemId == _dressUpData.bgId)
  131. {
  132. return true;
  133. }
  134. return _dressUpData.itemList.Contains(itemId);
  135. }
  136. /// <summary>
  137. /// 仅判断套装是否穿上
  138. /// </summary>
  139. /// <param name="id"></param>
  140. /// <returns></returns>
  141. public bool CheckSuitIsOn(int id)
  142. {
  143. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(id);
  144. if (suitCfg == null)
  145. {
  146. return false;
  147. }
  148. int[] items = suitCfg.partsArr;
  149. foreach (int itemId in items)
  150. {
  151. if (_dressUpData.actionId == id)
  152. {
  153. if (SuitCfgArray.Instance.CheckActionContainsItem(itemId, id))
  154. {
  155. continue;
  156. }
  157. }
  158. bool isOn = CheckDressUpItemIsOn(itemId);
  159. if (!isOn)
  160. {
  161. return false;
  162. }
  163. }
  164. return true;
  165. }
  166. public void AddOrRemove(int itemId, bool checkDefault, DressUpOption dressUpOption = DressUpOption.Auto)
  167. {
  168. int subType = ItemUtilCS.GetItemSubType(itemId);
  169. if (subType == ConstDressUpItemType.BEI_JING)
  170. {
  171. if (!_showBg)
  172. {
  173. return;
  174. }
  175. _dressUpData.bgId = itemId;
  176. List<DressUpLayerOperation> handlers = DressUpUtil.AddItemAsync(_dressUpData.bgId, _sceneObj, _needSetMask, true, _roleObj);
  177. TryAddHandlers(handlers);
  178. }
  179. else
  180. {
  181. if (!CheckDressUpItemIsOn(itemId))
  182. {
  183. if (dressUpOption != DressUpOption.Remove)
  184. {
  185. if (checkDefault)
  186. {
  187. TryCancelActionWhenPutOn(itemId);
  188. }
  189. CheckRemoveSameType(subType);
  190. Add(itemId);
  191. }
  192. }
  193. else
  194. {
  195. if (dressUpOption != DressUpOption.Add)
  196. {
  197. Remove(itemId);
  198. }
  199. }
  200. if (checkDefault)
  201. {
  202. checkDefaultItem();
  203. }
  204. }
  205. }
  206. //脱掉所有换装,换成默认装(不处理背景)
  207. public void TakeOffAll(bool checkDefault = true)
  208. {
  209. if(_sceneObj == null)
  210. {
  211. return;
  212. }
  213. _dressUpData.suitId = 0;
  214. _dressUpData.actionId = 0;
  215. foreach (int itemID in itemList)
  216. {
  217. AddOrRemove(itemID, false, DressUpOption.Remove);
  218. }
  219. if (checkDefault)
  220. {
  221. checkDefaultItem();
  222. }
  223. RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  224. // FightDataManager.Instance.score = roleLevelCfg.baseScore;
  225. // foreach (int itemId in _dressUpData.itemList)
  226. // {
  227. // FightDataManager.Instance.score += ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags);
  228. // }
  229. }
  230. //穿上或脱掉一个动作
  231. public void PutOnOrTakeOffAction(int actionId)
  232. {
  233. if (_dressUpData.actionId == actionId)
  234. {
  235. CancelAction();
  236. }
  237. else
  238. {
  239. PutOnAction(actionId);
  240. }
  241. }
  242. /// <summary>
  243. /// 尝试穿戴配置套装
  244. /// </summary>
  245. /// <param name="suitId">套装id</param>
  246. /// <param name="tryShowAction">尝试穿上动作</param>
  247. /// <param name="excludeType">排除类型列表</param>
  248. /// <param name="showOptional">是否显示可选部件</param>
  249. /// <param name="CheckOwn">是否只显示主角拥有的部件</param>
  250. public void PutOnSuitCfg(int suitId, bool tryShowAction, int[] excludeType = null, bool showOptional = true, bool CheckOwn = true,bool isDress = false)
  251. {
  252. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  253. if(suitCfg == null)
  254. {
  255. return;
  256. }
  257. bool oldIsAction = IsAction;
  258. _dressUpData.suitId = suitId;
  259. bool hasSuitActionRes = DressUpMenuSuitDataManager.CheckSuitHasActionRes(_dressUpData.suitId);
  260. _dressUpData.actionId = (hasSuitActionRes && tryShowAction) ? suitId : 0;
  261. //找到要穿的散件
  262. List<int> targetItemList = DressUpUtil.GetSuitItems(suitId, IsAction, excludeType, showOptional, CheckOwn, isDress);
  263. CompareAndAddItemList(oldIsAction, IsAction, targetItemList);
  264. checkDefaultItem();
  265. }
  266. /// <summary>
  267. /// 取消动作,默认直接脱下
  268. /// </summary>
  269. /// <param name="changeToStand">转换成站立动作</param>
  270. /// <param name="excludeType">转换成站立动作时排除一些类型不穿</param>
  271. public void CancelAction(bool changeToStand = false, int[] excludeType = null)
  272. {
  273. if (_dressUpData.actionId <= 0)
  274. {
  275. return;
  276. }
  277. var tempActionId = _dressUpData.actionId;
  278. _dressUpData.actionId = 0;
  279. //更新非场景类型部件形态
  280. foreach (int itemId in itemList)
  281. {
  282. if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId))
  283. {
  284. //场景类型不受动作影响并且本来就有动画,对非场景类型处理
  285. bool notInAction = SuitCfgArray.Instance.CheckItemNotInAction(itemId);
  286. if (notInAction)
  287. {
  288. //更新成图片模式
  289. Update(itemId);
  290. }
  291. }
  292. }
  293. if (changeToStand)
  294. {
  295. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(tempActionId);
  296. List<int> items = new List<int>(suitCfg.partsArr);
  297. if (suitCfg.partsOptionalArr != null && suitCfg.partsOptionalArr.Length > 0)
  298. {
  299. items.AddRange(suitCfg.partsOptionalArr);
  300. }
  301. foreach (int itemId in items)
  302. {
  303. if (DressUpMenuItemDataManager.CheckHasItem(itemId))
  304. {
  305. bool notInAction = SuitCfgArray.Instance.CheckItemNotInAction(itemId);
  306. if (!notInAction)
  307. {
  308. int subType = ItemDataManager.GetItemSubType(itemId);
  309. if (excludeType == null || Array.IndexOf(excludeType, subType) < 0)
  310. {
  311. AddOrRemove(itemId, false, DressUpOption.Add);
  312. }
  313. }
  314. }
  315. }
  316. }
  317. checkDefaultItem();
  318. }
  319. //穿戴一组换装数据
  320. public void PutOnDressUpData(DressUpData targetDressUpData, int[] excludeType = null)
  321. {
  322. bool oldIsAction = IsAction;
  323. _dressUpData.suitId = targetDressUpData.suitId;
  324. _dressUpData.actionId = targetDressUpData.actionId;
  325. var targetItemList = new List<int>();
  326. foreach(var itemId in targetDressUpData.itemList)
  327. {
  328. int subType = ItemUtilCS.GetItemSubType(itemId);
  329. if (excludeType == null || Array.IndexOf(excludeType, subType) < 0)
  330. {
  331. targetItemList.Add(itemId);
  332. }
  333. }
  334. if (targetDressUpData.bgId > 0 && (excludeType == null || Array.IndexOf(excludeType, ConstDressUpItemType.BEI_JING) < 0))
  335. {
  336. targetItemList.Add(targetDressUpData.bgId);
  337. }
  338. CompareAndAddItemList(oldIsAction, IsAction, targetItemList);
  339. checkDefaultItem();
  340. }
  341. //穿戴默认换装数据
  342. public void PutOnDefaultDressUpData(bool bgType = false)
  343. {
  344. var dressUpData = DressUpData.CreateDefault();
  345. if (bgType) {
  346. dressUpData.bgId = 180002;
  347. }
  348. PutOnDressUpData(dressUpData);
  349. }
  350. //穿戴一组散件数据(会脱掉不包含的部分)
  351. public void PutOnItemList(List<int> targetItemList)
  352. {
  353. bool oldIsAction = IsAction;
  354. _dressUpData.suitId = 0;
  355. _dressUpData.actionId = 0;
  356. CompareAndAddItemList(oldIsAction, IsAction, targetItemList);
  357. checkDefaultItem();
  358. }
  359. #region private
  360. private GameObject _sceneObj;
  361. private GameObject _roleObj;
  362. private bool _needSetMask;
  363. private bool _showSceneType = true;
  364. private bool _showBg = true;
  365. private DressUpData _dressUpData = new DressUpData();
  366. private List<DressUpOperationBase> handlers = new List<DressUpOperationBase>();
  367. //穿上一个动作
  368. private void PutOnAction(int actionId)
  369. {
  370. bool hasSuitActionRes = DressUpMenuSuitDataManager.CheckSuitHasActionRes(actionId);
  371. _dressUpData.actionId = actionId;
  372. if (hasSuitActionRes)
  373. {
  374. foreach (int itemId in itemList)
  375. {
  376. if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId))
  377. {
  378. //场景类型不受动作影响并且本来就有动画,对非场景类型处理
  379. bool notInAction = SuitCfgArray.Instance.CheckItemNotInAction(itemId);
  380. if (notInAction)
  381. {
  382. //更新成动画模式
  383. Update(itemId);
  384. }
  385. else
  386. {
  387. AddOrRemove(itemId, false, DressUpOption.Remove);
  388. }
  389. }
  390. }
  391. }
  392. else
  393. {
  394. CancelAction(true);
  395. }
  396. checkDefaultItem();
  397. }
  398. //当穿一件部件时检查是否需要取消动作,如果需要则取消该动作
  399. private void TryCancelActionWhenPutOn(int itemId)
  400. {
  401. if (_dressUpData.actionId > 0)
  402. {
  403. bool replaceableByAction = SuitCfgArray.Instance.CheckItemReaplaceableOnAction(itemId, _dressUpData.actionId);
  404. if (!replaceableByAction)
  405. {
  406. CancelAction();
  407. _dressUpData.actionId = 0;
  408. }
  409. }
  410. }
  411. private void Add(int itemId)
  412. {
  413. if (!_showSceneType)
  414. {
  415. if (DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId))
  416. {
  417. return;
  418. }
  419. }
  420. if (!_dressUpData.itemList.Contains(itemId))
  421. {
  422. _dressUpData.itemList.Add(itemId);
  423. Update(itemId);
  424. }
  425. }
  426. private void Update(int itemId)
  427. {
  428. bool showAni = IsAction || DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId);
  429. var handlers = DressUpUtil.AddItemAsync(itemId, _sceneObj, _needSetMask, showAni, _roleObj);
  430. TryAddHandlers(handlers);
  431. }
  432. private void Remove(int itemId)
  433. {
  434. if (_dressUpData.itemList == null)
  435. {
  436. return;
  437. }
  438. if (_dressUpData.itemList.Contains(itemId))
  439. {
  440. _dressUpData.itemList.Remove(itemId);
  441. var handler = DressUpUtil.RemoveItemAsync(itemId, _sceneObj, _roleObj);
  442. TryAddHandler(handler);
  443. }
  444. }
  445. private void CheckRemoveSameType(int subType)
  446. {
  447. ItemTypeCfg itemTypeCfg = ItemTypeCfgArray.Instance.GetCfg(subType);
  448. int count = 0;
  449. int firstTeshuId = 0;
  450. int maxNum = 1;
  451. if(itemTypeCfg != null && itemTypeCfg.maxNum > 0)
  452. {
  453. maxNum = itemTypeCfg.maxNum;
  454. }
  455. else if(subType > ConstDressUpItemType.TE_SHU)
  456. {
  457. maxNum = 3;
  458. }
  459. for (int i = 0; i < _dressUpData.itemList.Count; i++)
  460. {
  461. int itemID = (int)_dressUpData.itemList[i];
  462. int itemSubType = ItemUtilCS.GetItemSubType(itemID);
  463. bool isSameType = false;
  464. if(itemTypeCfg != null && itemTypeCfg.maxNum > 0)
  465. {
  466. if(itemSubType == subType)
  467. {
  468. isSameType = true;
  469. }
  470. }
  471. else if (subType > ConstDressUpItemType.TE_SHU && itemSubType > ConstDressUpItemType.TE_SHU)
  472. {
  473. isSameType = true;
  474. }
  475. else if (itemSubType == subType
  476. || (subType == ConstDressUpItemType.LIAN_YI_QUN && (itemSubType == ConstDressUpItemType.SHANG_YI || itemSubType == ConstDressUpItemType.XIA_ZHUANG || itemSubType == ConstDressUpItemType.NEI_DA))
  477. || (subType == ConstDressUpItemType.SHANG_YI && itemSubType == ConstDressUpItemType.LIAN_YI_QUN)
  478. || (subType == ConstDressUpItemType.XIA_ZHUANG && itemSubType == ConstDressUpItemType.LIAN_YI_QUN)
  479. || (subType == ConstDressUpItemType.NEI_DA && itemSubType == ConstDressUpItemType.LIAN_YI_QUN))
  480. {
  481. Remove(itemID);
  482. i--;
  483. }
  484. if (isSameType)
  485. {
  486. if (count == 0)
  487. {
  488. firstTeshuId = itemID;
  489. }
  490. count++;
  491. }
  492. }
  493. if (count >= maxNum)
  494. {
  495. //超出允许的件数会顶掉第一件
  496. Remove(firstTeshuId);
  497. }
  498. }
  499. //与身上的散件对比差异然后添加
  500. private void CompareAndAddItemList(bool oldIsAction, bool newIsAction, List<int> targetItemList)
  501. {
  502. bool actionStatusChanged = (oldIsAction && !newIsAction) || (!oldIsAction && newIsAction);
  503. foreach (int itemID in itemList)
  504. {
  505. if (!targetItemList.Contains(itemID))
  506. {
  507. //移除不穿的部件
  508. AddOrRemove(itemID, false, DressUpOption.Remove);
  509. }
  510. else if (actionStatusChanged)
  511. {
  512. //当动画形态切换时
  513. if (!DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemID))
  514. {
  515. //非场景类型重穿
  516. Update(itemID);
  517. targetItemList.Remove(itemID);
  518. }
  519. }
  520. }
  521. foreach (int itemID in targetItemList)
  522. {
  523. AddOrRemove(itemID, false, DressUpOption.Add);
  524. }
  525. }
  526. //检测当前穿戴是否是一件完整套装,且只穿了一件套装,返回套装id
  527. private int CheckCurDressIsSuit()
  528. {
  529. var suitId = 0;
  530. var suitIdList = new List<int>();
  531. for (int i = 0; i < _dressUpData.itemList.Count; i++)
  532. {
  533. int itemSuitId = SuitCfgArray.Instance.GetSuitIdOfItem(_dressUpData.itemList[i]);
  534. if (!suitIdList.Contains(itemSuitId))
  535. {
  536. suitIdList.Add(itemSuitId);
  537. }
  538. }
  539. foreach (var itemSuitId in suitIdList)
  540. {
  541. if (CheckSuitIsOn(itemSuitId))
  542. {
  543. suitId = itemSuitId;
  544. break;
  545. }
  546. }
  547. _dressUpData.suitId = suitId;
  548. return _dressUpData.suitId;
  549. }
  550. private void checkDefaultItem()
  551. {
  552. //是否有头发
  553. bool hasFaXing = false;
  554. //检查默认资源
  555. //是否有连衣裙
  556. int itemIdLianYiQun = 0;
  557. //是否有内搭
  558. bool hasNeiDa = false;
  559. //是否有上衣
  560. bool hasShangYi = false;
  561. //是否有下装
  562. bool hasXiaZhuang = false;
  563. //是否有默认内搭
  564. bool hasNeiDaDefault = false;
  565. //是否有默认下装
  566. bool hasXiaZhuangDefault = false;
  567. //是否有妆容
  568. bool hasZhuangRong = false;
  569. for (int i = 0; i < _dressUpData.itemList.Count; i++)
  570. {
  571. int itemID = (int)_dressUpData.itemList[i];
  572. int subType = ItemUtilCS.GetItemSubType(itemID);
  573. if (subType == (int)ConstDressUpItemType.FA_XING)
  574. {
  575. hasFaXing = true;
  576. }
  577. else if (subType == ConstDressUpItemType.LIAN_YI_QUN)
  578. {
  579. itemIdLianYiQun = itemID;
  580. }
  581. else if (subType == ConstDressUpItemType.NEI_DA)
  582. {
  583. hasNeiDa = true;
  584. }
  585. else if (subType == ConstDressUpItemType.XIA_ZHUANG)
  586. {
  587. hasXiaZhuang = true;
  588. }
  589. else if (subType == ConstDressUpItemType.SHANG_YI)
  590. {
  591. hasShangYi = true;
  592. }
  593. else if (subType == ConstDressUpItemType.ZHUANG_RONG)
  594. {
  595. hasZhuangRong = true;
  596. }
  597. if (itemID == ConstItemID.DEFULT_NEI_DA)
  598. {
  599. hasNeiDaDefault = true;
  600. }
  601. else if (itemID == ConstItemID.DEFULT_XIA_ZHUANG)
  602. {
  603. hasXiaZhuangDefault = true;
  604. }
  605. }
  606. if (!hasFaXing)
  607. {
  608. Add(ConstItemID.DEFULT_FA_XING);
  609. }
  610. if (!IsAction)
  611. {
  612. if (itemIdLianYiQun <= 0)
  613. {
  614. if (!hasShangYi && (!hasNeiDa || hasNeiDaDefault) && (!hasXiaZhuang || hasXiaZhuangDefault))
  615. {
  616. Remove(ConstItemID.DEFULT_XIA_ZHUANG);
  617. Remove(ConstItemID.DEFULT_NEI_DA);
  618. Add(ConstItemID.DEFULT_LIAN_YI_QUN);
  619. }
  620. //else
  621. //{
  622. // if (!hasXiaZhuang)
  623. // {
  624. // Add(ConstItemID.DEFULT_XIA_ZHUANG);
  625. // }
  626. // if (!hasNeiDa)
  627. // {
  628. // Add(ConstItemID.DEFULT_NEI_DA);
  629. // }
  630. //}
  631. }
  632. }
  633. CheckCurDressIsSuit();
  634. var handler = DressUpUtil.UpdateHeadAsync(!hasZhuangRong, _sceneObj, _needSetMask, _roleObj);
  635. TryAddHandler(handler);
  636. UpdateBodyView(itemIdLianYiQun);
  637. }
  638. //更新整个身体
  639. private void UpdateBodyView(int itemIdLianYiQun)
  640. {
  641. string actionRes = null;
  642. if (IsAction)
  643. {
  644. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_dressUpData.actionId);
  645. var hasAniRes = ResPathUtil.CheckDressUpAnimationResExist(suitCfg.aniRes);
  646. actionRes = hasAniRes ? suitCfg.aniRes : null;
  647. }
  648. var handler = DressUpUtil.UpdateBodyAsync(actionRes, _sceneObj, _needSetMask, _roleObj, itemIdLianYiQun);
  649. TryAddHandler(handler);
  650. }
  651. //遍历各部件操作器,检查状态并统一处理
  652. private void OnUpdate(object param = null)
  653. {
  654. if(_sceneObj == null)
  655. {
  656. ClearView();
  657. return;
  658. }
  659. if(handlers != null && handlers.Count > 0)
  660. {
  661. bool draw = true;
  662. foreach(var handler in handlers)
  663. {
  664. if(!handler.IsDone)
  665. {
  666. draw = false;
  667. }
  668. }
  669. if(draw)
  670. {
  671. var t = handlers.ToArray();
  672. handlers.Clear();
  673. foreach (var handler in t)
  674. {
  675. if(handler.Status == YooAsset.EOperationStatus.Succeed)
  676. {
  677. handler.UpdateView();
  678. }
  679. handler.Release();
  680. }
  681. onUpdateAction?.Invoke();
  682. //LogUtil.LogEditor($"draw {TimeHelper.ClientNow()}");
  683. }
  684. }
  685. }
  686. private void TryAddHandlers(List<DressUpLayerOperation> t)
  687. {
  688. if (t != null)
  689. {
  690. foreach(var h in t)
  691. {
  692. TryAddHandler(h);
  693. }
  694. //this.handlers.AddRange(t);
  695. }
  696. }
  697. private void TryAddHandler(DressUpOperationBase t)
  698. {
  699. if (t != null)
  700. {
  701. var len = handlers.Count;
  702. for (var i = len - 1; i >= 0; i--)
  703. {
  704. var h = handlers[i];
  705. if (h.CheckRepeated(t))
  706. {
  707. h.Cancel();
  708. h.Release();
  709. handlers.RemoveAt(i);
  710. }
  711. }
  712. this.handlers.Add(t);
  713. }
  714. }
  715. #endregion
  716. }
  717. }