using UnityEngine; using System.Collections; using System.Collections.Generic; using GCGame.Table; using UnityEngine.UI; public class AdvanceCopyItemInfo { public int _RewState; public int fubenId; public int score; public int remainTimes; public bool isGainFirstRew; public int bestPassTime; public int copyState; public AdvanceCopyItemInfo(int _state, int id, int _score, int time, bool gainFirst, int bestTime, int _copyState) { _RewState = _state; fubenId = id; score = _score; remainTimes = time; isGainFirstRew = gainFirst; bestPassTime = bestTime; copyState = _copyState; } } public class AdvanceCopySceneRootCtr : CopyCtrBase { public static new AdvanceCopySceneRootCtr Instance; public override void Awake() { curType = (int)CopySceneItemType.Advance; Instance = this; base.Awake(); GetAllCdList(); } private void OnDestroy() { Instance = null; } public GameObject itemprefab; public Transform prefabParent; public RectTransform _ContainerRect; private List copyBaseIdList = new List(); public void GetAllCdList() { foreach (var info in TableManager.GetNewCopyBase().Values) { if (info.Type == curType) { copyBaseIdList.Add(info.Id); } } } private void OnEnable() { AskForInfo(); } private int _PositionIndex = -1; public void SetPositionIndex(int index) { //Debug.LogError("PositionIndex : " + index); _PositionIndex = index; } public void AskForInfo() { CG_REQ_BASE_COPY_INFO req = (CG_REQ_BASE_COPY_INFO)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_BASE_COPY_INFO); req.SetCopyType(curType); req.SendPacket(); } public void OnPacketReceive(GC_RET_BASE_COPY_INFO info) { StartCoroutine(CreatePrefab(info)); } public void RefreshItemInfo(GC_RET_BASE_COPY_INFO info) { MainMissionCopyitemInfo itemInfo = new MainMissionCopyitemInfo(info.GetBaseCopyInfo(0).GetFirstReward, //这边判断时间,因为没有首次奖励 info.GetBaseCopyInfo(0).FubenId, info.GetBaseCopyInfo(0).Score, info.GetBaseCopyInfo(0).Num, info.GetBaseCopyInfo(0).GetFirstReward != 0 ? true : false, info.GetBaseCopyInfo(0).Time ); for (int index = 0; index < itemPrefabList.Count; index++) { if (itemPrefabList[index].GetComponent().curBseId == itemInfo.fubenId) { itemPrefabList[index].GetComponent().RefreshRemainTimes(itemInfo.remainTimes); } } } //默认选中第一个 public void ShowDefaultFirst() { if (itemPrefabList.Count > 0) { itemPrefabList[0].GetComponent().OnItemClick(); } } //创建预设 IEnumerator CreatePrefab(GC_RET_BASE_COPY_INFO info) { if (itemPrefabList.Count > 0) { InitPrefabItemInfo(info); yield break; } for (int index = 0; index < copyBaseIdList.Count; index++) { GameObject item = GameObject.Instantiate(itemprefab); item.transform.SetParent(prefabParent); item.transform.localPosition = Vector3.zero; item.transform.localRotation = Quaternion.Euler(Vector3.zero); item.transform.localScale = Vector3.one; itemPrefabList.Add(item); } InitPrefabItemInfo(info); yield break; } public int accomplishCount = 0; //初始化预制项目信息 public void InitPrefabItemInfo(GC_RET_BASE_COPY_INFO info) { Dictionary _ItemInfoDic = new Dictionary(); List _CopyItemList = new List(); List _InfoList = new List(); for (int index = 0; index < itemPrefabList.Count; index++) { var copyBase = TableManager.GetNewCopyBaseByID(info.GetBaseCopyInfo(index).FubenId, 0); var state = 3; if (copyBase.UnLockLevel > GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level) { state = 3; } else if (info.GetBaseCopyInfo(index).Num < 1) { state = 2; } else { state = 1; } AdvanceCopyItemInfo itemInfo = new AdvanceCopyItemInfo(info.GetBaseCopyInfo(index).GetFirstReward, //这边判断时间,因为没有首次奖励 info.GetBaseCopyInfo(index).FubenId, info.GetBaseCopyInfo(index).Score, info.GetBaseCopyInfo(index).Num, info.GetBaseCopyInfo(index).GetFirstReward != 0 ? true : false, info.GetBaseCopyInfo(index).Time, state ); _InfoList.Add(itemInfo); _ItemInfoDic.Add(info.GetBaseCopyInfo(index).FubenId, itemInfo); itemPrefabList[index].gameObject.GetComponent().InitItem(itemInfo); _CopyItemList.Add(itemPrefabList[index].gameObject.GetComponent()); } _InfoList.Sort((infoA, infoB) => { if(infoA.copyState < infoB.copyState) { return -1; }else if(infoA.copyState == infoB.copyState) { return infoA.fubenId < infoB.fubenId ? -1 : 1; } return 1; }); for (int index = 0; index < itemPrefabList.Count; index++) itemPrefabList[index].gameObject.GetComponent().InitItem(_InfoList[index]); if (_PositionIndex == -1) ShowDefaultFirst(); else PositionItem(); } void PositionItem() { if (itemPrefabList.Count > _PositionIndex) { var posY = itemPrefabList[_PositionIndex].GetComponent().anchoredPosition.y; _ContainerRect.anchoredPosition = new Vector2(_ContainerRect.anchoredPosition.x, Mathf.Abs(posY)); OnItemClick((itemPrefabList[_PositionIndex].GetComponent().curBseId)); } _PositionIndex = -1; } public void OnItemClick(int baseId) { base.OnCopyBaseItemClick(baseId); for (int index = 0; index < itemPrefabList.Count; index++) { if (itemPrefabList[index].GetComponent().curBseId == baseId) { itemPrefabList[index].GetComponent().ShowMarkIcon(true); } else { itemPrefabList[index].GetComponent().ShowMarkIcon(false); } } } public void ShowSweepBtn(int baseId) { Tab_NewCopyBase copyBase = TableManager.GetNewCopyBaseByID(baseId, 0); if (copyBase == null) { normalSweepBtn.gameObject.SetActive(false); advanceSweepBtn.gameObject.SetActive(false); } normalSweepBtn.SetActive(false); for (int index = 0; index < copyBase.getAdvancedSweepConditionCount(); index++) { if (!copyBase.GetNormalSweepConditionbyIndex(index).Equals("-1")) { normalSweepBtn.SetActive(true); break; } } advanceSweepBtn.SetActive(false); for (int index = 0; index < copyBase.getAdvancedSweepConditionCount(); index++) { if (!copyBase.GetAdvancedSweepConditionbyIndex(index).Equals("-1")) { advanceSweepBtn.SetActive(true); break; } } } public override void OnAdvanceSweepBtnClick() { base.OnAdvanceSweepBtnClick(); } public override void OnNormalSweepBtnClick() { base.OnNormalSweepBtnClick(); } }