DressUpObj.cs 32 KB

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