diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/GamefeelManager.cs |
+ init
Diffstat (limited to 'GameCode/GamefeelManager.cs')
-rw-r--r-- | GameCode/GamefeelManager.cs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/GameCode/GamefeelManager.cs b/GameCode/GamefeelManager.cs new file mode 100644 index 0000000..ac99a47 --- /dev/null +++ b/GameCode/GamefeelManager.cs @@ -0,0 +1,60 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class GamefeelManager : MonoBehaviour +{ + public static GamefeelManager instance; + + private List<GameFeeler> m_GameFeelers = new List<GameFeeler>(); + + private void Awake() + { + instance = this; + } + + public static void RegisterGamefeeler(GameFeeler gameFeeler) + { + instance.m_GameFeelers.Add(gameFeeler); + } + + public void AddUIGameFeel(Vector2 directionForce) + { + for (int i = 0; i < instance.m_GameFeelers.Count; i++) + { + instance.m_GameFeelers[i].OnUIGameFeel(directionForce); + } + } + + public void AddGameFeel(Vector2 directionForce) + { + for (int i = 0; i < instance.m_GameFeelers.Count; i++) + { + instance.m_GameFeelers[i].OnGameFeel(directionForce); + } + } + + public static void GameFeel(Vector2 directionForce) + { + for (int i = 0; i < instance.m_GameFeelers.Count; i++) + { + instance.m_GameFeelers[i].OnGameFeel(directionForce); + } + } + + public void AddUIGameFeelOverTime(float amount, float time) + { + StartCoroutine(DoUIGameFeelOverTime(amount, time)); + } + + private IEnumerator DoUIGameFeelOverTime(float amount, float time) + { + float startTime = time; + while (time > 0f) + { + instance.AddUIGameFeel(amount * (Vector2)Random.onUnitSphere * Time.unscaledDeltaTime * (time / startTime)); + time -= Time.unscaledDeltaTime; + yield return null; + } + } +} |