diff options
author | chai <chaifix@163.com> | 2022-04-22 09:24:15 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2022-04-22 09:24:15 +0800 |
commit | 06df35f1e8e9695b844553867a39cd12d68db8b4 (patch) | |
tree | 3af5c78db3d84bfe8bbea26a54031cf0b1169f7e /AlienSurvival/Assets/Scripts/Utils/TinyCountDown.cs | |
parent | ea0717eba0b624d47bd60edba7fb7862633f2f5f (diff) |
*arrow
Diffstat (limited to 'AlienSurvival/Assets/Scripts/Utils/TinyCountDown.cs')
-rw-r--r-- | AlienSurvival/Assets/Scripts/Utils/TinyCountDown.cs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/AlienSurvival/Assets/Scripts/Utils/TinyCountDown.cs b/AlienSurvival/Assets/Scripts/Utils/TinyCountDown.cs new file mode 100644 index 0000000..dbeae55 --- /dev/null +++ b/AlienSurvival/Assets/Scripts/Utils/TinyCountDown.cs @@ -0,0 +1,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); + } + } + + } +} |