summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/NotificationPopper.cs
blob: 8a9811546352e76ca91deb479a62a5addfa24c9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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<HudManager>.Instance.TaskText.isActiveAndEnabled)
			{
				float height = DestroyableSingleton<HudManager>.Instance.GameSettings.Height;
				Transform transform = DestroyableSingleton<HudManager>.Instance.GameSettings.transform;
				base.transform.localPosition = new Vector3(-num + 0.1f, transform.localPosition.y - height, this.zPos);
			}
			else
			{
				float height2 = DestroyableSingleton<HudManager>.Instance.TaskText.Height;
				Transform parent = DestroyableSingleton<HudManager>.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);
	}
}