public NotificationElement GetElement() { NotificationElement element = objects.Dequeue(); element.FadeIn(); return(element); }
IEnumerator Notify(string text, Color color) { NotificationElement element = pool.GetElement(); float duration = settings.Duration; element.SetText(text); element.SetColor(color); yield return(new WaitForSeconds(duration)); pool.AddElement(element); }
/// <summary> /// Creates pool for notification elements. /// </summary> /// <param name="parent">Parent transform of pool.</param> /// <param name="amount">Pool size.</param> public NotificationPool(Transform parent, int amount) { prefab = Resources.Load <GameObject>("Prefabs/NotificationElement"); objects = new Queue <NotificationElement>(); for (int i = 0; i < amount; i++) { NotificationElement element = Object.Instantiate(prefab, parent).GetComponent <NotificationElement>(); AddElement(element); } }
public void AddElement(NotificationElement element) { element.FadeOut(); objects.Enqueue(element); }