diff --git a/CHANGELOG.md b/CHANGELOG.md
index dec7796..051ac3f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,10 +4,17 @@ 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.5.0] - 2020-07-13
+
+- Added *UiAssetLoader* to load Ui assets to memory
+
+**Changed**:
+- Removed the *UiService* dependency from the *com.gamelovers.assetLoader*
+
## [0.4.0] - 2020-07-13
**Changed**:
-- Removed the *UiService* dependency from the *Addressables*
+- Removed the *UiService* dependency from the *com.unity.addressables*
- Modified the *UiService* to be testable and injectable into other systems
## [0.3.2] - 2020-04-18
diff --git a/Runtime/GameLovers.UiService.asmdef b/Runtime/GameLovers.UiService.asmdef
index 3769eb2..c1af9e3 100644
--- a/Runtime/GameLovers.UiService.asmdef
+++ b/Runtime/GameLovers.UiService.asmdef
@@ -1,9 +1,8 @@
{
- "name": "UiService",
+ "name": "GameLovers.UiService",
"references": [
"GUID:84651a3751eca9349aac36a66bba901b",
- "GUID:9e24947de15b9834991c9d8411ea37cf",
- "GUID:ebfc05ee5a737f94d8b07099524dab77"
+ "GUID:9e24947de15b9834991c9d8411ea37cf"
],
"includePlatforms": [],
"excludePlatforms": [],
diff --git a/Runtime/UiAssetLoader.cs b/Runtime/UiAssetLoader.cs
new file mode 100644
index 0000000..abe265b
--- /dev/null
+++ b/Runtime/UiAssetLoader.cs
@@ -0,0 +1,62 @@
+using System.Threading.Tasks;
+using UnityEngine;
+using UnityEngine.AddressableAssets;
+using UnityEngine.ResourceManagement.AsyncOperations;
+using UnityEngine.ResourceManagement.ResourceProviders;
+
+// ReSharper disable CheckNamespace
+
+namespace GameLovers.UiService
+{
+ ///
+ /// This interface allows to wrap the asset loading scheme into the UI memory
+ ///
+ public interface IUiAssetLoader
+ {
+ ///
+ /// Loads and instantiates the prefab in the given with the given
+ /// and the given to preserve the instance transform relative to world
+ /// space or relative to the parent.
+ /// To help the execution of this method is recommended to request the asset path from an .
+ /// This method can be controlled in an async method and returns the prefab instantiated
+ ///
+ Task InstantiatePrefabAsync(string path, Transform parent, bool instantiateInWorldSpace);
+
+ ///
+ /// Unloads the given from the game memory.
+ /// If is of type, then will also destroy it
+ ///
+ void UnloadAsset(T asset);
+ }
+
+ ///
+ public class UiAssetLoader : IUiAssetLoader
+ {
+ ///
+ public async Task InstantiatePrefabAsync(string path, Transform parent, bool instantiateInWorldSpace)
+ {
+ var operation = Addressables.InstantiateAsync(path, new InstantiationParameters(parent, instantiateInWorldSpace));
+
+ await operation.Task;
+
+ if (operation.Status != AsyncOperationStatus.Succeeded)
+ {
+ throw operation.OperationException;
+ }
+
+ return operation.Result;
+ }
+
+ ///
+ public void UnloadAsset(T asset)
+ {
+ Addressables.Release(asset);
+
+ var gameObject = asset as GameObject;
+ if (gameObject != null)
+ {
+ UnityEngine.Object.Destroy(gameObject);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/UiAssetLoader.cs.meta b/Runtime/UiAssetLoader.cs.meta
new file mode 100644
index 0000000..98a7e2e
--- /dev/null
+++ b/Runtime/UiAssetLoader.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 16bb54f918cc43fd976df9650a614516
+timeCreated: 1596908818
\ No newline at end of file
diff --git a/Runtime/UiConfig.cs b/Runtime/UiConfig.cs
deleted file mode 100644
index b087293..0000000
--- a/Runtime/UiConfig.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using System;
-
-// ReSharper disable CheckNamespace
-
-namespace GameLovers.UiService
-{
- ///
- /// Represents a configuration of an with all it's important data
- /// The Id is the int representation of the UI generated by the UiIdsGenerator code generator
- ///
- [Serializable]
- public struct UiConfig
- {
- public string AddressableAddress;
- public int Layer;
- public Type UiType;
- }
-}
\ No newline at end of file
diff --git a/Runtime/UiConfig.cs.meta b/Runtime/UiConfig.cs.meta
deleted file mode 100644
index 373eab0..0000000
--- a/Runtime/UiConfig.cs.meta
+++ /dev/null
@@ -1,3 +0,0 @@
-fileFormatVersion: 2
-guid: ba008bfe59a548a4809efbb1bcd4801d
-timeCreated: 1574986631
\ No newline at end of file
diff --git a/Runtime/UiConfigs.cs b/Runtime/UiConfigs.cs
index 10c2dc1..84b3a02 100644
--- a/Runtime/UiConfigs.cs
+++ b/Runtime/UiConfigs.cs
@@ -7,7 +7,19 @@
namespace GameLovers.UiService
{
///
- /// Scriptable Object tool to import the & to be used in the
+ /// Represents a configuration of an with all it's important data
+ /// The Id is the int representation of the UI generated by the UiIdsGenerator code generator
+ ///
+ [Serializable]
+ public struct UiConfig
+ {
+ public string AddressableAddress;
+ public int Layer;
+ public Type UiType;
+ }
+
+ ///
+ /// ScriptableObject tool to import the & to be used in the
///
[CreateAssetMenu(fileName = "UiConfigs", menuName = "ScriptableObjects/Configs/UiConfigs")]
public class UiConfigs : ScriptableObject
diff --git a/Runtime/UiPresenter.cs b/Runtime/UiPresenter.cs
index fd23a49..52faa6e 100644
--- a/Runtime/UiPresenter.cs
+++ b/Runtime/UiPresenter.cs
@@ -60,8 +60,8 @@ internal void InternalClose()
}
///
- /// Tags the as a to allow definning a specific state when
- /// opening it via the
+ /// Tags the as a to allow defining a specific state when
+ /// opening the UI via the
///
public interface IUiPresenterData {}
@@ -69,8 +69,7 @@ public interface IUiPresenterData {}
///
/// Extends the behaviour with defined data of type
///
- public abstract class UiPresenterData : UiPresenter, IUiPresenterData
- where T : struct
+ public abstract class UiPresenterData : UiPresenter, IUiPresenterData where T : struct
{
///
/// The Ui data defined when opened via the
diff --git a/Runtime/UiService.cs b/Runtime/UiService.cs
index c24af62..7cf4b5b 100644
--- a/Runtime/UiService.cs
+++ b/Runtime/UiService.cs
@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
using System.Threading.Tasks;
-using GameLovers.AssetLoader;
using UnityEngine;
// ReSharper disable CheckNamespace
@@ -11,21 +12,25 @@ namespace GameLovers.UiService
///
public class UiService : IUiService
{
- private readonly IAssetLoader _assetLoader;
+ private readonly IUiAssetLoader _assetLoader;
private readonly IDictionary _uiViews = new Dictionary();
private readonly IDictionary _uiConfigs = new Dictionary();
private readonly IDictionary _uiSets = new Dictionary();
private readonly IList _visibleUiList = new List();
private readonly IList