From 42bbf7bf09493c322fbf84b84208c152cb7497e6 Mon Sep 17 00:00:00 2001 From: "Simon (Darkside) Jackson" Date: Wed, 13 Mar 2024 17:17:13 +0000 Subject: [PATCH] V1.0.5 (#75) * Enable Scene based service loading/unloading (#67) * Moving the Service Framework editor menu items under tools, aligning with the Reality Toolkit for Asset store distribution * Update script icons to RC standard * Feature/utilities deprecation (#74) * Migrating out the single async helper used by the SF * Remove redirect [skip-ci] --------- Co-authored-by: realitycollectivebuildbot --- Editor/AssemblyInfo.cs.meta | 12 +- Editor/BaseProfileInspector.cs | 3 +- Editor/BaseProfileInspector.cs.meta | 2 +- Editor/ConfigurationProperty.cs | 1 - Editor/ConfigurationProperty.cs.meta | 2 +- .../BaseProfileInspectorExtensions.cs | 3 +- .../BaseProfileInspectorExtensions.cs.meta | 2 +- .../Extensions/EditorGUILayoutExtensions.cs | 32 +++ .../EditorGUILayoutExtensions.cs.meta | 11 + .../Extensions/ScriptableObjectExtensions.cs | 159 ++++++++++++ .../ScriptableObjectExtensions.cs.meta | 11 + Editor/LinkXmlInstaller.cs.meta | 2 +- Editor/Packages/AssetsInstaller.cs | 6 +- Editor/Packages/AssetsInstaller.cs.meta | 2 +- .../Packages/IPackageModulesInstaller.cs.meta | 2 +- Editor/Packages/PackageInstaller.cs | 2 +- Editor/Packages/PackageInstaller.cs.meta | 2 +- Editor/Packages/PackageInstallerProfile.cs | 2 +- .../Packages/PackageInstallerProfile.cs.meta | 2 +- .../PackageInstallerProfileInspector.cs | 6 +- .../PackageInstallerProfileInspector.cs.meta | 2 +- Editor/Packages/PackageInstallerWizard.cs | 4 +- .../Packages/PackageInstallerWizard.cs.meta | 2 +- Editor/PathFinderUtility.cs | 2 +- Editor/PathFinderUtility.cs.meta | 2 +- .../PlatformEntryPropertyDrawer.cs | 2 +- .../PlatformEntryPropertyDrawer.cs.meta | 2 +- .../PropertyDrawers/ProfilePropertyDrawer.cs | 5 +- .../ProfilePropertyDrawer.cs.meta | 2 +- ...SceneServiceConfigurationPropertyDrawer.cs | 35 +++ ...ServiceConfigurationPropertyDrawer.cs.meta | 11 + .../ServiceDisplayEditor.cs.meta | 2 +- .../TypeReferencePropertyDrawer.cs | 6 +- .../TypeReferencePropertyDrawer.cs.meta | 12 +- ...yCollective.ServiceFramework.Editor.asmdef | 4 +- Editor/ServiceFrameworkPreferences.cs | 14 +- Editor/ServiceFrameworkPreferences.cs.meta | 2 +- Editor/ServiceManagerInspector.cs | 11 +- Editor/ServiceManagerInspector.cs.meta | 2 +- Editor/ServiceProfileInspector.cs | 4 +- Editor/ServiceProfileInspector.cs.meta | 2 +- Editor/ServiceWizard.cs | 2 +- Editor/ServiceWizard.cs.meta | 12 +- Editor/Utilities/EditorMenuUtilities.cs | 4 +- Editor/Utilities/EditorMenuUtilities.cs.meta | 2 +- Editor/Utilities/EditorPreferences.cs | 145 +++++++++++ Editor/Utilities/EditorPreferences.cs.meta | 11 + Editor/Utilities/GuidRegenerator.cs | 194 ++++++++++++++ Editor/Utilities/GuidRegenerator.cs.meta | 11 + .../ServiceFrameworkEditorPathFinder.cs.meta | 2 +- .../ServiceFrameworkFinderUtility.cs | 2 +- .../ServiceFrameworkFinderUtility.cs.meta | 12 +- .../ServiceFrameworkInspectorUtility.cs.meta | 2 +- .../ServiceFrameworkPathFinder.cs.meta | 12 +- ...tyEditorPlayModeStateChangeHandler.cs.meta | 2 +- Editor/Utilities/UnityFileHelper.cs | 71 ++++++ Editor/Utilities/UnityFileHelper.cs.meta | 11 + README.md | 8 +- Runtime/AssemblyInfo.cs | 2 - Runtime/AssemblyInfo.cs.meta | 2 +- Runtime/Attributes/ExtendsAttribute.cs | 38 +++ Runtime/Attributes/ExtendsAttribute.cs.meta | 11 + Runtime/Attributes/ImplementsAttribute.cs | 38 +++ .../Attributes/ImplementsAttribute.cs.meta | 11 + .../InspectorExpandAttribute.cs.meta | 2 +- .../RuntimePlatformAttribute.cs.meta | 2 +- Runtime/Attributes/SystemTypeAttribute.cs | 52 ++++ .../Attributes/SystemTypeAttribute.cs.meta | 11 + .../CreateProfileMenuItemIndices.cs.meta | 12 +- .../Platforms/AllPlatforms.cs.meta | 2 +- .../Platforms/AndroidPlatform.cs.meta | 2 +- .../Platforms/BasePlatform.cs.meta | 2 +- .../CurrentBuildTargetPlatform.cs.meta | 2 +- .../Platforms/EditorPlatform.cs.meta | 2 +- .../Definitions/Platforms/IOSPlatform.cs.meta | 2 +- .../Platforms/LinuxPlatform.cs.meta | 2 +- .../Definitions/Platforms/OSXPlatform.cs.meta | 2 +- .../Definitions/Platforms/PS4Platform.cs.meta | 2 +- .../Definitions/Platforms/PS5Platform.cs.meta | 2 +- .../Platforms/TVOSPlatform.cs.meta | 2 +- .../UniversalWindowsPlatform.cs.meta | 2 +- .../Platforms/WebGlPlatform.cs.meta | 2 +- .../WindowsStandalonePlatform.cs.meta | 2 +- .../Platforms/XboxPlatform.cs.meta | 2 +- Runtime/Definitions/Process.cs | 6 +- Runtime/Definitions/Process.cs.meta | 2 +- Runtime/Definitions/Profiles/BaseProfile.cs | 6 + .../Definitions/Profiles/BaseProfile.cs.meta | 2 +- .../Profiles/BaseServiceProfile.cs.meta | 2 +- .../Profiles/SceneServiceProvidersProfile.cs | 24 ++ .../SceneServiceProvidersProfile.cs.meta | 11 + .../Profiles/ServiceProvidersProfile.cs | 20 +- .../Profiles/ServiceProvidersProfile.cs.meta | 2 +- Runtime/Definitions/RuntimePlatformEntry.cs | 7 +- .../Definitions/RuntimePlatformEntry.cs.meta | 2 +- .../RuntimeServiceFrameworkPreferences.cs | 14 ++ ...RuntimeServiceFrameworkPreferences.cs.meta | 11 + .../Definitions/SceneServiceConfiguration.cs | 24 ++ .../SceneServiceConfiguration.cs.meta | 11 + Runtime/Definitions/ServiceConfiguration.cs | 4 +- .../Definitions/ServiceConfiguration.cs.meta | 12 +- Runtime/Definitions/Utilities.meta | 8 + Runtime/Definitions/Utilities/TypeGrouping.cs | 38 +++ .../Utilities/TypeGrouping.cs.meta | 11 + Runtime/Extensions/ArrayExtensions.cs | 62 +++++ Runtime/Extensions/ArrayExtensions.cs.meta | 11 + Runtime/Extensions/AwaiterExtensions.cs | 80 ++++++ Runtime/Extensions/AwaiterExtensions.cs.meta | 11 + Runtime/Extensions/CollectionsExtensions.cs | 59 +++++ .../Extensions/CollectionsExtensions.cs.meta | 11 + Runtime/Extensions/ComponentExtensions.cs | 30 +++ .../Extensions/ComponentExtensions.cs.meta | 11 + Runtime/Extensions/StringExtensions.cs | 66 +++++ Runtime/Extensions/StringExtensions.cs.meta | 11 + Runtime/Extensions/TypeExtensions.cs | 170 ++++++++++++- Runtime/Extensions/TypeExtensions.cs.meta | 2 +- Runtime/Extensions/UnityObjectExtensions.cs | 67 +++++ .../Extensions/UnityObjectExtensions.cs.meta | 11 + Runtime/Interfaces/IEventService.cs.meta | 2 +- Runtime/Interfaces/IPlatform.cs.meta | 2 +- Runtime/Interfaces/IService.cs.meta | 2 +- Runtime/Interfaces/IServiceConfiguration.cs | 1 - .../Interfaces/IServiceConfiguration.cs.meta | 2 +- Runtime/Interfaces/IServiceModule.cs.meta | 2 +- Runtime/Interfaces/IServiceProfile.cs.meta | 2 +- Runtime/Modules/BaseServiceModule.cs.meta | 12 +- .../RealityCollective.ServiceFramework.asmdef | 3 +- Runtime/Services/BaseEventService.cs | 2 +- Runtime/Services/BaseEventService.cs.meta | 2 +- Runtime/Services/BaseService.cs.meta | 12 +- .../BaseServiceWithConstructor.cs.meta | 12 +- Runtime/Services/ServiceManager.cs | 236 ++++++++++++++++-- Runtime/Services/ServiceManager.cs.meta | 12 +- Runtime/Services/TemplateService.cs | 2 +- Runtime/Services/TemplateService.cs.meta | 12 +- Runtime/StandardAssets/Icons.meta | 8 + .../Icons/Icon_Toolkit_Component.png | Bin 0 -> 3218 bytes .../Icons/Icon_Toolkit_Component.png.meta | 179 +++++++++++++ .../StandardAssets/Icons/Icon_Toolkit_SO.png | Bin 0 -> 1397 bytes .../Icons/Icon_Toolkit_SO.png.meta | 179 +++++++++++++ .../Icons/Icon_Toolkit_Script.png | Bin 0 -> 1588 bytes .../Icons/Icon_Toolkit_Script.png.meta | 179 +++++++++++++ Runtime/Utilities/SceneServiceManager.cs | 65 +++++ Runtime/Utilities/SceneServiceManager.cs.meta | 11 + Runtime/Utilities/ServiceDisplayHook.cs.meta | 2 +- .../Utilities/ServiceFrameworkStatus.cs.meta | 2 +- Runtime/Utilities/ServiceManagerInstance.cs | 9 +- .../Utilities/ServiceManagerInstance.cs.meta | 2 +- Runtime/Utilities/SystemType.cs | 156 ++++++++++++ Runtime/Utilities/SystemType.cs.meta | 11 + Runtime/Utilities/TypeCache.cs | 27 ++ Runtime/Utilities/TypeCache.cs.meta | 11 + .../Utilities/ValidateConfiguration.cs.meta | 2 +- Tests/AssemblyInfo.cs.meta | 2 +- .../TestData/Interfaces/ITestService.cs.meta | 2 +- .../ITestService1ServiceModule.cs.meta | 2 +- .../ITestService1ServiceModuleA.cs.meta | 2 +- .../ITestService1ServiceModuleB.cs.meta | 2 +- .../BaseTestService1ServiceModule.cs.meta | 2 +- .../TestService1ServiceModuleA.cs.meta | 2 +- .../TestService1ServiceModuleB.cs.meta | 2 +- .../Profiles/TestService1Profile.cs.meta | 2 +- .../Profiles/TestService2Profile.cs.meta | 2 +- Tests/Tests/Service Disable Tests.cs.meta | 2 +- Tests/Tests/Service Enable Tests.cs.meta | 2 +- Tests/Tests/Service Interface Type Tests.cs | 2 +- .../Service Interface Type Tests.cs.meta | 2 +- Tests/Tests/Service Locator Tests.cs | 2 +- Tests/Tests/Service Locator Tests.cs.meta | 2 +- Tests/Tests/Service Registration Tests.cs | 4 +- .../Tests/Service Registration Tests.cs.meta | 2 +- Tests/Tests/Service Retrieval Tests.cs.meta | 2 +- Tests/Tests/Service UnRegistration Tests.cs | 35 +++ .../Service UnRegistration Tests.cs.meta | 2 +- .../Tests/ServiceManager_GetService_Tests.cs | 2 +- .../ServiceManager_GetService_Tests.cs.meta | 2 +- Tests/Tests/ServiceModuleDisableTests.cs.meta | 2 +- Tests/Tests/ServiceModuleEnableTests.cs.meta | 2 +- .../ServiceModuleRegistrationTests.cs.meta | 2 +- Tests/Tests/ServiceModuleRetrievalTests.cs | 4 +- .../Tests/ServiceModuleRetrievalTests.cs.meta | 2 +- .../ServiceModuleUnRegistrationTests.cs.meta | 2 +- Tests/Utilities/TestUtilities.cs | 8 +- Tests/Utilities/TestUtilities.cs.meta | 2 +- package.json | 3 +- 185 files changed, 2984 insertions(+), 210 deletions(-) create mode 100644 Editor/Extensions/EditorGUILayoutExtensions.cs create mode 100644 Editor/Extensions/EditorGUILayoutExtensions.cs.meta create mode 100644 Editor/Extensions/ScriptableObjectExtensions.cs create mode 100644 Editor/Extensions/ScriptableObjectExtensions.cs.meta create mode 100644 Editor/PropertyDrawers/SceneServiceConfigurationPropertyDrawer.cs create mode 100644 Editor/PropertyDrawers/SceneServiceConfigurationPropertyDrawer.cs.meta create mode 100644 Editor/Utilities/EditorPreferences.cs create mode 100644 Editor/Utilities/EditorPreferences.cs.meta create mode 100644 Editor/Utilities/GuidRegenerator.cs create mode 100644 Editor/Utilities/GuidRegenerator.cs.meta create mode 100644 Editor/Utilities/UnityFileHelper.cs create mode 100644 Editor/Utilities/UnityFileHelper.cs.meta create mode 100644 Runtime/Attributes/ExtendsAttribute.cs create mode 100644 Runtime/Attributes/ExtendsAttribute.cs.meta create mode 100644 Runtime/Attributes/ImplementsAttribute.cs create mode 100644 Runtime/Attributes/ImplementsAttribute.cs.meta create mode 100644 Runtime/Attributes/SystemTypeAttribute.cs create mode 100644 Runtime/Attributes/SystemTypeAttribute.cs.meta create mode 100644 Runtime/Definitions/Profiles/SceneServiceProvidersProfile.cs create mode 100644 Runtime/Definitions/Profiles/SceneServiceProvidersProfile.cs.meta create mode 100644 Runtime/Definitions/RuntimeServiceFrameworkPreferences.cs create mode 100644 Runtime/Definitions/RuntimeServiceFrameworkPreferences.cs.meta create mode 100644 Runtime/Definitions/SceneServiceConfiguration.cs create mode 100644 Runtime/Definitions/SceneServiceConfiguration.cs.meta create mode 100644 Runtime/Definitions/Utilities.meta create mode 100644 Runtime/Definitions/Utilities/TypeGrouping.cs create mode 100644 Runtime/Definitions/Utilities/TypeGrouping.cs.meta create mode 100644 Runtime/Extensions/ArrayExtensions.cs create mode 100644 Runtime/Extensions/ArrayExtensions.cs.meta create mode 100644 Runtime/Extensions/AwaiterExtensions.cs create mode 100644 Runtime/Extensions/AwaiterExtensions.cs.meta create mode 100644 Runtime/Extensions/CollectionsExtensions.cs create mode 100644 Runtime/Extensions/CollectionsExtensions.cs.meta create mode 100644 Runtime/Extensions/ComponentExtensions.cs create mode 100644 Runtime/Extensions/ComponentExtensions.cs.meta create mode 100644 Runtime/Extensions/StringExtensions.cs create mode 100644 Runtime/Extensions/StringExtensions.cs.meta create mode 100644 Runtime/Extensions/UnityObjectExtensions.cs create mode 100644 Runtime/Extensions/UnityObjectExtensions.cs.meta create mode 100644 Runtime/StandardAssets/Icons.meta create mode 100644 Runtime/StandardAssets/Icons/Icon_Toolkit_Component.png create mode 100644 Runtime/StandardAssets/Icons/Icon_Toolkit_Component.png.meta create mode 100644 Runtime/StandardAssets/Icons/Icon_Toolkit_SO.png create mode 100644 Runtime/StandardAssets/Icons/Icon_Toolkit_SO.png.meta create mode 100644 Runtime/StandardAssets/Icons/Icon_Toolkit_Script.png create mode 100644 Runtime/StandardAssets/Icons/Icon_Toolkit_Script.png.meta create mode 100644 Runtime/Utilities/SceneServiceManager.cs create mode 100644 Runtime/Utilities/SceneServiceManager.cs.meta create mode 100644 Runtime/Utilities/SystemType.cs create mode 100644 Runtime/Utilities/SystemType.cs.meta create mode 100644 Runtime/Utilities/TypeCache.cs create mode 100644 Runtime/Utilities/TypeCache.cs.meta diff --git a/Editor/AssemblyInfo.cs.meta b/Editor/AssemblyInfo.cs.meta index 5433fb6..adfb39a 100644 --- a/Editor/AssemblyInfo.cs.meta +++ b/Editor/AssemblyInfo.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: 337826795fb74e9e8e97023d226c171c -timeCreated: 1644252028 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/BaseProfileInspector.cs b/Editor/BaseProfileInspector.cs index 88438c4..863bcaf 100644 --- a/Editor/BaseProfileInspector.cs +++ b/Editor/BaseProfileInspector.cs @@ -1,10 +1,9 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Editor.Extensions; -using RealityCollective.Extensions; using RealityCollective.ServiceFramework.Definitions; using RealityCollective.ServiceFramework.Editor.Utilities; +using RealityCollective.ServiceFramework.Extensions; using System; using UnityEditor; using UnityEngine; diff --git a/Editor/BaseProfileInspector.cs.meta b/Editor/BaseProfileInspector.cs.meta index 951757c..94fc225 100644 --- a/Editor/BaseProfileInspector.cs.meta +++ b/Editor/BaseProfileInspector.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/ConfigurationProperty.cs b/Editor/ConfigurationProperty.cs index cbd4f4e..c3cb9d9 100644 --- a/Editor/ConfigurationProperty.cs +++ b/Editor/ConfigurationProperty.cs @@ -1,7 +1,6 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Definitions.Utilities; using System; using UnityEditor; diff --git a/Editor/ConfigurationProperty.cs.meta b/Editor/ConfigurationProperty.cs.meta index e6b3494..5bc373b 100644 --- a/Editor/ConfigurationProperty.cs.meta +++ b/Editor/ConfigurationProperty.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/Extensions/BaseProfileInspectorExtensions.cs b/Editor/Extensions/BaseProfileInspectorExtensions.cs index 52ea990..63bd2f5 100644 --- a/Editor/Extensions/BaseProfileInspectorExtensions.cs +++ b/Editor/Extensions/BaseProfileInspectorExtensions.cs @@ -1,8 +1,7 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Editor.Extensions; -using RealityCollective.Extensions; +using RealityCollective.ServiceFramework.Extensions; using RealityCollective.ServiceFramework.Definitions; using System; using UnityEditor; diff --git a/Editor/Extensions/BaseProfileInspectorExtensions.cs.meta b/Editor/Extensions/BaseProfileInspectorExtensions.cs.meta index fd569ea..7eda663 100644 --- a/Editor/Extensions/BaseProfileInspectorExtensions.cs.meta +++ b/Editor/Extensions/BaseProfileInspectorExtensions.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/Extensions/EditorGUILayoutExtensions.cs b/Editor/Extensions/EditorGUILayoutExtensions.cs new file mode 100644 index 0000000..fb727d9 --- /dev/null +++ b/Editor/Extensions/EditorGUILayoutExtensions.cs @@ -0,0 +1,32 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEditor; +using UnityEngine; + +namespace RealityCollective.ServiceFramework.Editor.Utilities +{ + /// + /// Extensions for usage. + /// + public static class EditorGUILayoutExtensions + { + /// + /// Draws a foldout but with bold label text. + /// + /// Foldout state. + /// Foldout label content. + /// Should the foldout toggle on label click? + /// Returns true, if foldout unfolded. + public static bool FoldoutWithBoldLabel(bool foldout, GUIContent content, bool toggleOnLabelClick = true) + { + GUIStyle defaultStyle = EditorStyles.foldout; + FontStyle previousStyle = defaultStyle.fontStyle; + defaultStyle.fontStyle = FontStyle.Bold; + foldout = EditorGUILayout.Foldout(foldout, content, toggleOnLabelClick); + defaultStyle.fontStyle = previousStyle; + + return foldout; + } + } +} \ No newline at end of file diff --git a/Editor/Extensions/EditorGUILayoutExtensions.cs.meta b/Editor/Extensions/EditorGUILayoutExtensions.cs.meta new file mode 100644 index 0000000..af58a58 --- /dev/null +++ b/Editor/Extensions/EditorGUILayoutExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fe056d2fb06ee6c4ca9c1e4505128691 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Extensions/ScriptableObjectExtensions.cs b/Editor/Extensions/ScriptableObjectExtensions.cs new file mode 100644 index 0000000..b0cedfa --- /dev/null +++ b/Editor/Extensions/ScriptableObjectExtensions.cs @@ -0,0 +1,159 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace RealityCollective.ServiceFramework.Editor.Utilities +{ + /// + /// Extensions for s + /// + public static class ScriptableObjectExtensions + { + /// + /// Creates, saves, and then optionally selects a new asset for the target . + /// + /// you want to create an asset file for. + /// The new asset should be selected and opened in the inspector. + public static T CreateAsset(this T scriptableObject, bool ping = true) where T : ScriptableObject + { + return CreateAsset(scriptableObject, null, ping); + } + + /// + /// Creates, saves, and then opens a new asset for the target . + /// + /// you want to create an asset file for. + /// Optional path for the new asset. + /// The new asset should be selected and opened in the inspector. + public static T CreateAsset(this T scriptableObject, string path, bool ping = true) where T : ScriptableObject + { + return CreateAsset(scriptableObject, path, null, ping); + } + + /// + /// Creates, saves, and then opens a new asset for the target . + /// + /// you want to create an asset file for. + /// Optional path for the new asset. + /// Optional filename for the new asset. + /// The new asset should be selected and opened in the inspector. + /// Is the new asset unique, or can we make copies? + public static T CreateAsset(this T scriptableObject, string path, string fileName, bool ping, bool unique = true) where T : ScriptableObject + { + var name = string.IsNullOrEmpty(fileName) ? $"{scriptableObject.GetType().Name}" : fileName; + + path ??= "Assets"; + + name = name.Replace(" ", string.Empty); + + path = path.Replace(".asset", string.Empty); + + if (!string.IsNullOrWhiteSpace(Path.GetExtension(path))) + { + var subtractedPath = path.Substring(path.LastIndexOf(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)); + path = path.Replace(subtractedPath, string.Empty); + } + + path = path.Replace($"{Directory.GetParent(Application.dataPath).FullName}{Path.DirectorySeparatorChar}", string.Empty); + + if (!Directory.Exists(Path.GetFullPath(path))) + { + Directory.CreateDirectory(Path.GetFullPath(path)); + } + + path = $"{path}/{name}.asset"; + + if (unique) + { + AssetDatabase.GenerateUniqueAssetPath(path); + } + + if (File.Exists(Path.GetFullPath(path))) + { + return AssetDatabase.LoadAssetAtPath(path); + } + + AssetDatabase.CreateAsset(scriptableObject, path); + AssetDatabase.SaveAssets(); + + if (!EditorApplication.isUpdating) + { + AssetDatabase.Refresh(); + } + + scriptableObject = AssetDatabase.LoadAssetAtPath(path); + + if (ping) + { + EditorApplication.delayCall += () => + { + EditorUtility.FocusProjectWindow(); + EditorGUIUtility.PingObject(scriptableObject); + Selection.activeObject = scriptableObject; + }; + } + + Debug.Assert(scriptableObject != null); + + return scriptableObject; + } + + /// + /// Attempts to find the asset associated to the instance of the , if none is found a new asset is created. + /// + /// you want to create an asset file for. + /// The new asset should be selected and opened in the inspector. + public static T GetOrCreateAsset(this T scriptableObject, bool ping = true) where T : ScriptableObject + { + return GetOrCreateAsset(scriptableObject, null, ping); + } + + /// + /// Attempts to find the asset associated to the instance of the , if none is found a new asset is created. + /// + /// you want to create an asset file for. + /// Optional path for the new asset. + /// The new asset should be selected and opened in the inspector. + public static T GetOrCreateAsset(this T scriptableObject, string path, bool ping = true) where T : ScriptableObject + { + return GetOrCreateAsset(scriptableObject, path, null, ping); + } + + /// + /// Attempts to find the asset associated to the instance of the , if none is found a new asset is created. + /// + /// you want get or create an asset file for. + /// Optional path for the new asset. + /// Optional filename for the new asset. + /// The new asset should be selected and opened in the inspector. + public static T GetOrCreateAsset(this T scriptableObject, string path, string fileName, bool ping) where T : ScriptableObject + { + return !AssetDatabase.TryGetGUIDAndLocalFileIdentifier(scriptableObject, out var guid, out long _) + ? scriptableObject.CreateAsset(path, fileName, ping, false) + : AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid)); + } + + /// + /// Gets all the scriptable object instances in the project. + /// + /// The Type of you're wanting to find instances of. + /// An Array of instances for the type. + public static T[] GetAllInstances() where T : ScriptableObject + { + // FindAssets uses tags check documentation for more info + var guids = AssetDatabase.FindAssets($"t:{typeof(T).Name}"); + var instances = new T[guids.Length]; + + for (int i = 0; i < guids.Length; i++) + { + instances[i] = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guids[i])); + } + + return instances; + } + } +} \ No newline at end of file diff --git a/Editor/Extensions/ScriptableObjectExtensions.cs.meta b/Editor/Extensions/ScriptableObjectExtensions.cs.meta new file mode 100644 index 0000000..9bbe00c --- /dev/null +++ b/Editor/Extensions/ScriptableObjectExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1cb30ee94ff692c4c9eb9ddf204e792b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/LinkXmlInstaller.cs.meta b/Editor/LinkXmlInstaller.cs.meta index 04f2e8c..4ea3397 100644 --- a/Editor/LinkXmlInstaller.cs.meta +++ b/Editor/LinkXmlInstaller.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/Packages/AssetsInstaller.cs b/Editor/Packages/AssetsInstaller.cs index 87208f4..4c73273 100644 --- a/Editor/Packages/AssetsInstaller.cs +++ b/Editor/Packages/AssetsInstaller.cs @@ -1,8 +1,8 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Editor.Utilities; -using RealityCollective.Extensions; +using RealityCollective.ServiceFramework.Editor.Utilities; +using RealityCollective.ServiceFramework.Extensions; using System; using System.Collections.Generic; using System.IO; @@ -46,6 +46,7 @@ public struct AssetInstallerEventArgs /// The destination path, typically inside the projects "Assets" directory. /// Should the guids for the copied assets be regenerated? /// If set, assets and configuration is installed without prompting the user. + /// Filter the assets from the package to ONLY those provided by Unity, the default is ALL files. /// true if the assets were successfully installed to the project. public static bool TryInstallAssets(string sourcePath, string destinationPath, bool regenerateGuids = false, bool skipDialog = false, bool onlyUnityAssets = false) => TryInstallAssets(new Dictionary { { sourcePath, destinationPath } }, regenerateGuids, skipDialog, onlyUnityAssets); @@ -56,6 +57,7 @@ public static bool TryInstallAssets(string sourcePath, string destinationPath, b /// The assets paths to be installed. Key is the source path of the assets to be installed. This should typically be from a hidden upm package folder marked with a "~". Value is the destination. /// Should the guids for the copied assets be regenerated? /// If set, assets and configuration is installed without prompting the user. + /// Filter the assets from the package to ONLY those provided by Unity, the default is ALL files. /// true if the assets were successfully installed to the project. public static bool TryInstallAssets(Dictionary installationPaths, bool regenerateGuids = false, bool skipDialog = false, bool onlyUnityAssets = false) { diff --git a/Editor/Packages/AssetsInstaller.cs.meta b/Editor/Packages/AssetsInstaller.cs.meta index fed7ae0..6193275 100644 --- a/Editor/Packages/AssetsInstaller.cs.meta +++ b/Editor/Packages/AssetsInstaller.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/Packages/IPackageModulesInstaller.cs.meta b/Editor/Packages/IPackageModulesInstaller.cs.meta index 26320ef..978921f 100644 --- a/Editor/Packages/IPackageModulesInstaller.cs.meta +++ b/Editor/Packages/IPackageModulesInstaller.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/Packages/PackageInstaller.cs b/Editor/Packages/PackageInstaller.cs index e6c57e9..fb6ad5d 100644 --- a/Editor/Packages/PackageInstaller.cs +++ b/Editor/Packages/PackageInstaller.cs @@ -1,8 +1,8 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Extensions; using RealityCollective.ServiceFramework.Definitions; +using RealityCollective.ServiceFramework.Extensions; using RealityCollective.ServiceFramework.Interfaces; using RealityCollective.ServiceFramework.Services; using System; diff --git a/Editor/Packages/PackageInstaller.cs.meta b/Editor/Packages/PackageInstaller.cs.meta index 8ff9cd7..b8863de 100644 --- a/Editor/Packages/PackageInstaller.cs.meta +++ b/Editor/Packages/PackageInstaller.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/Packages/PackageInstallerProfile.cs b/Editor/Packages/PackageInstallerProfile.cs index e97061e..74d2688 100644 --- a/Editor/Packages/PackageInstallerProfile.cs +++ b/Editor/Packages/PackageInstallerProfile.cs @@ -10,7 +10,7 @@ namespace RealityCollective.ServiceFramework.Editor.Packages /// A package profile defines services and modules that the package has to offer and may be installed /// to a to register those services and modules with the service container. /// - [CreateAssetMenu(menuName = "Reality Collective/Service Framework/" + nameof(PackageInstallerProfile), fileName = nameof(PackageInstallerProfile), order = (int)CreateProfileMenuItemIndices.Configuration)] + [CreateAssetMenu(menuName = RuntimeServiceFrameworkPreferences.Service_Framework_Editor_Menu_Keyword + "/Packaging/" + nameof(PackageInstallerProfile), fileName = nameof(PackageInstallerProfile), order = (int)CreateProfileMenuItemIndices.Configuration)] public class PackageInstallerProfile : BaseProfile { [SerializeField, Tooltip("The platforms the package can run on.")] diff --git a/Editor/Packages/PackageInstallerProfile.cs.meta b/Editor/Packages/PackageInstallerProfile.cs.meta index e8f9f80..17f7f15 100644 --- a/Editor/Packages/PackageInstallerProfile.cs.meta +++ b/Editor/Packages/PackageInstallerProfile.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/Packages/PackageInstallerProfileInspector.cs b/Editor/Packages/PackageInstallerProfileInspector.cs index f1b703f..217f8ec 100644 --- a/Editor/Packages/PackageInstallerProfileInspector.cs +++ b/Editor/Packages/PackageInstallerProfileInspector.cs @@ -1,13 +1,13 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Definitions.Utilities; -using RealityCollective.Editor.Extensions; -using RealityCollective.Extensions; using RealityCollective.ServiceFramework.Attributes; using RealityCollective.ServiceFramework.Definitions; +using RealityCollective.ServiceFramework.Definitions.Utilities; using RealityCollective.ServiceFramework.Editor.Profiles; using RealityCollective.ServiceFramework.Editor.PropertyDrawers; +using RealityCollective.ServiceFramework.Editor.Utilities; +using RealityCollective.ServiceFramework.Extensions; using RealityCollective.ServiceFramework.Services; using System; using System.Collections.Generic; diff --git a/Editor/Packages/PackageInstallerProfileInspector.cs.meta b/Editor/Packages/PackageInstallerProfileInspector.cs.meta index 7018f3a..4da5d1a 100644 --- a/Editor/Packages/PackageInstallerProfileInspector.cs.meta +++ b/Editor/Packages/PackageInstallerProfileInspector.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/Packages/PackageInstallerWizard.cs b/Editor/Packages/PackageInstallerWizard.cs index 3d7cd61..badc26b 100644 --- a/Editor/Packages/PackageInstallerWizard.cs +++ b/Editor/Packages/PackageInstallerWizard.cs @@ -1,9 +1,9 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Editor.Extensions; -using RealityCollective.Extensions; using RealityCollective.ServiceFramework.Definitions; +using RealityCollective.ServiceFramework.Editor.Utilities; +using RealityCollective.ServiceFramework.Extensions; using RealityCollective.ServiceFramework.Services; using System.Collections.Generic; using System.Linq; diff --git a/Editor/Packages/PackageInstallerWizard.cs.meta b/Editor/Packages/PackageInstallerWizard.cs.meta index 51a47e5..ed83762 100644 --- a/Editor/Packages/PackageInstallerWizard.cs.meta +++ b/Editor/Packages/PackageInstallerWizard.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/PathFinderUtility.cs b/Editor/PathFinderUtility.cs index 4c29e53..9d3e7ab 100644 --- a/Editor/PathFinderUtility.cs +++ b/Editor/PathFinderUtility.cs @@ -1,7 +1,7 @@ // Copyright (c) RealityCollective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Extensions; +using RealityCollective.ServiceFramework.Extensions; using System; using System.Collections.Generic; using System.IO; diff --git a/Editor/PathFinderUtility.cs.meta b/Editor/PathFinderUtility.cs.meta index ac13006..9a9226b 100644 --- a/Editor/PathFinderUtility.cs.meta +++ b/Editor/PathFinderUtility.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/PropertyDrawers/PlatformEntryPropertyDrawer.cs b/Editor/PropertyDrawers/PlatformEntryPropertyDrawer.cs index c761308..c50a88c 100644 --- a/Editor/PropertyDrawers/PlatformEntryPropertyDrawer.cs +++ b/Editor/PropertyDrawers/PlatformEntryPropertyDrawer.cs @@ -1,7 +1,7 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Extensions; +using RealityCollective.ServiceFramework.Extensions; using RealityCollective.ServiceFramework.Definitions; using RealityCollective.ServiceFramework.Definitions.Platforms; using RealityCollective.ServiceFramework.Services; diff --git a/Editor/PropertyDrawers/PlatformEntryPropertyDrawer.cs.meta b/Editor/PropertyDrawers/PlatformEntryPropertyDrawer.cs.meta index 947ca34..c8965a1 100644 --- a/Editor/PropertyDrawers/PlatformEntryPropertyDrawer.cs.meta +++ b/Editor/PropertyDrawers/PlatformEntryPropertyDrawer.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/PropertyDrawers/ProfilePropertyDrawer.cs b/Editor/PropertyDrawers/ProfilePropertyDrawer.cs index 0b6a15d..d924ec6 100644 --- a/Editor/PropertyDrawers/ProfilePropertyDrawer.cs +++ b/Editor/PropertyDrawers/ProfilePropertyDrawer.cs @@ -1,9 +1,9 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Extensions; using RealityCollective.ServiceFramework.Definitions; using RealityCollective.ServiceFramework.Editor.Utilities; +using RealityCollective.ServiceFramework.Extensions; using RealityCollective.ServiceFramework.Services; using System; using UnityEditor; @@ -93,7 +93,8 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten property.serializedObject.ApplyModifiedProperties(); if (!(selectedProfile is null) && - !(selectedProfile is ServiceProvidersProfile)) + !(selectedProfile is ServiceProvidersProfile) && + !(selectedProfile is SceneServiceProvidersProfile)) { Debug.Assert(!parent.IsNull(), $"Failed to find a valid parent profile for {selectedProfile.name}"); selectedProfile.ParentProfile = parent; diff --git a/Editor/PropertyDrawers/ProfilePropertyDrawer.cs.meta b/Editor/PropertyDrawers/ProfilePropertyDrawer.cs.meta index 974a319..c30f626 100644 --- a/Editor/PropertyDrawers/ProfilePropertyDrawer.cs.meta +++ b/Editor/PropertyDrawers/ProfilePropertyDrawer.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/PropertyDrawers/SceneServiceConfigurationPropertyDrawer.cs b/Editor/PropertyDrawers/SceneServiceConfigurationPropertyDrawer.cs new file mode 100644 index 0000000..5b9f37d --- /dev/null +++ b/Editor/PropertyDrawers/SceneServiceConfigurationPropertyDrawer.cs @@ -0,0 +1,35 @@ +using RealityCollective.ServiceFramework.Definitions; +using UnityEditor; +using UnityEngine; + +namespace RealityCollective.ServiceFramework.Editor.PropertyDrawers +{ + [CustomPropertyDrawer(typeof(SceneServiceConfiguration))] + public class SceneServiceConfigurationPropertyDrawer : PropertyDrawer + { + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + EditorGUI.BeginProperty(position, label, property); + + // Calculate half of the width for each field + float nameWidth = position.width * 0.2f; + + var profileField = property.FindPropertyRelative("profile"); + + Rect profileRect = new Rect(position.x + nameWidth, position.y, position.width - nameWidth, position.height); + EditorGUI.PropertyField(profileRect, profileField, GUIContent.none); + if (profileField.objectReferenceValue != null) + { + var objectRef = profileField.objectReferenceValue as SceneServiceProvidersProfile; + Rect nameRect = new Rect(position.x, position.y, nameWidth, position.height); + EditorGUI.LabelField(nameRect, objectRef.SceneName); + } + else + { + var nameRect = new Rect(position.x, position.y, nameWidth, position.height); + EditorGUI.LabelField(nameRect, "None"); + } + EditorGUI.EndProperty(); + } + } +} \ No newline at end of file diff --git a/Editor/PropertyDrawers/SceneServiceConfigurationPropertyDrawer.cs.meta b/Editor/PropertyDrawers/SceneServiceConfigurationPropertyDrawer.cs.meta new file mode 100644 index 0000000..5fd71b6 --- /dev/null +++ b/Editor/PropertyDrawers/SceneServiceConfigurationPropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 33d18797d3935f8419fbea8979e49b28 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/PropertyDrawers/ServiceDisplayEditor.cs.meta b/Editor/PropertyDrawers/ServiceDisplayEditor.cs.meta index f1363c1..9b4472e 100644 --- a/Editor/PropertyDrawers/ServiceDisplayEditor.cs.meta +++ b/Editor/PropertyDrawers/ServiceDisplayEditor.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/PropertyDrawers/TypeReferencePropertyDrawer.cs b/Editor/PropertyDrawers/TypeReferencePropertyDrawer.cs index 5637b1d..242f7e1 100644 --- a/Editor/PropertyDrawers/TypeReferencePropertyDrawer.cs +++ b/Editor/PropertyDrawers/TypeReferencePropertyDrawer.cs @@ -1,9 +1,9 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Attributes; -using RealityCollective.Definitions.Utilities; -using RealityCollective.Extensions; +using RealityCollective.ServiceFramework.Attributes; +using RealityCollective.ServiceFramework.Definitions.Utilities; +using RealityCollective.ServiceFramework.Extensions; using System; using System.Collections.Generic; using System.Linq; diff --git a/Editor/PropertyDrawers/TypeReferencePropertyDrawer.cs.meta b/Editor/PropertyDrawers/TypeReferencePropertyDrawer.cs.meta index e61abaf..b73d6dc 100644 --- a/Editor/PropertyDrawers/TypeReferencePropertyDrawer.cs.meta +++ b/Editor/PropertyDrawers/TypeReferencePropertyDrawer.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: 9b4d4e36abb74b1096927b7922bfbdec -timeCreated: 1644254968 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/RealityCollective.ServiceFramework.Editor.asmdef b/Editor/RealityCollective.ServiceFramework.Editor.asmdef index 8000fec..723bc67 100644 --- a/Editor/RealityCollective.ServiceFramework.Editor.asmdef +++ b/Editor/RealityCollective.ServiceFramework.Editor.asmdef @@ -2,9 +2,7 @@ "name": "RealityCollective.ServiceFramework.Editor", "rootNamespace": "", "references": [ - "GUID:13703f41b24bb904cb2305abe6317e3d", - "GUID:b2d046948d6452a4b8485efc9ce0f88c", - "GUID:2a3f0ca4e21332c44bfdce311ea8943e" + "GUID:13703f41b24bb904cb2305abe6317e3d" ], "includePlatforms": [ "Editor" diff --git a/Editor/ServiceFrameworkPreferences.cs b/Editor/ServiceFrameworkPreferences.cs index df88db9..ba52e92 100644 --- a/Editor/ServiceFrameworkPreferences.cs +++ b/Editor/ServiceFrameworkPreferences.cs @@ -1,9 +1,9 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Editor.Utilities; -using RealityCollective.Extensions; using RealityCollective.ServiceFramework.Definitions.Platforms; +using RealityCollective.ServiceFramework.Editor.Utilities; +using RealityCollective.ServiceFramework.Extensions; using RealityCollective.ServiceFramework.Interfaces; using RealityCollective.ServiceFramework.Services; using System; @@ -145,15 +145,7 @@ value is EditorPlatform || #endregion Current Platform Target - #region Menu Redirect - /// - /// Simple scene helper to create the beginnings of a scene, creating the scene root and a floor. - /// - [MenuItem(ServiceFrameworkPreferences.Editor_Menu_Keyword + "/Service Framework/Moved to Tools-Service Framework", false, 1)] - public static void RedirectNotice() - { - } - #endregion + [SettingsProvider] private static SettingsProvider Preferences() { diff --git a/Editor/ServiceFrameworkPreferences.cs.meta b/Editor/ServiceFrameworkPreferences.cs.meta index 6d49a8a..7615c74 100644 --- a/Editor/ServiceFrameworkPreferences.cs.meta +++ b/Editor/ServiceFrameworkPreferences.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/ServiceManagerInspector.cs b/Editor/ServiceManagerInspector.cs index e71d6ac..ea05489 100644 --- a/Editor/ServiceManagerInspector.cs +++ b/Editor/ServiceManagerInspector.cs @@ -1,11 +1,10 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Editor.Extensions; -using RealityCollective.Extensions; using RealityCollective.ServiceFramework.Definitions; using RealityCollective.ServiceFramework.Editor.Profiles; using RealityCollective.ServiceFramework.Editor.Utilities; +using RealityCollective.ServiceFramework.Extensions; using RealityCollective.ServiceFramework.Services; using UnityEditor; using UnityEngine; @@ -24,14 +23,6 @@ public class ServiceManagerInspector : UnityEditor.Editor private UnityEditor.Editor profileInspector; - private void Awake() - { - if (target.name != nameof(ServiceManagerInstance)) - { - target.name = nameof(ServiceManagerInstance); - } - } - private void OnEnable() { serviceProvidersProfile = serializedObject.FindProperty(nameof(serviceProvidersProfile)); diff --git a/Editor/ServiceManagerInspector.cs.meta b/Editor/ServiceManagerInspector.cs.meta index b92af79..d906425 100644 --- a/Editor/ServiceManagerInspector.cs.meta +++ b/Editor/ServiceManagerInspector.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/ServiceProfileInspector.cs b/Editor/ServiceProfileInspector.cs index a68c3dd..3abef77 100644 --- a/Editor/ServiceProfileInspector.cs +++ b/Editor/ServiceProfileInspector.cs @@ -1,13 +1,11 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Definitions.Utilities; -using RealityCollective.Editor.Extensions; -using RealityCollective.Extensions; using RealityCollective.ServiceFramework.Definitions; using RealityCollective.ServiceFramework.Definitions.Platforms; using RealityCollective.ServiceFramework.Editor.PropertyDrawers; using RealityCollective.ServiceFramework.Editor.Utilities; +using RealityCollective.ServiceFramework.Extensions; using RealityCollective.ServiceFramework.Interfaces; using RealityCollective.ServiceFramework.Services; using System; diff --git a/Editor/ServiceProfileInspector.cs.meta b/Editor/ServiceProfileInspector.cs.meta index 1e33d26..f7671cb 100644 --- a/Editor/ServiceProfileInspector.cs.meta +++ b/Editor/ServiceProfileInspector.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/ServiceWizard.cs b/Editor/ServiceWizard.cs index d96285b..d08f65f 100644 --- a/Editor/ServiceWizard.cs +++ b/Editor/ServiceWizard.cs @@ -1,9 +1,9 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Extensions; using RealityCollective.ServiceFramework.Definitions; using RealityCollective.ServiceFramework.Editor.Utilities; +using RealityCollective.ServiceFramework.Extensions; using RealityCollective.ServiceFramework.Interfaces; using RealityCollective.ServiceFramework.Modules; using RealityCollective.ServiceFramework.Services; diff --git a/Editor/ServiceWizard.cs.meta b/Editor/ServiceWizard.cs.meta index 79e801a..a8a74de 100644 --- a/Editor/ServiceWizard.cs.meta +++ b/Editor/ServiceWizard.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: 9a6978396f7e4740bff94710617c3164 -timeCreated: 1644255077 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Utilities/EditorMenuUtilities.cs b/Editor/Utilities/EditorMenuUtilities.cs index 8a1b738..7472b73 100644 --- a/Editor/Utilities/EditorMenuUtilities.cs +++ b/Editor/Utilities/EditorMenuUtilities.cs @@ -1,7 +1,7 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Extensions; +using RealityCollective.ServiceFramework.Extensions; using UnityEditor; using UnityEngine; @@ -19,7 +19,7 @@ public static void CreateServiceManagerInstance() GameObject serviceManagerGO; if (existingCheck.IsNull()) { - serviceManagerGO = new GameObject("ServiceManagerInstance"); + serviceManagerGO = new GameObject("GlobalServiceManager"); serviceManagerGO.AddComponent(); } else diff --git a/Editor/Utilities/EditorMenuUtilities.cs.meta b/Editor/Utilities/EditorMenuUtilities.cs.meta index 0f7b9b3..135d310 100644 --- a/Editor/Utilities/EditorMenuUtilities.cs.meta +++ b/Editor/Utilities/EditorMenuUtilities.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/Utilities/EditorPreferences.cs b/Editor/Utilities/EditorPreferences.cs new file mode 100644 index 0000000..fc0e557 --- /dev/null +++ b/Editor/Utilities/EditorPreferences.cs @@ -0,0 +1,145 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEditor; +using UnityEngine; + +namespace RealityCollective.ServiceFramework.Editor.Utilities +{ + /// + /// Convenience class for setting Editor Preferences with as key prefix. + /// + [InitializeOnLoad] + public static class EditorPreferences + { + static EditorPreferences() + { + applicationProductName = Application.productName; + applicationDataPath = Application.dataPath; + } + + private static string applicationDataPath; + + public static string ApplicationDataPath = applicationDataPath ?? (applicationDataPath = Application.dataPath); + + private static string applicationProductName = null; + + public static string ApplicationProductName => applicationProductName ?? (applicationProductName = Application.productName); + + /// + /// Set the saved from to . + /// + /// + /// + public static void Set(string key, string value) + { + Debug.Assert(!string.IsNullOrWhiteSpace(key)); + EditorPrefs.SetString($"{ApplicationProductName}_{key}", value); + } + + /// + /// Set the saved from to . + /// + /// + /// + public static void Set(string key, bool value) + { + Debug.Assert(!string.IsNullOrWhiteSpace(key)); + EditorPrefs.SetBool($"{ApplicationProductName}_{key}", value); + } + + /// + /// Set the saved from the . + /// + /// + /// + public static void Set(string key, float value) + { + Debug.Assert(!string.IsNullOrWhiteSpace(key)); + EditorPrefs.SetFloat($"{ApplicationProductName}_{key}", value); + } + + /// + /// Set the saved from the . + /// + /// + /// + public static void Set(string key, int value) + { + Debug.Assert(!string.IsNullOrWhiteSpace(key)); + EditorPrefs.SetInt($"{ApplicationProductName}_{key}", value); + } + + /// + /// Get the saved from the . + /// + /// + /// + public static string Get(string key, string defaultValue) + { + Debug.Assert(!string.IsNullOrWhiteSpace(key)); + + if (EditorPrefs.HasKey($"{ApplicationProductName}_{key}")) + { + return EditorPrefs.GetString($"{ApplicationProductName}_{key}"); + } + + EditorPrefs.SetString($"{ApplicationProductName}_{key}", defaultValue); + return defaultValue; + } + + /// + /// Get the saved from the . + /// + /// + /// + public static bool Get(string key, bool defaultValue) + { + Debug.Assert(!string.IsNullOrWhiteSpace(key)); + + if (EditorPrefs.HasKey($"{ApplicationProductName}_{key}")) + { + return EditorPrefs.GetBool($"{ApplicationProductName}_{key}"); + } + + EditorPrefs.SetBool($"{ApplicationProductName}_{key}", defaultValue); + return defaultValue; + } + + /// + /// Get the saved from the . + /// + /// + /// + public static float Get(string key, float defaultValue) + { + Debug.Assert(!string.IsNullOrWhiteSpace(key)); + + if (EditorPrefs.HasKey($"{ApplicationProductName}_{key}")) + { + return EditorPrefs.GetFloat($"{ApplicationProductName}_{key}"); + } + + EditorPrefs.SetFloat($"{ApplicationProductName}_{key}", defaultValue); + return defaultValue; + } + + /// + /// Get the saved from the . + /// + /// + /// + public static int Get(string key, int defaultValue) + { + Debug.Assert(!string.IsNullOrWhiteSpace(key)); + + if (EditorPrefs.HasKey($"{ApplicationProductName}_{key}")) + { + return EditorPrefs.GetInt($"{ApplicationProductName}_{key}"); + } + + EditorPrefs.SetInt($"{ApplicationProductName}_{key}", defaultValue); + return defaultValue; + } + } +} diff --git a/Editor/Utilities/EditorPreferences.cs.meta b/Editor/Utilities/EditorPreferences.cs.meta new file mode 100644 index 0000000..dd8aee6 --- /dev/null +++ b/Editor/Utilities/EditorPreferences.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ff436c6ae719c2c49a30de5892608579 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Utilities/GuidRegenerator.cs b/Editor/Utilities/GuidRegenerator.cs new file mode 100644 index 0000000..d3478d1 --- /dev/null +++ b/Editor/Utilities/GuidRegenerator.cs @@ -0,0 +1,194 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using UnityEditor; +using UnityEngine; + +namespace RealityCollective.ServiceFramework.Editor.Utilities +{ + /// + /// + /// Used to regenerate guids for Unity assets. + /// + /// + /// Based on https://gist.github.com/ZimM-LostPolygon/7e2f8a3e5a1be183ac19 + /// + /// + public static class GuidRegenerator + { + /// + /// Regenerate the guids for assets located in the . + /// + /// The root directory to search for assets to regenerate guids for. + /// Should be called after finishing regeneration? (Default is true) + public static void RegenerateGuids(string assetsRootPath, bool refreshAssetDatabase = true) + { + RegenerateGuids(new List { assetsRootPath }, refreshAssetDatabase); + } + + /// + /// Regenerate the guids for assets located in the . + /// + /// The root directory to search for assets to regenerate guids for. + /// Should be called after finishing regeneration? (Default is true) + public static void RegenerateGuids(List assetsRootPath, bool refreshAssetDatabase = true) + { + try + { + AssetDatabase.StartAssetEditing(); + RegenerateGuidsInternal(assetsRootPath); + } + finally + { + AssetDatabase.StopAssetEditing(); + EditorUtility.ClearProgressBar(); + + if (refreshAssetDatabase) + { + EditorApplication.delayCall += AssetDatabase.Refresh; + } + } + } + + private static void RegenerateGuidsInternal(List assetsRootPath) + { + // Get list of working files + var filesPaths = new List(); + + for (int i = 0; i < assetsRootPath.Count; i++) + { + filesPaths.AddRange(UnityFileHelper.GetAllFilesAtPath(assetsRootPath[i])); + } + + // Create dictionary to hold old-to-new GUID map + var guidOldToNewMap = new Dictionary(); + var guidsInFileMap = new Dictionary>(); + + // We must only replace GUIDs for Resources present in the path. + // Otherwise built-in resources (shader, meshes etc) get overwritten. + var ownGuids = new HashSet(); + + // Traverse all files, remember which GUIDs are in which files and generate new GUIDs + var counter = 0; + + foreach (var filePath in filesPaths) + { + EditorUtility.DisplayProgressBar("Gathering asset info...", filePath, counter / (float)filesPaths.Count); + + var isFirstGuid = true; + var guids = GetGuids(File.ReadAllText(filePath)); + + foreach (var oldGuid in guids) + { + // First GUID in .meta file is always the GUID of the asset itself + if (isFirstGuid && Path.GetExtension(filePath) == ".meta") + { + ownGuids.Add(oldGuid); + isFirstGuid = false; + } + + // Generate and save new GUID if we haven't added it before + if (!guidOldToNewMap.ContainsKey(oldGuid)) + { + var newGuid = Guid.NewGuid().ToString("N"); + guidOldToNewMap.Add(oldGuid, newGuid); + } + + if (!guidsInFileMap.ContainsKey(filePath)) + { + guidsInFileMap[filePath] = new List(); + } + + if (!guidsInFileMap[filePath].Contains(oldGuid)) + { + guidsInFileMap[filePath].Add(oldGuid); + } + } + + counter++; + } + + // Traverse the files again and replace the old GUIDs + counter = -1; + var guidsInFileMapKeysCount = guidsInFileMap.Keys.Count; + + foreach (var filePath in guidsInFileMap.Keys) + { + EditorUtility.DisplayProgressBar("Regenerating GUIDs...", filePath, counter / (float)guidsInFileMapKeysCount); + counter++; + + var contents = File.ReadAllText(filePath); + + foreach (var oldGuid in guidsInFileMap[filePath]) + { + if (!ownGuids.Contains(oldGuid)) { continue; } + + var newGuid = guidOldToNewMap[oldGuid]; + + if (string.IsNullOrEmpty(newGuid)) + { + throw new NullReferenceException("newGuid == null"); + } + + contents = contents.Replace($"guid: {oldGuid}", $"guid: {newGuid}"); + } + + try + { + var attributes = File.GetAttributes(filePath); + + if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) + { + attributes ^= FileAttributes.ReadOnly; + } + + File.SetAttributes(filePath, attributes); + File.WriteAllText(filePath, contents); + } + catch (Exception e) + { + Debug.LogError(e); + } + } + + EditorUtility.ClearProgressBar(); + } + + private static IEnumerable GetGuids(string text) + { + const string guidStart = "guid: "; + const int guidLength = 32; + var textLength = text.Length; + var guidStartLength = guidStart.Length; + var guids = new List(); + var index = 0; + + while (index + guidStartLength + guidLength < textLength) + { + index = text.IndexOf(guidStart, index, StringComparison.Ordinal); + + if (index == -1) + { + break; + } + + index += guidStartLength; + var guid = text.Substring(index, guidLength); + index += guidLength; + + if (IsGuid(guid)) + { + guids.Add(guid); + } + } + + return guids; + } + + private static bool IsGuid(string text) => text.All(c => (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')); + } +} \ No newline at end of file diff --git a/Editor/Utilities/GuidRegenerator.cs.meta b/Editor/Utilities/GuidRegenerator.cs.meta new file mode 100644 index 0000000..b8e1212 --- /dev/null +++ b/Editor/Utilities/GuidRegenerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ad5ae1d92b424da40aba5587e4d5685b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Utilities/ServiceFrameworkEditorPathFinder.cs.meta b/Editor/Utilities/ServiceFrameworkEditorPathFinder.cs.meta index a35c83c..9439008 100644 --- a/Editor/Utilities/ServiceFrameworkEditorPathFinder.cs.meta +++ b/Editor/Utilities/ServiceFrameworkEditorPathFinder.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/Utilities/ServiceFrameworkFinderUtility.cs b/Editor/Utilities/ServiceFrameworkFinderUtility.cs index 19cc23d..f5153d7 100644 --- a/Editor/Utilities/ServiceFrameworkFinderUtility.cs +++ b/Editor/Utilities/ServiceFrameworkFinderUtility.cs @@ -1,7 +1,7 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Extensions; +using RealityCollective.ServiceFramework.Extensions; using System; using System.Collections.Generic; using System.IO; diff --git a/Editor/Utilities/ServiceFrameworkFinderUtility.cs.meta b/Editor/Utilities/ServiceFrameworkFinderUtility.cs.meta index 24a02ed..f19b82d 100644 --- a/Editor/Utilities/ServiceFrameworkFinderUtility.cs.meta +++ b/Editor/Utilities/ServiceFrameworkFinderUtility.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: 210a8427d3404353a7d4a2d333000b92 -timeCreated: 1644255235 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Utilities/ServiceFrameworkInspectorUtility.cs.meta b/Editor/Utilities/ServiceFrameworkInspectorUtility.cs.meta index 08cb86a..8aed4f0 100644 --- a/Editor/Utilities/ServiceFrameworkInspectorUtility.cs.meta +++ b/Editor/Utilities/ServiceFrameworkInspectorUtility.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/Utilities/ServiceFrameworkPathFinder.cs.meta b/Editor/Utilities/ServiceFrameworkPathFinder.cs.meta index 60b42d0..9b64e0e 100644 --- a/Editor/Utilities/ServiceFrameworkPathFinder.cs.meta +++ b/Editor/Utilities/ServiceFrameworkPathFinder.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: c079a10cea8c4b9f98b526f555aec6f7 -timeCreated: 1644255235 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Utilities/UnityEditorPlayModeStateChangeHandler.cs.meta b/Editor/Utilities/UnityEditorPlayModeStateChangeHandler.cs.meta index e902d00..9ca8313 100644 --- a/Editor/Utilities/UnityEditorPlayModeStateChangeHandler.cs.meta +++ b/Editor/Utilities/UnityEditorPlayModeStateChangeHandler.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Editor/Utilities/UnityFileHelper.cs b/Editor/Utilities/UnityFileHelper.cs new file mode 100644 index 0000000..e0abeee --- /dev/null +++ b/Editor/Utilities/UnityFileHelper.cs @@ -0,0 +1,71 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using System.Collections.Generic; +using System.IO; +using UnityEngine; + +namespace RealityCollective.ServiceFramework.Editor.Utilities +{ + public static class UnityFileHelper + { + /// + /// Managed list of native Unity asset file extensions + /// + private static readonly string[] UnityFileExtensions = { + "*.meta", + "*.mat", + "*.anim", + "*.prefab", + "*.unity", + "*.asset", + "*.guiskin", + "*.fontsettings", + "*.controller", + "*.json" + }; + + /// + /// Utility to return all the unity recognized files, including meta files within a specific path + /// + /// Root folder from which to search from + public static List GetUnityAssetsAtPath(string assetsRootPath) + { + // Get list of working files + var filesPaths = new List(); + + assetsRootPath = Path.GetFullPath(assetsRootPath); + + foreach (var extension in UnityFileExtensions) + { + try + { + filesPaths.AddRange(Directory.GetFiles(assetsRootPath, extension, SearchOption.AllDirectories)); + } + catch (Exception e) + { + Debug.LogError($"{e}\n{assetsRootPath}"); + } + } + + return filesPaths; + } + + /// + /// Utility to return all recognized files, including meta files within a specific path + /// + /// Root folder from which to search from + public static List GetAllFilesAtPath(string assetsRootPath) + { + // Get list of working files + var filesPaths = new List(); + + assetsRootPath = Path.GetFullPath(assetsRootPath); + + filesPaths.AddRange(Directory.GetFiles(assetsRootPath, "*.*", SearchOption.AllDirectories)); + + return filesPaths; + } + } +} \ No newline at end of file diff --git a/Editor/Utilities/UnityFileHelper.cs.meta b/Editor/Utilities/UnityFileHelper.cs.meta new file mode 100644 index 0000000..f92a763 --- /dev/null +++ b/Editor/Utilities/UnityFileHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8957023a386e8ac4493a73764c8e23c2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md index 79d8023..b119fdb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # Service Framework + + + Shows an illustrated sun in light color mode and a moon with stars in dark color mode. + + The Service Framework package by the [Reality Collective](https://www.realityCollective.io). This package is an extensible service framework to build highly performant components for your Unity projects. [![openupm](https://img.shields.io/npm/v/com.realitycollective.service-framework?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.realitycollective.service-framework/) @@ -19,11 +24,10 @@ The Service framework provides a service repository for enabling background serv ## Requirements - [Unity 2021.3 or above](https://unity.com/) -- [RealityCollective.Utilities](https://github.com/realitycollective/com.realitycollective.utilities) ### OpenUPM -The simplest way to getting started using the utilities package in your project is via OpenUPM. Visit [OpenUPM](https://openupm.com/docs/) to learn more about it. Once you have the OpenUPM CLI set up use the following command to add the package to your project: +The simplest way to getting started using the Service Framework package in your project is via OpenUPM. Visit [OpenUPM](https://openupm.com/docs/) to learn more about it. Once you have the OpenUPM CLI set up use the following command to add the package to your project: ```text openupm add com.realitycollective.service-framework diff --git a/Runtime/AssemblyInfo.cs b/Runtime/AssemblyInfo.cs index 296e59f..a05b35f 100644 --- a/Runtime/AssemblyInfo.cs +++ b/Runtime/AssemblyInfo.cs @@ -14,5 +14,3 @@ // Note: these are the names of the assembly definitions themselves, not necessarily the actual namespace the class is in. [assembly: InternalsVisibleTo("RealityCollective.ServiceFramework.Editor")] [assembly: InternalsVisibleTo("RealityCollective.ServiceFramework.Tests")] -[assembly: InternalsVisibleTo("RealityCollective.Editor")] -[assembly: InternalsVisibleTo("RealityCollective")] \ No newline at end of file diff --git a/Runtime/AssemblyInfo.cs.meta b/Runtime/AssemblyInfo.cs.meta index 0781500..a8a07c6 100644 --- a/Runtime/AssemblyInfo.cs.meta +++ b/Runtime/AssemblyInfo.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Attributes/ExtendsAttribute.cs b/Runtime/Attributes/ExtendsAttribute.cs new file mode 100644 index 0000000..b1b1440 --- /dev/null +++ b/Runtime/Attributes/ExtendsAttribute.cs @@ -0,0 +1,38 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using RealityCollective.ServiceFramework.Definitions.Utilities; +using System; + +namespace RealityCollective.ServiceFramework.Attributes +{ + /// + /// Constraint that allows selection of classes that extend a specific class when + /// selecting a with the Unity inspector. + /// + public sealed class ExtendsAttribute : SystemTypeAttribute + { + /// + /// Gets the type of class that selectable classes must derive from. + /// + public Type BaseType { get; private set; } + + /// + /// Initializes a new instance of the class. + /// + /// Type of class that selectable classes must derive from. + /// Gets or sets grouping of selectable classes. Defaults to unless explicitly specified. + public ExtendsAttribute(Type baseType, TypeGrouping grouping) : base(baseType, grouping) + { + BaseType = baseType; + } + + /// + public override bool IsConstraintSatisfied(Type type) + { + return base.IsConstraintSatisfied(type) && + BaseType.IsAssignableFrom(type) && + type != BaseType; + } + } +} \ No newline at end of file diff --git a/Runtime/Attributes/ExtendsAttribute.cs.meta b/Runtime/Attributes/ExtendsAttribute.cs.meta new file mode 100644 index 0000000..7d97348 --- /dev/null +++ b/Runtime/Attributes/ExtendsAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c3fd156fb43e4594b509b38a4e09e570 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Attributes/ImplementsAttribute.cs b/Runtime/Attributes/ImplementsAttribute.cs new file mode 100644 index 0000000..39c4972 --- /dev/null +++ b/Runtime/Attributes/ImplementsAttribute.cs @@ -0,0 +1,38 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using RealityCollective.ServiceFramework.Definitions.Utilities; +using System; +using System.Linq; + +namespace RealityCollective.ServiceFramework.Attributes +{ + /// + /// Constraint that allows selection of classes that implement a specific interface + /// when selecting a with the Unity inspector. + /// + public sealed class ImplementsAttribute : SystemTypeAttribute + { + /// + /// Gets the type of interface that selectable classes must implement. + /// + public Type InterfaceType { get; } + + /// + /// Initializes a new instance of the class. + /// + /// Type of interface that selectable classes must implement. + /// Gets or sets grouping of selectable classes. Defaults to unless explicitly specified. + public ImplementsAttribute(Type interfaceType, TypeGrouping grouping) + : base(interfaceType, grouping) + { + InterfaceType = interfaceType; + } + + /// + public override bool IsConstraintSatisfied(Type type) + { + return base.IsConstraintSatisfied(type) && type.GetInterfaces().Any(t => t == InterfaceType); + } + } +} \ No newline at end of file diff --git a/Runtime/Attributes/ImplementsAttribute.cs.meta b/Runtime/Attributes/ImplementsAttribute.cs.meta new file mode 100644 index 0000000..94c8732 --- /dev/null +++ b/Runtime/Attributes/ImplementsAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8dfb85bbf32e4faeb88677a4b482ef93 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Attributes/InspectorExpandAttribute.cs.meta b/Runtime/Attributes/InspectorExpandAttribute.cs.meta index 4072c94..cca3341 100644 --- a/Runtime/Attributes/InspectorExpandAttribute.cs.meta +++ b/Runtime/Attributes/InspectorExpandAttribute.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Attributes/RuntimePlatformAttribute.cs.meta b/Runtime/Attributes/RuntimePlatformAttribute.cs.meta index 09d3d34..55ab1a0 100644 --- a/Runtime/Attributes/RuntimePlatformAttribute.cs.meta +++ b/Runtime/Attributes/RuntimePlatformAttribute.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Attributes/SystemTypeAttribute.cs b/Runtime/Attributes/SystemTypeAttribute.cs new file mode 100644 index 0000000..a6374c1 --- /dev/null +++ b/Runtime/Attributes/SystemTypeAttribute.cs @@ -0,0 +1,52 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using RealityCollective.ServiceFramework.Definitions.Utilities; +using System; +using UnityEngine; + +namespace RealityCollective.ServiceFramework.Attributes +{ + /// + /// Base class for class selection constraints that can be applied when selecting + /// a with the Unity inspector. + /// + public class SystemTypeAttribute : PropertyAttribute + { + /// + /// Gets or sets grouping of selectable classes. Defaults to unless explicitly specified. + /// + public TypeGrouping Grouping { get; protected set; } + + /// + /// Gets or sets whether abstract classes can be selected from drop-down. + /// Defaults to a value of false unless explicitly specified. + /// + public bool AllowAbstract { get; protected set; } = false; + + /// + /// + /// + /// Initializes a new instance of the class. + /// Gets or sets grouping of selectable classes. Defaults to unless explicitly specified. + public SystemTypeAttribute(Type type, TypeGrouping grouping = TypeGrouping.ByNamespaceFlat) + { + bool isValid = type.IsClass || type.IsInterface || type.IsValueType && !type.IsEnum; + Debug.Assert(isValid, $"Invalid Type {type} in attribute."); + Grouping = grouping; + } + + /// + /// Determines whether the specified satisfies filter constraint. + /// + /// Type to test. + /// + /// A value indicating if the type specified by + /// satisfies this constraint and should thus be selectable. + /// + public virtual bool IsConstraintSatisfied(Type type) + { + return AllowAbstract || !type.IsAbstract; + } + } +} \ No newline at end of file diff --git a/Runtime/Attributes/SystemTypeAttribute.cs.meta b/Runtime/Attributes/SystemTypeAttribute.cs.meta new file mode 100644 index 0000000..d78a534 --- /dev/null +++ b/Runtime/Attributes/SystemTypeAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5658ed6e9b7f4cd8b1d7ebedcd4e62ee +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Definitions/CreateProfileMenuItemIndices.cs.meta b/Runtime/Definitions/CreateProfileMenuItemIndices.cs.meta index 380a040..165b52b 100644 --- a/Runtime/Definitions/CreateProfileMenuItemIndices.cs.meta +++ b/Runtime/Definitions/CreateProfileMenuItemIndices.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: af3fb215c2c6481ea6d4e37573fba52b -timeCreated: 1644253722 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/AllPlatforms.cs.meta b/Runtime/Definitions/Platforms/AllPlatforms.cs.meta index 9279277..06b49e6 100644 --- a/Runtime/Definitions/Platforms/AllPlatforms.cs.meta +++ b/Runtime/Definitions/Platforms/AllPlatforms.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/AndroidPlatform.cs.meta b/Runtime/Definitions/Platforms/AndroidPlatform.cs.meta index d2b8bf8..5c9ad5e 100644 --- a/Runtime/Definitions/Platforms/AndroidPlatform.cs.meta +++ b/Runtime/Definitions/Platforms/AndroidPlatform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/BasePlatform.cs.meta b/Runtime/Definitions/Platforms/BasePlatform.cs.meta index 699da5f..1625ad9 100644 --- a/Runtime/Definitions/Platforms/BasePlatform.cs.meta +++ b/Runtime/Definitions/Platforms/BasePlatform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/CurrentBuildTargetPlatform.cs.meta b/Runtime/Definitions/Platforms/CurrentBuildTargetPlatform.cs.meta index 33d2087..5522c48 100644 --- a/Runtime/Definitions/Platforms/CurrentBuildTargetPlatform.cs.meta +++ b/Runtime/Definitions/Platforms/CurrentBuildTargetPlatform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/EditorPlatform.cs.meta b/Runtime/Definitions/Platforms/EditorPlatform.cs.meta index 0a75c99..98fab7c 100644 --- a/Runtime/Definitions/Platforms/EditorPlatform.cs.meta +++ b/Runtime/Definitions/Platforms/EditorPlatform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/IOSPlatform.cs.meta b/Runtime/Definitions/Platforms/IOSPlatform.cs.meta index 07e0e93..b6cf188 100644 --- a/Runtime/Definitions/Platforms/IOSPlatform.cs.meta +++ b/Runtime/Definitions/Platforms/IOSPlatform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/LinuxPlatform.cs.meta b/Runtime/Definitions/Platforms/LinuxPlatform.cs.meta index 1dc79f2..67fce11 100644 --- a/Runtime/Definitions/Platforms/LinuxPlatform.cs.meta +++ b/Runtime/Definitions/Platforms/LinuxPlatform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/OSXPlatform.cs.meta b/Runtime/Definitions/Platforms/OSXPlatform.cs.meta index 31ee2cf..9b1e72d 100644 --- a/Runtime/Definitions/Platforms/OSXPlatform.cs.meta +++ b/Runtime/Definitions/Platforms/OSXPlatform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/PS4Platform.cs.meta b/Runtime/Definitions/Platforms/PS4Platform.cs.meta index 57660dc..e8cb80d 100644 --- a/Runtime/Definitions/Platforms/PS4Platform.cs.meta +++ b/Runtime/Definitions/Platforms/PS4Platform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/PS5Platform.cs.meta b/Runtime/Definitions/Platforms/PS5Platform.cs.meta index dfb4e02..93aefc2 100644 --- a/Runtime/Definitions/Platforms/PS5Platform.cs.meta +++ b/Runtime/Definitions/Platforms/PS5Platform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/TVOSPlatform.cs.meta b/Runtime/Definitions/Platforms/TVOSPlatform.cs.meta index a7f7f59..c404f50 100644 --- a/Runtime/Definitions/Platforms/TVOSPlatform.cs.meta +++ b/Runtime/Definitions/Platforms/TVOSPlatform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/UniversalWindowsPlatform.cs.meta b/Runtime/Definitions/Platforms/UniversalWindowsPlatform.cs.meta index 4b21460..d6cb7b6 100644 --- a/Runtime/Definitions/Platforms/UniversalWindowsPlatform.cs.meta +++ b/Runtime/Definitions/Platforms/UniversalWindowsPlatform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/WebGlPlatform.cs.meta b/Runtime/Definitions/Platforms/WebGlPlatform.cs.meta index 19211db..724c1da 100644 --- a/Runtime/Definitions/Platforms/WebGlPlatform.cs.meta +++ b/Runtime/Definitions/Platforms/WebGlPlatform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/WindowsStandalonePlatform.cs.meta b/Runtime/Definitions/Platforms/WindowsStandalonePlatform.cs.meta index a1b8f34..49103d8 100644 --- a/Runtime/Definitions/Platforms/WindowsStandalonePlatform.cs.meta +++ b/Runtime/Definitions/Platforms/WindowsStandalonePlatform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Platforms/XboxPlatform.cs.meta b/Runtime/Definitions/Platforms/XboxPlatform.cs.meta index a12a068..03d08c9 100644 --- a/Runtime/Definitions/Platforms/XboxPlatform.cs.meta +++ b/Runtime/Definitions/Platforms/XboxPlatform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Process.cs b/Runtime/Definitions/Process.cs index 97d0fe3..754a630 100644 --- a/Runtime/Definitions/Process.cs +++ b/Runtime/Definitions/Process.cs @@ -6,15 +6,15 @@ namespace RealityCollective.ServiceFramework.Definitions public delegate void UpdateMethod(float dt); /// - /// Proccess description for subscribing to the service manager update loop as a proccess not as a full service or module. + /// Process description for subscribing to the service manager update loop as a process not as a full service or module. /// - public class Proccess + public class Process { public UpdateMethod updateMethod; public readonly float period; public float periodCurrent; - public Proccess(UpdateMethod updateMethod, float period) + public Process(UpdateMethod updateMethod, float period) { this.updateMethod = updateMethod; this.period = period; diff --git a/Runtime/Definitions/Process.cs.meta b/Runtime/Definitions/Process.cs.meta index d5f6bd5..9b52db4 100644 --- a/Runtime/Definitions/Process.cs.meta +++ b/Runtime/Definitions/Process.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Profiles/BaseProfile.cs b/Runtime/Definitions/Profiles/BaseProfile.cs index d3da945..98459d2 100644 --- a/Runtime/Definitions/Profiles/BaseProfile.cs +++ b/Runtime/Definitions/Profiles/BaseProfile.cs @@ -5,6 +5,12 @@ namespace RealityCollective.ServiceFramework.Definitions { + /// + /// Base profile for service configuration. + /// + /// + /// Used for when a service does not require a profile or external configuration at design time. + /// public abstract class BaseProfile : ScriptableObject { /// diff --git a/Runtime/Definitions/Profiles/BaseProfile.cs.meta b/Runtime/Definitions/Profiles/BaseProfile.cs.meta index f65df85..9d24d6c 100644 --- a/Runtime/Definitions/Profiles/BaseProfile.cs.meta +++ b/Runtime/Definitions/Profiles/BaseProfile.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Profiles/BaseServiceProfile.cs.meta b/Runtime/Definitions/Profiles/BaseServiceProfile.cs.meta index 495751b..5237488 100644 --- a/Runtime/Definitions/Profiles/BaseServiceProfile.cs.meta +++ b/Runtime/Definitions/Profiles/BaseServiceProfile.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/Profiles/SceneServiceProvidersProfile.cs b/Runtime/Definitions/Profiles/SceneServiceProvidersProfile.cs new file mode 100644 index 0000000..c492563 --- /dev/null +++ b/Runtime/Definitions/Profiles/SceneServiceProvidersProfile.cs @@ -0,0 +1,24 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using RealityCollective.ServiceFramework.Interfaces; +using UnityEngine; + +namespace RealityCollective.ServiceFramework.Definitions +{ + /// + /// Scene base service configuration profile, for loading services only for a specific scene. + /// + [CreateAssetMenu(menuName = RuntimeServiceFrameworkPreferences.Service_Framework_Editor_Menu_Keyword + "/Scene Service Providers Profile", fileName = "SceneServiceProvidersProfile", order = (int)CreateProfileMenuItemIndices.ServiceProviders)] + public class SceneServiceProvidersProfile : BaseServiceProfile + { + [SerializeField] + [Tooltip("The selected scene name to load the services for.")] + private string sceneName; + + /// + /// The selected scene name to load the services for. + /// + public string SceneName => sceneName; + } +} \ No newline at end of file diff --git a/Runtime/Definitions/Profiles/SceneServiceProvidersProfile.cs.meta b/Runtime/Definitions/Profiles/SceneServiceProvidersProfile.cs.meta new file mode 100644 index 0000000..e8d3808 --- /dev/null +++ b/Runtime/Definitions/Profiles/SceneServiceProvidersProfile.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c9541e53e6ad7c7429def6741e120e7e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Definitions/Profiles/ServiceProvidersProfile.cs b/Runtime/Definitions/Profiles/ServiceProvidersProfile.cs index 957be4a..cade5e0 100644 --- a/Runtime/Definitions/Profiles/ServiceProvidersProfile.cs +++ b/Runtime/Definitions/Profiles/ServiceProvidersProfile.cs @@ -6,15 +6,18 @@ namespace RealityCollective.ServiceFramework.Definitions { - [CreateAssetMenu(menuName = "Reality Collective/Service Framework/Service Providers Profile", fileName = "ServiceProvidersProfile", order = (int)CreateProfileMenuItemIndices.ServiceProviders)] + /// + /// Service configuration profile, for loading services for the entire project. + /// + [CreateAssetMenu(menuName = RuntimeServiceFrameworkPreferences.Service_Framework_Editor_Menu_Keyword + "/Service Providers Profile", fileName = "ServiceProvidersProfile", order = (int)CreateProfileMenuItemIndices.ServiceProviders)] public class ServiceProvidersProfile : BaseServiceProfile { [SerializeField] - [Tooltip("The service manager will only initialise services in the Editor when it is running in play mode.\nThe default is to always be active and validating service configuration.")] + [Tooltip("The service manager will only initialize services in the Editor when it is running in play mode.\nThe default is to always be active and validating service configuration.")] private bool initializeOnPlay = false; /// - /// The service manager will only initialise services in the Editor when it is running in play mode. + /// The service manager will only initialize services in the Editor when it is running in play mode. /// The default is to always be active and validating service configuration. /// public bool InitializeOnPlay => initializeOnPlay; @@ -27,5 +30,14 @@ public class ServiceProvidersProfile : BaseServiceProfile /// Ensure that the Service Manager Instance is not destroyed on scene change. /// public bool DoNotDestroyServiceManagerOnLoad => doNotDestroyServiceManagerOnLoad; + + [SerializeField] + [Tooltip("The scene based service configuration.")] + private SceneServiceConfiguration[] sceneServiceConfiguration; + + /// + /// The scene based service configuration. + /// + public SceneServiceConfiguration[] SceneServiceConfiguration => sceneServiceConfiguration; } -} +} \ No newline at end of file diff --git a/Runtime/Definitions/Profiles/ServiceProvidersProfile.cs.meta b/Runtime/Definitions/Profiles/ServiceProvidersProfile.cs.meta index 0219576..564d48e 100644 --- a/Runtime/Definitions/Profiles/ServiceProvidersProfile.cs.meta +++ b/Runtime/Definitions/Profiles/ServiceProvidersProfile.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/RuntimePlatformEntry.cs b/Runtime/Definitions/RuntimePlatformEntry.cs index 8fed808..f565f54 100644 --- a/Runtime/Definitions/RuntimePlatformEntry.cs +++ b/Runtime/Definitions/RuntimePlatformEntry.cs @@ -1,8 +1,8 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Attributes; -using RealityCollective.Definitions.Utilities; +using RealityCollective.ServiceFramework.Attributes; +using RealityCollective.ServiceFramework.Definitions.Utilities; using RealityCollective.ServiceFramework.Interfaces; using System; using System.Collections.Generic; @@ -10,6 +10,9 @@ namespace RealityCollective.ServiceFramework.Definitions { + /// + /// Runtime platform entry, for loading services for specific platforms. + /// [Serializable] public class RuntimePlatformEntry { diff --git a/Runtime/Definitions/RuntimePlatformEntry.cs.meta b/Runtime/Definitions/RuntimePlatformEntry.cs.meta index 0897588..08bc28f 100644 --- a/Runtime/Definitions/RuntimePlatformEntry.cs.meta +++ b/Runtime/Definitions/RuntimePlatformEntry.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Definitions/RuntimeServiceFrameworkPreferences.cs b/Runtime/Definitions/RuntimeServiceFrameworkPreferences.cs new file mode 100644 index 0000000..f444d82 --- /dev/null +++ b/Runtime/Definitions/RuntimeServiceFrameworkPreferences.cs @@ -0,0 +1,14 @@ +namespace RealityCollective.ServiceFramework +{ + /// + /// Runtime service framework preferences, editor helpers for organizing where options appear in the Unity Editor. + /// + public static class RuntimeServiceFrameworkPreferences + { + public const string Editor_Menu_Keyword = "Reality Collective"; + + public const string Service_Framework_Editor_Menu_Keyword = "Service Framework"; + + private static readonly string[] Package_Keywords = { "Reality", "Collective", "Mixed", "Reality", "Service", "Framework" }; + } +} diff --git a/Runtime/Definitions/RuntimeServiceFrameworkPreferences.cs.meta b/Runtime/Definitions/RuntimeServiceFrameworkPreferences.cs.meta new file mode 100644 index 0000000..898f4ef --- /dev/null +++ b/Runtime/Definitions/RuntimeServiceFrameworkPreferences.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9438f29c49b2f20418c780a4bc7fa69f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Definitions/SceneServiceConfiguration.cs b/Runtime/Definitions/SceneServiceConfiguration.cs new file mode 100644 index 0000000..f80ac8a --- /dev/null +++ b/Runtime/Definitions/SceneServiceConfiguration.cs @@ -0,0 +1,24 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEngine; + +namespace RealityCollective.ServiceFramework.Definitions +{ + /// + /// Scene service configuration definition, for loading services only for a specific scene. + /// + [System.Serializable] + public class SceneServiceConfiguration + { + [SerializeField] + private SceneServiceProvidersProfile profile; + + /// + public SceneServiceProvidersProfile Profile + { + get => profile; + internal set => profile = value; + } + } +} \ No newline at end of file diff --git a/Runtime/Definitions/SceneServiceConfiguration.cs.meta b/Runtime/Definitions/SceneServiceConfiguration.cs.meta new file mode 100644 index 0000000..d147a1d --- /dev/null +++ b/Runtime/Definitions/SceneServiceConfiguration.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 34f08eb5853f18348bbc3ed8bfa4ee7a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 213bc0c4d7915b547a02e4c966be1cf1, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Definitions/ServiceConfiguration.cs b/Runtime/Definitions/ServiceConfiguration.cs index 333a13b..2e59260 100644 --- a/Runtime/Definitions/ServiceConfiguration.cs +++ b/Runtime/Definitions/ServiceConfiguration.cs @@ -1,8 +1,8 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Attributes; -using RealityCollective.Definitions.Utilities; +using RealityCollective.ServiceFramework.Attributes; +using RealityCollective.ServiceFramework.Definitions.Utilities; using RealityCollective.ServiceFramework.Interfaces; using System; using System.Collections.Generic; diff --git a/Runtime/Definitions/ServiceConfiguration.cs.meta b/Runtime/Definitions/ServiceConfiguration.cs.meta index 2bd352c..d8449d6 100644 --- a/Runtime/Definitions/ServiceConfiguration.cs.meta +++ b/Runtime/Definitions/ServiceConfiguration.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: 90d14a7efbfe4b079692467ee7754779 -timeCreated: 1644253505 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 213bc0c4d7915b547a02e4c966be1cf1, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Definitions/Utilities.meta b/Runtime/Definitions/Utilities.meta new file mode 100644 index 0000000..a5cbab0 --- /dev/null +++ b/Runtime/Definitions/Utilities.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2880fcc667ad00446b3f496ca3051ea5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Definitions/Utilities/TypeGrouping.cs b/Runtime/Definitions/Utilities/TypeGrouping.cs new file mode 100644 index 0000000..1a00eab --- /dev/null +++ b/Runtime/Definitions/Utilities/TypeGrouping.cs @@ -0,0 +1,38 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace RealityCollective.ServiceFramework.Definitions.Utilities +{ + /// + /// Indicates how selectable classes should be collated in drop-down menu. + /// + public enum TypeGrouping + { + /// + /// No grouping, just show type names in a list; for instance, "Some.Nested.Namespace.SpecialClass". + /// + None, + + /// + /// No grouping, just show the type names in a list; for instance, "SpecialClass". + /// + NoneByNameNoNamespace, + + /// + /// Group classes by namespace and show foldout menus for nested namespaces; for + /// instance, "Some > Nested > Namespace > SpecialClass". + /// + ByNamespace, + + /// + /// Group classes by namespace; for instance, "Some.Nested.Namespace > SpecialClass". + /// + ByNamespaceFlat, + + /// + /// Group classes in the same way as Unity does for its component menu. This + /// grouping method must only be used for types. + /// + ByAddComponentMenu, + } +} diff --git a/Runtime/Definitions/Utilities/TypeGrouping.cs.meta b/Runtime/Definitions/Utilities/TypeGrouping.cs.meta new file mode 100644 index 0000000..db9620b --- /dev/null +++ b/Runtime/Definitions/Utilities/TypeGrouping.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8619cedd211344ba97c5abf3409345ff +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Extensions/ArrayExtensions.cs b/Runtime/Extensions/ArrayExtensions.cs new file mode 100644 index 0000000..dbd9b23 --- /dev/null +++ b/Runtime/Extensions/ArrayExtensions.cs @@ -0,0 +1,62 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; + +namespace RealityCollective.ServiceFramework.Extensions +{ + /// + /// type method extensions. + /// + public static class ArrayExtensions + { + /// + /// Extends an existing array to add a new item + /// + /// + /// The array to extend + /// The item to add to the array + /// + public static T[] AddItem(this T[] array, T newItem) + { + // Initialise the array if it is null + if (array == null) + { + return new[] { newItem }; + } + + //Extend the array, copy the items and add the new one + var newArray = new T[array.Length + 1]; + array.CopyTo(newArray, 0); + newArray[array.Length] = newItem; + return newArray; + } + + /// + /// Provides a List style Contains search for an array containing Items + /// + /// The type of data contained with the array + /// The Array of items to search + /// The item to search for in the array + /// True if the array contains the supplied item + public static bool Contains(this T[] array, T item) where T : IComparable + { + if (array == null || array.Length == 0) + { + return false; + } + bool isFound = false; + + for (int i = 0; i < array.Length; i++) + { + if (array[i].CompareTo(item) == 0) + { + isFound = true; + break; + } + } + + return isFound; + } + } +} \ No newline at end of file diff --git a/Runtime/Extensions/ArrayExtensions.cs.meta b/Runtime/Extensions/ArrayExtensions.cs.meta new file mode 100644 index 0000000..2f740a9 --- /dev/null +++ b/Runtime/Extensions/ArrayExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 266a82df85ae476fb5653035500d82d7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Extensions/AwaiterExtensions.cs b/Runtime/Extensions/AwaiterExtensions.cs new file mode 100644 index 0000000..0c6c44a --- /dev/null +++ b/Runtime/Extensions/AwaiterExtensions.cs @@ -0,0 +1,80 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using System.Threading; +using System.Threading.Tasks; +using UnityEngine; + +namespace RealityCollective.ServiceFramework.Extensions +{ + public static class AwaiterExtensions + { + /// + /// Use this awaiter to wait until the condition is met. + /// Author: Oguzhan Soykan + /// Source: https://stackoverflow.com/questions/29089417/c-sharp-wait-until-condition-is-true + /// + /// Passing in -1 will make this wait indefinitely for the condition to be met. + /// + /// + /// The predicate condition to meet. + /// The number of seconds before timing out and throwing an exception. (-1 is indefinite) + /// ReSharper disable once ExceptionNotThrown + /// A can be thrown when the condition isn't satisfied after timeout. + public static async Task WaitUntil(this T element, Func predicate, int timeout = 10) + { + if (timeout < 1) + { + Debug.LogError("Timeout must be greater than 1."); + return await Task.FromException(new ArgumentException("Timeout must be greater than 1")); + } + + using (var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(timeout))) + { + var tcs = new TaskCompletionSource(); + + void Exception() + { + tcs.TrySetException(new TimeoutException()); + tcs.TrySetCanceled(); + } + + cancellationTokenSource.Token.Register(Exception); +#if UNITY_EDITOR + var editorCancelled = false; + UnityEditor.EditorApplication.playModeStateChanged += playModeStateChanged => editorCancelled = true; +#endif + + while (!cancellationTokenSource.IsCancellationRequested) + { +#if UNITY_EDITOR + if (editorCancelled) + { + tcs.TrySetCanceled(CancellationToken.None); + } +#endif + try + { + if (!predicate(element)) + { + await Task.Delay(1, cancellationTokenSource.Token); + continue; + } + } + catch (Exception e) + { + tcs.TrySetException(e); + } + + tcs.TrySetResult(Task.CompletedTask); + break; + } + + await tcs.Task; + } + + return element; + } + } +} \ No newline at end of file diff --git a/Runtime/Extensions/AwaiterExtensions.cs.meta b/Runtime/Extensions/AwaiterExtensions.cs.meta new file mode 100644 index 0000000..9ede7b6 --- /dev/null +++ b/Runtime/Extensions/AwaiterExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3f14376c110df4c46bc3e20ba3a8228e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Extensions/CollectionsExtensions.cs b/Runtime/Extensions/CollectionsExtensions.cs new file mode 100644 index 0000000..e2da256 --- /dev/null +++ b/Runtime/Extensions/CollectionsExtensions.cs @@ -0,0 +1,59 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System.Collections.Generic; + +namespace RealityCollective.ServiceFramework.Extensions +{ + /// + /// Extension methods for .Net Collection objects, e.g. Lists, Dictionaries, Arrays + /// + public static class CollectionsExtensions + { + /// + /// Validate if a list contains an item and add it if not found. + /// + /// Data type used in the List. + /// The instance of the List to validate. + /// The item of Type T to add to the list if not found + /// True if a new item was added to the collection + public static bool EnsureListItem(this IList list, T item) + { + if (!list.Contains(item)) + { + list.Add(item); + return true; + } + + return false; + } + + /// + /// Validate if a contains an item and add it if not found."/> + /// + /// + /// Will update the existing value when found unless overridden using the 'update' parameter + /// + /// Data type used in the Dictionary Key. + /// Data type used in the Dictionary Value. + /// The instance of the to validate. + /// The Key of a to validate against the dictionary with. + /// The Value of a to set the dictionary item with if required. + /// By default, the Ensure function will override the existing dictionary value if found, if this is not required it can be overridden with this bool. Setting this to will leave the dictionary item untouched if found. + /// True if a new item was added to the collection + public static bool EnsureDictionaryItem(this Dictionary dictionary, TKey key, TValue value, bool update = true) + { + if (!dictionary.TryGetValue(key, out _)) + { + dictionary.Add(key, value); + return true; + } + + if (update) + { + dictionary[key] = value; + } + return false; + } + } +} \ No newline at end of file diff --git a/Runtime/Extensions/CollectionsExtensions.cs.meta b/Runtime/Extensions/CollectionsExtensions.cs.meta new file mode 100644 index 0000000..8d02ba7 --- /dev/null +++ b/Runtime/Extensions/CollectionsExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f69552827b26bfb4ea0dc642039864ca +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Extensions/ComponentExtensions.cs b/Runtime/Extensions/ComponentExtensions.cs new file mode 100644 index 0000000..f60d34e --- /dev/null +++ b/Runtime/Extensions/ComponentExtensions.cs @@ -0,0 +1,30 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEngine; + +namespace RealityCollective.ServiceFramework.Extensions +{ + /// + /// Extensions methods for the Unity Component class. + /// This also includes some component-related extensions for the GameObject class. + /// + public static class ComponentExtensions + { + /// + /// Ensure that a component of type exists on the game object. + /// If it doesn't exist, creates it. + /// + /// Type of the component. + /// Game object on which component should be. + /// The component that was retrieved or created. + /// + /// This extension has to remain in this class as it is required by the method + /// + public static T EnsureComponent(this GameObject gameObject) where T : Component + { + T foundComponent = gameObject.GetComponent(); + return foundComponent.IsNull() ? gameObject.AddComponent() : foundComponent; + } + } +} \ No newline at end of file diff --git a/Runtime/Extensions/ComponentExtensions.cs.meta b/Runtime/Extensions/ComponentExtensions.cs.meta new file mode 100644 index 0000000..6214b26 --- /dev/null +++ b/Runtime/Extensions/ComponentExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ea7a3d3a0e19410ba881a506bb28b48f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Extensions/StringExtensions.cs b/Runtime/Extensions/StringExtensions.cs new file mode 100644 index 0000000..44bfe8c --- /dev/null +++ b/Runtime/Extensions/StringExtensions.cs @@ -0,0 +1,66 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System.IO; +using System.Text; + +namespace RealityCollective.ServiceFramework.Extensions +{ + /// + /// Extensions. + /// + public static class StringExtensions + { + public const string WhiteSpace = " "; + + /// + /// Capitalize the first character and add a space before each capitalized letter (except the first character). + /// + /// + public static string ToProperCase(this string value) + { + // If there are 0 or 1 characters, just return the string. + if (value == null) { return string.Empty; } + if (value.Length < 4) { return value.ToUpper(); } + // If there's already spaces in the string, return. + if (value.Contains(WhiteSpace)) { return value; } + + // Start with the first character. + var result = new StringBuilder(value.Substring(0, 1).ToUpper()); + + // Add the remaining characters. + for (int i = 1; i < value.Length; i++) + { + var wasLastCharUpper = char.IsUpper(value[i - 1]); + var nextIsLower = i + 1 < value.Length && char.IsLower(value[i + 1]); + var isUpper = char.IsLetter(value[i]) && char.IsUpper(value[i]); + + if (isUpper && !wasLastCharUpper && nextIsLower) + { + result.Append(WhiteSpace); + } + + result.Append(value[i]); + + if (isUpper && wasLastCharUpper && !nextIsLower) + { + result.Append(WhiteSpace); + } + } + + return result.ToString(); + } + + /// + /// Replaces all back slashes in the string with forward slashes. + /// + public static string ForwardSlashes(this string value) + => value.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + + /// + /// Replaces all forward slashes in the string with back slashes. + /// + public static string BackSlashes(this string value) + => value.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); + } +} \ No newline at end of file diff --git a/Runtime/Extensions/StringExtensions.cs.meta b/Runtime/Extensions/StringExtensions.cs.meta new file mode 100644 index 0000000..afa3985 --- /dev/null +++ b/Runtime/Extensions/StringExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 94095c20539a05e4bbdc610b1a1c37a0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Extensions/TypeExtensions.cs b/Runtime/Extensions/TypeExtensions.cs index 7fd9db4..86a9ad0 100644 --- a/Runtime/Extensions/TypeExtensions.cs +++ b/Runtime/Extensions/TypeExtensions.cs @@ -3,10 +3,11 @@ using RealityCollective.ServiceFramework.Interfaces; using RealityCollective.ServiceFramework.Services; -using RealityCollective.Utilities; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; +using UnityEngine; namespace RealityCollective.ServiceFramework.Extensions { @@ -147,5 +148,172 @@ private static bool IsValidServiceType(Type inputType, out Type returnType) } return false; } + + internal static Dictionary BuildTypeCache(Dictionary typeCache) + { + if (typeCache == null) + { + throw new ArgumentNullException("typeCache", "No type cache dictionary supplied"); + } + + var assemblies = AppDomain.CurrentDomain.GetAssemblies().filterIgnoredDomains(); + foreach (var assembly in assemblies) + { + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.BaseType != null && type.BaseType.Name.Contains("Delegate")) + { + continue; + } + if (type.IsClass && !type.IsAbstract && type.GUID != Guid.Empty) + { + try + { + var guid = type.GUID; + if (!typeCache.ContainsKey(guid)) + { + typeCache.Add(guid, type); + } + } + catch (Exception ex) + { + // In some cases at runtime in a player build built using + // IL2CPP accessing Type.GUID throws an unsupported exception crashing the application. + // Tests have shown that catching the exception prevents the app from crashing + // without actually breaking functionality of the application. + // TODO: Why are some types causing these exceptions? + Debug.LogError($"Failed to add {type.Name} to type cache."); + Debug.LogException(ex); + } + } + } + } + return typeCache; + } + + private static string[] ignoredDomains = new string[] + { + "UnityEngine", + "Unity", + "System", + "Mono", + "NetStandard", + "nunit", + "log4net", + "Bee", + "NiceIO" + }; + + private static Assembly[] filterIgnoredDomains(this Assembly[] assemblies) + { + List returnAssemblies = new List(); + for (int i = assemblies.Length - 1; i > 0; i--) + { + bool ignoreAssembly = false; + + for (int j = ignoredDomains.Length - 1; j > 0; j--) + { + if (assemblies[i].FullName.ToLower().Contains(ignoredDomains[j].ToLower())) + { + ignoreAssembly = true; + } + } + + if (!ignoreAssembly) + { + returnAssemblies.Add(assemblies[i]); + } + } + return returnAssemblies.ToArray(); + } + + /// + /// Attempts to resolve the type using the class . + /// + /// Class reference. + /// The resolved . + /// True if the was successfully obtained from or added to the , otherwise false. + public static bool TryResolveType(Guid guid, out Type resolvedType) + { + resolvedType = null; + + if (guid == Guid.Empty) + { + return false; + } + + if (!TypeCache.Current.TryGetValue(guid, out resolvedType)) + { + //Serious enough to put severe logging here as it will cause you many hours of hair pulling, only to find it is because Unity removed the class to be helpful with its Code Stripping functionality. + //Add a Link.XML to the project and sleep better. + var message = $"Configured Type Guid [{guid}] not found, either missing or lost to the curring room floor of Unity Code Stripping.\n If the class is in the project, consider including it in a Link.xml"; + Debug.LogError(message); + System.Diagnostics.Debug.WriteLine(message); + return false; + } + + if (resolvedType != null && !resolvedType.IsAbstract) + { + if (!TypeCache.Current.ContainsKey(guid)) + { + TypeCache.Current.Add(guid, resolvedType); + } + + return true; + } + + return false; + } + + /// + /// Attempts to resolve the type using a the or as . + /// + /// The or as . + /// The resolved . + /// True if the was successfully obtained from or added to the , otherwise false. + public static bool TryResolveType(string typeRef, out Type resolvedType) + { + resolvedType = null; + + if (string.IsNullOrEmpty(typeRef)) + { + return false; + } + + if (Guid.TryParse(typeRef, out var guid)) + { + return TryResolveType(guid, out resolvedType); + } + + resolvedType = Type.GetType(typeRef); + return resolvedType != null && !resolvedType.IsAbstract; + } + + /// + /// Recursively looks for generic type arguments in type hierarchy, starting with the + /// root type provided. If no generic type arguments are found on a type, it's base + /// type is checked. + /// + /// Root type to start looking for generic type arguments at. + /// The maximum recursion depth until execution gets canceled even if no results found. + /// Found generic type arguments array or null, if none found. + public static Type[] FindTopmostGenericTypeArguments(this Type root, int maxRecursionDepth = 5) + { + var genericTypeArgs = root?.GenericTypeArguments; + + if (genericTypeArgs != null && genericTypeArgs.Length > 0) + { + return genericTypeArgs; + } + + if (maxRecursionDepth > 0 && root != null) + { + return FindTopmostGenericTypeArguments(root.BaseType, --maxRecursionDepth); + } + + Debug.LogError($"{nameof(FindTopmostGenericTypeArguments)} - Maximum recursion depth reached without finding generic type arguments."); + return null; + } } } \ No newline at end of file diff --git a/Runtime/Extensions/TypeExtensions.cs.meta b/Runtime/Extensions/TypeExtensions.cs.meta index 9cad8c4..6e0c36c 100644 --- a/Runtime/Extensions/TypeExtensions.cs.meta +++ b/Runtime/Extensions/TypeExtensions.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Extensions/UnityObjectExtensions.cs b/Runtime/Extensions/UnityObjectExtensions.cs new file mode 100644 index 0000000..b9296ce --- /dev/null +++ b/Runtime/Extensions/UnityObjectExtensions.cs @@ -0,0 +1,67 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEngine; +using Object = UnityEngine.Object; + +namespace RealityCollective.ServiceFramework.Extensions +{ + /// + /// Extension methods for Unity's Object class + /// + public static class UnityObjectExtensions + { + + /// + /// Checks if a Unity is null. + /// + /// + /// Checks both the managed object and the underling Unity-managed native object. + /// True if null, otherwise false. + public static bool IsNull(this Object @object) + { + try + { + return @object == null; + } + catch + { + return true; + } + } + + /// + /// Checks if a Unity is not null. + /// + /// + /// Checks both the managed object and the underling Unity-managed native object. + /// True if not null, otherwise false. + public static bool IsNotNull(this Object @object) => !@object.IsNull(); + + /// + /// Destroys a Unity appropriately depending if running in in edit or play mode. + /// + /// Unity to destroy + /// Time in seconds at which to destroy the object, if applicable. + public static void Destroy(this Object @object, float t = 0.0f) + { + if (@object.IsNull()) { return; } + + if (Application.isPlaying) + { + Object.Destroy(@object, t); + } + else + { +#if UNITY_EDITOR + // Must use DestroyImmediate in edit mode but it is not allowed when called from + // trigger/contact, animation event callbacks or OnValidate. Must use Destroy instead. + // Delay call to counter this issue in editor. + UnityEditor.EditorApplication.delayCall += () => Object.DestroyImmediate(@object); +#else + Object.DestroyImmediate(@object); +#endif + } + } + } +} \ No newline at end of file diff --git a/Runtime/Extensions/UnityObjectExtensions.cs.meta b/Runtime/Extensions/UnityObjectExtensions.cs.meta new file mode 100644 index 0000000..a71ecf2 --- /dev/null +++ b/Runtime/Extensions/UnityObjectExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cb5acbcd47dd4c7fb3d138d2d39cb47d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Interfaces/IEventService.cs.meta b/Runtime/Interfaces/IEventService.cs.meta index 8818b3d..e70e925 100644 --- a/Runtime/Interfaces/IEventService.cs.meta +++ b/Runtime/Interfaces/IEventService.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Interfaces/IPlatform.cs.meta b/Runtime/Interfaces/IPlatform.cs.meta index d4fe0bf..ee71a42 100644 --- a/Runtime/Interfaces/IPlatform.cs.meta +++ b/Runtime/Interfaces/IPlatform.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Interfaces/IService.cs.meta b/Runtime/Interfaces/IService.cs.meta index df972f1..4652b66 100644 --- a/Runtime/Interfaces/IService.cs.meta +++ b/Runtime/Interfaces/IService.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Interfaces/IServiceConfiguration.cs b/Runtime/Interfaces/IServiceConfiguration.cs index afb0328..caa7271 100644 --- a/Runtime/Interfaces/IServiceConfiguration.cs +++ b/Runtime/Interfaces/IServiceConfiguration.cs @@ -1,7 +1,6 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Definitions.Utilities; using RealityCollective.ServiceFramework.Definitions; using System.Collections.Generic; diff --git a/Runtime/Interfaces/IServiceConfiguration.cs.meta b/Runtime/Interfaces/IServiceConfiguration.cs.meta index 45cf6f7..850cc3f 100644 --- a/Runtime/Interfaces/IServiceConfiguration.cs.meta +++ b/Runtime/Interfaces/IServiceConfiguration.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Interfaces/IServiceModule.cs.meta b/Runtime/Interfaces/IServiceModule.cs.meta index 20afc8b..ff7e016 100644 --- a/Runtime/Interfaces/IServiceModule.cs.meta +++ b/Runtime/Interfaces/IServiceModule.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Interfaces/IServiceProfile.cs.meta b/Runtime/Interfaces/IServiceProfile.cs.meta index 90de3cb..198f3ff 100644 --- a/Runtime/Interfaces/IServiceProfile.cs.meta +++ b/Runtime/Interfaces/IServiceProfile.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Modules/BaseServiceModule.cs.meta b/Runtime/Modules/BaseServiceModule.cs.meta index 7a5d81f..a56d760 100644 --- a/Runtime/Modules/BaseServiceModule.cs.meta +++ b/Runtime/Modules/BaseServiceModule.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: f5b39aad6738472f8cc745826a7db48e -timeCreated: 1644255202 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 213bc0c4d7915b547a02e4c966be1cf1, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/RealityCollective.ServiceFramework.asmdef b/Runtime/RealityCollective.ServiceFramework.asmdef index 73fe581..3fb295b 100644 --- a/Runtime/RealityCollective.ServiceFramework.asmdef +++ b/Runtime/RealityCollective.ServiceFramework.asmdef @@ -2,8 +2,7 @@ "name": "RealityCollective.ServiceFramework", "rootNamespace": "", "references": [ - "GUID:478a2357cc57436488a56e564b08d223", - "GUID:b2d046948d6452a4b8485efc9ce0f88c" + "GUID:478a2357cc57436488a56e564b08d223" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Runtime/Services/BaseEventService.cs b/Runtime/Services/BaseEventService.cs index 21a4748..04f6cf9 100644 --- a/Runtime/Services/BaseEventService.cs +++ b/Runtime/Services/BaseEventService.cs @@ -3,7 +3,7 @@ using RealityCollective.ServiceFramework.Definitions; using RealityCollective.ServiceFramework.Interfaces; -using RealityCollective.Utilities.Async; +using RealityCollective.ServiceFramework.Extensions; using System; using System.Collections.Generic; using UnityEngine; diff --git a/Runtime/Services/BaseEventService.cs.meta b/Runtime/Services/BaseEventService.cs.meta index d44eb42..824717e 100644 --- a/Runtime/Services/BaseEventService.cs.meta +++ b/Runtime/Services/BaseEventService.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 213bc0c4d7915b547a02e4c966be1cf1, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Services/BaseService.cs.meta b/Runtime/Services/BaseService.cs.meta index 784c70a..932f953 100644 --- a/Runtime/Services/BaseService.cs.meta +++ b/Runtime/Services/BaseService.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: 82159c3a71f24e53b4811e85d8296b71 -timeCreated: 1644253487 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 213bc0c4d7915b547a02e4c966be1cf1, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Services/BaseServiceWithConstructor.cs.meta b/Runtime/Services/BaseServiceWithConstructor.cs.meta index b9be24d..89a6558 100644 --- a/Runtime/Services/BaseServiceWithConstructor.cs.meta +++ b/Runtime/Services/BaseServiceWithConstructor.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: 3303ce23470243a6b8ab290a0d32bb61 -timeCreated: 1644253487 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 213bc0c4d7915b547a02e4c966be1cf1, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Services/ServiceManager.cs b/Runtime/Services/ServiceManager.cs index 27fdd05..3a5a843 100644 --- a/Runtime/Services/ServiceManager.cs +++ b/Runtime/Services/ServiceManager.cs @@ -1,23 +1,19 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Extensions; using RealityCollective.ServiceFramework.Definitions; using RealityCollective.ServiceFramework.Definitions.Platforms; using RealityCollective.ServiceFramework.Extensions; using RealityCollective.ServiceFramework.Interfaces; -using RealityCollective.Utilities.Async; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using UnityEngine; using UnityEngine.EventSystems; +using UnityEngine.SceneManagement; using Debug = UnityEngine.Debug; -// ServiceGenerator - interfacevalidation -// Limit Service Type lookups for "testing" - Type Service/DataProvider - namespace RealityCollective.ServiceFramework.Services { [ExecuteInEditMode] @@ -96,7 +92,7 @@ public void ResetProfile(ServiceProvidersProfile profile, GameObject instance = { // The application is running in editor play mode, can't // reset profiles in this state as it will cause destruction - // and reinitialization of services in use. + // and re-initialization of services in use. return; } @@ -407,6 +403,8 @@ private void InitializeServiceLocator(GameObject instance = null) TryRegisterServiceConfigurations(orderedConfig); } + LoadServicesForScene(SceneManager.GetActiveScene().name); + #if UNITY_EDITOR if (Application.isPlaying) { @@ -458,6 +456,9 @@ internal void OnEnable() internal void Start() { + SceneManager.sceneLoaded += OnSceneLoaded; + SceneManager.sceneUnloaded += OnSceneUnloaded; + if (Application.isPlaying) { StartAllServices(); @@ -814,6 +815,47 @@ public bool TryRegisterService(Type interfaceType, IService serviceInstance) #region Unregister Services + /// + /// Removed all the s from active the active runtime, defined in the provided configuration collection. + /// + /// The interface type for the to be removed. + /// The list of s. + /// True, if all active instances have been successfully removed. + public bool TryUnRegisterServiceConfigurations(IServiceConfiguration[] configurations) where T : IService + { + bool anyFailed = false; + + for (var i = 0; i < configurations?.Length; i++) + { + var configuration = configurations[i]; + var interfacesList = GetInterfacesFromType(configuration.InstancedType.Type); + if (interfacesList != null && interfacesList.Length > 0) + { + for (int j = 0; j < interfacesList.Length; j++) + { + if (interfacesList.Length > 1 && interfacesList.Length > j + 1 && interfacesList[j].IsAssignableFrom(interfacesList[j + 1])) + { + continue; + } + if (TryGetService(interfacesList[j], configuration.Name, out var serviceInstance)) + { + if (!TryUnregisterService(serviceInstance)) + { + anyFailed = true; + } + } + } + } + else + { + Debug.LogError($"Failed to find {configuration.Name}!"); + anyFailed = true; + } + } + + return !anyFailed; + } + /// /// Remove all services from the Service Manager active service registry for a given type /// @@ -866,11 +908,11 @@ private bool TryUnregisterService(Type interfaceType, string serviceName) whe for (int i = 0; i < activeServiceModules.Count; i++) { - var dataProvider = activeServiceModules[i]; + var serviceModule = activeServiceModules[i]; - if (dataProvider.ParentService.Equals(serviceInstance)) + if (serviceModule.ParentService.Equals(serviceInstance)) { - result &= TryUnregisterService(dataProvider); + result &= TryUnregisterService(serviceModule); } } @@ -1139,6 +1181,27 @@ public bool TryGetServices(Type interfaceType, string serviceName, ref List 0; } + public bool TryGetService(IService service, out IService serviceInstance) + { + serviceInstance = null; + + if (service == null) + { + return false; + } + + if (activeServices.TryGetValue(service.GetType(), out var activeService)) + { + if (activeService.Equals(service)) + { + serviceInstance = activeService; + return true; + } + } + + return false; + } + /// /// Gets all s by type. /// @@ -1162,7 +1225,7 @@ public void GetAllServices(ref List services) } /// - /// Retrieve a cached refernece of an from the . + /// Retrieve a cached reference of an from the . /// /// The interface type for the Service to be retrieved. /// The instance of the that is registered. @@ -1217,7 +1280,7 @@ public async Task GetSystemCachedAsync(int timeout = 10) where T : IServic /// /// The interface type for the Service to be retrieved. /// The instance of the Service class that is registered. - /// Returns true if the was found, otherwise false. + /// Returns true if the was found, otherwise false. public bool TryGetServiceCached(out T service) where T : IService { service = GetServiceCached(); @@ -1537,9 +1600,9 @@ public void DestroyAllServices() #endregion Service Management - #region Proccess Management + #region Process Management - private static readonly List activeProcess = new List(); + private static readonly List activeProcess = new List(); private float durationToleranceMs = 10; private bool doNotRemoveIfTooLong = false; @@ -1551,10 +1614,10 @@ public void AddProcessToUpdate(UpdateMethod onUpdate, float period) { if (onUpdate == null) return; - foreach (Proccess currSub in activeProcess) + foreach (Process currSub in activeProcess) if (currSub.updateMethod.Equals(onUpdate)) return; - activeProcess.Add(new Proccess(onUpdate, period)); + activeProcess.Add(new Process(onUpdate, period)); } /// @@ -1626,13 +1689,13 @@ void Remove(int index, string msg) } } - #endregion Proccess Management + #endregion Process Management #region Service Utilities - private string[] ignoredNamespaces = { "Service.IDisposable", + private string[] ignoredNamespaces = { "System.IDisposable", "RealityCollective.ServiceFramework.Interfaces.IService", - "RealityCollective.ServiceFramework.Interfaces.IServiceDataProvider"}; + "RealityCollective.ServiceFramework.Interfaces.IServiceModule"}; /// /// Query the for the existence of a . @@ -1770,6 +1833,21 @@ private void ClearServiceCache() searchedServiceTypes.Clear(); } + private Type[] GetInterfacesFromType(Type objectType) + { + var interfaces = objectType.GetInterfaces(); + var interfaceCount = interfaces.Length; + List detectedInterfaces = new List(); + + for (int i = 0; i < interfaceCount; i++) + { + if (ignoredNamespaces.Contains(interfaces[i].FullName)) continue; + + detectedInterfaces.Add(interfaces[i]); + } + return detectedInterfaces.ToArray(); + } + private Type[] GetInterfacesFromType(object concreteObject) { var interfaces = concreteObject.GetType().GetInterfaces(); @@ -1820,7 +1898,7 @@ internal static void CheckPlatforms() if (platform.IsAvailable #if UNITY_EDITOR || platform.IsBuildTargetAvailable && - RealityCollective.Extensions.TypeExtensions.TryResolveType(UnityEditor.EditorPrefs.GetString("CurrentPlatformTarget", string.Empty), out var resolvedPlatform) && + Extensions.TypeExtensions.TryResolveType(UnityEditor.EditorPrefs.GetString("CurrentPlatformTarget", string.Empty), out var resolvedPlatform) && resolvedPlatform == platformType #endif ) @@ -1946,5 +2024,125 @@ private static void EnsureEventSystemSetup() } #endregion Service Dependencies + + #region Scene Management + + private readonly Dictionary[]> sceneServiceConfigurations = new Dictionary[]>(); + private readonly List sceneServiceLoaded = new List(); + + /// + /// Load services for a specific scene. + /// + /// The scene for which to load the services for. + public void LoadServicesForScene(string sceneName) + { + bool sceneLoaded = false; + + if (string.IsNullOrEmpty(sceneName)) + { + Debug.LogError("Selected Scene name to load is null or empty."); + return; + } + + if (ActiveProfile?.SceneServiceConfiguration != null) + { + var sceneServiceConfig = ActiveProfile.SceneServiceConfiguration; + for (int i = 0; i < sceneServiceConfig.Length; i++) + { + if (sceneServiceConfig[i] == null || sceneServiceConfig[i].Profile.IsNull()) + { + continue; + } + var sceneConfig = sceneServiceConfig[i]; + if (sceneConfig.Profile.SceneName == sceneName) + { + sceneLoaded = TryRegisterServiceConfigurations(sceneConfig.Profile.ServiceConfigurations); + } + } + } + + if(!sceneLoaded && !sceneServiceLoaded.Contains(sceneName)) + { + if (sceneServiceConfigurations.TryGetValue(sceneName, out var serviceConfigurations)) + { + if(TryRegisterServiceConfigurations(serviceConfigurations)) + { + sceneServiceLoaded.Add(sceneName); + } + } + } + } + + /// + /// Unload services for a specific scene. + /// + /// The scene for which to unload the services for. + public void UnloadServicesForScene(string sceneName) + { + if (ActiveProfile?.SceneServiceConfiguration != null) + { + var sceneServiceConfig = ActiveProfile.SceneServiceConfiguration; + for (int i = 0; i < sceneServiceConfig.Length; i++) + { + if (sceneServiceConfig[i] == null || sceneServiceConfig[i].Profile.IsNull()) + { + continue; + } + var sceneConfig = sceneServiceConfig[i]; + if (sceneConfig.Profile.SceneName == sceneName) + { + TryUnRegisterServiceConfigurations(sceneConfig.Profile.ServiceConfigurations); + } + } + + if (sceneServiceConfigurations.TryGetValue(sceneName, out var serviceConfigurations)) + { + if(TryUnRegisterServiceConfigurations(serviceConfigurations)) + { + sceneServiceConfigurations.Remove(sceneName); + sceneServiceLoaded.Remove(sceneName); + } + } + } + } + + /// + /// Add a for a specific scene. + /// + /// The scene for which to add configuration for. + /// The for the specific scene. + public void AddServiceConfigurationForScene(string sceneName, IServiceConfiguration[] serviceConfigurations) + { + if (string.IsNullOrEmpty(sceneName)) + { + Debug.LogError("Selected Scene name to load is null or empty."); + return; + } + + if (serviceConfigurations == null || serviceConfigurations.Length == 0) + { + Debug.LogError("Selected Service Configurations to load are null or empty."); + return; + } +#if UNITY_2021_1_OR_NEWER + sceneServiceConfigurations.TryAdd(sceneName, serviceConfigurations); +#else + sceneServiceConfigurations.EnsureDictionaryItem(sceneName, serviceConfigurations); +#endif + } + + void OnSceneLoaded(Scene scene, LoadSceneMode mode) + { + LoadServicesForScene(scene.name); + // Handle the loaded scene here + Debug.Log($"Scene {scene.name} has been loaded."); + } + + private void OnSceneUnloaded(Scene scene) + { + UnloadServicesForScene(scene.name); + Debug.Log($"Scene {scene.name} has been unloaded."); + } + #endregion Scene Management } } \ No newline at end of file diff --git a/Runtime/Services/ServiceManager.cs.meta b/Runtime/Services/ServiceManager.cs.meta index 9af8686..29065cb 100644 --- a/Runtime/Services/ServiceManager.cs.meta +++ b/Runtime/Services/ServiceManager.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: 9ccaa8817c344b59a5c87d02585d0ef9 -timeCreated: 1644253487 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 09dab47bcf113eb4fba376f3caf8fea7, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Services/TemplateService.cs b/Runtime/Services/TemplateService.cs index 793ec52..588c930 100644 --- a/Runtime/Services/TemplateService.cs +++ b/Runtime/Services/TemplateService.cs @@ -1,8 +1,8 @@ // Copyright (c) Reality Collective. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using RealityCollective.Extensions; using RealityCollective.ServiceFramework.Definitions; +using RealityCollective.ServiceFramework.Extensions; using RealityCollective.ServiceFramework.Interfaces; using System; diff --git a/Runtime/Services/TemplateService.cs.meta b/Runtime/Services/TemplateService.cs.meta index 82eb786..13c4897 100644 --- a/Runtime/Services/TemplateService.cs.meta +++ b/Runtime/Services/TemplateService.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: f2625cf7581049d5a51e333a421e8767 -timeCreated: 1644253487 \ No newline at end of file +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/StandardAssets/Icons.meta b/Runtime/StandardAssets/Icons.meta new file mode 100644 index 0000000..5f7316b --- /dev/null +++ b/Runtime/StandardAssets/Icons.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3f907377a5988af40b713c1a64d31b6f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/StandardAssets/Icons/Icon_Toolkit_Component.png b/Runtime/StandardAssets/Icons/Icon_Toolkit_Component.png new file mode 100644 index 0000000000000000000000000000000000000000..debb6d2b7ebf995644acb2a19a3640f5dd89701d GIT binary patch literal 3218 zcmV;D3~lp?P)<;t?_6qMi1O0#qz#-xNkw9x;V;K8q;00hsOgz_q}56gD41PBJg#B>-pa z0OWCZMB(a{Y@XK{Tk4D*ixQb9A|EfycQOeW7v^|cu0fHH*Q5Mm9B@1^J~+$<(VzgF zu|0v`0Q&)#MLvF}fv{5w{0gb%Kl7PHHbg#Nh(hWxXY3ITj9m-d4@?9u08R)FH7D|^ z1x6v2e>(E z24EAg8K?k00^UOr;k$V}A5>Ibg2MAT&e)~d95pno0Y5{r{;J5wALJV7jBN?*4ICOK zabbAB2T+1?fhx4P%J6=3xYic=mz0oFuPwj~U^ieFXY43cK&{GF9R^J*bH=`ewB`*I zwhI%0Gj=!%LsNhUvW#hu1k?}M7gc^6kZLby=1$4sFI6&e&OzkCzlA0Hj8{0y8sJ$Qip!Sl|$p zv2_fSG{E1(L_JVhKpnpdX-*vkf3Y7*jn4x10lp8c1Ex7+Ujr6JK3P)Ry7EGYGP7gU{%0tTRLa1n4T+S#jt_koWhA6MqN@SF$&oa>C8 z5uSMk67-qC4^RU1jx+WV;LXU#8`Hi%88{+*FA+%^P=a#oo+!Vb8$RC$xCRj#t5E*^ zGO#REZG%xo_yJIlv`EX&O2Uh@zv;Dobr!Ap0{Mx)C_#D)Y2Iky45W=OJ7aGLJ_*Fh z)5sSMbjA*heEep<0ysTP%7@911^j6F%#VD$A>4m6VwMH~Wg!DBcg9WxrlQdIBg9EecE;Wn`FNc( z_Cr*>jRfimpk6WLjO_!=Ma;}YVd0|@6LTjpCo=_h#u{Yz`$axJFl3I$0t1mbwMS$| z%dqIy$ji4x+LDS6o5KH9K^Tis89ga{{~q8!z`2=uL&!mf1R;zBoO0fWNiwxayH4 z33w#D?V5DsBoi2j!rb&U4~#Rm18_FVu#&J1B|}{)z5v>V`{ts;j{-V4V~?S3syqor zfyBx%X`*dW{LCaT_eFGdE|ienp*02VP?#-6(IH!Qxfk;MHJTYp>ay^?ddRj@<){!z zN6HSfp&B{QMpM)|up_mNmZ}`%+9Bth>4RD(dnlc}EHP0tlLW9h{2hau5I`Nu={7`HXQCB~{hyNCSv3ZgXm__DHP2M%3Y6{L z5c#;KlN{*vW5T@FC*3$n0EC zunncgF)%*z@mm?+y97lCP>8OFBz5|j+G=hDQ0j~wk8J#li;EK2Mp}MiiwSYK@hpSCHXs!m)_X>mEK%r0|n8U@3LW+2O#wz}e|6Yvkhv zk&mwdPC^>7np%#)Q(P@rgBIN@{GE)NvgbrTo}RJzPT|_Uh^+m4HFdeJ4d5>V{GK(nV}z0 z17~ax)GE7)`XReD2}m*lht#WM#^*buOmHwT#Th#pwZOLqI(h+cN+?UGAdlP+nMZF# zuk{Ik+oOalwEr`%F!8} z-Kn3|m7;3#0^}cFaK`>E^6_j$VOOGlpbH(LWzN_)kTBaK(z9ImuyAC=Pekk}q~#&!j!A$7_Jsab$y zTC}oQhnk$RCnHWWWdg&}&#za1TF6m;fzQ6-Wy$&znVI{~;J0V{HB0N7p zw)+wAUuWzlWENYH&{`mW(*_B=7wRe7-^Ni1+gIUQF&UHe>8G9q5#)^UJj2B1% z+mQXHFEUkEG!=`1^CKUZWgF0tWMi}wClz5b>HUCwpWjs6K?5!NoXkx)Z}TL{#m`qA zWx(?pouYckhq`)BJ(6#8wh$-uF6y>ik8=E6nOAe59Jnu3sCgrA`Z_q1myi(VkkA2c zMyy4>%-`x(>g}i;%Os^p{ zx`Pw>_!HD9`3X7^`eh--IE_aq(q=T}W=;OVMCcUvL3Q~^bd-I2Imo5x2;O7By!4~= zjYYA4GP5^oWe-5LdSB|YxQ)R�v~ccu{{e1vO5x8#>(ZJ)|8y!{5%R z&6Uk@Zb9K}1){sZKnWf+%>V!Z literal 0 HcmV?d00001 diff --git a/Runtime/StandardAssets/Icons/Icon_Toolkit_Component.png.meta b/Runtime/StandardAssets/Icons/Icon_Toolkit_Component.png.meta new file mode 100644 index 0000000..504a6eb --- /dev/null +++ b/Runtime/StandardAssets/Icons/Icon_Toolkit_Component.png.meta @@ -0,0 +1,179 @@ +fileFormatVersion: 2 +guid: 09dab47bcf113eb4fba376f3caf8fea7 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Windows Store Apps + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/StandardAssets/Icons/Icon_Toolkit_SO.png b/Runtime/StandardAssets/Icons/Icon_Toolkit_SO.png new file mode 100644 index 0000000000000000000000000000000000000000..cfe994ac6a4d1b13458ad7d06d19c0e500be62b1 GIT binary patch literal 1397 zcmV-*1&aEKP)RCt{2n_XyJMHI(>Tau06u}22FwiOi#aHc1 zqdxdSMTo-Kht{^XR&6n~)vBP5SbY$Mg2wg1>Z>Bus%3(<#TG3x2EjgP`jJYoCYyA9 zn47O{cJJKXxqENO{vm93@0oMY{O`=1nRCu9l*?rnG8ScRK-OpxkhK9>W5E;9meq}o zP~E^2(bo^8)km_hqtI+GV1!x&yb3%}ap?_0Y<1BfZf1TR3CZcz(HWQ zwEBEA>`I*gBUA_Q46qBh-m}>ypbvOkT0NSUZIB`XMyLYN1MCM@)v0C>cn&B^t5Y#F z6#|S2R!5<{ul5<^#9AijUH|KfgRH7!TKz` z8bJs!LM;P!0-J!281esr*Ma@g>XE4ZQruAA0xXGXKMK4B?3Gpz*Kf5$Lj)M1+HkA- zOTda4@iK4-*eR|4vx>f(fxW;ZKp{roIbaWPP+C2n#O|4>n*bx!{lEcWjfeOVV6(LP zM^D{dz#Blfhxi#_tF-z{AKjHmOn?#UPTUZ_$3y%#oNZ(|2cE`Fv(6atGVl?wOIm%_M}I5ctAx4?bpVNfs_q3*&hlrlzirL_87wTp4_fTc+d z%OPs^Aw)bt0!NKdd7J{V2pJIB0IWAc(Fm1=8%&I}VuGE(o51O4 zGgB9$wx=Uq!8;G>#{^dcpBtgl+zK~@W(7sNfdL~_$iq+&G&3q(03HQ;j8Kgnhl3)E zu=o<-dEiMSRMLP*aAcMjz;*cj4DS!LGD9r_S_EWmK-S1|5e$i$XZl3@hxtmt1TK#_ z68-%feQyI6<04m!aKud1QZ(NPC;{hzUxA;16Tlz9FfLyJ(<7jOBjN8_3g-&}Wn9O< z1wM{GhosdtpRNz)0|6!A7vLRSlJsIo<#{Jy6gUdJ2pp4EUkQDKJQGmD4fV~yskGAL zc_rWq@G~w1c1l`ZHbN~2-ow=#Ag#X2-5H@KNh$)pKGP+y1PtM#Km#+L{8Z;XFe&$7 zoM0Yzf@8qfz~PEHKiR3`Tu&dSMn$ngz9!-b81YdO5M^B9#35<*r7ALUVKuL?+azid z5M@;QlPGKu6TnGepjkKcnF5dD%G)ldYYO1p-Z5NuxhaSxKw3Q}t=@x+@P5ebgGXrm z1Dve%_mKxk44-!1i=ednth9O~(1j~T2#qrC$xFdPH1gdXcM!Vk8G}A!=V0 ziM@cd`na_EURcW*tB z96)E(zA75p2S}^OrPUg@J{(~BNLnx2nIrL8?*YiCU675Cw0c-ty$!gH`rT#$xEB9< z;vfjR6O>jDMkOihaOJH@aUF0=j7(R9*JmM>t#DM+dpEAO$hWMufP4CPL@Dt~Ol@&z z9C~IU`n{(@z9v#T3rMTW(&|rf(_$;G1U?QOz*=DC9M^jB>{KMz>m!)A7bZ%$@|V7} z-xHWb>y??T-W*-9FHPkQc?^g&6)gg?HXv&(cmn1a literal 0 HcmV?d00001 diff --git a/Runtime/StandardAssets/Icons/Icon_Toolkit_SO.png.meta b/Runtime/StandardAssets/Icons/Icon_Toolkit_SO.png.meta new file mode 100644 index 0000000..8690c53 --- /dev/null +++ b/Runtime/StandardAssets/Icons/Icon_Toolkit_SO.png.meta @@ -0,0 +1,179 @@ +fileFormatVersion: 2 +guid: 213bc0c4d7915b547a02e4c966be1cf1 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Windows Store Apps + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/StandardAssets/Icons/Icon_Toolkit_Script.png b/Runtime/StandardAssets/Icons/Icon_Toolkit_Script.png new file mode 100644 index 0000000000000000000000000000000000000000..ee10f7f1d3255fd0cca155a1f100e6418e452124 GIT binary patch literal 1588 zcmV-42Fv-0P)GRUHTL&-LCrb4_QQw3##ujjd>*l|{R#Oe##F zkdi2=ph%*?9icsmF#o8?VTh!S^nfUn9*U&F5Yto=y=>D%v6u>WhK)^`j*ppUyiWJt z{`l=nhckQM?%C(;bM7?rg$?Jd$8W9m-D~~U@Aq44Pc1DiIht|Yq&qNa93x=T9hfwZ zdIDxfA*4vMm*YK1acU)Z654eU58}7@a$4p)|5t^nVRnHc$!76!yaQ*n7Ss*);1*n) zmigmNg@#=MH{n`qZ}4y$-j8n=Np@mWq1FTxN%kpR(YF2=aVfSnWws)qNU{s?*0w$B z2>%v3pbl>+lI)VYjJ8VfO*pe<-BDu+KgV{Qh&SRnePy05l=P1N$^#QnB-uJVZ{Tir zgC%?qm#1Yu4@HvQggbCfU)dMb323tfPN|-?fO*`wJa|aU{ExWZ;mhIVIst76n8s9# zdR<@vkJY5_5jvq4({%#c5U^-6Mot~3Fjtel8SDDeYPZ6XSb}|6#P9IWnobOY1IbN$ghk>wGP2sV{8@e)un}U;r z$QTQ{&;ippsfryo#^YDOe&Gg>1zixZ4qp?FOq;2^q#bds(3vyTf!sRG8P4B0;tin^ z{~AU>R}rBuaX)?{Vt)6Cli=1kk_gy~8?YlS^Iwii=#fIec3hX1`L9MT_(&k&dTdS0 zd~X-R*D?VM;_}6|w9NZYc}9k{ybF9r$AhQc44Bcqp>jK}uN!=kWT%LO&KY5BJ%+t$ znJ-rP(|EQpr}v0Ml}E8VE%U?97}^kU06)beMjx`CspMaimifNkj3UW4<1M%Z=i&r0 z_+9ukmKEe#;$-OWViw(j?P;06y{W-L@i0Cl&h17$J!i46|IHUkb_TwL*Y=e^O^|V8 zPukg4+VAlUY|?NpNDBh0X*87eH3*6%+la5@!Yb)Ld`lQaXX2^owF^$h`l`;;#Ekk* zll-;33oPSu{~i1f@xHXocP(cYNwzU9^L<5<&EbW3vrz7@!1=MhfA2k>RMS=ES^|nBJHZM^${k=zDAf67 zZC+tL&Z~a^0e7t+V-LPBE=jG&5AZtd!>#yAU8SZOuw4Wto-m&9)Ew@`2gUBPjFZGV zCITgO*I__f=DUg{yGAU7f8f3N3x1rI`C)H<8BGLSwA!AJ5C?_A>P7F}zggk?&-ay4 zB-xZ0_&dcea1hstm$$h{vdgeDE%U>6gCKdM4k1y4g4{mLoh1A1#usF4}YmpA!Zed;`C(>VFki*S&oj zZi^R5_Ge*EjuUs{(zMK?)zfXYp#W#~%|-2>=t4Ao>!&M;kiP8JiJn) zO-ta5LX(aYTaeUcq-B0HUMa4{9uUfKlOSZbSOTXC%kUmS%q;G!bAWnLOF&xYJA_9z zPMj_@c`ed1zYCWMk}kr<;*DRJmiYsC2v_4O{08r;o)yvf#Ypv$!L8!H{kU)&uIM@j z(2K@^NLuFmh5LDfu(HO1*WmSIY749UW~fNAi}7xuUAO4=RQU_S;Tg*;80w>`{|Bt) mnBZ7&jDSgZVA4413HT2xL4rv<*HzR20000 + /// Manages the services for a scene. + /// + /// + /// This component is used to manage the services for a scene. It will register the services with the Service Manager when the scene is loaded and unregister them when the scene is unloaded. + /// This includes when the component is enabled and disabled, which will load and unload the services respectively. + /// Additionally, the component can ONLY run if there is a `Service Manager Instance` present or loaded in the project, it cannot currently run standalone + /// + [AddComponentMenu(RuntimeServiceFrameworkPreferences.Service_Framework_Editor_Menu_Keyword + "/Scene Service Manager")] + [ExecuteInEditMode] + [DisallowMultipleComponent] + public class SceneServiceManager : MonoBehaviour + { + private string sceneName = null; + + [SerializeField] + [Tooltip("The services to registered with the Service Manager for the scene this manager is in. Services will be unloaded on scene exit (or manager if the manager is disabled).")] + private ServiceProvidersProfile serviceProvidersProfile = null; + + #region MonoBehaviour Implementation + private void OnEnable() + { + sceneName = gameObject.scene.name; + if (ServiceManager.IsActiveAndInitialized && serviceProvidersProfile != null && !string.IsNullOrEmpty(sceneName)) + { + ServiceManager.Instance.AddServiceConfigurationForScene(sceneName, serviceProvidersProfile.ServiceConfigurations); + ServiceManager.Instance.LoadServicesForScene(sceneName); + } + else + { + // A Service Manager Instance MUST be loaded in the project prior to this scene loading for this component to work + if (Application.isPlaying) + { + Debug.LogError($"Service Manager is not active or initialized, services for scene '{sceneName}' will not be loaded."); + } + } + } + +#if UNITY_EDITOR + private void OnValidate() + { + if (ServiceManager.IsActiveAndInitialized && serviceProvidersProfile != null && !string.IsNullOrEmpty(sceneName)) + { + ServiceManager.Instance.AddServiceConfigurationForScene(sceneName, serviceProvidersProfile.ServiceConfigurations); + ServiceManager.Instance.LoadServicesForScene(sceneName); + } + } +#endif + + private void OnDisable() + { + ServiceManager.Instance?.UnloadServicesForScene(sceneName); + } + #endregion MonoBehaviour Implementation + } +} \ No newline at end of file diff --git a/Runtime/Utilities/SceneServiceManager.cs.meta b/Runtime/Utilities/SceneServiceManager.cs.meta new file mode 100644 index 0000000..17735c2 --- /dev/null +++ b/Runtime/Utilities/SceneServiceManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e8b32230d9a6559428da9c50a8334798 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 09dab47bcf113eb4fba376f3caf8fea7, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Utilities/ServiceDisplayHook.cs.meta b/Runtime/Utilities/ServiceDisplayHook.cs.meta index 45abdb4..f41f2a9 100644 --- a/Runtime/Utilities/ServiceDisplayHook.cs.meta +++ b/Runtime/Utilities/ServiceDisplayHook.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 09dab47bcf113eb4fba376f3caf8fea7, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Utilities/ServiceFrameworkStatus.cs.meta b/Runtime/Utilities/ServiceFrameworkStatus.cs.meta index 559c171..0052aaa 100644 --- a/Runtime/Utilities/ServiceFrameworkStatus.cs.meta +++ b/Runtime/Utilities/ServiceFrameworkStatus.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Utilities/ServiceManagerInstance.cs b/Runtime/Utilities/ServiceManagerInstance.cs index 176781d..95f6a18 100644 --- a/Runtime/Utilities/ServiceManagerInstance.cs +++ b/Runtime/Utilities/ServiceManagerInstance.cs @@ -11,6 +11,7 @@ namespace RealityCollective.ServiceFramework { + [AddComponentMenu(RuntimeServiceFrameworkPreferences.Service_Framework_Editor_Menu_Keyword + "/Global Service Manager")] [ExecuteInEditMode] [DisallowMultipleComponent] public class ServiceManagerInstance : MonoBehaviour @@ -47,9 +48,9 @@ internal void SubscribetoUnityEvents(ServiceManager serviceManager) } /// - /// Initializes the associcated with this instance. + /// Initializes the associated with this instance. /// - public void InitialiseServiceManager() + public void InitializeServiceManager() { if (serviceManagerInstance == null) { @@ -81,7 +82,7 @@ private void OnValidate() if (serviceManagerInstance == null) { - InitialiseServiceManager(); + InitializeServiceManager(); } if (isServiceManagerInstanceConfigured && @@ -98,7 +99,7 @@ private void Awake() { if (Application.isPlaying && gameObject.activeInHierarchy && enabled) { - InitialiseServiceManager(); + InitializeServiceManager(); } serviceManagerInstance?.Awake(); } diff --git a/Runtime/Utilities/ServiceManagerInstance.cs.meta b/Runtime/Utilities/ServiceManagerInstance.cs.meta index 1076106..ce89d10 100644 --- a/Runtime/Utilities/ServiceManagerInstance.cs.meta +++ b/Runtime/Utilities/ServiceManagerInstance.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 09dab47bcf113eb4fba376f3caf8fea7, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Runtime/Utilities/SystemType.cs b/Runtime/Utilities/SystemType.cs new file mode 100644 index 0000000..b8e815c --- /dev/null +++ b/Runtime/Utilities/SystemType.cs @@ -0,0 +1,156 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using RealityCollective.ServiceFramework.Extensions; +using UnityEngine; + +namespace RealityCollective.ServiceFramework +{ + /// + /// Reference to a class with support for Unity serialization. + /// + [Serializable] + public sealed class SystemType : ISerializationCallbackReceiver + { +#if UNITY_EDITOR + /// + /// Initializes a new instance of the class. + /// + /// The serialized property of the type reference. + public SystemType(UnityEditor.SerializedProperty property) + { + TypeExtensions.TryResolveType(property.FindPropertyRelative(nameof(reference)).stringValue, out var resolvedType); + Type = resolvedType; + } +#endif + /// + /// Initializes a new instance of the class. + /// + /// Class type. + public SystemType(Type type) + { + Type = type; + } + + /// + /// Initializes a new instance of the class. + /// + /// reference as . + public SystemType(string typeGuid) + { + TypeExtensions.TryResolveType(typeGuid, out var resolvedType); + Type = resolvedType; + } + + /// + /// Initializes a new instance of the class. + /// + /// reference of the type to instantiate. + public SystemType(Guid guid) + { + TypeExtensions.TryResolveType(guid, out var resolvedType); + Type = resolvedType; + } + + #region ISerializationCallbackReceiver Members + + [SerializeField] + private string reference = string.Empty; + + void ISerializationCallbackReceiver.OnAfterDeserialize() + { + TypeExtensions.TryResolveType(reference, out type); + } + + void ISerializationCallbackReceiver.OnBeforeSerialize() + { + } + + #endregion ISerializationCallbackReceiver Members + + private Type type; + + /// + /// Gets or sets type of class reference. + /// + public Type Type + { + get => type; + set + { + if (value != null) + { + bool isValid = value.IsValueType && !value.IsEnum && !value.IsAbstract || value.IsClass; + + if (!isValid) + { + Debug.LogError($"'{value.FullName}' is not a valid class or struct type."); + } + } + + type = value; + + if (type != null) + { + guid = type.GUID; + reference = guid.ToString(); + } + else + { + guid = Guid.Empty; + reference = string.Empty; + } + } + } + + public static implicit operator Guid(SystemType type) + { + return type.type == null ? Guid.Empty : type.Guid; + } + + public static implicit operator string(SystemType type) + { + return type.reference; + } + + public static implicit operator Type(SystemType type) + { + return type?.Type; + } + + public static implicit operator SystemType(Type type) + { + return new SystemType(type); + } + + public static implicit operator SystemType(Guid guid) + { + return new SystemType(guid); + } + + private Guid guid = Guid.Empty; + + /// + /// Gets the associated with the . + /// + public Guid Guid + { + get + { + if (guid == Guid.Empty) + { + guid = type.GUID; + } + + return guid; + } + } + + /// + public override string ToString() + { + return Type?.FullName ?? (string.IsNullOrWhiteSpace(reference) ? "{None}" : reference); + } + } +} diff --git a/Runtime/Utilities/SystemType.cs.meta b/Runtime/Utilities/SystemType.cs.meta new file mode 100644 index 0000000..9fe2d84 --- /dev/null +++ b/Runtime/Utilities/SystemType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 56e45df5179e2cc4db4ef4196e920fa9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Utilities/TypeCache.cs b/Runtime/Utilities/TypeCache.cs new file mode 100644 index 0000000..21d5d62 --- /dev/null +++ b/Runtime/Utilities/TypeCache.cs @@ -0,0 +1,27 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using RealityCollective.ServiceFramework.Extensions; +using System; +using System.Collections.Generic; + +namespace RealityCollective.ServiceFramework +{ + public static class TypeCache + { + private static readonly Dictionary typeCache = new Dictionary(); + + public static Dictionary Current + { + get + { + if (typeCache.Count == 0) + { + TypeExtensions.BuildTypeCache(typeCache); + } + + return typeCache; + } + } + } +} \ No newline at end of file diff --git a/Runtime/Utilities/TypeCache.cs.meta b/Runtime/Utilities/TypeCache.cs.meta new file mode 100644 index 0000000..fd5472f --- /dev/null +++ b/Runtime/Utilities/TypeCache.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 824ede96852b97a4bbd4a44b9573ce1c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Utilities/ValidateConfiguration.cs.meta b/Runtime/Utilities/ValidateConfiguration.cs.meta index dc6fef4..a691713 100644 --- a/Runtime/Utilities/ValidateConfiguration.cs.meta +++ b/Runtime/Utilities/ValidateConfiguration.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/AssemblyInfo.cs.meta b/Tests/AssemblyInfo.cs.meta index e7e0a7a..0e98386 100644 --- a/Tests/AssemblyInfo.cs.meta +++ b/Tests/AssemblyInfo.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/TestData/Interfaces/ITestService.cs.meta b/Tests/TestData/Interfaces/ITestService.cs.meta index e91ad9f..b83cea5 100644 --- a/Tests/TestData/Interfaces/ITestService.cs.meta +++ b/Tests/TestData/Interfaces/ITestService.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/TestData/Interfaces/ITestService1ServiceModule.cs.meta b/Tests/TestData/Interfaces/ITestService1ServiceModule.cs.meta index b3b52ff..bf7ed2f 100644 --- a/Tests/TestData/Interfaces/ITestService1ServiceModule.cs.meta +++ b/Tests/TestData/Interfaces/ITestService1ServiceModule.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/TestData/Interfaces/ITestService1ServiceModuleA.cs.meta b/Tests/TestData/Interfaces/ITestService1ServiceModuleA.cs.meta index 8c6c2d2..cdb0537 100644 --- a/Tests/TestData/Interfaces/ITestService1ServiceModuleA.cs.meta +++ b/Tests/TestData/Interfaces/ITestService1ServiceModuleA.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/TestData/Interfaces/ITestService1ServiceModuleB.cs.meta b/Tests/TestData/Interfaces/ITestService1ServiceModuleB.cs.meta index d434839..4701bb4 100644 --- a/Tests/TestData/Interfaces/ITestService1ServiceModuleB.cs.meta +++ b/Tests/TestData/Interfaces/ITestService1ServiceModuleB.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/TestData/Modules/BaseTestService1ServiceModule.cs.meta b/Tests/TestData/Modules/BaseTestService1ServiceModule.cs.meta index 3179f23..7a92776 100644 --- a/Tests/TestData/Modules/BaseTestService1ServiceModule.cs.meta +++ b/Tests/TestData/Modules/BaseTestService1ServiceModule.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/TestData/Modules/TestService1ServiceModuleA.cs.meta b/Tests/TestData/Modules/TestService1ServiceModuleA.cs.meta index 87f571c..999110c 100644 --- a/Tests/TestData/Modules/TestService1ServiceModuleA.cs.meta +++ b/Tests/TestData/Modules/TestService1ServiceModuleA.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/TestData/Modules/TestService1ServiceModuleB.cs.meta b/Tests/TestData/Modules/TestService1ServiceModuleB.cs.meta index ee76cac..205c1cd 100644 --- a/Tests/TestData/Modules/TestService1ServiceModuleB.cs.meta +++ b/Tests/TestData/Modules/TestService1ServiceModuleB.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/TestData/Profiles/TestService1Profile.cs.meta b/Tests/TestData/Profiles/TestService1Profile.cs.meta index 89df561..d085d0a 100644 --- a/Tests/TestData/Profiles/TestService1Profile.cs.meta +++ b/Tests/TestData/Profiles/TestService1Profile.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/TestData/Profiles/TestService2Profile.cs.meta b/Tests/TestData/Profiles/TestService2Profile.cs.meta index c1e3475..c009bb5 100644 --- a/Tests/TestData/Profiles/TestService2Profile.cs.meta +++ b/Tests/TestData/Profiles/TestService2Profile.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Tests/Service Disable Tests.cs.meta b/Tests/Tests/Service Disable Tests.cs.meta index 052cda5..41d0d83 100644 --- a/Tests/Tests/Service Disable Tests.cs.meta +++ b/Tests/Tests/Service Disable Tests.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Tests/Service Enable Tests.cs.meta b/Tests/Tests/Service Enable Tests.cs.meta index a97c546..88fc3a6 100644 --- a/Tests/Tests/Service Enable Tests.cs.meta +++ b/Tests/Tests/Service Enable Tests.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Tests/Service Interface Type Tests.cs b/Tests/Tests/Service Interface Type Tests.cs index bc22286..176c251 100644 --- a/Tests/Tests/Service Interface Type Tests.cs +++ b/Tests/Tests/Service Interface Type Tests.cs @@ -7,7 +7,7 @@ using RealityCollective.ServiceFramework.Tests.Interfaces; using RealityCollective.ServiceFramework.Tests.Modules; -namespace RealityCollective.ServiceFramework.Tests +namespace RealityCollective.ServiceFramework.Tests.L_ServiceInterfaceType { internal class ServiceInterfaceTypeTests { diff --git a/Tests/Tests/Service Interface Type Tests.cs.meta b/Tests/Tests/Service Interface Type Tests.cs.meta index f61312d..4d87218 100644 --- a/Tests/Tests/Service Interface Type Tests.cs.meta +++ b/Tests/Tests/Service Interface Type Tests.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Tests/Service Locator Tests.cs b/Tests/Tests/Service Locator Tests.cs index c535b14..f204e86 100644 --- a/Tests/Tests/Service Locator Tests.cs +++ b/Tests/Tests/Service Locator Tests.cs @@ -51,7 +51,7 @@ public void Test_01_03_InitializeServiceManagerGameObject() EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single); var serviceManagerGameObject = new GameObject(nameof(ServiceManager)); var serviceManagerInstance = serviceManagerGameObject.AddComponent(); - serviceManagerInstance.InitialiseServiceManager(); + serviceManagerInstance.InitializeServiceManager(); var serviceManagerGO = GameObject.Find(nameof(ServiceManager)); ServiceManagerInstance instance = serviceManagerGO.GetComponent(); diff --git a/Tests/Tests/Service Locator Tests.cs.meta b/Tests/Tests/Service Locator Tests.cs.meta index 3f6a6b3..a2c99c5 100644 --- a/Tests/Tests/Service Locator Tests.cs.meta +++ b/Tests/Tests/Service Locator Tests.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Tests/Service Registration Tests.cs b/Tests/Tests/Service Registration Tests.cs index 7e9514a..bfbf045 100644 --- a/Tests/Tests/Service Registration Tests.cs +++ b/Tests/Tests/Service Registration Tests.cs @@ -58,10 +58,10 @@ public void Test_02_02_RegisterSecondService() [Test] public void Test_02_03_TryRegisterServiceTwice() { - LogAssert.Expect(LogType.Error, new Regex("There is already a ITestService1.Test Service 1 registered!")); - TestUtilities.InitializeServiceManagerScene(ref testServiceManager); + LogAssert.Expect(LogType.Error, new Regex("There is already a ITestService1.Test Service 1 registered!")); + var activeServiceCount = testServiceManager.ActiveServices.Count; // Register diff --git a/Tests/Tests/Service Registration Tests.cs.meta b/Tests/Tests/Service Registration Tests.cs.meta index c2e67e8..ce1e133 100644 --- a/Tests/Tests/Service Registration Tests.cs.meta +++ b/Tests/Tests/Service Registration Tests.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Tests/Service Retrieval Tests.cs.meta b/Tests/Tests/Service Retrieval Tests.cs.meta index 31c4fdb..cf9de3b 100644 --- a/Tests/Tests/Service Retrieval Tests.cs.meta +++ b/Tests/Tests/Service Retrieval Tests.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Tests/Service UnRegistration Tests.cs b/Tests/Tests/Service UnRegistration Tests.cs index 440c69d..beeac53 100644 --- a/Tests/Tests/Service UnRegistration Tests.cs +++ b/Tests/Tests/Service UnRegistration Tests.cs @@ -1,9 +1,13 @@ // Copyright (c) Reality Collective. All rights reserved. using NUnit.Framework; +using RealityCollective.ServiceFramework.Definitions; +using RealityCollective.ServiceFramework.Definitions.Platforms; +using RealityCollective.ServiceFramework.Interfaces; using RealityCollective.ServiceFramework.Services; using RealityCollective.ServiceFramework.Tests.Interfaces; using RealityCollective.ServiceFramework.Tests.Modules; +using RealityCollective.ServiceFramework.Tests.Profiles; using RealityCollective.ServiceFramework.Tests.Services; using RealityCollective.ServiceFramework.Tests.Utilities; using System.Text.RegularExpressions; @@ -258,6 +262,37 @@ public void Test_06_08_UnregisterSingleServiceFromMultipleByInterface() Assert.AreEqual(activeServiceCount + 1, testServiceManager.ActiveServices.Count, "More or less services found than was expected"); } + [Test] + public void Test_06_09_UnRegisterServiceConfigurations() + { + TestUtilities.InitializeServiceManagerScene(ref testServiceManager); + + var activeServiceCount = testServiceManager.ActiveServices.Count; + + var configurations = new ServiceConfiguration[2]; + + + var testService1Profile = (TestService1Profile)ScriptableObject.CreateInstance(typeof(TestService1Profile)); + var dataProvider1Configuration = new ServiceConfiguration(typeof(TestServiceModule1), TestServiceModule1.TestName, 1, AllPlatforms.Platforms, null); + testService1Profile.AddConfiguration(dataProvider1Configuration); + + var testService2Profile = (TestService2Profile)ScriptableObject.CreateInstance(typeof(TestService2Profile)); + var dataProvider2Configuration = new ServiceConfiguration(typeof(TestServiceModule2), TestServiceModule2.TestName, 1, AllPlatforms.Platforms, null); + testService2Profile.AddConfiguration(dataProvider2Configuration); + + configurations[0] = new ServiceConfiguration(typeof(TestService1), TestService1.TestName, 1, AllPlatforms.Platforms, testService1Profile); + configurations[1] = new ServiceConfiguration(typeof(TestService2), TestService2.TestName, 1, AllPlatforms.Platforms, testService2Profile); + + var result = testServiceManager.TryRegisterServiceConfigurations(configurations); + + // Tests + Assert.IsTrue(result, "Test services were not registered"); + Assert.AreEqual(activeServiceCount + 3, testServiceManager.ActiveServices.Count, "More or less services found than was expected"); + + var unregisterResult = testServiceManager.TryUnRegisterServiceConfigurations(configurations); + Assert.IsTrue(result, "Test services were successfully unregistered"); + Assert.AreEqual(0, testServiceManager.ActiveServices.Count, "More or less services found than was expected"); + } #endregion Service unRegistration } } \ No newline at end of file diff --git a/Tests/Tests/Service UnRegistration Tests.cs.meta b/Tests/Tests/Service UnRegistration Tests.cs.meta index 50f5d07..1a74223 100644 --- a/Tests/Tests/Service UnRegistration Tests.cs.meta +++ b/Tests/Tests/Service UnRegistration Tests.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Tests/ServiceManager_GetService_Tests.cs b/Tests/Tests/ServiceManager_GetService_Tests.cs index d5c0749..3db989e 100644 --- a/Tests/Tests/ServiceManager_GetService_Tests.cs +++ b/Tests/Tests/ServiceManager_GetService_Tests.cs @@ -8,7 +8,7 @@ using RealityCollective.ServiceFramework.Tests.Utilities; using UnityEngine; -namespace RealityCollective.ServiceFramework.Tests +namespace RealityCollective.ServiceFramework.Tests.M_ServiceManager_GetService { /// /// This class contains tests for all APIs diff --git a/Tests/Tests/ServiceManager_GetService_Tests.cs.meta b/Tests/Tests/ServiceManager_GetService_Tests.cs.meta index f4b0a2b..6ff3b6a 100644 --- a/Tests/Tests/ServiceManager_GetService_Tests.cs.meta +++ b/Tests/Tests/ServiceManager_GetService_Tests.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Tests/ServiceModuleDisableTests.cs.meta b/Tests/Tests/ServiceModuleDisableTests.cs.meta index 410233d..c6f5ca9 100644 --- a/Tests/Tests/ServiceModuleDisableTests.cs.meta +++ b/Tests/Tests/ServiceModuleDisableTests.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Tests/ServiceModuleEnableTests.cs.meta b/Tests/Tests/ServiceModuleEnableTests.cs.meta index f5fa34c..cce1618 100644 --- a/Tests/Tests/ServiceModuleEnableTests.cs.meta +++ b/Tests/Tests/ServiceModuleEnableTests.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Tests/ServiceModuleRegistrationTests.cs.meta b/Tests/Tests/ServiceModuleRegistrationTests.cs.meta index a96b72c..a50608d 100644 --- a/Tests/Tests/ServiceModuleRegistrationTests.cs.meta +++ b/Tests/Tests/ServiceModuleRegistrationTests.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Tests/ServiceModuleRetrievalTests.cs b/Tests/Tests/ServiceModuleRetrievalTests.cs index 04edc8a..421e82c 100644 --- a/Tests/Tests/ServiceModuleRetrievalTests.cs +++ b/Tests/Tests/ServiceModuleRetrievalTests.cs @@ -161,14 +161,14 @@ public void Test_05_06_ServiceServiceModuleDoesNotExist() [Test] public void Test_05_07_RetrieveRegisterServiceConfigurationsWithServiceModules() { + TestUtilities.InitializeServiceManagerScene(ref testServiceManager); + // Check logs LogAssert.Expect(LogType.Log, new Regex("Test Service 1 is Initialised")); LogAssert.Expect(LogType.Log, new Regex("Test Service Module 1 is Initialised")); LogAssert.Expect(LogType.Log, new Regex("Test Service 2 is Initialised")); LogAssert.Expect(LogType.Error, new Regex("Unable to find ITestServiceModule2 service.")); - TestUtilities.InitializeServiceManagerScene(ref testServiceManager); - var activeServiceCount = testServiceManager.ActiveServices.Count; var configurations = new ServiceConfiguration[2]; diff --git a/Tests/Tests/ServiceModuleRetrievalTests.cs.meta b/Tests/Tests/ServiceModuleRetrievalTests.cs.meta index 6241f78..3c38aae 100644 --- a/Tests/Tests/ServiceModuleRetrievalTests.cs.meta +++ b/Tests/Tests/ServiceModuleRetrievalTests.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Tests/ServiceModuleUnRegistrationTests.cs.meta b/Tests/Tests/ServiceModuleUnRegistrationTests.cs.meta index 5315ef7..94ce960 100644 --- a/Tests/Tests/ServiceModuleUnRegistrationTests.cs.meta +++ b/Tests/Tests/ServiceModuleUnRegistrationTests.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/Tests/Utilities/TestUtilities.cs b/Tests/Utilities/TestUtilities.cs index b687c99..44efc18 100644 --- a/Tests/Utilities/TestUtilities.cs +++ b/Tests/Utilities/TestUtilities.cs @@ -1,14 +1,16 @@ // Copyright (c) Reality Collective. All rights reserved. using NUnit.Framework; -using RealityCollective.Editor.Extensions; using RealityCollective.ServiceFramework.Definitions; +using RealityCollective.ServiceFramework.Editor.Utilities; using RealityCollective.ServiceFramework.Services; using System; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using UnityEditor.SceneManagement; using UnityEngine; +using UnityEngine.TestTools; namespace RealityCollective.ServiceFramework.Tests.Utilities { @@ -31,6 +33,10 @@ public static void CleanupScene() public static void InitializeServiceManagerScene(ref ServiceManager serviceManager, bool useDefaultProfile = false) { +#if UNITY_2022_1_OR_NEWER + LogAssert.Expect(LogType.Error, new Regex("Selected Scene name to load is null or empty.")); +#endif + // Setup serviceManager = null; CleanupScene(); diff --git a/Tests/Utilities/TestUtilities.cs.meta b/Tests/Utilities/TestUtilities.cs.meta index 037fa98..61aa632 100644 --- a/Tests/Utilities/TestUtilities.cs.meta +++ b/Tests/Utilities/TestUtilities.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: 0d9870c831e9c1d48a93f478ee082078, type: 3} userData: assetBundleName: assetBundleVariant: diff --git a/package.json b/package.json index 7ab1b07..15b930d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "Services", "Extensions" ], - "version": "1.0.4", + "version": "1.0.5-pre.3", "unity": "2020.3", "homepage": "https://realitycollective.io", "bugs": { @@ -27,7 +27,6 @@ "dependencies": { "com.unity.editorcoroutines": "1.0.0", "com.unity.addressables": "1.20.5", - "com.realitycollective.utilities": "1.0.7", "com.unity.ugui": "1.0.0" } }