using System; using System.Text; using UnityEngine; public class NotificationPopper : MonoBehaviour { public TextRenderer TextArea; public float zPos = -350f; private float alphaTimer; public float ShowDuration = 5f; public float FadeDuration = 1f; public Color textColor = Color.white; private StringBuilder builder = new StringBuilder(); public AudioClip NotificationSound; public void Update() { if (this.alphaTimer > 0f) { float num = Camera.main.orthographicSize * Camera.main.aspect; if (!DestroyableSingleton.Instance.TaskText.isActiveAndEnabled) { float height = DestroyableSingleton.Instance.GameSettings.Height; Transform transform = DestroyableSingleton.Instance.GameSettings.transform; base.transform.localPosition = new Vector3(-num + 0.1f, transform.localPosition.y - height, this.zPos); } else { float height2 = DestroyableSingleton.Instance.TaskText.Height; Transform parent = DestroyableSingleton.Instance.TaskText.transform.parent; base.transform.localPosition = new Vector3(-num + 0.1f, parent.localPosition.y - height2 - 0.2f, this.zPos); } this.alphaTimer -= Time.deltaTime; this.textColor.a = Mathf.Clamp(this.alphaTimer / this.FadeDuration, 0f, 1f); this.TextArea.Color = this.textColor; if (this.alphaTimer <= 0f) { this.builder.Clear(); this.TextArea.Text = string.Empty; } } } public void AddItem(string item) { this.builder.AppendLine(item); this.TextArea.Text = this.builder.ToString(); this.alphaTimer = this.ShowDuration; SoundManager.Instance.PlaySound(this.NotificationSound, false, 1f); } }