static int Comparison(AlertParts a, AlertParts b) { if (a.movementStart < b.movementStart) { return(-1); } if (a.movementStart > b.movementStart) { return(1); } return(0); }
AlertParts Create(bool icon) { // See if an unused entry can be reused if (mUnused.Count > 0) { for (int i = 0; i < mUnused.Count; i++) { AlertParts comp = mUnused[i]; if (comp.isIcon == icon) { mUnused.RemoveAt(i); comp.time = Time.realtimeSinceStartup; comp.gameObject.SetActive(true); comp.offsetY = 0f; comp.offsetX = 0; comp.sign = 0; mList.Add(comp); return(comp); } } } // New entry AlertParts item = null; if (icon) { item = Instantiate(iconLabelPrefab); } else { item = Instantiate(labelPrefab); } item.gameObject.SetActive(true); item.mTransform.SetParent(windowBox); item.mTransform.localPosition = Vector3.zero; item.time = Time.realtimeSinceStartup; item.sign = 0; //ne.label = NGUITools.AddWidget<UILabel>(gameObject); item.name = counter.ToString(); // Make it small so that it's invisible to start with item.mTransform.localScale = new Vector3(0.01f, 0.01f, 0.01f); mList.Add(item); ++counter; return(item); }
public void ShowAlert(Sprite sp, string tip, Vector2 initPos) { if (!enabled) { return; } //float time = Time.realtimeSinceStartup; float val = 0f; // Create a new entry AlertParts ne = Create(sp != null ? true : false); ne.stay = 0; //ne.label.color = c; ne.val = val; ne.initOffY = 0; ne.initPos = initPos; ne.UpdateImage(sp); ne.label.text = tip; // Sort the list mList.Sort(Comparison); }
void Delete(AlertParts ent) { mList.Remove(ent); mUnused.Add(ent); ent.gameObject.SetActive(false); }
void Update() { if (mList.Count == 0) { return; } float time = Time.realtimeSinceStartup; Keyframe[] offsetYs = offsetYCurve.keys; Keyframe[] offsetXs = offsetXCurve.keys; Keyframe[] alphas = alphaCurve.keys; Keyframe[] scales = scaleCurve.keys; float offsetYEnd = offsetYs[offsetYs.Length - 1].time; float offsetXEnd = offsetYs[offsetXs.Length - 1].time; float alphaEnd = alphas[alphas.Length - 1].time; float scalesEnd = scales[scales.Length - 1].time; float totalEnd = Mathf.Max(scalesEnd, Mathf.Max(offsetYEnd, alphaEnd, offsetXEnd)); // Adjust alpha and delete old entries for (int i = mList.Count; i > 0;) { AlertParts ent = mList[--i]; float currentTime = time - ent.movementStart; ent.offsetY = offsetYCurve.Evaluate(currentTime); ent.offsetX = offsetXCurve.Evaluate(currentTime); float alp = alphaCurve.Evaluate(currentTime); Color orgColor = ent.label.color; ent.label.color = new Color(orgColor.r, orgColor.g, orgColor.b, alp); // Make the label scale in float s = scaleCurve.Evaluate(time - ent.time) * 1; if (s < 0.001f) { s = 0.001f; } ent.mTransform.localScale = new Vector3(s, s, s); // Delete the entry when needed if (currentTime > totalEnd) { Delete(ent); } else { ent.enabled = true; } } float offsetY = 0f; float offsetX = 0f; // Move the entries for (int i = mList.Count; i > 0;) { AlertParts ent = mList[--i]; offsetY = Mathf.Max(offsetY, ent.offsetY) + ent.initOffY + ent.initPos.y; offsetX = Mathf.Max(offsetX, ent.offsetX) * ent.sign + ent.initPos.x; ent.mTransform.localPosition = new Vector3(offsetX, offsetY, 0f); offsetY += Mathf.Round(ent.mTransform.localScale.y); } }