Skip to content

Commit 2bab5ef

Browse files
Merge pull request #17 from CoderGamester/develop
Release 0.9.0
2 parents 085e117 + 5e8f321 commit 2bab5ef

File tree

4 files changed

+51
-16
lines changed

4 files changed

+51
-16
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this package will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
66

7+
8+
## [0.9.0] - 2024-11-01
9+
10+
- Added *GetUi<T>* method to the *IUiService*. It requests the *UiPresenter* by directly using generic T
11+
- Added *IsVisible<T>* method to the *IUiService*. It requests the visibility state of *UiPresenter*
12+
- Added IReadOnlyList property *VisiblePresenters* to the *IUiService* to allow external entities to access the list of visible *UiPresenter*
13+
14+
***Changed**:
15+
- Removed *GetAllVisibleUi()* method. Use *IsVisible<T>* method instead
16+
717
## [0.8.0] - 2024-10-29
818

919
- Added new *PresenterDelayerBase*, *AnimationDelayer* and *TimeDelayer* to support presenters that open/close with a delay

Runtime/IUiService.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public interface IUiService
1717
/// Gets a read-only dictionary of the Presenters currently Loaded in memory by the UI service.
1818
/// </summary>
1919
IReadOnlyDictionary<Type, UiPresenter> LoadedPresenters { get; }
20+
21+
/// <summary>
22+
/// Gets a read-only list of the Presenters currently currently visible and were opened by the UI service.
23+
/// </summary>
24+
IReadOnlyList<Type> VisiblePresenters { get; }
2025

2126
/// <summary>
2227
/// Gets a read-only dictionary of the layers used by the UI service.
@@ -28,6 +33,23 @@ public interface IUiService
2833
/// </summary>
2934
IReadOnlyDictionary<int, UiSetConfig> UiSets { get; }
3035

36+
/// <summary>
37+
/// Requests the UI of given type <typeparamref name="T"/>
38+
/// </summary>
39+
/// <exception cref="KeyNotFoundException">
40+
/// Thrown if the service does NOT contain an <see cref="UiPresenter"/> of the given <typeparamref name="T"/>
41+
/// </exception>
42+
/// <typeparam name="T">The type of UI presenter requested.</typeparam>
43+
/// <returns>The UI of type <typeparamref name="T"/> requested</returns>
44+
T GetUi<T>() where T : UiPresenter;
45+
46+
/// <summary>
47+
/// Requests the visible state of the given UI type <typeparamref name="T"/>.
48+
/// </summary>
49+
/// <typeparam name="T">The type of UI presenter to check if is visible or not.</typeparam>
50+
/// <returns>True if the UI is visble, false otherwise</returns>
51+
bool IsVisible<T>() where T : UiPresenter;
52+
3153
/// <summary>
3254
/// Adds a UI configuration to the service.
3355
/// </summary>
@@ -141,12 +163,6 @@ public interface IUiService
141163
/// <exception cref="KeyNotFoundException">Thrown if the service does not contain a UI set with the specified ID.</exception>
142164
void UnloadUiSet(int setId);
143165

144-
/// <summary>
145-
/// Gets a list of all visible UI presenters.
146-
/// </summary>
147-
/// <returns>A list of types of visible UI presenters.</returns>
148-
List<Type> GetAllVisibleUi();
149-
150166
/// <summary>
151167
/// Opens a UI presenter asynchronously, loading its assets if necessary.
152168
/// </summary>

Runtime/UiService.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class UiService : IUiServiceInit
1919
private readonly IDictionary<int, GameObject> _layers = new Dictionary<int, GameObject>();
2020
private readonly IDictionary<Type, UiPresenter> _uiPresenters = new Dictionary<Type, UiPresenter>();
2121

22+
private Type _loadingSpinnerType;
23+
private Transform _uiParent;
24+
2225
/// <inheritdoc />
2326
public IReadOnlyDictionary<Type, UiPresenter> LoadedPresenters => new Dictionary<Type, UiPresenter>(_uiPresenters);
2427

@@ -28,8 +31,8 @@ public class UiService : IUiServiceInit
2831
/// <inheritdoc />
2932
public IReadOnlyDictionary<int, UiSetConfig> UiSets => new Dictionary<int, UiSetConfig>(_uiSets);
3033

31-
private Type _loadingSpinnerType;
32-
private Transform _uiParent;
34+
/// <inheritdoc />
35+
public IReadOnlyList<Type> VisiblePresenters => new List<Type>(_visibleUiList);
3336

3437
public UiService() : this(new UiAssetLoader()) { }
3538

@@ -65,6 +68,18 @@ public void Init(UiConfigs configs)
6568
}
6669
}
6770

71+
/// <inheritdoc />
72+
public T GetUi<T>() where T : UiPresenter
73+
{
74+
return _uiPresenters[typeof(T)] as T;
75+
}
76+
77+
/// <inheritdoc />
78+
public bool IsVisible<T>() where T : UiPresenter
79+
{
80+
return _visibleUiList.Contains(typeof(T));
81+
}
82+
6883
/// <inheritdoc />
6984
public void AddUiConfig(UiConfig config)
7085
{
@@ -219,12 +234,6 @@ public void UnloadUiSet(int setId)
219234
}
220235
}
221236

222-
/// <inheritdoc />
223-
public List<Type> GetAllVisibleUi()
224-
{
225-
return new List<Type>(_visibleUiList);
226-
}
227-
228237
/// <inheritdoc />
229238
public async Task<UiPresenter> OpenUiAsync(Type type)
230239
{

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "com.gamelovers.uiservice",
33
"displayName": "UiService",
44
"author": "Miguel Tomas",
5-
"version": "0.8.0",
6-
"unity": "2022.4",
5+
"version": "0.9.0",
6+
"unity": "2022.3",
77
"license": "MIT",
88
"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",
99
"dependencies": {

0 commit comments

Comments
 (0)