using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; // 新的福利大厅-在线奖励活动控制 public class WelfareOnLineCtr2 : WelfarePageBaseCS { public static WelfareOnLineCtr2 Instance; public GameObject[] hasnGetImage; public GameObject[] hasGetImage; public Slider progress; private List info; void Awake() { Instance = this; } private void OnDestroy() { Instance = null; } public override void OnPacketRec(NodePageInfoRet packet) { base.OnPacketRec(packet); info = packet._SubNodeList; SetProgress(); _SubNodeContainer.InitContentItem(packet._SubNodeList); } // 当Index = -1 时会主动遍历信息,得到一个初始进度 // 当index != -1 时,为子物体调用 public void SetProgress(int index = -1, int passTime = 0) { float curProgress = 0.0f; // 总的进度 float runingProgress = 0.0f; // 正在进行项的进度 if (index == -1) { int hasFinishCount = 0; for(int i = 0; i < info.Count; ++i) { if(info[i]._SubNodeState == 0) { if(i == 0) { runingProgress = (float)info[i]._PassedTime / (float)info[i]._TotalTime; } else { runingProgress = ((float)info[i]._PassedTime - (float)info[i - 1]._TotalTime) / ((float)info[i]._TotalTime - (float)info[i - 1]._TotalTime); } break; } else { curProgress += 0.25f; ++hasFinishCount; } } ShowProgressIcon(hasFinishCount); curProgress += runingProgress * 0.25f; progress.value = curProgress; } else { if (index == 0) { runingProgress = (float)passTime / (float)info[index]._TotalTime; } else { runingProgress = ((float)passTime - (float)info[index - 1]._TotalTime) / ((float)info[index]._TotalTime - (float)info[index - 1]._TotalTime); } curProgress += index * 0.25f; curProgress += runingProgress * 0.25f; progress.value = curProgress; } } private void ShowProgressIcon(int count) { for(int i = 0; i < hasnGetImage.Length; ++i) { if(i < count) { hasnGetImage[i].SetActive(false); hasGetImage[i].SetActive(true); } else { hasnGetImage[i].SetActive(true); hasGetImage[i].SetActive(false); } } } }