diff --git a/Assets/_DDD/_Scripts/GameUi/BaseUi/InteractionUis/InteractionMessageUi.cs b/Assets/_DDD/_Scripts/GameUi/BaseUi/InteractionUis/InteractionMessageUi.cs index 13b3bddfb..fa5191a46 100644 --- a/Assets/_DDD/_Scripts/GameUi/BaseUi/InteractionUis/InteractionMessageUi.cs +++ b/Assets/_DDD/_Scripts/GameUi/BaseUi/InteractionUis/InteractionMessageUi.cs @@ -1,5 +1,4 @@ using TMPro; -using Unity.VisualScripting; using UnityEngine; using UnityEngine.Localization; using UnityEngine.Localization.Components; @@ -18,29 +17,24 @@ public class InteractionMessageUi : BaseUi, IEventHandler(this); - EventBus.Register(this); - } - - protected override void OnClosedEvents() - { - base.OnClosedEvents(); - + base.OnDestroy(); + EventBus.Unregister(this); EventBus.Unregister(this); } + protected override void OnCreatedInitialize() + { + base.OnCreatedInitialize(); + + _filledImage.fillAmount = 0f; + + EventBus.Register(this); + EventBus.Register(this); + } + public void Invoke(ShowInteractionUiEvent evt) { ShowInteractionUiEvent(evt); diff --git a/Assets/_DDD/_Scripts/GameUi/BaseUi/PopupUis/UiState.cs b/Assets/_DDD/_Scripts/GameUi/BaseUi/PopupUis/UiState.cs index f23f7e963..ecb2e0bc5 100644 --- a/Assets/_DDD/_Scripts/GameUi/BaseUi/PopupUis/UiState.cs +++ b/Assets/_DDD/_Scripts/GameUi/BaseUi/PopupUis/UiState.cs @@ -109,7 +109,7 @@ public bool HasMatchingPopupUis(GameFlowState flowState) public void CreateUi(BaseUi ui, Transform parent) { - if (_uis.TryGetValue(ui.GetType(), out var registered) && registered == ui) return; + if (_uis.ContainsKey(ui.GetType())) return; var instance = Instantiate(ui, parent); instance.name = ui.name; @@ -118,7 +118,7 @@ public void CreateUi(BaseUi ui, Transform parent) public void DestroyUi(BaseUi ui) { - if (_uis.TryGetValue(ui.GetType(), out var registered) && registered == ui) return; + if (_uis.ContainsKey(ui.GetType())) return; Destroy(ui.gameObject); } diff --git a/Assets/_DDD/_Scripts/GameUi/UiManager.cs b/Assets/_DDD/_Scripts/GameUi/UiManager.cs index 7b1db12ef..c70640413 100644 --- a/Assets/_DDD/_Scripts/GameUi/UiManager.cs +++ b/Assets/_DDD/_Scripts/GameUi/UiManager.cs @@ -21,7 +21,10 @@ private void OnDestroy() public void PreInit() { - ClearAll(); + Utils.DestroyAllChildren(_hudRoot); + Utils.DestroyAllChildren(_interactionUiRoot); + Utils.DestroyAllChildren(_popupUiRoot); + Utils.DestroyAllChildren(_commonUiRoot); GameFlowManager.Instance.FlowHandlers.Add(this); } @@ -50,22 +53,6 @@ public void PostInit() } - private void ClearObjects(Transform root) - { - foreach (Transform child in root) - { - Destroy(child.gameObject); - } - } - - private void ClearAll() - { - ClearObjects(_hudRoot); - ClearObjects(_interactionUiRoot); - ClearObjects(_popupUiRoot); - ClearObjects(_commonUiRoot); - } - public Task OnReadyNewFlow(GameFlowState newFlowState) { var flowToUiMapping = UiData.FlowToUiMapping;