From 5e8f321d9b336d1b552efde2bcba323a3e77e309 Mon Sep 17 00:00:00 2001 From: CoderGamester Date: Fri, 1 Nov 2024 02:16:18 +0000 Subject: [PATCH] - Added *GetUi* method to the *IUiService*. It requests the *UiPresenter* by directly using generic T - Added *IsVisible* method to the *IUiService*. It requests the visibility state of *UiPresenter* - Added IReadOnlyList property *VisiblePresenters* to the *IUiService* to allow external entities to access the list of visible *UiPresenter* ***Changed**: - Removed *GetAllVisibleUi()* method. Use *IsVisible* method instead --- CHANGELOG.md | 10 ++++++++++ Runtime/IUiService.cs | 28 ++++++++++++++++++++++------ Runtime/UiService.cs | 25 +++++++++++++++++-------- package.json | 4 ++-- 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0fd605..5b76404 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html) + +## [0.9.0] - 2024-11-01 + +- Added *GetUi* method to the *IUiService*. It requests the *UiPresenter* by directly using generic T +- Added *IsVisible* method to the *IUiService*. It requests the visibility state of *UiPresenter* +- Added IReadOnlyList property *VisiblePresenters* to the *IUiService* to allow external entities to access the list of visible *UiPresenter* + +***Changed**: +- Removed *GetAllVisibleUi()* method. Use *IsVisible* method instead + ## [0.8.0] - 2024-10-29 - Added new *PresenterDelayerBase*, *AnimationDelayer* and *TimeDelayer* to support presenters that open/close with a delay diff --git a/Runtime/IUiService.cs b/Runtime/IUiService.cs index 71ddf2c..75d5e83 100644 --- a/Runtime/IUiService.cs +++ b/Runtime/IUiService.cs @@ -17,6 +17,11 @@ public interface IUiService /// Gets a read-only dictionary of the Presenters currently Loaded in memory by the UI service. /// IReadOnlyDictionary LoadedPresenters { get; } + + /// + /// Gets a read-only list of the Presenters currently currently visible and were opened by the UI service. + /// + IReadOnlyList VisiblePresenters { get; } /// /// Gets a read-only dictionary of the layers used by the UI service. @@ -28,6 +33,23 @@ public interface IUiService /// IReadOnlyDictionary UiSets { get; } + /// + /// Requests the UI of given type + /// + /// + /// Thrown if the service does NOT contain an of the given + /// + /// The type of UI presenter requested. + /// The UI of type requested + T GetUi() where T : UiPresenter; + + /// + /// Requests the visible state of the given UI type . + /// + /// The type of UI presenter to check if is visible or not. + /// True if the UI is visble, false otherwise + bool IsVisible() where T : UiPresenter; + /// /// Adds a UI configuration to the service. /// @@ -141,12 +163,6 @@ public interface IUiService /// Thrown if the service does not contain a UI set with the specified ID. void UnloadUiSet(int setId); - /// - /// Gets a list of all visible UI presenters. - /// - /// A list of types of visible UI presenters. - List GetAllVisibleUi(); - /// /// Opens a UI presenter asynchronously, loading its assets if necessary. /// diff --git a/Runtime/UiService.cs b/Runtime/UiService.cs index a14013f..a56464b 100644 --- a/Runtime/UiService.cs +++ b/Runtime/UiService.cs @@ -19,6 +19,9 @@ public class UiService : IUiServiceInit private readonly IDictionary _layers = new Dictionary(); private readonly IDictionary _uiPresenters = new Dictionary(); + private Type _loadingSpinnerType; + private Transform _uiParent; + /// public IReadOnlyDictionary LoadedPresenters => new Dictionary(_uiPresenters); @@ -28,8 +31,8 @@ public class UiService : IUiServiceInit /// public IReadOnlyDictionary UiSets => new Dictionary(_uiSets); - private Type _loadingSpinnerType; - private Transform _uiParent; + /// + public IReadOnlyList VisiblePresenters => new List(_visibleUiList); public UiService() : this(new UiAssetLoader()) { } @@ -65,6 +68,18 @@ public void Init(UiConfigs configs) } } + /// + public T GetUi() where T : UiPresenter + { + return _uiPresenters[typeof(T)] as T; + } + + /// + public bool IsVisible() where T : UiPresenter + { + return _visibleUiList.Contains(typeof(T)); + } + /// public void AddUiConfig(UiConfig config) { @@ -219,12 +234,6 @@ public void UnloadUiSet(int setId) } } - /// - public List GetAllVisibleUi() - { - return new List(_visibleUiList); - } - /// public async Task OpenUiAsync(Type type) { diff --git a/package.json b/package.json index d05ba69..0b8e80d 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "com.gamelovers.uiservice", "displayName": "UiService", "author": "Miguel Tomas", - "version": "0.8.0", - "unity": "2022.4", + "version": "0.9.0", + "unity": "2022.3", "license": "MIT", "description": "This package provides a service to help manage an Unity's, game UI.\nIt allows to open, close, load, unload and request any Ui Configured in the game.\nThe package provides a Ui Set that allows to group a set of Ui Presenters to help load, open and close multiple Uis at the same time.\n\nTo help configure the game's UI you need to create a UiConfigs Scriptable object by:\n- Right Click on the Project View > Create > ScriptableObjects > Configs > UiConfigs", "dependencies": {