using UnityEngine; using System.Collections; using System.Collections.Generic; using GCGame.Table; using UnityEngine.UI; public class EffectPanel : MonoBehaviour { #region public UICameraTexture cameraTexture; public GameObject itemPrefab; public Transform prefabParent; public Sprite normalBtnImage; public Sprite cantClickBtnImage; public List markList; public List btnDescList; public Button saveBtn; public Text panelDesc; #endregion public static EffectPanel Instance; private void Awake() { Instance = this; } void OnEnable() { LoadAllItemToDic(); //读取配置表 ShowDefaultFirst(); //默认显示第一列 ShowDefaultModel(); } private List effectList = new List(); private List wingList = new List(); private List effectItemList = new List(); private List wingItemList = new List(); void LoadAllItemToDic() //分成两类 { effectList.Clear(); wingList.Clear(); var auraConfigDic = TableManager.GetAuraConfig().Values; foreach (var item in auraConfigDic) { if(item.AuraType == 0) { effectList.Add(item.AuraID); }else if (item.AuraType == 1) { wingList.Add(item.AuraID); } } } void ShowDefaultFirst() { ShowItemByClassId(0); } private int _LatClassId = -1; public void ShowItemByClassId(int classID) { if(_LatClassId == classID) { return; } _LatClassId = classID; ClearAllPrefabs(); curClassType = classID; if(classID == 0) { for(int index = 0; index < effectList.Count; index++) { CreatePrefabs(); } } else { for(int index = 0; index < wingList.Count; index++) { CreatePrefabs(); } } var mainPlayer = Singleton.Instance.MainPlayer; if (mainPlayer == null) { return; } //预设体创建完毕 初始化Item if (classID == 0) { effectItemList.Clear(); for(int index = 0; index < effectList.Count; index++) { prefabList[index].gameObject.GetComponent().InitItem(effectList[index], classID, index); effectItemList.Add(prefabList[index].gameObject); effectItemList[index].GetComponent().markIcon.SetActive( effectList[index] == mainPlayer.EffectAuraId ? true : false); effectItemList[index].GetComponent().dressDesc.gameObject.SetActive( effectList[index] == mainPlayer.EffectAuraId ? true : false); } } else { wingItemList.Clear(); for (int index = 0; index < wingList.Count; index++) { prefabList[index].gameObject.GetComponent().InitItem(wingList[index], classID, index); wingItemList.Add(prefabList[index].gameObject); wingItemList[index].GetComponent().markIcon.SetActive( wingList[index] == mainPlayer.WingModelAuraid ? true : false); wingItemList[index].GetComponent().dressDesc.gameObject.SetActive( wingList[index] == mainPlayer.WingModelAuraid ? true : false); } } for (int _Index = 0; _Index < markList.Count; _Index++) { markList[_Index].gameObject.SetActive(_Index == classID); } //统一颜色 不再变色 panelDesc.text = classID == 0 ? StrDictionary.GetClientDictionaryString("#{42638}") : StrDictionary.GetClientDictionaryString("#{42641}"); RefreshBtnState(); //将当前穿戴的特效的IsOn设为True; RefreshModelCamera(); //刷新当前的相机为当前穿戴的模型 } void ClearAllPrefabs() { for(int index = 0; index < prefabList.Count; index++) { GameObject.Destroy(prefabList[index].gameObject); } prefabList.Clear(); } private List prefabList = new List(); void CreatePrefabs() { GameObject item = GameObject.Instantiate(itemPrefab) as GameObject; item.transform.SetParent(prefabParent); item.transform.localPosition = Vector3.zero; item.transform.localScale = Vector3.one; item.transform.localRotation = Quaternion.Euler(Vector3.zero); //item.GetComponentInChildren().group = m_ToggleGroup; prefabList.Add(item); } public void ShowDefaultModel() { var mainPlayer = Singleton.Instance.MainPlayer; cameraTexture.InitPlayerModel(mainPlayer); } public void ShowItemMarkIcon(int _Index) { for(int index = 0; index < prefabList.Count; index++) { if(index == _Index && prefabList[index].gameObject.GetComponent().markIcon.activeInHierarchy) //关闭打开的按钮 { prefabList[index].gameObject.GetComponent().markIcon.SetActive(false); }else { prefabList[index].gameObject.GetComponent().markIcon.SetActive(index == _Index ? true : false); } } } private int _CurSelectClassId = 0; //默认0 private int curSelectedIndex = -1; private int CurAuraConfigId = -1; public void SetEffectId(int classId, int auraConfigId, int selectedIndex) { _CurSelectClassId = classId; var mainPlayer = Singleton.Instance.MainPlayer; if (mainPlayer == null) { return; } ShowItemMarkIcon(selectedIndex); //设置背景 saveBtn.interactable = false; //先设定保存按钮不能点击 if (classId == 0) { bool hasEffectItemOn = false; for (int index = 0; index < effectItemList.Count; index++) { if (effectItemList[index].gameObject.GetComponent().markIcon.activeInHierarchy) { curSelectedIndex = index; hasEffectItemOn = true; CurAuraConfigId = auraConfigId; if (!effectItemList[index].GetComponent().dressDesc.isActiveAndEnabled) { effectItemList[index].GetComponent().dressDesc.gameObject.SetActive(true); } effectItemList[index].GetComponent().dressDesc.gameObject.SetActive(true); effectItemList[index].GetComponent().dressDesc.text = effectList[index] == mainPlayer.EffectAuraId ? StrDictionary.GetClientDictionaryString("#{42642}") : StrDictionary.GetClientDictionaryString("#{42643}"); }else { effectItemList[index].GetComponent().dressDesc.gameObject.SetActive(false); } } if (!hasEffectItemOn) { curSelectedIndex = -1; CurAuraConfigId = -1; } } else { bool hasWingItemOn = false; for (int index = 0; index < wingItemList.Count; index++) { if (wingItemList[index].GetComponent().markIcon.activeInHierarchy) { CurAuraConfigId = auraConfigId; curSelectedIndex = index; hasWingItemOn = true; RefreshBtnState(); if (!wingItemList[index].GetComponent().markIcon.activeInHierarchy) { wingItemList[index].GetComponent().dressDesc.gameObject.SetActive(true); } wingItemList[index].GetComponent().dressDesc.gameObject.SetActive(true); wingItemList[index].GetComponent().dressDesc.text = wingList[index] == mainPlayer.WingModelAuraid ? StrDictionary.GetClientDictionaryString("#{42642}") : StrDictionary.GetClientDictionaryString("#{42643}"); } else { wingItemList[index].GetComponent().dressDesc.gameObject.SetActive(false); } } if (!hasWingItemOn) { curSelectedIndex = -1; CurAuraConfigId = -1; } } OnItemClick(classId, CurAuraConfigId); } private int curClassType = -1; public void OnItemClick(int classId, int auraId) { curClassType = classId; var mainPlayer = Singleton.Instance.MainPlayer; if (classId == 0) { cameraTexture.InitModel(mainPlayer.Profession, mainPlayer.ModelID, mainPlayer.WeaponDataID, mainPlayer.WingModelAuraid, mainPlayer.WeaponEffectGem, auraId, mainPlayer.IsShowWing ? mainPlayer.AdvanceWingId : -1); } else { cameraTexture.InitModel(mainPlayer.Profession, mainPlayer.ModelID, mainPlayer.WeaponDataID, auraId, mainPlayer.WeaponEffectGem, mainPlayer.EffectAuraId, mainPlayer.IsShowWing ? mainPlayer.AdvanceWingId : -1); } SetSaveBtnState(classId, curSelectedIndex); } public void RefreshBtnState() { var mainPlayer = Singleton.Instance.MainPlayer; if (curClassType == 0) { for (int index = 0; index < effectItemList.Count; index++) { var item = effectItemList[index].GetComponent(); item.RefreshItemNameDesc(); if (item.markIcon.activeInHierarchy) { item.dressDesc.text = effectList[index] == mainPlayer.EffectAuraId ? StrDictionary.GetClientDictionaryString("#{42642}") : StrDictionary.GetClientDictionaryString("#{42643}"); } } } else { for (int index = 0; index < wingItemList.Count; index++) { var item = wingItemList[index].GetComponent(); item.RefreshItemNameDesc(); if (item.markIcon.activeInHierarchy) { item.dressDesc.text = wingList[index] == mainPlayer.WingModelAuraid ? StrDictionary.GetClientDictionaryString("#{42642}") : StrDictionary.GetClientDictionaryString("#{42643}"); } } } SetSaveBtnState(_CurSelectClassId, curSelectedIndex); } public void SetSaveBtnState(int classId, int index) { var mainPlayer = Singleton.Instance.MainPlayer; if (index == -1) { saveBtn.interactable = true; return; } if (classId == 0) { int auraId = effectList[index]; if(GameManager.gameManager.PlayerDataPool.PlerfaFashiuonDataCtr.CurOwnEffectInfo.ContainsKey(auraId)) //拥有 可点击 { //当前是否穿戴 if(mainPlayer.EffectAuraId == auraId) { saveBtn.interactable = false; }else { saveBtn.interactable = true; } } else { saveBtn.interactable = false; } } else { int auraId = wingList[index]; if (GameManager.gameManager.PlayerDataPool.PlerfaFashiuonDataCtr.CurOwnEffectInfo.ContainsKey(auraId)) //拥有 可点击 { //当前是否穿戴 if (mainPlayer .WingModelAuraid== auraId) { saveBtn.interactable = false; } else { saveBtn.interactable = true; } } else { saveBtn.interactable = false; } } } private void OnDisable() { //prefabList.Clear(); _LatClassId = -1; } private void OnDestroy() { prefabList.Clear(); Instance = null; } public void OnSaveBtnClick() { var mainPlayer = Singleton.Instance.MainPlayer; if(mainPlayer == null) { return; } if (curClassType == 0) { bool hasToggleOn = false; for(int index = 0; index < effectItemList.Count; index++) { if (effectItemList[index].GetComponent().markIcon.activeInHierarchy ) { hasToggleOn = true; if (effectList[index] == mainPlayer.EffectAuraId) { break; }else { //穿戴当前特效 CG_ASK_WEAR_AURA req = (CG_ASK_WEAR_AURA)PacketDistributed.CreatePacket(MessageID.PACKET_CG_ASK_WEAR_AURA); req.SetAuraID(effectList[index]); req.SendPacket(); } } } if(!hasToggleOn) { if(mainPlayer.EffectAuraId != 0) { //脱下当前穿戴 CG_ASK_TAKEOFF_AURA takeOff = (CG_ASK_TAKEOFF_AURA)PacketDistributed.CreatePacket(MessageID.PACKET_CG_ASK_TAKEOFF_AURA); takeOff.SetAuraType(curClassType); takeOff.SendPacket(); } } } else { bool hasToggleOn = false; for (int index = 0; index < wingItemList.Count; index++) { if (wingItemList[index].GetComponent().markIcon.activeInHierarchy) { hasToggleOn = true; if (wingList[index] == mainPlayer.WingModelAuraid) { break; } else { //穿戴当前特效 CG_ASK_WEAR_AURA req = (CG_ASK_WEAR_AURA)PacketDistributed.CreatePacket(MessageID.PACKET_CG_ASK_WEAR_AURA); req.SetAuraID(wingList[index]); req.SendPacket(); } } } if (!hasToggleOn) { if (mainPlayer.WingModelAuraid != 0) { //脱下当前穿戴 CG_ASK_TAKEOFF_AURA takeOff = (CG_ASK_TAKEOFF_AURA)PacketDistributed.CreatePacket(MessageID.PACKET_CG_ASK_TAKEOFF_AURA); takeOff.SetAuraType(curClassType); takeOff.SendPacket(); } } } } public void RefreshModelCamera() { var mainPlayer = Singleton.Instance.MainPlayer; cameraTexture.InitPlayerModel(mainPlayer); RefreshItemState(); } public void RefreshItemState() { var mainPlayer = Singleton.Instance.MainPlayer; if (mainPlayer == null) { return; } if (curClassType == 0) { for (int index = 0; index < effectList.Count; index++) { effectItemList[index].GetComponent().dressDesc.gameObject.SetActive( effectList[index] == mainPlayer.EffectAuraId ? true : false); } } else { for (int index = 0; index < wingList.Count; index++) { wingItemList[index].GetComponent().dressDesc.gameObject.SetActive( wingList[index] == mainPlayer.WingModelAuraid ? true : false); } } } }