summaryrefslogtreecommitdiff
path: root/SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs
blob: dbeae5528e6c18f6dd67b47c14680cb339c7d369 (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
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TinyCountDown :Singleton<TinyCountDown>
{

	private Dictionary<string, float> m_CountDown = new Dictionary<string, float>();
	public TinyCountDown()
	{
	}

	public void Set(string key, float time)
	{
		if (!m_CountDown.ContainsKey(key))
		{
			m_CountDown.Add(key, time);
		}
		else
		{
			m_CountDown[key] = time;
		}
	}

	public float Get(string key)
	{
		if (m_CountDown.ContainsKey(key))
		{
			return m_CountDown[key];
		}
		return 0;
	}

	public void Update()
	{
		List<string> keys = new List<string>(m_CountDown.Keys);
		foreach (var key in keys)
		{
			m_CountDown[key] -= Time.deltaTime;
			if(m_CountDown[key] <= 0)
			{
				m_CountDown.Remove(key);
			}
		}

	}
}