using UnityEngine; using System.Collections; using System.Collections.Generic; using GCGame.Table; using UnityEngine.UI; using Games.Item; using Games.GlobeDefine; public class FashionPanelCtr : MonoBehaviour { public GameObject attrPanel; public List attrNameList; public List attrValueTetx; public Text combatValue; public void ShowFashionAttr(Tab_FashionItem Fashion,int classID) { attrPanel.SetActive(false); if (Fashion == null) { return; } if (Fashion.GetAttrIdbyIndex(0) == -1) { return; } attrPanel.SetActive(true); for (int index = 0; index < attrNameList.Count; index++) { if(Fashion.getAttrIdCount() <= index) { attrNameList[index].gameObject.SetActive(false); attrValueTetx[index].gameObject.SetActive(false); continue; } if (Fashion.GetAttrIdbyIndex(index) != -1) { attrNameList[index].gameObject.SetActive(true); attrValueTetx[index].gameObject.SetActive(true); int strId = Fashion.GetAttrIdbyIndex(index) + 10000; attrNameList[index].text = StrDictionary.GetClientDictionaryString("#{" + strId + "}") + ":"; attrValueTetx[index].text = Fashion.GetAttrValuebyIndex(index).ToString(); } else { attrNameList[index].gameObject.SetActive(false); attrValueTetx[index].gameObject.SetActive(false); } } combatValue.text = Fashion.CombatPower.ToString(); } #region public UICameraTexture _UICameraTexture; //角色模型摄像机 public GameObject itemPrefab; public Transform prefabParent; public List markList; public List btnDescList; public FashionEquipItem[] fashionEquipItems; #endregion public static FashionPanelCtr Instance; private void Awake() { Instance = this; } private void OnDestroy() { Instance = null; GlobalData.IsSelectedWeaponFashion = false; //关闭或者切换当前页面的时候置为false(UICameraTexture中对武器时装进行特殊处理) } private void OnEnable() { LoadAllBackpackItemToList(); UpdatePalyerInfo(); //显示角色ModelTexture LoadAllFashionItem(); //读取表中信息 ShowDefaultFirst(); //默认显示第一个 InitEquipItem(); } //初始化装备的时装Item public void InitEquipItem() { //武器 if (GameManager.gameManager.PlayerDataPool.WeaponFashionId != -1) { fashionEquipItems[1].gameObject.SetActive(true); //需要判断当前的武器ID是不是时装... int fashionItemId = GlobalData.GetFshionItemIdByDataId(GameManager.gameManager.PlayerDataPool.WeaponFashionId); if(fashionItemId == -1) { fashionEquipItems[1].GetComponent().InitItem(-1); }else { Tab_FashionItem fashionItem = TableManager.GetFashionItemByID(fashionItemId, 0); if(fashionItem != null) { fashionEquipItems[1].GetComponent().InitItem(fashionItem.ShowWeaponId); } } }else { fashionEquipItems[1].GetComponent().InitItem(-1); } bool hasFind = false; if (GameManager.gameManager.PlayerDataPool.ModelVisualID != -1) { fashionEquipItems[0].gameObject.SetActive(true); var fashionItemDic = TableManager.GetFashionItem().Values; foreach(var item in fashionItemDic) { if(item.ItemVisualId == GameManager.gameManager.PlayerDataPool.ModelVisualID) { fashionEquipItems[0].GetComponent().InitItem(item.ShowItemId); hasFind = true; break; } } } if (!hasFind) { fashionEquipItems[0].GetComponent().InitItem(-1); } } private List m_BackPackItemList = null; void LoadAllBackpackItemToList() { m_BackPackItemList = ItemTool.ItemFilter(GameManager.gameManager.PlayerDataPool.BackPack, 0); //过滤背包中所有物品 存储在ItemList中 } void ShowDefaultFirst() { lastClickIndex = -1; //默认显示第一个 OnItemClick(0); } private int needShowCount = 0; private int curSelectedClassId = -1; void InitFashionItemByClassId(int classId) { curSelectedClassId = classId; if (classId == 0) //初始化时装 { needShowCount = fashionClothItemList.Count; } else //初始化武器 { needShowCount = fashionWeaponItemList.Count; } if (needShowCount < itemPrefabList.Count) { //显示并初始化 for (int index = 0; index < needShowCount; index++) { itemPrefabList[index].gameObject.SetActive(true); InitFashionItem(index, classId); } //隐藏多余的Item for (int index = needShowCount; index < itemPrefabList.Count; index++) { if (itemPrefabList[index].activeInHierarchy) { itemPrefabList[index].SetActive(false); } } } else { for (int index = 0; index < itemPrefabList.Count; index++) { itemPrefabList[index].SetActive(true); InitFashionItem(index, classId); } //创建不足的Item for (int index = itemPrefabList.Count; index < needShowCount; index++) { CraateItemPrefab(); InitFashionItem(index, classId); } } } private int curSelectedWeaponDatad; //是物品ID (可能情况; 在模型表可以找到,但是不能在EquipAttr中找到) public int CurSelectedWeaponDataId { get { return curSelectedWeaponDatad; } } public void SetCurWeaponDataId(int id) { curSelectedWeaponDatad = id; } public void SetCurSelectedWeaponDataId(int id) { curSelectedWeaponDatad = id; } public void ShowSelectedBG(int _Index) { for(int index = 0; index < itemPrefabList.Count; index++) { if(_Index == index) { itemPrefabList[index].GetComponent().markBG.gameObject.SetActive(true); }else { itemPrefabList[index].GetComponent().markBG.gameObject.SetActive(false); } } JudgeIsHaveTheFashionItemOrNot(); //判断背包中时是否有对应的时装 } void InitFashionItem(int index, int classId) { if (classId == 0) //时装 { itemPrefabList[index].GetComponent().InitItem(fashionClothItemList[index], index); } else //武器 { itemPrefabList[index].GetComponent().InitItem(fashionWeaponItemList[index], index); } ShowFashionAttr(fashionClothItemList[index], classId); } public enum FashionItemState { INVALID = -1, OWN = 0, //拥有(未激活) ISOFF = 1, //未穿戴 ISON = 2, //穿戴 OVERTIME, //过期 DONTOWN, //未拥有 } public void JudgeIsHaveTheFashionItemOrNot() { FashionItemState curState = FashionItemState.INVALID; var _BackPack = GameManager.gameManager.PlayerDataPool.BackPack; if (curSelectedClassId == 0) //衣服 { for(int index = 0; index < fashionClothItemList.Count; index++) { if(GameManager.gameManager.PlayerDataPool.PlerfaFashiuonDataCtr.CurFashionState.ContainsKey(fashionClothItemList[index].Id)) { if(GameManager.gameManager.PlayerDataPool.PlerfaFashiuonDataCtr.CurFashionState[fashionClothItemList[index].Id] == 0) { curState = FashionItemState.OVERTIME; } else { curState = FashionItemState.OWN; //拥有 } }else //没有使用过这个时装(有可能背包有) { bool hasFind = false; //只用判断背包有没有对应道具 for (int itemIdIndex = 0; itemIdIndex < fashionClothItemList[index].getCommonitemIdCount(); itemIdIndex++) { if (_BackPack.GetItemCountByDataId(fashionClothItemList[index].GetCommonitemIdbyIndex(itemIdIndex)) > 0) { curState = FashionItemState.OWN; //拥有 hasFind = true; break; } } if (!hasFind) { curState = FashionItemState.DONTOWN; } } itemPrefabList[index].GetComponent().InitState(curState); } } else //武器 { for (int index = 0; index < fashionWeaponItemList.Count; index++) { if (GameManager.gameManager.PlayerDataPool.PlerfaFashiuonDataCtr.CurFashionState.ContainsKey(fashionWeaponItemList[index].Id)) { if (GameManager.gameManager.PlayerDataPool.PlerfaFashiuonDataCtr.CurFashionState[fashionWeaponItemList[index].Id] == 0) { curState = FashionItemState.OVERTIME; } else { curState = FashionItemState.OWN; //拥有 } } else //没有使用过这个时装(有可能背包有) { bool hasFind = false; //只用判断背包有没有对应道具 for (int itemIdIndex = 0; itemIdIndex < fashionWeaponItemList[index].getCommonitemIdCount(); itemIdIndex++) { if (_BackPack.GetItemCountByDataId(fashionWeaponItemList[index].GetCommonitemIdbyIndex(itemIdIndex)) > 0) { curState = FashionItemState.OWN; //拥有 hasFind = true; break; } } if (!hasFind) { curState = FashionItemState.DONTOWN; } } itemPrefabList[index].GetComponent().InitState(curState); } } } private List itemPrefabList = new List(); void CraateItemPrefab() { GameObject item = GameObject.Instantiate(itemPrefab); //设置位置 item.transform.SetParent(prefabParent); item.transform.localPosition = Vector3.zero; item.transform.localScale = Vector3.one; item.transform.localRotation = Quaternion.Euler(Vector3.zero); itemPrefabList.Add(item); } private List fashionClothItemList = new List(); private List fashionWeaponItemList = new List(); //初始化Item void LoadAllFashionItem() { ClearAllList(); //按照类型进行分类 foreach(var item in TableManager.GetFashionItem().Values) { if (item.ClassId == 0) { fashionClothItemList.Add(item); } else { fashionWeaponItemList.Add(item); } } } void ClearAllList() { fashionClothItemList.Clear(); fashionWeaponItemList.Clear(); } public void UpdatePalyerInfo() { var mainPlayer = Singleton.GetInstance().MainPlayer; if(mainPlayer != null) _UICameraTexture.InitPlayerModel(mainPlayer); } private int lastClickIndex = -1; public void OnItemClick(int index) { if(index == lastClickIndex) { return; } for (int _Index = 0; _Index < markList.Count; _Index++) { markList[_Index].gameObject.SetActive(_Index == index); } //if(index == 0) //{ // btnDescList[0].text = StrDictionary.GetClientDictionaryString("#{46220}");//"外饰"; // btnDescList[1].text = StrDictionary.GetClientDictionaryString("#{46221}");//"武器"; //} //else //{ // btnDescList[0].text = StrDictionary.GetClientDictionaryString("#{46222}");//"外饰"; // btnDescList[1].text = StrDictionary.GetClientDictionaryString("#{46223}");//"武器"; //} InitFashionItemByClassId(index); ShowSelectedBG(-1); //重置选择背景 } public void ShowModelOnTexture(int modelVisualId, int classId, int fashionItemId, bool showAll = false) { StartCoroutine(ShowModel(modelVisualId, classId, fashionItemId, showAll)); } IEnumerator ShowModel(int modelVisualId, int classId, int fashionItemId, bool showAll = false) { yield return new WaitForEndOfFrame(); var mainPlayer = Singleton.GetInstance().MainPlayer; if (showAll) //不再分类 全部显示 { _UICameraTexture.InitPlayerModel(mainPlayer); } else { if (classId == 0) //试穿衣服 { var fashionitem = TableManager.GetFashionItemByID(fashionItemId, 0); if(fashionitem == null) { Module.Log.LogModule.ErrorLog("FashonItemTab is null : " + fashionItemId); yield break; } _UICameraTexture.InitModel(mainPlayer.Profession, GlobalData.GetCharModelId(mainPlayer.Profession, modelVisualId), fashionitem.WeaponId != -1 ? fashionitem.WeaponId : mainPlayer.WeaponDataID, mainPlayer.WingModelAuraid, mainPlayer.WeaponEffectGem, mainPlayer.EffectAuraId, mainPlayer.AdcaneMountId); } else //试穿武器 { _UICameraTexture.InitModel(mainPlayer.Profession, mainPlayer.ModelID, curSelectedWeaponDatad, mainPlayer.WingModelAuraid, mainPlayer.WeaponEffectGem, mainPlayer.EffectAuraId, mainPlayer.AdcaneMountId); } } yield break; } private void OnDisable() //关闭或者切换页面的时候都为false { GlobalData.IsSelectedWeaponFashion = false; } }