Last active
July 8, 2021 03:39
-
-
Save DDru/cabe670a5abd684d20c2982355f5145f to your computer and use it in GitHub Desktop.
LeoECS disable systems by tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Установка тега. TestSystem для отключения систем по тегу | |
| m_Systems | |
| .Add(new Player.Systems.RotateSystem()).SetTag("test") | |
| .Add(new Player.Systems.MoveSystem()).SetTag("test") | |
| .Add(new TestSystem()) | |
| // Класс расширения с методами | |
| public static class EcsSystemDisabler { | |
| private static EcsSystems _anySystem; | |
| private static Dictionary<string, List<int>> _store; | |
| public static EcsSystems SetTag(this EcsSystems system, string tag) { | |
| if (_store == null) _store = new Dictionary<string, List<int>>(); | |
| _anySystem = system; | |
| if (_store.TryGetValue(tag, out var list)) { | |
| list.Add(GetIdx()); | |
| } else { | |
| _store.Add(tag, new List<int> { | |
| GetIdx() | |
| }); | |
| } | |
| return system; | |
| } | |
| public static void SetEnable(string tag, bool enable) { | |
| if (_store.TryGetValue(tag, out var list)) { | |
| for (var i = 0; i < list.Count; i++) { | |
| _anySystem.SetRunSystemState(list[i], enable); | |
| } | |
| } | |
| } | |
| private static int GetIdx() { | |
| return _anySystem.GetRunSystems().Count - 1; | |
| } | |
| } | |
| // Тестовая система для проверки | |
| internal class TestSystem : IEcsRunSystem { | |
| private readonly string systemsTag = "test"; | |
| public void Run() { | |
| if (Input.GetKeyDown(KeyCode.Tab)) { | |
| EcsSystemDisabler.SetEnable(systemsTag, false); | |
| } | |
| if (Input.GetKeyDown(KeyCode.LeftShift)) { | |
| EcsSystemDisabler.SetEnable(systemsTag, true); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment