public void UpdateTimeImage() { foreach (Image img in m_PreRemoveImgList) { if (m_TimeImageDict.ContainsKey(img)) { if (m_TimeImageDict[img].hideObjOnRemove != null) { m_TimeImageDict[img].hideObjOnRemove.SetActive(false); } m_TimeImageDict.Remove(img); } } m_PreRemoveImgList.Clear(); List <Image> list = new List <Image>(m_TimeImageDict.Keys); foreach (Image img in list) { CountdownImgInfo info = m_TimeImageDict[img]; if (info.text) { int sec = (int)System.Math.Ceiling(img.fillAmount * info.time); info.text.text = sec.ToString(); } img.fillAmount -= Time.unscaledDeltaTime / info.time; if (img.fillAmount <= 0.0f) { img.fillAmount = 0.0f; if (info.text) { info.text.text = "0"; } bool bRemove = true; if (info.callFuc != null) { bRemove = info.callFuc(0, false, img, info.userdata); } if (bRemove) { m_PreRemoveImgList.Add(img); } } } }
public void AddTimeImage(Image img, float time, float fill, CallBackFunc fun, Text t = null, bool bHaveBtn = false, string userdata = "", GameObject hideObjOnRemove = null) { img.fillAmount = fill; m_PreRemoveImgList.Remove(img); if (!m_TimeImageDict.ContainsKey(img)) { CountdownImgInfo info = new CountdownImgInfo(); info.time = time; info.callFuc = fun; info.text = t; info.hideObjOnRemove = hideObjOnRemove; info.userdata = userdata; if (bHaveBtn) { Button[] btns = img.transform.parent.GetComponentsInChildren <Button>(); if (btns.Length > 0) { btns[0].onClick.RemoveAllListeners(); btns[0].onClick.AddListener(() => { fun(1, true, img, info.userdata); m_PreRemoveImgList.Add(img); }); } if (btns.Length > 1) { btns[1].onClick.RemoveAllListeners(); btns[1].onClick.AddListener(() => { fun(0, true, img, info.userdata); m_PreRemoveImgList.Add(img); }); } } m_TimeImageDict.Add(img, info); } else { CountdownImgInfo info = m_TimeImageDict[img]; info.time = time; info.callFuc = fun; info.text = t; info.hideObjOnRemove = hideObjOnRemove; info.userdata = userdata; m_TimeImageDict[img] = info; } }
public void RemoveTimeImage(Image img, bool bCallFun = false) { if (m_TimeImageDict.ContainsKey(img)) { CountdownImgInfo info = m_TimeImageDict[img]; img.fillAmount = 0; bool bRemove = true; if (bCallFun && info.callFuc != null) { bRemove = info.callFuc(0, false, img, info.userdata); } if (bRemove) { m_PreRemoveImgList.Add(img); } } }