123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593 |
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- using System.Linq;
- using ET;
- namespace GFGGame
- {
- public class DressUpObj
- {
- private GameObject _sceneObj;
- private GameObject _roleObj;
- private bool _needSetMask;
- private bool _showSceneType = true;
- private bool _showBg = true;
- private DressUpData _dressUpData = new DressUpData();
- public int bgId
- {
- get
- {
- return _dressUpData.bgId;
- }
- }
- public int suitId
- {
- get
- {
- return _dressUpData.suitId;
- }
- }
- public int actionId
- {
- get
- {
- return _dressUpData.actionId;
- }
- }
- public bool IsAction
- {
- get
- {
- return _dressUpData.actionId > 0;
- }
- }
- public List<int> itemList
- {
- get
- {
- return _dressUpData.itemList.ToList();
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="sceneObj"></param>
- /// <param name="needSetMask"></param>
- /// <param name="showSceneType"></param>
- /// <param name="roleObj"></param>
- /// <param name="showBg"></param>
- /// <param name="resetData">是否重置装备数据</param>
- public void setSceneObj(GameObject sceneObj, bool needSetMask = false, bool showSceneType = true, GameObject roleObj = null, bool showBg = true)
- {
- if (_sceneObj != null && _sceneObj != sceneObj)
- {
- GameObject.Destroy(_sceneObj);
- }
- _sceneObj = sceneObj;
- _needSetMask = needSetMask;
- _showSceneType = showSceneType;
- _showBg = showBg;
- _roleObj = roleObj;
- if(_dressUpData.IsNew)
- {
- PutOnDefaultDressUpData();
- }
- else
- {
- UpdateRoleView();
- }
- }
- public DressUpData DressUpDataClone()
- {
- return _dressUpData.Clone();
- }
- public void Dispose()
- {
- _sceneObj = null;
- _dressUpData = null;
- }
- //传入一个服装部件Id,判断是否有与此部件同类型服装已穿着
- public bool CheckSameTypeIsOn(int itemId)
- {
- int subType = ItemUtilCS.GetItemSubType(itemId);
- for (int i = 0; i < _dressUpData.itemList.Count; i++)
- {
- int _subType = ItemUtilCS.GetItemSubType(_dressUpData.itemList[i]);
- if (subType == _subType) return true;
- }
- return false;
- }
- /// <summary>
- /// 仅判断换装部件是否已穿着
- /// </summary>
- /// <param name="itemId"></param>
- /// <returns></returns>
- public bool CheckDressUpItemIsOn(int itemId)
- {
- if (itemId == _dressUpData.bgId)
- {
- return true;
- }
- return _dressUpData.itemList.Contains(itemId);
- }
- /// <summary>
- /// 仅判断套装是否穿上
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool CheckSuitIsOn(int id)
- {
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(id);
- if (suitCfg == null)
- {
- return false;
- }
- int[] items = suitCfg.partsArr;
- foreach (int itemId in items)
- {
- if (_dressUpData.actionId == id)
- {
- if (SuitCfgArray.Instance.CheckActionContainsItem(itemId, id))
- {
- continue;
- }
- }
- bool isOn = CheckDressUpItemIsOn(itemId);
- if (!isOn)
- {
- return false;
- }
- }
- return true;
- }
- public void AddOrRemove(int itemId, bool checkDefault, bool isAdd = false, bool isRemove = false)
- {
- int subType = ItemUtilCS.GetItemSubType(itemId);
- if (subType == ConstDressUpItemType.BEI_JING)
- {
- if (!_showBg)
- {
- return;
- }
- _dressUpData.bgId = itemId;
- bool showAni = IsAction || DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId);
- DressUpUtil.AddItem(_dressUpData.bgId, _sceneObj, _needSetMask, showAni, _roleObj);
- }
- else
- {
- if (!CheckDressUpItemIsOn(itemId))
- {
- if (!isRemove)
- {
- checkRemoveSameType(subType);
- Add(itemId);
- }
- }
- else
- {
- if (!isAdd)
- {
- Remove(itemId);
- }
- }
- if (checkDefault)
- {
- checkDefaultItem();
- }
- }
- }
- public void checkRemoveSameType(int type)
- {
- int count = 0;
- int firstTeshuId = 0;
- for (int i = 0; i < _dressUpData.itemList.Count; i++)
- {
- int itemID = (int)_dressUpData.itemList[i];
- int subType = ItemUtilCS.GetItemSubType(itemID);
- if (subType == type
- || (type == ConstDressUpItemType.LIAN_YI_QUN && (subType == ConstDressUpItemType.SHANG_YI || subType == ConstDressUpItemType.XIA_ZHUANG || subType == ConstDressUpItemType.NEI_DA))
- || (type == ConstDressUpItemType.SHANG_YI && subType == ConstDressUpItemType.LIAN_YI_QUN)
- || (type == ConstDressUpItemType.XIA_ZHUANG && subType == ConstDressUpItemType.LIAN_YI_QUN)
- || (type == ConstDressUpItemType.NEI_DA && subType == ConstDressUpItemType.LIAN_YI_QUN))
- {
- Remove(itemID);
- i--;
- }
- if (subType > ConstDressUpItemType.TE_SHU)
- {
- if (count == 0)
- {
- firstTeshuId = itemID;
- }
- count++;
- }
- }
- if (type > ConstDressUpItemType.TE_SHU && count >= 3)
- {
- //特殊饰品最多穿三件,第四件会自动顶掉第一件
- Remove(firstTeshuId);
- }
- }
- //脱掉所有换装,换成默认装(不处理背景)
- public void TakeOffAll(bool checkDefault = true)
- {
- _dressUpData.suitId = 0;
- _dressUpData.actionId = 0;
- foreach (int itemID in itemList)
- {
- AddOrRemove(itemID, false, false, true);
- }
- if (checkDefault)
- {
- checkDefaultItem();
- UpdateWholeBodyView();
- }
- RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
- // FightDataManager.Instance.score = roleLevelCfg.baseScore;
- // foreach (int itemId in _dressUpData.itemList)
- // {
- // FightDataManager.Instance.score += ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags);
- // }
- }
- //穿上或脱掉一个动作
- public void PutOnOrTakeOffAction(int actionId)
- {
- if (_dressUpData.actionId == actionId)
- {
- CancelAction();
- }
- else
- {
- PutOnAction(actionId);
- }
- }
- //当穿一件部件时检查是否需要取消动作,如果需要则取消该动作
- public void CheckCancelActionWhenPutOn(int itemId)
- {
- if (_dressUpData.actionId > 0)
- {
- bool replaceableByAction = SuitCfgArray.Instance.CheckItemReaplaceableByAction(itemId, _dressUpData.actionId);
- if (!replaceableByAction)
- {
- CancelAction();
- _dressUpData.actionId = 0;
- }
- }
- }
- //刷新视图,用于新设置sceneobj后的初始显示
- private void UpdateRoleView()
- {
- PutOnDressUpData(DressUpDataClone());
- }
- /// <summary>
- /// 尝试穿戴配置套装
- /// </summary>
- /// <param name="id">套装id</param>
- /// <param name="tryShowAction">尝试穿上动作</param>
- /// <param name="excludeType">排除类型列表</param>
- /// <param name="showOptional">是否显示可选部件</param>
- /// <param name="CheckOwn">是否只显示主角拥有的部件</param>
- public void PutOnSuitCfg(int id, bool tryShowAction, int[] excludeType = null, bool showOptional = true, bool CheckOwn = true)
- {
- if (_dressUpData.suitId == id)
- {
- return;
- }
- TakeOffAll(false);
- _dressUpData.suitId = id;
- bool hasSuitActionRes = DressUpMenuSuitDataManager.CheckSuitHasAction(_dressUpData.suitId);
- _dressUpData.actionId = (hasSuitActionRes && tryShowAction) ? id : 0;
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_dressUpData.suitId);
- List<int> items = new List<int>(suitCfg.partsArr);
- if (showOptional)
- {
- if (suitCfg.partsOptionalArr != null && suitCfg.partsOptionalArr.Length > 0)
- {
- items.AddRange(suitCfg.partsOptionalArr);
- }
- }
- int subType = 0;
- foreach (int itemId in items)
- {
- if (!CheckOwn || DressUpMenuItemDataManager.CheckHasItem(itemId))
- {
- subType = ItemUtilCS.GetItemSubType(itemId);
- bool replaceableByAction = SuitCfgArray.Instance.CheckItemReaplaceableByAction(itemId, suitId);
- if (!IsAction || replaceableByAction)
- {
- if (excludeType == null || Array.IndexOf(excludeType, subType) < 0)
- {
- AddOrRemove(itemId, false, true);
- }
- }
- }
- }
- checkDefaultItem();
- UpdateWholeBodyView();
- }
- //穿戴一组换装数据
- public void PutOnDressUpData(DressUpData dressUpData)
- {
- TakeOffAll(false);
- _dressUpData.suitId = dressUpData.suitId;
- _dressUpData.actionId = dressUpData.actionId;
- if (dressUpData.bgId > 0)
- {
- AddOrRemove(dressUpData.bgId, false);
- }
- foreach (int itemID in dressUpData.itemList)
- {
- AddOrRemove(itemID, false, true);
- }
- checkDefaultItem();
- UpdateWholeBodyView();
- }
- //穿戴默认换装数据
- public void PutOnDefaultDressUpData()
- {
- PutOnDressUpData(DressUpData.CreateDefault());
- }
- //穿戴一组散件数据(会先脱掉原来的再穿)
- public void PutOnItemList(List<int> itemList)
- {
- TakeOffAll(false);
- foreach (int itemID in itemList)
- {
- AddOrRemove(itemID, false, true);
- }
- checkDefaultItem();
- UpdateWholeBodyView();
- }
- public int GetItemIdBuyType(int subType)
- {
- for (int i = 0; i < itemList.Count; i++)
- {
- if (itemList[i] != ConstItemID.DEFULT_LIAN_YI_QUN && itemList[i] != ConstItemID.DEFULT_NEI_DA && itemList[i] != ConstItemID.DEFULT_XIA_ZHUANG && itemList[i] != ConstItemID.DEFULT_FA_XING)
- {
- if (subType == ItemUtilCS.GetItemSubType(itemList[i]))
- {
- return itemList[i];
- }
- }
- }
- if (suitId > 0)
- {
- return suitId;
- }
- return 0;
- }
- private void Add(int itemId)
- {
- if (!_showSceneType)
- {
- if (DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId))
- {
- return;
- }
- }
- if (!_dressUpData.itemList.Contains(itemId))
- {
- _dressUpData.itemList.Add(itemId);
- bool showAni = IsAction || DressUpMenuItemCfg1Array.Instance.CheckIsSceneType(itemId);
- DressUpUtil.AddItem(itemId, _sceneObj, _needSetMask, showAni, _roleObj);
- // FightDataManager.Instance.score += ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags);
- }
- }
- private void Remove(int itemId)
- {
- if (_dressUpData.itemList == null)
- {
- return;
- }
- if (_dressUpData.itemList.Contains(itemId))
- {
- _dressUpData.itemList.Remove(itemId);
- DressUpUtil.RemoveItem(itemId, _sceneObj, _roleObj);
- // FightDataManager.Instance.score -= ItemDataManager.GetItemAdditionScore(itemId, InstanceZonesDataManager.currentScoreType, InstanceZonesDataManager.currentFightTags);
- }
- }
- //检测当前穿戴是否是一件完整套装,且只穿了一件套装,返回套装id
- private int CheckCurDressIsSuit()
- {
- var suitId = 0;
- var suitIdList = new List<int>();
- for (int i = 0; i < _dressUpData.itemList.Count; i++)
- {
- int itemSuitId = SuitCfgArray.Instance.GetSuitIdOfItem(_dressUpData.itemList[i]);
- if (!suitIdList.Contains(itemSuitId))
- {
- suitIdList.Add(itemSuitId);
- }
- }
- foreach (var itemSuitId in suitIdList)
- {
- if (CheckSuitIsOn(itemSuitId))
- {
- suitId = itemSuitId;
- break;
- }
- }
- _dressUpData.suitId = suitId;
- return _dressUpData.suitId;
- }
- private void checkDefaultItem()
- {
- //是否有头发
- bool hasFaXing = false;
- //检查默认资源
- //是否有连衣裙
- bool hasLianYiQun = false;
- //是否有内搭
- bool hasNeiDa = false;
- //是否有上衣
- bool hasShangYi = false;
- //是否有下装
- bool hasXiaZhuang = false;
- //是否有默认内搭
- bool hasNeiDaDefault = false;
- //是否有默认下装
- bool hasXiaZhuangDefault = false;
- for (int i = 0; i < _dressUpData.itemList.Count; i++)
- {
- int itemID = (int)_dressUpData.itemList[i];
- int subType = ItemUtilCS.GetItemSubType(itemID);
- if (subType == (int)ConstDressUpItemType.FA_XING)
- {
- hasFaXing = true;
- }
- else if (subType == ConstDressUpItemType.LIAN_YI_QUN)
- {
- hasLianYiQun = true;
- }
- else if (subType == ConstDressUpItemType.NEI_DA)
- {
- hasNeiDa = true;
- }
- else if (subType == ConstDressUpItemType.XIA_ZHUANG)
- {
- hasXiaZhuang = true;
- }
- else if (subType == ConstDressUpItemType.SHANG_YI)
- {
- hasShangYi = true;
- }
- if (itemID == ConstItemID.DEFULT_NEI_DA)
- {
- hasNeiDaDefault = true;
- }
- else if (itemID == ConstItemID.DEFULT_XIA_ZHUANG)
- {
- hasXiaZhuangDefault = true;
- }
- }
- if (!hasFaXing)
- {
- Add(ConstItemID.DEFULT_FA_XING);
- }
- if (!IsAction)
- {
- if (!hasLianYiQun)
- {
- if (!hasShangYi && (!hasNeiDa || hasNeiDaDefault) && (!hasXiaZhuang || hasXiaZhuangDefault))
- {
- Remove(ConstItemID.DEFULT_XIA_ZHUANG);
- Remove(ConstItemID.DEFULT_NEI_DA);
- Add(ConstItemID.DEFULT_LIAN_YI_QUN);
- }
- else
- {
- if (!hasXiaZhuang)
- {
- Add(ConstItemID.DEFULT_XIA_ZHUANG);
- }
- if (!hasNeiDa)
- {
- Add(ConstItemID.DEFULT_NEI_DA);
- }
- }
- }
- }
- CheckCurDressIsSuit();
- }
- //更新整个身体层(包括头和躯干)
- private void UpdateWholeBodyView()
- {
- if (IsAction)
- {
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_dressUpData.actionId);
- var hasAniRes = ResPathUtil.CheckDressUpAnimationExist(suitCfg.aniRes);
- var res = hasAniRes ? suitCfg.aniRes : null;
- DressUpUtil.UpdateWholeBody(res, _sceneObj, hasAniRes, suitCfg.effRes, false, _roleObj);
- }
- else
- {
- DressUpUtil.UpdateWholeBody(null, _sceneObj, false, null, _needSetMask, _roleObj);
- }
- }
- //穿上一个动作
- public void PutOnAction(int actionId)
- {
- _dressUpData.actionId = actionId;
- foreach (int itemId in itemList)
- {
- bool replaceableByAction = SuitCfgArray.Instance.CheckItemReaplaceableByAction(itemId, _dressUpData.actionId);
- if (!replaceableByAction)
- {
- AddOrRemove(itemId, false, false, true);
- }
- }
- checkDefaultItem();
- UpdateWholeBodyView();
- }
- //取消动作
- public void CancelAction(bool changeToStand = false)
- {
- if (_dressUpData.actionId <= 0)
- {
- return;
- }
- var tempActionId = _dressUpData.actionId;
- _dressUpData.actionId = 0;
- if(changeToStand)
- {
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(tempActionId);
- List<int> items = new List<int>(suitCfg.partsArr);
- if (suitCfg.partsOptionalArr != null && suitCfg.partsOptionalArr.Length > 0)
- {
- items.AddRange(suitCfg.partsOptionalArr);
- }
- int subType = 0;
- foreach (int itemId in items)
- {
- if (DressUpMenuItemDataManager.CheckHasItem(itemId))
- {
- subType = ItemUtilCS.GetItemSubType(itemId);
- bool replaceableByAction = SuitCfgArray.Instance.CheckItemReaplaceableByAction(itemId, tempActionId);
- if (!replaceableByAction)
- {
- AddOrRemove(itemId, false, true);
- }
- }
- }
- }
- checkDefaultItem();
- UpdateWholeBodyView();
- }
-
- }
- }
|