summaryrefslogtreecommitdiff
path: root/SurvivalTest/Assets/Scripts/Utils
diff options
context:
space:
mode:
Diffstat (limited to 'SurvivalTest/Assets/Scripts/Utils')
-rw-r--r--SurvivalTest/Assets/Scripts/Utils/GameLoop.cs20
-rw-r--r--SurvivalTest/Assets/Scripts/Utils/GameLoop.cs.meta11
-rw-r--r--SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs18
-rw-r--r--SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs.meta11
-rw-r--r--SurvivalTest/Assets/Scripts/Utils/Singleton.cs24
-rw-r--r--SurvivalTest/Assets/Scripts/Utils/Singleton.cs.meta11
-rw-r--r--SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs48
-rw-r--r--SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs.meta11
8 files changed, 154 insertions, 0 deletions
diff --git a/SurvivalTest/Assets/Scripts/Utils/GameLoop.cs b/SurvivalTest/Assets/Scripts/Utils/GameLoop.cs
new file mode 100644
index 0000000..6ae7d87
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/Utils/GameLoop.cs
@@ -0,0 +1,20 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class GameLoop : Singleton<GameLoop>
+{
+
+ public GameLoop()
+ {
+ indexOfUpdate = 0;
+ }
+
+ public int indexOfUpdate { get; private set; } = 0;
+
+ public void Update()
+ {
+ ++indexOfUpdate;
+ }
+
+} \ No newline at end of file
diff --git a/SurvivalTest/Assets/Scripts/Utils/GameLoop.cs.meta b/SurvivalTest/Assets/Scripts/Utils/GameLoop.cs.meta
new file mode 100644
index 0000000..fa6fa0e
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/Utils/GameLoop.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 5ce4c552f3823e842853a52a52d3cc3b
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: -1100
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs b/SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs
new file mode 100644
index 0000000..416f097
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs
@@ -0,0 +1,18 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public static class GameObjectUtils
+{
+
+ public static T AddOrGetComponent<T>(this GameObject go) where T : MonoBehaviour
+ {
+ T comp = go.GetComponent<T>();
+ if(comp == null)
+ {
+ comp = go.AddComponent<T>();
+ }
+ return comp;
+ }
+
+} \ No newline at end of file
diff --git a/SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs.meta b/SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs.meta
new file mode 100644
index 0000000..eb4979a
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: a2cfaa149609631408d5f2f301a232fe
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SurvivalTest/Assets/Scripts/Utils/Singleton.cs b/SurvivalTest/Assets/Scripts/Utils/Singleton.cs
new file mode 100644
index 0000000..d7aad49
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/Utils/Singleton.cs
@@ -0,0 +1,24 @@
+public class Singleton<T> where T : class, new()
+{
+ private static T _instance;
+ private static readonly object syslock = new object();
+
+ public static T Instance
+ {
+ get
+ {
+ if (_instance == null)
+ {
+ lock (syslock)
+ {
+ if (_instance == null)
+ {
+ _instance = new T();
+ }
+ }
+ }
+ return _instance;
+
+ }
+ }
+} \ No newline at end of file
diff --git a/SurvivalTest/Assets/Scripts/Utils/Singleton.cs.meta b/SurvivalTest/Assets/Scripts/Utils/Singleton.cs.meta
new file mode 100644
index 0000000..ff0aab9
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/Utils/Singleton.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1b80a3ccdebef4b4db85130a4bde2d00
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs b/SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs
new file mode 100644
index 0000000..dbeae55
--- /dev/null
+++ b/SurvivalTest/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);
+ }
+ }
+
+ }
+}
diff --git a/SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs.meta b/SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs.meta
new file mode 100644
index 0000000..c9f5545
--- /dev/null
+++ b/SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: de0d1a4a5baf48a4083e5d7f457ea8b0
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: