using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using GCGame.Table; using Module.Log; public class PrivilegePerMissionsPanelCtr : MonoBehaviour { public static PrivilegePerMissionsPanelCtr Instance; private void OnDisable() { Instance = null; ClearOblPrefabItem(); } private void OnDestroy() { ClearOblPrefabItem(); } void ClearOblPrefabItem() { //删除多余的 var _itemList = gameObject.GetComponentsInChildren(); for (int index = 0; index < _itemList.Length; index++) { DestroyImmediate(_itemList[index].gameObject); } _PrivilegegePerMissionAttrDescItemList.Clear(); _CurSelectType = -1; } private void OnEnable() { SortFuncTabDicByType(); Instance = this; ShowDefaultFirst(); _SetOnEnable(); } private void ShowDefaultFirst() { OnMenuItemClick((int)PrivilegeVipRoot.PRIVILEGE_VIP_TYPE.SHABI); } void SortFuncTabDicByType() { funcDic = new Dictionary>(); foreach (var info in TableManager.GetPrivilegeFunction().Values) { if (funcDic.ContainsKey(info.PrivilegeVipType)) { funcDic[info.PrivilegeVipType].Add(info.Id); } else { List _idList = new List(); _idList.Add(info.Id); funcDic.Add(info.PrivilegeVipType, _idList); } } } //分类(0.白银 1.钻石 2.黄金) private Dictionary> funcDic; public List MenuItemList; private int _CurSelectType = -99; public void OnMenuItemClick(int _Index) { for (int index = 0; index < MenuItemList.Count; index++) { MenuItemList[index].ShowMarkIcon((int)MenuItemList[index]._MenuItemType == _Index); } _CurSelectType = _Index; //InitPagepanel(); } public GameObject attrDescItemPrefab; public Transform attrDescItemParent; private List _PrivilegegePerMissionAttrDescItemList = new List(); private void InitPagepanel() { if (funcDic.ContainsKey(_CurSelectType)) { StartCoroutine(CteateAndInitAttrDescItem()); } else { LogModule.ErrorLog("funcDic doesn't contain the key"); return; } } IEnumerator CteateAndInitAttrDescItem() { yield return new WaitForEndOfFrame(); var _lackCount = funcDic[_CurSelectType].Count - _PrivilegegePerMissionAttrDescItemList.Count; if(_lackCount > 0) { for (int index = 0; index < _lackCount; index++) { var item = GameObject.Instantiate(attrDescItemPrefab); item.transform.SetParent(attrDescItemParent); item.transform.localPosition = Vector3.zero; item.transform.localScale = Vector3.one; item.transform.localRotation = Quaternion.Euler(Vector3.zero); _PrivilegegePerMissionAttrDescItemList.Add(item.GetComponent()); } } else { for(int index = funcDic[_CurSelectType].Count; index < _PrivilegegePerMissionAttrDescItemList.Count; index++) { _PrivilegegePerMissionAttrDescItemList[index].gameObject.SetActive(false); } } //等待一帧刷新 yield return new WaitForEndOfFrame(); //init for(int index = 0; index < funcDic[_CurSelectType].Count; index++) { _PrivilegegePerMissionAttrDescItemList[index].gameObject.SetActive(true); _PrivilegegePerMissionAttrDescItemList[index].InitItem(funcDic[_CurSelectType][index], index); } yield break; } #region vip修改 /// /// 标签预设 /// public GameObject _MenuItemPrefab; /// /// 标签容器 /// public Transform _MenuItemParent; /// /// vip权限描述预设 /// public GameObject VipAttrDescItemPrefab; /// /// vip权限描述预设容器 /// public Transform VipAttrDescItemParent; /// /// 标签预设列表 /// private List _MenuItemPrefabList = new List(); private void _SetOnEnable() { //if (_MenuItemPrefabList.Count <= 0) //{ // StartCoroutine(CreateMenuItem()); //} //else //{ // //ReqWelfarePanelInfo(); // ShowFirstCanAcceptPanel(); //} StartCoroutine(CreateMenuItem()); } IEnumerator CreateMenuItem() { yield return new WaitForEndOfFrame(); for (int i = 0; i < _MenuItemParent.childCount; i++) { _MenuItemParent.GetChild(i).gameObject.SetActive(false); } //_MenuItemPrefabList.Clear(); foreach (var info in TableManager.GetVipBook().Values) { if (info.VipLevel == 0) { continue; } var item = GameObject.Instantiate(_MenuItemPrefab); item.transform.SetParent(_MenuItemParent); item.transform.localPosition = Vector3.zero; item.transform.localScale = Vector3.one; item.transform.localRotation = Quaternion.Euler(Vector3.zero); item.GetComponent().InitMenuItem(info.VipLevel); _MenuItemPrefabList.Add(item); } ShowFirstCanAcceptPanel(); yield break; } public void ShowFirstCanAcceptPanel() { newOnMenuItemClick(PrivilegeWelfarePanelCtr.Instance._CurSelectVipLevel); } public bool isUse ; private void scrollViewShowPosition(int vipLevel) { if (isUse) { return; } if (vipLevel <= 4) { _MenuItemParent.transform.localPosition = new Vector3(_MenuItemParent.transform.localPosition.x, 0, 0); } if (vipLevel > 4 && vipLevel <= 8) { _MenuItemParent.transform.localPosition = new Vector3(_MenuItemParent.transform.localPosition.x, 300, 0); } if (vipLevel > 8) { _MenuItemParent.transform.localPosition = new Vector3(_MenuItemParent.transform.localPosition.x, 670, 0); } } public int _CurSelectVipLevel = -1; public void newOnMenuItemClick(int vipLevel) { scrollViewShowPosition(vipLevel); _CurSelectVipLevel = vipLevel; PrivilegeWelfarePanelCtr.Instance.newCurSelectVipLevel = vipLevel; for (int index = 0; index < _MenuItemPrefabList.Count; index++) { _MenuItemPrefabList[index].GetComponent().ShowMarkIcon( vipLevel == _MenuItemPrefabList[index].GetComponent()._MenuItemVipLevel); } StartCoroutine(InitPage()); } private Tab_VipBook _CurPageVipBookTab = null; IEnumerator InitPage() { if (!TableManager.GetVipBook().TryGetValue(_CurSelectVipLevel, out _CurPageVipBookTab)) { LogModule.ErrorLog("_CurSelectVipLevel is null : " + _CurSelectVipLevel); yield break; } //初始化描述文字Icon InitPageDescIcon(); yield break; } private List _VipAttrDescItemList = new List(); void InitPageDescIcon() { if (_VipAttrDescItemList.Count < _CurPageVipBookTab.getVipDescCount()) { var _NeedCreateCount = _CurPageVipBookTab.getVipDescCount() - _VipAttrDescItemList.Count; for (int index = 0; index < _NeedCreateCount; index++) { GameObject rewItem = GameObject.Instantiate(VipAttrDescItemPrefab); rewItem.transform.SetParent(VipAttrDescItemParent); rewItem.transform.localPosition = Vector3.zero; rewItem.transform.localRotation = Quaternion.Euler(Vector3.zero); rewItem.transform.localScale = Vector3.one; rewItem.SetActive(false); _VipAttrDescItemList.Add(rewItem); } } for (int index = 0; index < _CurPageVipBookTab.getVipDescCount(); index++) { if (_CurPageVipBookTab.GetVipDescbyIndex(index) == "") { _VipAttrDescItemList[index].SetActive(false); } else { _VipAttrDescItemList[index].SetActive(true); _VipAttrDescItemList[index].GetComponent().text = _CurPageVipBookTab.GetVipDescbyIndex(index); } } } #endregion }