From ded822e98e8eda49618d17e53407b0df1896e539 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 22 Apr 2022 19:24:15 +0800 Subject: * rename AlienSurvival project to SurvivalTest --- SurvivalTest/Assets/Scripts/Utils/GameLoop.cs | 20 +++++++++ SurvivalTest/Assets/Scripts/Utils/GameLoop.cs.meta | 11 +++++ .../Assets/Scripts/Utils/GameObjectUtils.cs | 18 ++++++++ .../Assets/Scripts/Utils/GameObjectUtils.cs.meta | 11 +++++ SurvivalTest/Assets/Scripts/Utils/Singleton.cs | 24 +++++++++++ .../Assets/Scripts/Utils/Singleton.cs.meta | 11 +++++ SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs | 48 ++++++++++++++++++++++ .../Assets/Scripts/Utils/TinyCountDown.cs.meta | 11 +++++ 8 files changed, 154 insertions(+) create mode 100644 SurvivalTest/Assets/Scripts/Utils/GameLoop.cs create mode 100644 SurvivalTest/Assets/Scripts/Utils/GameLoop.cs.meta create mode 100644 SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs create mode 100644 SurvivalTest/Assets/Scripts/Utils/GameObjectUtils.cs.meta create mode 100644 SurvivalTest/Assets/Scripts/Utils/Singleton.cs create mode 100644 SurvivalTest/Assets/Scripts/Utils/Singleton.cs.meta create mode 100644 SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs create mode 100644 SurvivalTest/Assets/Scripts/Utils/TinyCountDown.cs.meta (limited to 'SurvivalTest/Assets/Scripts/Utils') 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 +{ + + 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(this GameObject go) where T : MonoBehaviour + { + T comp = go.GetComponent(); + if(comp == null) + { + comp = go.AddComponent(); + } + 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 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 +{ + + private Dictionary m_CountDown = new Dictionary(); + 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 keys = new List(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: -- cgit v1.1-26-g67d0