From 060c64b2b44bdc0c9b2b97e2b930edeb1429bf0a Mon Sep 17 00:00:00 2001 From: Anatoly Brizhan Date: Sat, 2 Mar 2024 03:12:51 +0100 Subject: [PATCH 1/5] Add Core dependency --- Assets/BetterLocators/Runtime/BetterLocators.Runtime.asmdef | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/BetterLocators/Runtime/BetterLocators.Runtime.asmdef b/Assets/BetterLocators/Runtime/BetterLocators.Runtime.asmdef index 91e9827..f0a3f95 100644 --- a/Assets/BetterLocators/Runtime/BetterLocators.Runtime.asmdef +++ b/Assets/BetterLocators/Runtime/BetterLocators.Runtime.asmdef @@ -1,6 +1,6 @@ { "name": "BetterLocators.Runtime", - "rootNamespace": "Better.Locators", + "rootNamespace": "Better.Locators.Runtime", "references": [ "GUID:35101f455c979e94c9a0a4793484b7fd", "GUID:a59e3daedde9ca94bba45364d4ead25f", From 46b4255e74c72fea22fabe7c5e03da36ef0ac612 Mon Sep 17 00:00:00 2001 From: Anatoly Brizhan Date: Sat, 2 Mar 2024 03:13:12 +0100 Subject: [PATCH 2/5] Update package --- Assets/BetterLocators/package.json | 1 + Packages/manifest.json | 1 + Packages/packages-lock.json | 7 +++++++ ProjectSettings/PackageManagerSettings.asset | 6 +++--- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Assets/BetterLocators/package.json b/Assets/BetterLocators/package.json index 9503971..12d7a3a 100644 --- a/Assets/BetterLocators/package.json +++ b/Assets/BetterLocators/package.json @@ -5,6 +5,7 @@ "unity": "2021.3", "description": " ", "dependencies": { + "com.tdw.better.internal.core": "0.0.2", "com.uurha.betterattributes": "2.1.48" }, "author": { diff --git a/Packages/manifest.json b/Packages/manifest.json index 0a484d6..5bcbd75 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,5 +1,6 @@ { "dependencies": { + "com.tdw.better.internal.core": "0.0.2", "com.unity.collab-proxy": "2.0.1", "com.unity.feature.development": "1.0.1", "com.unity.ide.rider": "3.0.18", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index f15f35a..afdd61f 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,5 +1,12 @@ { "dependencies": { + "com.tdw.better.internal.core": { + "version": "0.0.2", + "depth": 0, + "source": "registry", + "dependencies": {}, + "url": "https://package.openupm.com" + }, "com.unity.collab-proxy": { "version": "2.0.1", "depth": 0, diff --git a/ProjectSettings/PackageManagerSettings.asset b/ProjectSettings/PackageManagerSettings.asset index 2b960c9..f5c6348 100644 --- a/ProjectSettings/PackageManagerSettings.asset +++ b/ProjectSettings/PackageManagerSettings.asset @@ -13,7 +13,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_EnablePreReleasePackages: 0 - m_EnablePackageDependencies: 0 + m_EnablePackageDependencies: 1 m_AdvancedSettingsExpanded: 1 m_ScopedRegistriesSettingsExpanded: 1 m_SeeAllPackageVersions: 0 @@ -40,6 +40,6 @@ MonoBehaviour: m_RegistryInfoDraft: m_Modified: 0 m_ErrorMessage: - m_UserModificationsInstanceId: -850 - m_OriginalInstanceId: -852 + m_UserModificationsInstanceId: -830 + m_OriginalInstanceId: -834 m_LoadAssets: 0 From 7ca241c4bc7494f8acc01bf9cabc897af3817c8f Mon Sep 17 00:00:00 2001 From: Anatoly Brizhan Date: Sat, 2 Mar 2024 03:13:23 +0100 Subject: [PATCH 3/5] Logs clean-up --- .../Runtime/Installers/MonoLocatorInstaller.cs | 2 +- .../Runtime/Installers/Services/ServicesInstaller.cs | 3 +-- Assets/BetterLocators/Runtime/Locator.cs | 7 ++++--- Assets/BetterLocators/Runtime/ServiceLocator.cs | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Assets/BetterLocators/Runtime/Installers/MonoLocatorInstaller.cs b/Assets/BetterLocators/Runtime/Installers/MonoLocatorInstaller.cs index e73b349..38e6a41 100644 --- a/Assets/BetterLocators/Runtime/Installers/MonoLocatorInstaller.cs +++ b/Assets/BetterLocators/Runtime/Installers/MonoLocatorInstaller.cs @@ -24,7 +24,7 @@ public override Task InstallBindingsAsync(CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { - Debug.LogError($"[{nameof(MonoLocatorInstaller)}] {nameof(InstallBindingsAsync)}: operation was cancelled"); + Debug.LogError("Operation was cancelled"); return Task.CompletedTask; } diff --git a/Assets/BetterLocators/Runtime/Installers/Services/ServicesInstaller.cs b/Assets/BetterLocators/Runtime/Installers/Services/ServicesInstaller.cs index 86dc37b..3bc843d 100644 --- a/Assets/BetterLocators/Runtime/Installers/Services/ServicesInstaller.cs +++ b/Assets/BetterLocators/Runtime/Installers/Services/ServicesInstaller.cs @@ -1,6 +1,5 @@ #if BETTER_SERVICES using System; - using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -22,7 +21,7 @@ public override async Task InstallBindingsAsync(CancellationToken cancellationTo if (cancellationToken.IsCancellationRequested) { - Debug.LogError($"[{nameof(ServicesInstaller)}] {nameof(InstallBindingsAsync)}: operation was cancelled"); + Debug.LogError("Operation was cancelled"); return; } diff --git a/Assets/BetterLocators/Runtime/Locator.cs b/Assets/BetterLocators/Runtime/Locator.cs index 0ee286d..15aa069 100644 --- a/Assets/BetterLocators/Runtime/Locator.cs +++ b/Assets/BetterLocators/Runtime/Locator.cs @@ -14,8 +14,9 @@ public virtual void Register(T item) where T : TItem if (_services.ContainsKey(type)) { - var message = $"[{nameof(Locator)}] {nameof(Register)}: Service of type {type} is already registered. Operation cancelled"; + var message = $"Service of type {type} is already registered. Operation cancelled"; Debug.LogError(message); + return; } _services[type] = item; @@ -27,7 +28,7 @@ public virtual void Unregister(T service) where T : TItem if (!_services.ContainsKey(type)) { - var message = $"[{nameof(Locator)}] {nameof(Unregister)}: Item of type {type} is not registered. Operation cancelled"; + var message = $"Item of type {type} is not registered. Operation cancelled"; Debug.LogError(message); return; } @@ -44,7 +45,7 @@ public virtual T Get() where T : TItem return (T)item; } - var message = $"[{nameof(Locator)}] {nameof(Get)}: Item of type {type} is not registered."; + var message = $"Item of type {type} is not registered."; throw new InvalidOperationException(message); } } diff --git a/Assets/BetterLocators/Runtime/ServiceLocator.cs b/Assets/BetterLocators/Runtime/ServiceLocator.cs index 15ec669..3e5807b 100644 --- a/Assets/BetterLocators/Runtime/ServiceLocator.cs +++ b/Assets/BetterLocators/Runtime/ServiceLocator.cs @@ -6,19 +6,19 @@ namespace Better.Locators.Runtime { public static class ServiceLocator { + private static readonly Locator _locator; + static ServiceLocator() { _locator = new Locator(); } - private static readonly Locator _locator; - public static void RegisterService(T item) where T : IService { var type = item.GetType(); if (!item.Initialized) { - var message = $"[{nameof(ServiceLocator)}] {nameof(RegisterService)}: Service of type {type} not {nameof(IService.Initialized)}"; + var message = $"Service of type {type} not {nameof(IService.Initialized)}"; Debug.LogWarning(message); } From 7ffbdd02cb8a856e8ddef00edb6c629a5ab8fa8b Mon Sep 17 00:00:00 2001 From: Anatoly Brizhan Date: Tue, 5 Mar 2024 18:01:05 +0100 Subject: [PATCH 4/5] Add public validation method --- Assets/BetterLocators/Runtime/Locator.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Assets/BetterLocators/Runtime/Locator.cs b/Assets/BetterLocators/Runtime/Locator.cs index 15aa069..51d7fde 100644 --- a/Assets/BetterLocators/Runtime/Locator.cs +++ b/Assets/BetterLocators/Runtime/Locator.cs @@ -11,8 +11,7 @@ public class Locator public virtual void Register(T item) where T : TItem { var type = item.GetType(); - - if (_services.ContainsKey(type)) + if (HasRegistered()) { var message = $"Service of type {type} is already registered. Operation cancelled"; Debug.LogError(message); @@ -22,11 +21,16 @@ public virtual void Register(T item) where T : TItem _services[type] = item; } + public virtual bool HasRegistered() where T : TItem + { + var type = typeof(T); + return _services.ContainsKey(type); + } + public virtual void Unregister(T service) where T : TItem { var type = service.GetType(); - - if (!_services.ContainsKey(type)) + if (!HasRegistered()) { var message = $"Item of type {type} is not registered. Operation cancelled"; Debug.LogError(message); From 723e2013d9a8a634889ab52e436cdc72c84af306 Mon Sep 17 00:00:00 2001 From: Anatoly Brizhan Date: Thu, 7 Mar 2024 00:02:13 +0100 Subject: [PATCH 5/5] Update dependency and handlers --- .../Runtime/Contexts/MonoContext.cs | 2 +- Assets/BetterLocators/Runtime/Locator.cs | 60 --------------- Assets/BetterLocators/Runtime/Locator.cs.meta | 3 - Assets/BetterLocators/Runtime/Locators.meta | 3 + .../Runtime/Locators/Implementations.meta | 3 + .../Implementations/InternalLocator.cs | 73 +++++++++++++++++++ .../Implementations/InternalLocator.cs.meta | 11 +++ .../Locators/Implementations/MonoLocator.cs | 22 ++++++ .../Implementations}/MonoLocator.cs.meta | 0 .../Locators/Implementations/PocoLocator.cs | 25 +++++++ .../Implementations/PocoLocator.cs.meta | 3 + .../Implementations/ServiceLocator.cs | 44 +++++++++++ .../Implementations}/ServiceLocator.cs.meta | 0 .../Runtime/Locators/Interfaces.meta | 3 + .../Runtime/Locators/Interfaces/ILocator.cs | 10 +++ .../Locators/Interfaces/ILocator.cs.meta | 3 + .../Runtime/Locators/Properties.meta | 3 + .../Locators/Properties/ServiceProperty.cs | 26 +++++++ .../Properties/ServiceProperty.cs.meta} | 0 Assets/BetterLocators/Runtime/MonoLocator.cs | 33 --------- .../Runtime/ServiceContainer.cs | 24 ------ .../BetterLocators/Runtime/ServiceLocator.cs | 39 ---------- Assets/BetterLocators/package.json | 5 +- Packages/manifest.json | 5 +- Packages/packages-lock.json | 26 ++++--- 25 files changed, 252 insertions(+), 174 deletions(-) delete mode 100644 Assets/BetterLocators/Runtime/Locator.cs delete mode 100644 Assets/BetterLocators/Runtime/Locator.cs.meta create mode 100644 Assets/BetterLocators/Runtime/Locators.meta create mode 100644 Assets/BetterLocators/Runtime/Locators/Implementations.meta create mode 100644 Assets/BetterLocators/Runtime/Locators/Implementations/InternalLocator.cs create mode 100644 Assets/BetterLocators/Runtime/Locators/Implementations/InternalLocator.cs.meta create mode 100644 Assets/BetterLocators/Runtime/Locators/Implementations/MonoLocator.cs rename Assets/BetterLocators/Runtime/{ => Locators/Implementations}/MonoLocator.cs.meta (100%) create mode 100644 Assets/BetterLocators/Runtime/Locators/Implementations/PocoLocator.cs create mode 100644 Assets/BetterLocators/Runtime/Locators/Implementations/PocoLocator.cs.meta create mode 100644 Assets/BetterLocators/Runtime/Locators/Implementations/ServiceLocator.cs rename Assets/BetterLocators/Runtime/{ => Locators/Implementations}/ServiceLocator.cs.meta (100%) create mode 100644 Assets/BetterLocators/Runtime/Locators/Interfaces.meta create mode 100644 Assets/BetterLocators/Runtime/Locators/Interfaces/ILocator.cs create mode 100644 Assets/BetterLocators/Runtime/Locators/Interfaces/ILocator.cs.meta create mode 100644 Assets/BetterLocators/Runtime/Locators/Properties.meta create mode 100644 Assets/BetterLocators/Runtime/Locators/Properties/ServiceProperty.cs rename Assets/BetterLocators/Runtime/{ServiceContainer.cs.meta => Locators/Properties/ServiceProperty.cs.meta} (100%) delete mode 100644 Assets/BetterLocators/Runtime/MonoLocator.cs delete mode 100644 Assets/BetterLocators/Runtime/ServiceContainer.cs delete mode 100644 Assets/BetterLocators/Runtime/ServiceLocator.cs diff --git a/Assets/BetterLocators/Runtime/Contexts/MonoContext.cs b/Assets/BetterLocators/Runtime/Contexts/MonoContext.cs index 2441d43..b1df0eb 100644 --- a/Assets/BetterLocators/Runtime/Contexts/MonoContext.cs +++ b/Assets/BetterLocators/Runtime/Contexts/MonoContext.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; using Better.Attributes.Runtime.Select; -using Better.Extensions.Runtime.TasksExtension; +using Better.Extensions.Runtime; using Better.Locators.Runtime.Installers; using UnityEngine; diff --git a/Assets/BetterLocators/Runtime/Locator.cs b/Assets/BetterLocators/Runtime/Locator.cs deleted file mode 100644 index 51d7fde..0000000 --- a/Assets/BetterLocators/Runtime/Locator.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace Better.Locators.Runtime -{ - public class Locator - { - private readonly Dictionary _services = new(); - - public virtual void Register(T item) where T : TItem - { - var type = item.GetType(); - if (HasRegistered()) - { - var message = $"Service of type {type} is already registered. Operation cancelled"; - Debug.LogError(message); - return; - } - - _services[type] = item; - } - - public virtual bool HasRegistered() where T : TItem - { - var type = typeof(T); - return _services.ContainsKey(type); - } - - public virtual void Unregister(T service) where T : TItem - { - var type = service.GetType(); - if (!HasRegistered()) - { - var message = $"Item of type {type} is not registered. Operation cancelled"; - Debug.LogError(message); - return; - } - - _services.Remove(type); - } - - public virtual T Get() where T : TItem - { - var type = typeof(T); - - if (_services.TryGetValue(type, out var item)) - { - return (T)item; - } - - var message = $"Item of type {type} is not registered."; - throw new InvalidOperationException(message); - } - } - - public class Locator : Locator - { - } -} \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/Locator.cs.meta b/Assets/BetterLocators/Runtime/Locator.cs.meta deleted file mode 100644 index 2e524ed..0000000 --- a/Assets/BetterLocators/Runtime/Locator.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 9fbb80dd2bbd4b08ba9eff8350d1d40d -timeCreated: 1707589850 \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/Locators.meta b/Assets/BetterLocators/Runtime/Locators.meta new file mode 100644 index 0000000..b357ae2 --- /dev/null +++ b/Assets/BetterLocators/Runtime/Locators.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0007d77e367c447498cec5523b39c0d0 +timeCreated: 1709661144 \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/Locators/Implementations.meta b/Assets/BetterLocators/Runtime/Locators/Implementations.meta new file mode 100644 index 0000000..073f8c6 --- /dev/null +++ b/Assets/BetterLocators/Runtime/Locators/Implementations.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ef0eef3e041341d1a3102b4821adb9b9 +timeCreated: 1709661851 \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/Locators/Implementations/InternalLocator.cs b/Assets/BetterLocators/Runtime/Locators/Implementations/InternalLocator.cs new file mode 100644 index 0000000..8811d8d --- /dev/null +++ b/Assets/BetterLocators/Runtime/Locators/Implementations/InternalLocator.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using Better.Extensions.Runtime; + +namespace Better.Locators.Runtime +{ + internal class InternalLocator : ILocator + { + private readonly Dictionary _typeItemsMap; + + public InternalLocator() + { + _typeItemsMap = new(); + } + + public void Register(T item) where T : TItem + { + if (item == null) + { + DebugUtility.LogException(nameof(item)); + return; + } + + var type = item.GetType(); + if (HasRegistered()) + { + var message = $"{nameof(item)} of type {type} is already registered. Operation cancelled"; + DebugUtility.LogException(message); + return; + } + + _typeItemsMap[type] = item; + } + + public bool HasRegistered() where T : TItem + { + var type = typeof(T); + return _typeItemsMap.ContainsKey(type); + } + + public void Unregister(T item) where T : TItem + { + if (item == null) + { + DebugUtility.LogException(nameof(item)); + return; + } + + var type = item.GetType(); + if (!HasRegistered()) + { + var message = $"{nameof(item)} of type {type} is not registered. Operation cancelled"; + DebugUtility.LogException(message); + return; + } + + _typeItemsMap.Remove(type); + } + + public T Get() where T : TItem + { + var type = typeof(T); + if (_typeItemsMap.TryGetValue(type, out var item)) + { + return (T)item; + } + + var message = $"Element type {type} is not registered"; + DebugUtility.LogException(message); + return default; + } + } +} \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/Locators/Implementations/InternalLocator.cs.meta b/Assets/BetterLocators/Runtime/Locators/Implementations/InternalLocator.cs.meta new file mode 100644 index 0000000..d1b541f --- /dev/null +++ b/Assets/BetterLocators/Runtime/Locators/Implementations/InternalLocator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9fbb80dd2bbd4b08ba9eff8350d1d40d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BetterLocators/Runtime/Locators/Implementations/MonoLocator.cs b/Assets/BetterLocators/Runtime/Locators/Implementations/MonoLocator.cs new file mode 100644 index 0000000..f599a5b --- /dev/null +++ b/Assets/BetterLocators/Runtime/Locators/Implementations/MonoLocator.cs @@ -0,0 +1,22 @@ +using UnityEngine; + +namespace Better.Locators.Runtime +{ + public abstract class MonoLocator : MonoBehaviour, ILocator + { + protected ILocator _internalLocator = new InternalLocator(); + + #region ILocator + + public virtual void Register(T item) where T : TItem => _internalLocator.Register(item); + public bool HasRegistered() where T : TItem => _internalLocator.HasRegistered(); + public virtual void Unregister(T item) where T : TItem => _internalLocator.Unregister(item); + public virtual T Get() where T : TItem => _internalLocator.Get(); + + #endregion + } + + public class MonoLocator : MonoLocator + { + } +} \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/MonoLocator.cs.meta b/Assets/BetterLocators/Runtime/Locators/Implementations/MonoLocator.cs.meta similarity index 100% rename from Assets/BetterLocators/Runtime/MonoLocator.cs.meta rename to Assets/BetterLocators/Runtime/Locators/Implementations/MonoLocator.cs.meta diff --git a/Assets/BetterLocators/Runtime/Locators/Implementations/PocoLocator.cs b/Assets/BetterLocators/Runtime/Locators/Implementations/PocoLocator.cs new file mode 100644 index 0000000..989d115 --- /dev/null +++ b/Assets/BetterLocators/Runtime/Locators/Implementations/PocoLocator.cs @@ -0,0 +1,25 @@ +namespace Better.Locators.Runtime +{ + public abstract class PocoLocator : ILocator + { + protected ILocator _internalLocator; + + protected PocoLocator() + { + _internalLocator = new InternalLocator(); + } + + #region ILocator + + public virtual void Register(T item) where T : TItem => _internalLocator.Register(item); + public virtual bool HasRegistered() where T : TItem => _internalLocator.HasRegistered(); + public virtual void Unregister(T item) where T : TItem => _internalLocator.Unregister(item); + public virtual T Get() where T : TItem => _internalLocator.Get(); + + #endregion + } + + public class PocoLocator : MonoLocator + { + } +} \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/Locators/Implementations/PocoLocator.cs.meta b/Assets/BetterLocators/Runtime/Locators/Implementations/PocoLocator.cs.meta new file mode 100644 index 0000000..1e5b487 --- /dev/null +++ b/Assets/BetterLocators/Runtime/Locators/Implementations/PocoLocator.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: eeba4425126f425b9b58295f3c1b8047 +timeCreated: 1709663116 \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/Locators/Implementations/ServiceLocator.cs b/Assets/BetterLocators/Runtime/Locators/Implementations/ServiceLocator.cs new file mode 100644 index 0000000..c49256a --- /dev/null +++ b/Assets/BetterLocators/Runtime/Locators/Implementations/ServiceLocator.cs @@ -0,0 +1,44 @@ +#if BETTER_SERVICES +using Better.Services.Runtime.Interfaces; +using UnityEngine; + +namespace Better.Locators.Runtime +{ + public static class ServiceLocator + { + private static readonly ILocator _internalLocator; + + static ServiceLocator() + { + _internalLocator = new InternalLocator(); + } + + public static void Register(T service) where T : IService + { + _internalLocator.Register(service); + + if (service is { Initialized: false }) + { + var type = service.GetType(); + var message = $"Service of type {type} not initialized"; + Debug.LogWarning(message); + } + } + + public static bool HasRegistered() where T : IService + { + return _internalLocator.HasRegistered(); + } + + public static void Unregister(T service) where T : IService + { + _internalLocator.Unregister(service); + } + + public static T Get() where T : IService + { + return _internalLocator.Get(); + } + } +} +#endif \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/ServiceLocator.cs.meta b/Assets/BetterLocators/Runtime/Locators/Implementations/ServiceLocator.cs.meta similarity index 100% rename from Assets/BetterLocators/Runtime/ServiceLocator.cs.meta rename to Assets/BetterLocators/Runtime/Locators/Implementations/ServiceLocator.cs.meta diff --git a/Assets/BetterLocators/Runtime/Locators/Interfaces.meta b/Assets/BetterLocators/Runtime/Locators/Interfaces.meta new file mode 100644 index 0000000..556b7f2 --- /dev/null +++ b/Assets/BetterLocators/Runtime/Locators/Interfaces.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4664b40a13074a478fcc364381d3801d +timeCreated: 1709661862 \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/Locators/Interfaces/ILocator.cs b/Assets/BetterLocators/Runtime/Locators/Interfaces/ILocator.cs new file mode 100644 index 0000000..af95501 --- /dev/null +++ b/Assets/BetterLocators/Runtime/Locators/Interfaces/ILocator.cs @@ -0,0 +1,10 @@ +namespace Better.Locators.Runtime +{ + public interface ILocator + { + void Register(T item) where T : TItem; + bool HasRegistered() where T : TItem; + void Unregister(T item) where T : TItem; + T Get() where T : TItem; + } +} \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/Locators/Interfaces/ILocator.cs.meta b/Assets/BetterLocators/Runtime/Locators/Interfaces/ILocator.cs.meta new file mode 100644 index 0000000..e20e9a8 --- /dev/null +++ b/Assets/BetterLocators/Runtime/Locators/Interfaces/ILocator.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ea305b6657a04fd89465ef7057c96088 +timeCreated: 1709661335 \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/Locators/Properties.meta b/Assets/BetterLocators/Runtime/Locators/Properties.meta new file mode 100644 index 0000000..b06ecd2 --- /dev/null +++ b/Assets/BetterLocators/Runtime/Locators/Properties.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 963fc87a01234401ac1c67255b4fd69b +timeCreated: 1709661833 \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/Locators/Properties/ServiceProperty.cs b/Assets/BetterLocators/Runtime/Locators/Properties/ServiceProperty.cs new file mode 100644 index 0000000..65492d3 --- /dev/null +++ b/Assets/BetterLocators/Runtime/Locators/Properties/ServiceProperty.cs @@ -0,0 +1,26 @@ +#if BETTER_SERVICES +using Better.Services.Runtime.Interfaces; + +namespace Better.Locators.Runtime +{ + public sealed class ServiceProperty where T : IService + { + private T _cachedService; + + public T CachedService + { + get + { + if (_cachedService == null) + { + _cachedService = ServiceLocator.Get(); + } + + return _cachedService; + } + } + + public bool IsRegistered => ServiceLocator.HasRegistered(); + } +} +#endif \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/ServiceContainer.cs.meta b/Assets/BetterLocators/Runtime/Locators/Properties/ServiceProperty.cs.meta similarity index 100% rename from Assets/BetterLocators/Runtime/ServiceContainer.cs.meta rename to Assets/BetterLocators/Runtime/Locators/Properties/ServiceProperty.cs.meta diff --git a/Assets/BetterLocators/Runtime/MonoLocator.cs b/Assets/BetterLocators/Runtime/MonoLocator.cs deleted file mode 100644 index 9375975..0000000 --- a/Assets/BetterLocators/Runtime/MonoLocator.cs +++ /dev/null @@ -1,33 +0,0 @@ -using UnityEngine; - -namespace Better.Locators.Runtime -{ - public class MonoLocator : MonoLocator - { - } - - public abstract class MonoLocator : MonoBehaviour - { - protected Locator _locator; - - protected virtual void Awake() - { - _locator = new Locator(); - } - - public virtual void Register(T item) where T : TItem - { - _locator.Register(item); - } - - public virtual void Unregister(T item) where T : TItem - { - _locator.Unregister(item); - } - - public virtual T Get() where T : TItem - { - return _locator.Get(); - } - } -} \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/ServiceContainer.cs b/Assets/BetterLocators/Runtime/ServiceContainer.cs deleted file mode 100644 index aa83276..0000000 --- a/Assets/BetterLocators/Runtime/ServiceContainer.cs +++ /dev/null @@ -1,24 +0,0 @@ -#if BETTER_SERVICES -using Better.Services.Runtime.Interfaces; - -namespace Better.Locators.Runtime -{ - public sealed class ServiceContainer where T : IService - { - private T _service; - - public T Service - { - get - { - if (_service == null) - { - _service = ServiceLocator.GetService(); - } - - return _service; - } - } - } -} -#endif \ No newline at end of file diff --git a/Assets/BetterLocators/Runtime/ServiceLocator.cs b/Assets/BetterLocators/Runtime/ServiceLocator.cs deleted file mode 100644 index 3e5807b..0000000 --- a/Assets/BetterLocators/Runtime/ServiceLocator.cs +++ /dev/null @@ -1,39 +0,0 @@ -#if BETTER_SERVICES -using Better.Services.Runtime.Interfaces; -using UnityEngine; - -namespace Better.Locators.Runtime -{ - public static class ServiceLocator - { - private static readonly Locator _locator; - - static ServiceLocator() - { - _locator = new Locator(); - } - - public static void RegisterService(T item) where T : IService - { - var type = item.GetType(); - if (!item.Initialized) - { - var message = $"Service of type {type} not {nameof(IService.Initialized)}"; - Debug.LogWarning(message); - } - - _locator.Register(item); - } - - public static void UnregisterService(T item) where T : IService - { - _locator.Unregister(item); - } - - public static T GetService() where T : IService - { - return _locator.Get(); - } - } -} -#endif \ No newline at end of file diff --git a/Assets/BetterLocators/package.json b/Assets/BetterLocators/package.json index 12d7a3a..796f633 100644 --- a/Assets/BetterLocators/package.json +++ b/Assets/BetterLocators/package.json @@ -6,7 +6,8 @@ "description": " ", "dependencies": { "com.tdw.better.internal.core": "0.0.2", - "com.uurha.betterattributes": "2.1.48" + "com.uurha.betterextensions": "1.5.94", + "com.uurha.betterattributes": "3.0.11" }, "author": { "name": "Better Plugins", @@ -15,7 +16,7 @@ "changelogUrl": "https://github.com/techno-dwarf-works/better-locator", "documentationUrl": "https://github.com/techno-dwarf-works/better-locator/tree/main#readme", "license": "MIT", - "licensesUrl":"https://github.com/techno-dwarf-works/better-locator/blob/main/LICENSE", + "licensesUrl": "https://github.com/techno-dwarf-works/better-locator/blob/main/LICENSE", "keywords": [ "locators", "reference management", diff --git a/Packages/manifest.json b/Packages/manifest.json index 5bcbd75..0ac81f4 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -11,8 +11,9 @@ "com.unity.timeline": "1.6.4", "com.unity.ugui": "1.0.0", "com.unity.visualscripting": "1.8.0", - "com.uurha.betterattributes": "2.1.48", - "com.uurha.betterextensions": "1.1.98", + "com.uurha.betterattributes": "3.0.11", + "com.uurha.betterdatastructures": "0.1.7", + "com.uurha.betterextensions": "1.5.94", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", "com.unity.modules.animation": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index afdd61f..f65a503 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -143,36 +143,42 @@ "url": "https://packages.unity.com" }, "com.uurha.betterattributes": { - "version": "2.1.48", + "version": "3.0.11", "depth": 0, "source": "registry", "dependencies": { - "com.uurha.bettereditortools": "1.0.69" + "com.uurha.bettereditortools": "1.5.23", + "com.tdw.better.internal.core": "0.0.2" }, "url": "https://package.openupm.com" }, "com.uurha.betterdatastructures": { - "version": "0.1.2", - "depth": 2, + "version": "0.1.7", + "depth": 0, "source": "registry", - "dependencies": {}, + "dependencies": { + "com.tdw.better.internal.core": "0.0.2" + }, "url": "https://package.openupm.com" }, "com.uurha.bettereditortools": { - "version": "1.0.69", + "version": "1.5.23", "depth": 1, "source": "registry", "dependencies": { - "com.uurha.betterdatastructures": "0.1.2", - "com.uurha.betterextensions": "1.1.98" + "com.uurha.betterdatastructures": "0.1.7", + "com.uurha.betterextensions": "1.5.94", + "com.tdw.better.internal.core": "0.0.2" }, "url": "https://package.openupm.com" }, "com.uurha.betterextensions": { - "version": "1.1.98", + "version": "1.5.94", "depth": 0, "source": "registry", - "dependencies": {}, + "dependencies": { + "com.tdw.better.internal.core": "0.0.2" + }, "url": "https://package.openupm.com" }, "com.unity.modules.ai": {