From bc48d7e7e192c32888b5cc495f8b179ca3f18458 Mon Sep 17 00:00:00 2001 From: geondo55 <102933884+geondo55@users.noreply.github.com> Date: Wed, 9 Apr 2025 09:10:58 +0900 Subject: [PATCH] =?UTF-8?q?UserInputManager=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/Studio/Managers/UpdateRunner.cs | 37 ++++++++++++ .../Studio/Managers/UpdateRunner.cs.meta | 2 + .../Studio/Managers/UserInputManager.cs | 58 ++++++++----------- 3 files changed, 64 insertions(+), 33 deletions(-) create mode 100644 Assets/Scripts/Studio/Managers/UpdateRunner.cs create mode 100644 Assets/Scripts/Studio/Managers/UpdateRunner.cs.meta diff --git a/Assets/Scripts/Studio/Managers/UpdateRunner.cs b/Assets/Scripts/Studio/Managers/UpdateRunner.cs new file mode 100644 index 00000000..10e0c1c9 --- /dev/null +++ b/Assets/Scripts/Studio/Managers/UpdateRunner.cs @@ -0,0 +1,37 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using UnityEngine; +using XED.Core; + +namespace XED +{ + public class UpdateRunner : UnitySingleton + { + private static List updateActions = new List(); + + public static void AddAction(Action action) + { + if (!updateActions.Contains(action)) + { + updateActions.Add(action); + } + } + + public static void RemoveAction(Action action) + { + if (updateActions.Contains(action)) + { + updateActions.Remove(action); + } + } + + void Update() + { + foreach (Action action in updateActions) + { + action?.Invoke(); + } + } + } +} diff --git a/Assets/Scripts/Studio/Managers/UpdateRunner.cs.meta b/Assets/Scripts/Studio/Managers/UpdateRunner.cs.meta new file mode 100644 index 00000000..1ac3dffe --- /dev/null +++ b/Assets/Scripts/Studio/Managers/UpdateRunner.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 40294507f68cc2942b2bef179e37eb08 \ No newline at end of file diff --git a/Assets/Scripts/Studio/Managers/UserInputManager.cs b/Assets/Scripts/Studio/Managers/UserInputManager.cs index e7998038..b5e19cda 100644 --- a/Assets/Scripts/Studio/Managers/UserInputManager.cs +++ b/Assets/Scripts/Studio/Managers/UserInputManager.cs @@ -104,63 +104,55 @@ namespace XED.Manage } updateLoop += handler.updateLoop; } - IEnumerator UpdateCoroutine() + void Update() { - while (true) + foreach (var key in downKeyActionTable.Keys) { - foreach (var key in downKeyActionTable.Keys) + if (Input.GetKeyDown(key)) { - if (Input.GetKeyDown(key)) - { - Debug.Log("1"); - downKeyActionTable[key]?.Invoke(); - } + downKeyActionTable[key]?.Invoke(); } + } - foreach (var key in getKeyActionTable.Keys) + foreach (var key in getKeyActionTable.Keys) + { + if (Input.GetKey(key)) { - if (Input.GetKey(key)) - { - Debug.Log("2"); - getKeyActionTable[key]?.Invoke(); - } + getKeyActionTable[key]?.Invoke(); } + } - foreach (var key in upKeyActionTable.Keys) + foreach (var key in upKeyActionTable.Keys) + { + if (Input.GetKeyUp(key)) { - if (Input.GetKeyUp(key)) - { - Debug.Log("3"); - upKeyActionTable[key]?.Invoke(); - } + upKeyActionTable[key]?.Invoke(); } + } - foreach (var key in shortCutActionTable.Keys) + foreach (var key in shortCutActionTable.Keys) + { + if (Input.GetKey(key)) { - if (Input.GetKey(key)) + if (shortCutActionTable.TryGetValue(key, out var kk)) { - Debug.Log("4"); - if (shortCutActionTable.TryGetValue(key, out var kk)) + foreach (var k in kk) { - foreach (var k in kk) + if (Input.GetKeyDown(k.Key)) { - if (Input.GetKeyDown(k.Key)) - { - k.Value?.Invoke(); - } + k.Value?.Invoke(); } } } } - - updateLoop?.Invoke(); - yield return null; } + + updateLoop?.Invoke(); } public override void Init() { - CoroutineRunner.instance.StartCoroutine(UpdateCoroutine()); + UpdateRunner.AddAction(Update); } } }