Files
JJBB/Assets/Project/Script/GUI/BackPack/EffectPanel.cs
2024-08-23 15:49:34 +08:00

475 lines
16 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<Image> markList;
public List<Text> btnDescList;
public Button saveBtn;
public Text panelDesc;
#endregion
public static EffectPanel Instance;
private void Awake()
{
Instance = this;
}
void OnEnable()
{
LoadAllItemToDic(); //读取配置表
ShowDefaultFirst(); //默认显示第一列
ShowDefaultModel();
}
private List<int> effectList = new List<int>();
private List<int> wingList = new List<int>();
private List<GameObject> effectItemList = new List<GameObject>();
private List<GameObject> wingItemList = new List<GameObject>();
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<ObjManager>.Instance.MainPlayer;
if (mainPlayer == null)
{
return;
}
//预设体创建完毕 初始化Item
if (classID == 0)
{
effectItemList.Clear();
for(int index = 0; index < effectList.Count; index++)
{
prefabList[index].gameObject.GetComponent<EffectItem>().InitItem(effectList[index], classID, index);
effectItemList.Add(prefabList[index].gameObject);
effectItemList[index].GetComponent<EffectItem>().markIcon.SetActive(
effectList[index] == mainPlayer.EffectAuraId ? true : false);
effectItemList[index].GetComponent<EffectItem>().dressDesc.gameObject.SetActive(
effectList[index] == mainPlayer.EffectAuraId ? true : false);
}
}
else
{
wingItemList.Clear();
for (int index = 0; index < wingList.Count; index++)
{
prefabList[index].gameObject.GetComponent<EffectItem>().InitItem(wingList[index], classID, index);
wingItemList.Add(prefabList[index].gameObject);
wingItemList[index].GetComponent<EffectItem>().markIcon.SetActive(
wingList[index] == mainPlayer.WingModelAuraid ? true : false);
wingItemList[index].GetComponent<EffectItem>().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<GameObject> prefabList = new List<GameObject>();
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<Toggle>().group = m_ToggleGroup;
prefabList.Add(item);
}
public void ShowDefaultModel()
{
var mainPlayer = Singleton<ObjManager>.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<EffectItem>().markIcon.activeInHierarchy) //关闭打开的按钮
{
prefabList[index].gameObject.GetComponent<EffectItem>().markIcon.SetActive(false);
}else
{
prefabList[index].gameObject.GetComponent<EffectItem>().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<ObjManager>.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<EffectItem>().markIcon.activeInHierarchy)
{
curSelectedIndex = index;
hasEffectItemOn = true;
CurAuraConfigId = auraConfigId;
if (!effectItemList[index].GetComponent<EffectItem>().dressDesc.isActiveAndEnabled)
{
effectItemList[index].GetComponent<EffectItem>().dressDesc.gameObject.SetActive(true);
}
effectItemList[index].GetComponent<EffectItem>().dressDesc.gameObject.SetActive(true);
effectItemList[index].GetComponent<EffectItem>().dressDesc.text = effectList[index] ==
mainPlayer.EffectAuraId ? StrDictionary.GetClientDictionaryString("#{42642}") : StrDictionary.GetClientDictionaryString("#{42643}");
}else
{
effectItemList[index].GetComponent<EffectItem>().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<EffectItem>().markIcon.activeInHierarchy)
{
CurAuraConfigId = auraConfigId;
curSelectedIndex = index;
hasWingItemOn = true;
RefreshBtnState();
if (!wingItemList[index].GetComponent<EffectItem>().markIcon.activeInHierarchy)
{
wingItemList[index].GetComponent<EffectItem>().dressDesc.gameObject.SetActive(true);
}
wingItemList[index].GetComponent<EffectItem>().dressDesc.gameObject.SetActive(true);
wingItemList[index].GetComponent<EffectItem>().dressDesc.text = wingList[index] ==
mainPlayer.WingModelAuraid ? StrDictionary.GetClientDictionaryString("#{42642}") : StrDictionary.GetClientDictionaryString("#{42643}");
}
else
{
wingItemList[index].GetComponent<EffectItem>().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<ObjManager>.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<ObjManager>.Instance.MainPlayer;
if (curClassType == 0)
{
for (int index = 0; index < effectItemList.Count; index++)
{
var item = effectItemList[index].GetComponent<EffectItem>();
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<EffectItem>();
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<ObjManager>.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<ObjManager>.Instance.MainPlayer;
if(mainPlayer == null)
{
return;
}
if (curClassType == 0)
{
bool hasToggleOn = false;
for(int index = 0; index < effectItemList.Count; index++)
{
if (effectItemList[index].GetComponent<EffectItem>().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<EffectItem>().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<ObjManager>.Instance.MainPlayer;
cameraTexture.InitPlayerModel(mainPlayer);
RefreshItemState();
}
public void RefreshItemState()
{
var mainPlayer = Singleton<ObjManager>.Instance.MainPlayer;
if (mainPlayer == null)
{
return;
}
if (curClassType == 0)
{
for (int index = 0; index < effectList.Count; index++)
{
effectItemList[index].GetComponent<EffectItem>().dressDesc.gameObject.SetActive(
effectList[index] == mainPlayer.EffectAuraId ? true : false);
}
}
else
{
for (int index = 0; index < wingList.Count; index++)
{
wingItemList[index].GetComponent<EffectItem>().dressDesc.gameObject.SetActive(
wingList[index] == mainPlayer.WingModelAuraid ? true : false);
}
}
}
}