DressUpObj.cs 28 KB

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