com.wallstop-studios.unity-helpers 2.0.0-rc81.9 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +1 -1
- package/.gitattributes +1 -1
- package/.githooks/pre-commit +31 -5
- package/.githooks/pre-push +50 -0
- package/.github/dependabot.yml +24 -2
- package/.github/scripts/check-markdown-links.ps1 +77 -0
- package/.github/scripts/check_markdown_links.py +89 -0
- package/.github/scripts/check_markdown_url_encoding.py +74 -0
- package/.github/scripts/validate_markdown_links.py +194 -0
- package/.github/workflows/csharpier-autofix.yml +152 -0
- package/.github/workflows/format-on-demand.yml +305 -0
- package/.github/workflows/lint-doc-links.yml +8 -5
- package/.github/workflows/markdown-json.yml +6 -2
- package/.github/workflows/npm-publish.yml +1 -1
- package/.github/workflows/prettier-autofix.yml +195 -0
- package/.github/workflows/update-dotnet-tools.yml +80 -0
- package/.github/workflows/yaml-format-lint.yml +41 -0
- package/.lychee.toml +4 -4
- package/.markdownlint.jsonc +21 -0
- package/.pre-commit-config.yaml +11 -3
- package/.yamllint.yaml +31 -0
- package/AGENTS.md +5 -1
- package/Docs/CHANGELOG.md +11 -0
- package/Docs/CONTRIBUTING.md +49 -0
- package/Docs/CONTRIBUTING.md.meta +7 -0
- package/{EDITOR_TOOLS_GUIDE.md → Docs/EDITOR_TOOLS_GUIDE.md} +4 -0
- package/Docs/EFFECTS_SYSTEM.md +1316 -0
- package/{EFFECTS_SYSTEM_TUTORIAL.md → Docs/EFFECTS_SYSTEM_TUTORIAL.md} +1 -1
- package/{GETTING_STARTED.md → Docs/GETTING_STARTED.md} +50 -64
- package/{GLOSSARY.md → Docs/GLOSSARY.md} +4 -4
- package/Docs/HELPER_UTILITIES.md +885 -0
- package/Docs/HELPER_UTILITIES.md.meta +7 -0
- package/{INDEX.md → Docs/INDEX.md} +107 -62
- package/Docs/MATH_AND_EXTENSIONS.md +1039 -0
- package/{RANDOM_PERFORMANCE.md → Docs/RANDOM_PERFORMANCE.md} +15 -15
- package/{RELATIONAL_COMPONENTS.md → Docs/RELATIONAL_COMPONENTS.md} +111 -84
- package/{SERIALIZATION.md → Docs/SERIALIZATION.md} +15 -0
- package/{SPATIAL_TREES_2D_GUIDE.md → Docs/SPATIAL_TREES_2D_GUIDE.md} +2 -2
- package/{SPATIAL_TREES_3D_GUIDE.md → Docs/SPATIAL_TREES_3D_GUIDE.md} +1 -1
- package/Docs/SPATIAL_TREE_2D_PERFORMANCE.md +241 -0
- package/Docs/SPATIAL_TREE_3D_PERFORMANCE.md +243 -0
- package/{THIRD_PARTY_NOTICES.md → Docs/THIRD_PARTY_NOTICES.md} +1 -1
- package/Docs/UTILITY_COMPONENTS.md +906 -0
- package/Docs/UTILITY_COMPONENTS.md.meta +7 -0
- package/Docs/VISUAL_COMPONENTS.md +337 -0
- package/Docs/VISUAL_COMPONENTS.md.meta +7 -0
- package/Editor/AnimationEventEditor.cs +337 -160
- package/Editor/Core/Helper/AnimationEventHelpers.cs +178 -152
- package/Editor/CustomEditors/PersistentDirectoryGUI.cs +20 -11
- package/Editor/CustomEditors/TexturePlatformOverrideEntryDrawer.cs +11 -2
- package/Editor/FitTextureSizeWindow.cs +43 -19
- package/Editor/PersistentDirectorySettings.cs +64 -12
- package/Editor/PrefabChecker.cs +72 -5
- package/Editor/Sprites/AnimationCopier.cs +131 -55
- package/Editor/Sprites/AnimationCreator.cs +63 -22
- package/Editor/Sprites/AnimationViewerWindow.cs +42 -6
- package/Editor/Sprites/TexturePlatformNameHelper.cs +50 -39
- package/Editor/Sprites/TextureResizerWizard.cs +23 -1
- package/Editor/Sprites/TextureSettingsApplierWindow.cs +148 -85
- package/Editor/Tools/ImageBlurTool.cs +81 -10
- package/Editor/Utils/EditorUi.cs +1 -1
- package/Editor/Utils/ScriptableObjectSingletonCreator.cs +1 -1
- package/README.md +428 -2433
- package/Runtime/AssemblyInfo.cs +4 -0
- package/Runtime/Core/Attributes/NotNullAttribute.cs +1 -3
- package/Runtime/Core/Attributes/RelationalComponentAssigner.cs +50 -5
- package/Runtime/Core/DataStructure/CyclicBuffer.cs +0 -1
- package/Runtime/Core/DataStructure/KDTree3D.cs +1 -1
- package/Runtime/Core/DataStructure/OctTree3D.cs +1 -1
- package/Runtime/Core/Extension/AsyncOperationExtensions.cs +122 -0
- package/Runtime/Core/Extension/RandomExtensions.cs +68 -0
- package/Runtime/Core/Extension/WallstopStudiosLogger.cs +16 -0
- package/Runtime/Core/Helper/Partials/ObjectHelpers.cs +4 -1
- package/Runtime/Core/Helper/ReflectionHelpers.cs +21 -10
- package/Runtime/Core/Helper/SpriteHelpers.cs +3 -1
- package/Runtime/Core/Helper/UnityMainThreadDispatcher.cs +45 -1
- package/Runtime/Core/Serialization/JsonConverters/GameObjectConverter.cs +13 -5
- package/Runtime/Core/Serialization/JsonConverters/ResolutionConverter.cs +1 -1
- package/Runtime/Core/Serialization/JsonConverters/TypeConverter.cs +1 -1
- package/Runtime/Core/Serialization/ProtobufUnitySurrogates.cs +24 -29
- package/Runtime/Core/Serialization/Serializer.cs +101 -0
- package/Runtime/Integrations/Reflex/AssemblyInfo.cs +7 -0
- package/Runtime/Integrations/Reflex/AssemblyInfo.cs.meta +11 -0
- package/Runtime/Integrations/Reflex/ContainerRelationalExtensions.cs +198 -0
- package/Runtime/Integrations/Reflex/ContainerRelationalExtensions.cs.meta +11 -0
- package/Runtime/Integrations/Reflex/RelationalComponentsInstaller.cs +86 -0
- package/Runtime/Integrations/Reflex/RelationalComponentsInstaller.cs.meta +11 -0
- package/Runtime/Integrations/Reflex/RelationalReflexSceneBootstrapper.cs +316 -0
- package/Runtime/Integrations/Reflex/RelationalReflexSceneBootstrapper.cs.meta +11 -0
- package/Runtime/Integrations/Reflex/RelationalSceneAssignmentOptions.cs +86 -0
- package/Runtime/Integrations/Reflex/RelationalSceneAssignmentOptions.cs.meta +11 -0
- package/Runtime/Integrations/Reflex/WallstopStudios.UnityHelpers.Integration.Reflex.asmdef +20 -0
- package/Runtime/Integrations/Reflex/WallstopStudios.UnityHelpers.Integration.Reflex.asmdef.meta +7 -0
- package/Runtime/Integrations/Reflex.meta +8 -0
- package/Runtime/Integrations/VContainer/AssemblyInfo.cs +9 -0
- package/Runtime/Integrations/VContainer/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Integrations/VContainer/ObjectResolverRelationalExtensions.cs +96 -0
- package/Runtime/Integrations/VContainer/RelationalComponentEntryPoint.cs +90 -10
- package/Runtime/Integrations/VContainer/RelationalComponentsBuilderExtensions.cs +13 -1
- package/Runtime/Integrations/VContainer/RelationalObjectPools.cs +114 -0
- package/Runtime/Integrations/VContainer/RelationalObjectPools.cs.meta +11 -0
- package/Runtime/Integrations/VContainer/RelationalSceneAssignmentOptions.cs +16 -4
- package/Runtime/Integrations/VContainer/RelationalSceneLoadListener.cs +241 -0
- package/Runtime/Integrations/VContainer/RelationalSceneLoadListener.cs.meta +11 -0
- package/Runtime/Integrations/Zenject/AssemblyInfo.cs +9 -0
- package/Runtime/Integrations/Zenject/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Integrations/Zenject/DiContainerRelationalExtensions.cs +69 -2
- package/Runtime/Integrations/Zenject/RelationalComponentSceneInitializer.cs +89 -12
- package/Runtime/Integrations/Zenject/RelationalComponentsInstaller.cs +23 -1
- package/Runtime/Integrations/Zenject/RelationalMemoryPools.cs +44 -0
- package/Runtime/Integrations/Zenject/RelationalMemoryPools.cs.meta +11 -0
- package/Runtime/Integrations/Zenject/RelationalSceneAssignmentOptions.cs +16 -10
- package/Runtime/Integrations/Zenject/RelationalSceneLoadListener.cs +243 -0
- package/Runtime/Integrations/Zenject/RelationalSceneLoadListener.cs.meta +11 -0
- package/Runtime/Tags/AttributeMetadataCache.cs +1 -4
- package/Runtime/Utils/Buffers.cs +4 -4
- package/Runtime/Utils/ScriptableObjectSingleton.cs +1 -2
- package/Runtime/Utils/SetTextureImportData.cs +3 -1
- package/Runtime/Utils/TextureScale.cs +10 -2
- package/Runtime/Visuals/UGUI/EnhancedImage.cs +6 -0
- package/Runtime/Visuals/UIToolkit/LayeredImage.cs +4 -1
- package/Samples~/DI - Reflex/README.md +527 -0
- package/Samples~/DI - Reflex/README.md.meta +7 -0
- package/Samples~/DI - Reflex/Scripts/ReflexPaletteService.cs +36 -0
- package/Samples~/DI - Reflex/Scripts/ReflexPaletteService.cs.meta +11 -0
- package/Samples~/DI - Reflex/Scripts/ReflexRelationalConsumer.cs +79 -0
- package/Samples~/DI - Reflex/Scripts/ReflexRelationalConsumer.cs.meta +11 -0
- package/Samples~/DI - Reflex/Scripts/ReflexSampleInstaller.cs +30 -0
- package/Samples~/DI - Reflex/Scripts/ReflexSampleInstaller.cs.meta +11 -0
- package/Samples~/DI - Reflex/Scripts/ReflexSpawner.cs +79 -0
- package/Samples~/DI - Reflex/Scripts/ReflexSpawner.cs.meta +11 -0
- package/Samples~/DI - Reflex/Scripts/Samples.UnityHelpers.DI.Reflex.asmdef +26 -0
- package/Samples~/DI - Reflex/Scripts/Samples.UnityHelpers.DI.Reflex.asmdef.meta +9 -0
- package/Samples~/DI - Reflex/Scripts.meta +8 -0
- package/Samples~/DI - Reflex.meta +8 -0
- package/Samples~/DI - VContainer/README.md +238 -56
- package/Samples~/DI - VContainer/Scripts/GameLifetimeScope.cs +22 -4
- package/Samples~/DI - VContainer/Scripts/RelationalConsumer.cs +5 -2
- package/Samples~/DI - VContainer/Scripts/Spawner.cs +113 -4
- package/Samples~/DI - Zenject/README.md +223 -58
- package/Samples~/DI - Zenject/Scripts/RelationalConsumer.cs +3 -0
- package/Samples~/DI - Zenject/Scripts/RelationalConsumerPool.cs +37 -0
- package/Samples~/DI - Zenject/Scripts/RelationalConsumerPool.cs.meta +12 -0
- package/Samples~/DI - Zenject/Scripts/SpawnerZenject.cs +74 -3
- package/Samples~/Random - PRNG/README.md +2 -1
- package/Samples~/Relational Components - Basic/README.md +3 -1
- package/Samples~/Serialization - JSON/README.md +2 -1
- package/Samples~/Spatial Structures - 2D and 3D/README.md +2 -1
- package/Samples~/UGUI - EnhancedImage/README.md +2 -1
- package/Samples~/UI Toolkit - MultiFile Selector (Editor)/README.md +2 -1
- package/Tests/Editor/Attributes/AnimationEventHelpersTests.cs +16 -0
- package/Tests/Editor/Core/Attributes/RelationalComponentAssignerTests.cs +32 -34
- package/Tests/Editor/Integrations/Reflex/ReflexIntegrationCompilationTests.cs +41 -0
- package/Tests/Editor/Integrations/Reflex/ReflexIntegrationCompilationTests.cs.meta +11 -0
- package/Tests/Editor/Integrations/Reflex/WallstopStudios.UnityHelpers.Tests.Editor.Reflex.asmdef +27 -0
- package/Tests/Editor/Integrations/Reflex/WallstopStudios.UnityHelpers.Tests.Editor.Reflex.asmdef.meta +7 -0
- package/Tests/Editor/Integrations/Reflex.meta +8 -0
- package/Tests/Editor/Integrations/VContainer/VContainerRelationalEntryPointTests.cs +21 -18
- package/Tests/Editor/Integrations/VContainer/VContainerRelationalHelpersTests.cs +164 -0
- package/Tests/Editor/Integrations/VContainer/VContainerRelationalHelpersTests.cs.meta +11 -0
- package/Tests/Editor/Integrations/VContainer/WallstopStudios.UnityHelpers.Tests.Editor.VContainer.asmdef +2 -1
- package/Tests/Editor/Integrations/Zenject/WallstopStudios.UnityHelpers.Tests.Editor.Zenject.asmdef +3 -2
- package/Tests/Editor/Integrations/Zenject/ZenjectRelationalHelpersTests.cs +127 -0
- package/Tests/Editor/Integrations/Zenject/ZenjectRelationalHelpersTests.cs.meta +11 -0
- package/Tests/Editor/Integrations/Zenject/ZenjectRelationalInitializerTests.cs +25 -23
- package/Tests/Editor/PersistentDirectorySettingsTests.cs +58 -0
- package/Tests/Editor/PersistentDirectorySettingsTests.cs.meta +11 -0
- package/Tests/Editor/PrefabCheckerReportTests.cs +32 -0
- package/Tests/Editor/PrefabCheckerReportTests.cs.meta +11 -0
- package/Tests/Editor/Sprites/AnimationCopierFilterTests.cs +63 -0
- package/Tests/Editor/Sprites/AnimationCopierFilterTests.cs.meta +11 -0
- package/Tests/Editor/Sprites/AnimationCopierWindowTests.cs +1 -1
- package/Tests/Editor/Sprites/AnimationViewerWindowTests.cs +38 -0
- package/Tests/Editor/Sprites/AnimationViewerWindowTests.cs.meta +11 -0
- package/Tests/Editor/Sprites/ScriptableSpriteAtlasEditorTests.cs +1 -1
- package/Tests/Editor/Sprites/SpriteCropperAdditionalTests.cs +12 -12
- package/Tests/Editor/Sprites/SpriteCropperTests.cs +9 -9
- package/Tests/Editor/Sprites/SpritePivotAdjusterTests.cs +3 -3
- package/Tests/Editor/Sprites/TexturePlatformNameHelperTests.cs +18 -0
- package/Tests/Editor/Sprites/TextureResizerWizardTests.cs +5 -5
- package/Tests/Editor/Sprites/TextureSettingsApplierAPITests.cs +3 -3
- package/Tests/Editor/Sprites/TextureSettingsApplierWizardAdditionalTests.cs +4 -4
- package/Tests/Editor/Sprites/TextureSettingsApplierWizardTests.cs +4 -4
- package/Tests/Editor/Tools/ImageBlurToolTests.cs +22 -110
- package/Tests/Editor/Utils/CommonTestBase.cs +60 -1
- package/Tests/Editor/Utils/ScriptableObjectSingletonCreatorTests.cs +6 -6
- package/Tests/Editor/Windows/FitTextureSizeWindowTests.cs +66 -74
- package/Tests/Runtime/Attributes/RelationalComponentInitializerTests.cs +4 -15
- package/Tests/Runtime/DataStructures/SpatialTree3DBoundsConsistencyTests.cs +29 -29
- package/Tests/Runtime/Extensions/AsyncOperationExtensionsTests.cs +179 -0
- package/Tests/Runtime/Extensions/RandomExtensionTests.cs +55 -0
- package/Tests/Runtime/Integrations/Reflex/RelationalComponentsReflexTests.cs +445 -0
- package/Tests/Runtime/Integrations/Reflex/RelationalComponentsReflexTests.cs.meta +11 -0
- package/Tests/Runtime/Integrations/Reflex/WallstopStudios.UnityHelpers.Tests.Runtime.Reflex.asmdef +28 -0
- package/Tests/Runtime/Integrations/Reflex/WallstopStudios.UnityHelpers.Tests.Runtime.Reflex.asmdef.meta +7 -0
- package/Tests/Runtime/Integrations/Reflex.meta +8 -0
- package/Tests/Runtime/Integrations/VContainer/RelationalComponentsVContainerTests.cs +257 -221
- package/Tests/Runtime/Integrations/VContainer/RelationalObjectPoolsVContainerTests.cs +91 -0
- package/Tests/Runtime/Integrations/VContainer/RelationalObjectPoolsVContainerTests.cs.meta +11 -0
- package/Tests/Runtime/Integrations/Zenject/RelationalComponentsZenjectTests.cs +251 -233
- package/Tests/Runtime/Performance/RandomPerformanceTests.cs +1 -1
- package/Tests/Runtime/Performance/SpatialTree2DPerformanceTests.cs +6 -1
- package/Tests/Runtime/Performance/SpatialTree3DPerformanceTests.cs +4 -1
- package/Tests/Runtime/Serialization/JsonConverterAdditionalTests.cs +30 -0
- package/Tests/Runtime/Serialization/JsonConverterAdditionalTests.cs.meta +11 -0
- package/Tests/Runtime/Serialization/JsonConverterTests.cs +8 -12
- package/Tests/Runtime/Serialization/JsonRoundtripComprehensiveTests.cs +4 -9
- package/Tests/Runtime/Serialization/JsonSerializationTest.cs +16 -5
- package/Tests/Runtime/Serialization/ProtoRoundtripComprehensiveTests.cs +13 -13
- package/Tests/Runtime/Serialization/SerializerAdditionalTests.cs +12 -0
- package/Tests/Runtime/Serialization/SerializerFileIoTests.cs +105 -0
- package/Tests/Runtime/Serialization/SerializerFileIoTests.cs.meta +11 -0
- package/Tests/Runtime/Serialization/UnityEngineObjectJsonTests.cs +247 -0
- package/Tests/Runtime/Serialization/UnityEngineObjectJsonTests.cs.meta +11 -0
- package/Tests/Runtime/TestUtils/CommonTestBase.cs +99 -0
- package/Tests/Runtime/TestUtils/ReflexTestSupport.cs +111 -0
- package/Tests/Runtime/TestUtils/ReflexTestSupport.cs.meta +12 -0
- package/Tests/Runtime/Utils/CoroutineHandlerTests.cs +1 -1
- package/Tests/Runtime/Utils/LZMAComprehensiveTests.cs +1 -1
- package/Tests/Runtime/Utils/LZMATests.cs +1 -1
- package/Tests/Runtime/Utils/MatchColliderToSpriteTests.cs +5 -5
- package/Tests/Runtime/Visuals/EnhancedImageTests.cs +25 -56
- package/Tests/Runtime/Visuals/VisualsTestHelpers.cs +1 -8
- package/Tests/TestUtils.meta +8 -0
- package/package-lock.json.meta +7 -0
- package/package.json +13 -4
- package/scripts/check-eol.ps1 +4 -5
- package/scripts/lint-tests.ps1 +156 -0
- package/scripts/lint-tests.ps1.meta +7 -0
- package/scripts/normalize-eol.ps1 +6 -9
- package/.github/workflows/csharpier.yml +0 -135
- package/CHANGELOG.md +0 -0
- package/EFFECTS_SYSTEM.md +0 -242
- package/MATH_AND_EXTENSIONS.md +0 -316
- package/SPATIAL_TREE_2D_PERFORMANCE.md +0 -238
- package/SPATIAL_TREE_3D_PERFORMANCE.md +0 -240
- /package/{CHANGELOG.md.meta → Docs/CHANGELOG.md.meta} +0 -0
- /package/{DATA_STRUCTURES.md → Docs/DATA_STRUCTURES.md} +0 -0
- /package/{DATA_STRUCTURES.md.meta → Docs/DATA_STRUCTURES.md.meta} +0 -0
- /package/{EDITOR_TOOLS_GUIDE.md.meta → Docs/EDITOR_TOOLS_GUIDE.md.meta} +0 -0
- /package/{EFFECTS_SYSTEM.md.meta → Docs/EFFECTS_SYSTEM.md.meta} +0 -0
- /package/{EFFECTS_SYSTEM_TUTORIAL.md.meta → Docs/EFFECTS_SYSTEM_TUTORIAL.md.meta} +0 -0
- /package/{GETTING_STARTED.md.meta → Docs/GETTING_STARTED.md.meta} +0 -0
- /package/{GLOSSARY.md.meta → Docs/GLOSSARY.md.meta} +0 -0
- /package/{HULLS.md → Docs/HULLS.md} +0 -0
- /package/{HULLS.md.meta → Docs/HULLS.md.meta} +0 -0
- /package/{INDEX.md.meta → Docs/INDEX.md.meta} +0 -0
- /package/{LICENSE.md → Docs/LICENSE.md} +0 -0
- /package/{LICENSE.md.meta → Docs/LICENSE.md.meta} +0 -0
- /package/{MATH_AND_EXTENSIONS.md.meta → Docs/MATH_AND_EXTENSIONS.md.meta} +0 -0
- /package/{RANDOM_PERFORMANCE.md.meta → Docs/RANDOM_PERFORMANCE.md.meta} +0 -0
- /package/{REFLECTION_HELPERS.md → Docs/REFLECTION_HELPERS.md} +0 -0
- /package/{REFLECTION_HELPERS.md.meta → Docs/REFLECTION_HELPERS.md.meta} +0 -0
- /package/{RELATIONAL_COMPONENTS.md.meta → Docs/RELATIONAL_COMPONENTS.md.meta} +0 -0
- /package/{SERIALIZATION.md.meta → Docs/SERIALIZATION.md.meta} +0 -0
- /package/{SINGLETONS.md → Docs/SINGLETONS.md} +0 -0
- /package/{SINGLETONS.md.meta → Docs/SINGLETONS.md.meta} +0 -0
- /package/{SPATIAL_TREES_2D_GUIDE.md.meta → Docs/SPATIAL_TREES_2D_GUIDE.md.meta} +0 -0
- /package/{SPATIAL_TREES_3D_GUIDE.md.meta → Docs/SPATIAL_TREES_3D_GUIDE.md.meta} +0 -0
- /package/{SPATIAL_TREE_2D_PERFORMANCE.md.meta → Docs/SPATIAL_TREE_2D_PERFORMANCE.md.meta} +0 -0
- /package/{SPATIAL_TREE_3D_PERFORMANCE.md.meta → Docs/SPATIAL_TREE_3D_PERFORMANCE.md.meta} +0 -0
- /package/{SPATIAL_TREE_SEMANTICS.md → Docs/SPATIAL_TREE_SEMANTICS.md} +0 -0
- /package/{SPATIAL_TREE_SEMANTICS.md.meta → Docs/SPATIAL_TREE_SEMANTICS.md.meta} +0 -0
- /package/{THIRD_PARTY_NOTICES.md.meta → Docs/THIRD_PARTY_NOTICES.md.meta} +0 -0
|
@@ -15,10 +15,9 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
15
15
|
[ProtoMember(2)]
|
|
16
16
|
public float y;
|
|
17
17
|
|
|
18
|
-
public static implicit operator Vector2Surrogate(Vector2 v) =>
|
|
19
|
-
new Vector2Surrogate { x = v.x, y = v.y };
|
|
18
|
+
public static implicit operator Vector2Surrogate(Vector2 v) => new() { x = v.x, y = v.y };
|
|
20
19
|
|
|
21
|
-
public static implicit operator Vector2(Vector2Surrogate s) => new
|
|
20
|
+
public static implicit operator Vector2(Vector2Surrogate s) => new(s.x, s.y);
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
[ProtoContract]
|
|
@@ -34,14 +33,14 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
34
33
|
public float z;
|
|
35
34
|
|
|
36
35
|
public static implicit operator Vector3Surrogate(Vector3 v) =>
|
|
37
|
-
new
|
|
36
|
+
new()
|
|
38
37
|
{
|
|
39
38
|
x = v.x,
|
|
40
39
|
y = v.y,
|
|
41
40
|
z = v.z,
|
|
42
41
|
};
|
|
43
42
|
|
|
44
|
-
public static implicit operator Vector3(Vector3Surrogate s) => new
|
|
43
|
+
public static implicit operator Vector3(Vector3Surrogate s) => new(s.x, s.y, s.z);
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
[ProtoContract]
|
|
@@ -60,7 +59,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
60
59
|
public float w;
|
|
61
60
|
|
|
62
61
|
public static implicit operator QuaternionSurrogate(Quaternion q) =>
|
|
63
|
-
new
|
|
62
|
+
new()
|
|
64
63
|
{
|
|
65
64
|
x = q.x,
|
|
66
65
|
y = q.y,
|
|
@@ -69,7 +68,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
69
68
|
};
|
|
70
69
|
|
|
71
70
|
public static implicit operator Quaternion(QuaternionSurrogate s) =>
|
|
72
|
-
new
|
|
71
|
+
new(s.x, s.y, s.z, s.w);
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
[ProtoContract]
|
|
@@ -88,7 +87,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
88
87
|
public float a;
|
|
89
88
|
|
|
90
89
|
public static implicit operator ColorSurrogate(Color c) =>
|
|
91
|
-
new
|
|
90
|
+
new()
|
|
92
91
|
{
|
|
93
92
|
r = c.r,
|
|
94
93
|
g = c.g,
|
|
@@ -96,7 +95,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
96
95
|
a = c.a,
|
|
97
96
|
};
|
|
98
97
|
|
|
99
|
-
public static implicit operator Color(ColorSurrogate s) => new
|
|
98
|
+
public static implicit operator Color(ColorSurrogate s) => new(s.r, s.g, s.b, s.a);
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
[ProtoContract]
|
|
@@ -115,7 +114,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
115
114
|
public byte a;
|
|
116
115
|
|
|
117
116
|
public static implicit operator Color32Surrogate(Color32 c) =>
|
|
118
|
-
new
|
|
117
|
+
new()
|
|
119
118
|
{
|
|
120
119
|
r = c.r,
|
|
121
120
|
g = c.g,
|
|
@@ -123,8 +122,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
123
122
|
a = c.a,
|
|
124
123
|
};
|
|
125
124
|
|
|
126
|
-
public static implicit operator Color32(Color32Surrogate s) =>
|
|
127
|
-
new Color32(s.r, s.g, s.b, s.a);
|
|
125
|
+
public static implicit operator Color32(Color32Surrogate s) => new(s.r, s.g, s.b, s.a);
|
|
128
126
|
}
|
|
129
127
|
|
|
130
128
|
[ProtoContract]
|
|
@@ -143,7 +141,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
143
141
|
public float height;
|
|
144
142
|
|
|
145
143
|
public static implicit operator RectSurrogate(Rect r) =>
|
|
146
|
-
new
|
|
144
|
+
new()
|
|
147
145
|
{
|
|
148
146
|
x = r.x,
|
|
149
147
|
y = r.y,
|
|
@@ -151,8 +149,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
151
149
|
height = r.height,
|
|
152
150
|
};
|
|
153
151
|
|
|
154
|
-
public static implicit operator Rect(RectSurrogate s) =>
|
|
155
|
-
new Rect(s.x, s.y, s.width, s.height);
|
|
152
|
+
public static implicit operator Rect(RectSurrogate s) => new(s.x, s.y, s.width, s.height);
|
|
156
153
|
}
|
|
157
154
|
|
|
158
155
|
[ProtoContract]
|
|
@@ -171,7 +168,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
171
168
|
public int height;
|
|
172
169
|
|
|
173
170
|
public static implicit operator RectIntSurrogate(RectInt r) =>
|
|
174
|
-
new
|
|
171
|
+
new()
|
|
175
172
|
{
|
|
176
173
|
x = r.x,
|
|
177
174
|
y = r.y,
|
|
@@ -180,7 +177,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
180
177
|
};
|
|
181
178
|
|
|
182
179
|
public static implicit operator RectInt(RectIntSurrogate s) =>
|
|
183
|
-
new
|
|
180
|
+
new(s.x, s.y, s.width, s.height);
|
|
184
181
|
}
|
|
185
182
|
|
|
186
183
|
[ProtoContract]
|
|
@@ -205,7 +202,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
205
202
|
public float sz;
|
|
206
203
|
|
|
207
204
|
public static implicit operator BoundsSurrogate(Bounds b) =>
|
|
208
|
-
new
|
|
205
|
+
new()
|
|
209
206
|
{
|
|
210
207
|
cx = b.center.x,
|
|
211
208
|
cy = b.center.y,
|
|
@@ -216,7 +213,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
216
213
|
};
|
|
217
214
|
|
|
218
215
|
public static implicit operator Bounds(BoundsSurrogate s) =>
|
|
219
|
-
new
|
|
216
|
+
new(new Vector3(s.cx, s.cy, s.cz), new Vector3(s.sx, s.sy, s.sz));
|
|
220
217
|
}
|
|
221
218
|
|
|
222
219
|
[ProtoContract]
|
|
@@ -241,7 +238,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
241
238
|
public int sz;
|
|
242
239
|
|
|
243
240
|
public static implicit operator BoundsIntSurrogate(BoundsInt b) =>
|
|
244
|
-
new
|
|
241
|
+
new()
|
|
245
242
|
{
|
|
246
243
|
px = b.position.x,
|
|
247
244
|
py = b.position.y,
|
|
@@ -252,7 +249,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
252
249
|
};
|
|
253
250
|
|
|
254
251
|
public static implicit operator BoundsInt(BoundsIntSurrogate s) =>
|
|
255
|
-
new
|
|
252
|
+
new(new Vector3Int(s.px, s.py, s.pz), new Vector3Int(s.sx, s.sy, s.sz));
|
|
256
253
|
}
|
|
257
254
|
|
|
258
255
|
[ProtoContract]
|
|
@@ -265,10 +262,9 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
265
262
|
public int y;
|
|
266
263
|
|
|
267
264
|
public static implicit operator Vector2IntSurrogate(Vector2Int v) =>
|
|
268
|
-
new
|
|
265
|
+
new() { x = v.x, y = v.y };
|
|
269
266
|
|
|
270
|
-
public static implicit operator Vector2Int(Vector2IntSurrogate s) =>
|
|
271
|
-
new Vector2Int(s.x, s.y);
|
|
267
|
+
public static implicit operator Vector2Int(Vector2IntSurrogate s) => new(s.x, s.y);
|
|
272
268
|
}
|
|
273
269
|
|
|
274
270
|
[ProtoContract]
|
|
@@ -284,15 +280,14 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
284
280
|
public int z;
|
|
285
281
|
|
|
286
282
|
public static implicit operator Vector3IntSurrogate(Vector3Int v) =>
|
|
287
|
-
new
|
|
283
|
+
new()
|
|
288
284
|
{
|
|
289
285
|
x = v.x,
|
|
290
286
|
y = v.y,
|
|
291
287
|
z = v.z,
|
|
292
288
|
};
|
|
293
289
|
|
|
294
|
-
public static implicit operator Vector3Int(Vector3IntSurrogate s) =>
|
|
295
|
-
new Vector3Int(s.x, s.y, s.z);
|
|
290
|
+
public static implicit operator Vector3Int(Vector3IntSurrogate s) => new(s.x, s.y, s.z);
|
|
296
291
|
}
|
|
297
292
|
|
|
298
293
|
[ProtoContract]
|
|
@@ -309,7 +304,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
309
304
|
|
|
310
305
|
[Obsolete("Obsolete")]
|
|
311
306
|
public static implicit operator ResolutionSurrogate(Resolution r) =>
|
|
312
|
-
new
|
|
307
|
+
new()
|
|
313
308
|
{
|
|
314
309
|
width = r.width,
|
|
315
310
|
height = r.height,
|
|
@@ -318,7 +313,7 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
318
313
|
|
|
319
314
|
public static implicit operator Resolution(ResolutionSurrogate s)
|
|
320
315
|
{
|
|
321
|
-
Resolution r = new
|
|
316
|
+
Resolution r = new() { width = s.width, height = s.height };
|
|
322
317
|
#if !UNITY_2022_2_OR_NEWER
|
|
323
318
|
r.refreshRate = s.refreshRate;
|
|
324
319
|
#endif
|
|
@@ -277,6 +277,10 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
277
277
|
None = 0,
|
|
278
278
|
|
|
279
279
|
/// <summary>Legacy .NET BinaryFormatter. Trusted/ephemeral data only.</summary>
|
|
280
|
+
[Obsolete(
|
|
281
|
+
"BinaryFormatter is obsolete and unsafe for untrusted data. "
|
|
282
|
+
+ "Prefer Json or Protobuf for new code."
|
|
283
|
+
)]
|
|
280
284
|
SystemBinary = 1,
|
|
281
285
|
|
|
282
286
|
/// <summary>protobuf-net compact binary. Best for networking and high-performance.</summary>
|
|
@@ -608,7 +612,9 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
608
612
|
{
|
|
609
613
|
switch (serializationType)
|
|
610
614
|
{
|
|
615
|
+
#pragma warning disable CS0618 // Type or member is obsolete
|
|
611
616
|
case SerializationType.SystemBinary:
|
|
617
|
+
#pragma warning restore CS0618 // Type or member is obsolete
|
|
612
618
|
{
|
|
613
619
|
return BinaryDeserialize<T>(serialized);
|
|
614
620
|
}
|
|
@@ -650,7 +656,9 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
650
656
|
{
|
|
651
657
|
switch (serializationType)
|
|
652
658
|
{
|
|
659
|
+
#pragma warning disable CS0618 // Type or member is obsolete
|
|
653
660
|
case SerializationType.SystemBinary:
|
|
661
|
+
#pragma warning restore CS0618 // Type or member is obsolete
|
|
654
662
|
{
|
|
655
663
|
return BinarySerialize(instance);
|
|
656
664
|
}
|
|
@@ -689,7 +697,9 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
689
697
|
{
|
|
690
698
|
switch (serializationType)
|
|
691
699
|
{
|
|
700
|
+
#pragma warning disable CS0618 // Type or member is obsolete
|
|
692
701
|
case SerializationType.SystemBinary:
|
|
702
|
+
#pragma warning restore CS0618 // Type or member is obsolete
|
|
693
703
|
{
|
|
694
704
|
return BinarySerialize(instance, ref buffer);
|
|
695
705
|
}
|
|
@@ -1494,6 +1504,35 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
1494
1504
|
return JsonDeserialize<T>(settingsAsBytes);
|
|
1495
1505
|
}
|
|
1496
1506
|
|
|
1507
|
+
/// <summary>
|
|
1508
|
+
/// Asynchronously reads JSON with cancellation.
|
|
1509
|
+
/// </summary>
|
|
1510
|
+
public static async Task<T> ReadFromJsonFileAsync<T>(
|
|
1511
|
+
string path,
|
|
1512
|
+
System.Threading.CancellationToken cancellationToken
|
|
1513
|
+
)
|
|
1514
|
+
{
|
|
1515
|
+
using FileStream fs = new(
|
|
1516
|
+
path,
|
|
1517
|
+
FileMode.Open,
|
|
1518
|
+
FileAccess.Read,
|
|
1519
|
+
FileShare.Read,
|
|
1520
|
+
4096,
|
|
1521
|
+
useAsync: true
|
|
1522
|
+
);
|
|
1523
|
+
using Utils.PooledResource<PooledBufferStream> lease = PooledBufferStream.Rent(
|
|
1524
|
+
out PooledBufferStream stream
|
|
1525
|
+
);
|
|
1526
|
+
byte[] buffer = new byte[8192];
|
|
1527
|
+
int read;
|
|
1528
|
+
while ((read = await fs.ReadAsync(buffer, 0, buffer.Length, cancellationToken)) > 0)
|
|
1529
|
+
{
|
|
1530
|
+
stream.Write(buffer, 0, read);
|
|
1531
|
+
}
|
|
1532
|
+
ArraySegment<byte> seg = stream.GetWrittenSegment();
|
|
1533
|
+
return JsonDeserialize<T>(seg.Array.AsSpan(0, seg.Count).ToArray());
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1497
1536
|
/// <summary>
|
|
1498
1537
|
/// Writes an instance to a JSON file (UTF‑8).
|
|
1499
1538
|
/// </summary>
|
|
@@ -1520,6 +1559,29 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
1520
1559
|
await File.WriteAllTextAsync(path, jsonAsText);
|
|
1521
1560
|
}
|
|
1522
1561
|
|
|
1562
|
+
/// <summary>
|
|
1563
|
+
/// Asynchronously writes an instance to a JSON file (UTF‑8) with cancellation.
|
|
1564
|
+
/// </summary>
|
|
1565
|
+
public static async Task WriteToJsonFileAsync<T>(
|
|
1566
|
+
T input,
|
|
1567
|
+
string path,
|
|
1568
|
+
bool pretty,
|
|
1569
|
+
System.Threading.CancellationToken cancellationToken
|
|
1570
|
+
)
|
|
1571
|
+
{
|
|
1572
|
+
string jsonAsText = JsonStringify(input, pretty);
|
|
1573
|
+
byte[] bytes = SerializerEncoding.Encoding.GetBytes(jsonAsText);
|
|
1574
|
+
using FileStream fs = new(
|
|
1575
|
+
path,
|
|
1576
|
+
FileMode.Create,
|
|
1577
|
+
FileAccess.Write,
|
|
1578
|
+
FileShare.None,
|
|
1579
|
+
4096,
|
|
1580
|
+
useAsync: true
|
|
1581
|
+
);
|
|
1582
|
+
await fs.WriteAsync(bytes, 0, bytes.Length, cancellationToken);
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1523
1585
|
/// <summary>
|
|
1524
1586
|
/// Writes an instance to a JSON file (UTF‑8) using the provided <paramref name="options"/>.
|
|
1525
1587
|
/// </summary>
|
|
@@ -1549,6 +1611,45 @@ namespace WallstopStudios.UnityHelpers.Core.Serialization
|
|
|
1549
1611
|
string jsonAsText = JsonStringify(input, options);
|
|
1550
1612
|
await File.WriteAllTextAsync(path, jsonAsText);
|
|
1551
1613
|
}
|
|
1614
|
+
|
|
1615
|
+
/// <summary>
|
|
1616
|
+
/// Attempts to read JSON into an instance, returns false if file missing or invalid.
|
|
1617
|
+
/// </summary>
|
|
1618
|
+
public static bool TryReadFromJsonFile<T>(string path, out T value)
|
|
1619
|
+
{
|
|
1620
|
+
try
|
|
1621
|
+
{
|
|
1622
|
+
if (!File.Exists(path))
|
|
1623
|
+
{
|
|
1624
|
+
value = default;
|
|
1625
|
+
return false;
|
|
1626
|
+
}
|
|
1627
|
+
string json = File.ReadAllText(path);
|
|
1628
|
+
value = JsonDeserialize<T>(json);
|
|
1629
|
+
return true;
|
|
1630
|
+
}
|
|
1631
|
+
catch
|
|
1632
|
+
{
|
|
1633
|
+
value = default;
|
|
1634
|
+
return false;
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
/// <summary>
|
|
1639
|
+
/// Attempts to write JSON to a file, returns false on failure.
|
|
1640
|
+
/// </summary>
|
|
1641
|
+
public static bool TryWriteToJsonFile<T>(T input, string path, bool pretty = true)
|
|
1642
|
+
{
|
|
1643
|
+
try
|
|
1644
|
+
{
|
|
1645
|
+
WriteToJsonFile(input, path, pretty);
|
|
1646
|
+
return true;
|
|
1647
|
+
}
|
|
1648
|
+
catch
|
|
1649
|
+
{
|
|
1650
|
+
return false;
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1552
1653
|
}
|
|
1553
1654
|
|
|
1554
1655
|
// Internal pooled, growable write stream backed by ArrayPool<byte> to reduce allocations
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
using System.Runtime.CompilerServices;
|
|
2
|
+
|
|
3
|
+
[assembly: InternalsVisibleTo("WallstopStudios.UnityHelpers.Tests.Editor")]
|
|
4
|
+
[assembly: InternalsVisibleTo("WallstopStudios.UnityHelpers.Tests.Runtime")]
|
|
5
|
+
[assembly: InternalsVisibleTo("WallstopStudios.UnityHelpers.Editor")]
|
|
6
|
+
[assembly: InternalsVisibleTo("WallstopStudios.UnityHelpers.Tests.Runtime.Reflex")]
|
|
7
|
+
[assembly: InternalsVisibleTo("WallstopStudios.UnityHelpers.Tests.Editor.Reflex")]
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
#if REFLEX_PRESENT
|
|
2
|
+
namespace WallstopStudios.UnityHelpers.Integrations.Reflex
|
|
3
|
+
{
|
|
4
|
+
using System;
|
|
5
|
+
using System.Collections.Generic;
|
|
6
|
+
using global::Reflex.Core;
|
|
7
|
+
using global::Reflex.Injectors;
|
|
8
|
+
using UnityEngine;
|
|
9
|
+
using WallstopStudios.UnityHelpers.Core.Attributes;
|
|
10
|
+
using WallstopStudios.UnityHelpers.Utils;
|
|
11
|
+
|
|
12
|
+
/// <summary>
|
|
13
|
+
/// Extension methods that bridge Reflex containers with relational component assignment.
|
|
14
|
+
/// </summary>
|
|
15
|
+
public static class ContainerRelationalExtensions
|
|
16
|
+
{
|
|
17
|
+
/// <summary>
|
|
18
|
+
/// Injects a component using Reflex and assigns its relational fields.
|
|
19
|
+
/// </summary>
|
|
20
|
+
/// <typeparam name="T">Component type.</typeparam>
|
|
21
|
+
/// <param name="container">Reflex container.</param>
|
|
22
|
+
/// <param name="component">Component instance to inject and hydrate.</param>
|
|
23
|
+
/// <returns>The injected component instance.</returns>
|
|
24
|
+
public static T InjectWithRelations<T>(this Container container, T component)
|
|
25
|
+
where T : Component
|
|
26
|
+
{
|
|
27
|
+
if (component == null)
|
|
28
|
+
{
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (container != null)
|
|
33
|
+
{
|
|
34
|
+
AttributeInjector.Inject(component, container);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
container.AssignRelationalComponents(component);
|
|
38
|
+
return component;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// <summary>
|
|
42
|
+
/// Assigns relational component fields on the supplied component.
|
|
43
|
+
/// </summary>
|
|
44
|
+
/// <param name="container">Reflex container.</param>
|
|
45
|
+
/// <param name="component">Component to hydrate.</param>
|
|
46
|
+
public static void AssignRelationalComponents(this Container container, Component component)
|
|
47
|
+
{
|
|
48
|
+
if (component == null)
|
|
49
|
+
{
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
IRelationalComponentAssigner assigner = ResolveAssigner(container);
|
|
54
|
+
if (assigner != null)
|
|
55
|
+
{
|
|
56
|
+
assigner.Assign(component);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
component.AssignRelationalComponents();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/// <summary>
|
|
64
|
+
/// Assigns relational component fields across a GameObject hierarchy.
|
|
65
|
+
/// </summary>
|
|
66
|
+
/// <param name="container">Reflex container.</param>
|
|
67
|
+
/// <param name="root">Hierarchy root.</param>
|
|
68
|
+
/// <param name="includeInactiveChildren">
|
|
69
|
+
/// When true, includes inactive children during assignment.
|
|
70
|
+
/// </param>
|
|
71
|
+
public static void AssignRelationalHierarchy(
|
|
72
|
+
this Container container,
|
|
73
|
+
GameObject root,
|
|
74
|
+
bool includeInactiveChildren = true
|
|
75
|
+
)
|
|
76
|
+
{
|
|
77
|
+
if (root == null)
|
|
78
|
+
{
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
IRelationalComponentAssigner assigner = ResolveAssigner(container);
|
|
83
|
+
if (assigner != null)
|
|
84
|
+
{
|
|
85
|
+
assigner.AssignHierarchy(root, includeInactiveChildren);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
using PooledResource<List<Component>> pooledComponents = Buffers<Component>.List.Get(
|
|
90
|
+
out List<Component> components
|
|
91
|
+
);
|
|
92
|
+
root.GetComponentsInChildren(includeInactiveChildren, components);
|
|
93
|
+
for (int i = 0; i < components.Count; i++)
|
|
94
|
+
{
|
|
95
|
+
Component component = components[i];
|
|
96
|
+
if (component == null)
|
|
97
|
+
{
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
component.AssignRelationalComponents();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/// <summary>
|
|
105
|
+
/// Instantiates a component prefab, injects it, and assigns relational fields.
|
|
106
|
+
/// </summary>
|
|
107
|
+
/// <typeparam name="T">Component type contained by the prefab.</typeparam>
|
|
108
|
+
/// <param name="container">Reflex container.</param>
|
|
109
|
+
/// <param name="prefab">Component prefab.</param>
|
|
110
|
+
/// <param name="parent">Optional parent transform.</param>
|
|
111
|
+
/// <returns>The instantiated and hydrated component.</returns>
|
|
112
|
+
public static T InstantiateComponentWithRelations<T>(
|
|
113
|
+
this Container container,
|
|
114
|
+
T prefab,
|
|
115
|
+
Transform parent = null
|
|
116
|
+
)
|
|
117
|
+
where T : Component
|
|
118
|
+
{
|
|
119
|
+
if (prefab == null)
|
|
120
|
+
{
|
|
121
|
+
throw new ArgumentNullException(nameof(prefab));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
T instance = UnityEngine.Object.Instantiate(prefab, parent);
|
|
125
|
+
return container.InjectWithRelations(instance);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/// <summary>
|
|
129
|
+
/// Instantiates a GameObject prefab, injects the hierarchy, and assigns relational fields.
|
|
130
|
+
/// </summary>
|
|
131
|
+
/// <param name="container">Reflex container.</param>
|
|
132
|
+
/// <param name="prefab">GameObject prefab.</param>
|
|
133
|
+
/// <param name="parent">Optional parent transform.</param>
|
|
134
|
+
/// <param name="includeInactiveChildren">
|
|
135
|
+
/// When true, includes inactive children during relational assignment.
|
|
136
|
+
/// </param>
|
|
137
|
+
/// <returns>The instantiated GameObject.</returns>
|
|
138
|
+
public static GameObject InstantiateGameObjectWithRelations(
|
|
139
|
+
this Container container,
|
|
140
|
+
GameObject prefab,
|
|
141
|
+
Transform parent = null,
|
|
142
|
+
bool includeInactiveChildren = true
|
|
143
|
+
)
|
|
144
|
+
{
|
|
145
|
+
if (prefab == null)
|
|
146
|
+
{
|
|
147
|
+
throw new ArgumentNullException(nameof(prefab));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
GameObject instance = UnityEngine.Object.Instantiate(prefab, parent);
|
|
151
|
+
container.InjectGameObjectWithRelations(instance, includeInactiveChildren);
|
|
152
|
+
return instance;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/// <summary>
|
|
156
|
+
/// Injects all components in a hierarchy and assigns relational fields.
|
|
157
|
+
/// </summary>
|
|
158
|
+
/// <param name="container">Reflex container.</param>
|
|
159
|
+
/// <param name="root">Root GameObject.</param>
|
|
160
|
+
/// <param name="includeInactiveChildren">
|
|
161
|
+
/// When true, includes inactive children during relational assignment.
|
|
162
|
+
/// </param>
|
|
163
|
+
public static void InjectGameObjectWithRelations(
|
|
164
|
+
this Container container,
|
|
165
|
+
GameObject root,
|
|
166
|
+
bool includeInactiveChildren = true
|
|
167
|
+
)
|
|
168
|
+
{
|
|
169
|
+
if (root == null)
|
|
170
|
+
{
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (container != null)
|
|
175
|
+
{
|
|
176
|
+
GameObjectInjector.InjectRecursive(root, container);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
container.AssignRelationalHierarchy(root, includeInactiveChildren);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private static IRelationalComponentAssigner ResolveAssigner(Container container)
|
|
183
|
+
{
|
|
184
|
+
if (container == null)
|
|
185
|
+
{
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (container.HasBinding<IRelationalComponentAssigner>())
|
|
190
|
+
{
|
|
191
|
+
return container.Resolve<IRelationalComponentAssigner>();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
#endif
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#if REFLEX_PRESENT
|
|
2
|
+
namespace WallstopStudios.UnityHelpers.Integrations.Reflex
|
|
3
|
+
{
|
|
4
|
+
using global::Reflex.Core;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
using UnityEngine.SceneManagement;
|
|
7
|
+
using WallstopStudios.UnityHelpers.Core.Attributes;
|
|
8
|
+
using WallstopStudios.UnityHelpers.Tags;
|
|
9
|
+
|
|
10
|
+
/// <summary>
|
|
11
|
+
/// Reflex installer that binds relational component services and optionally hydrates scenes.
|
|
12
|
+
/// </summary>
|
|
13
|
+
[AddComponentMenu("Wallstop Studios/Relational Components/Reflex Installer")]
|
|
14
|
+
public sealed class RelationalComponentsInstaller : MonoBehaviour, IInstaller
|
|
15
|
+
{
|
|
16
|
+
[SerializeField]
|
|
17
|
+
[Tooltip(
|
|
18
|
+
"When enabled, relational fields within the scene are assigned immediately after the container is built."
|
|
19
|
+
)]
|
|
20
|
+
private bool _assignSceneOnInitialize = true;
|
|
21
|
+
|
|
22
|
+
[SerializeField]
|
|
23
|
+
[Tooltip("Include inactive GameObjects when scanning for relational assignments.")]
|
|
24
|
+
private bool _includeInactiveObjects = true;
|
|
25
|
+
|
|
26
|
+
[SerializeField]
|
|
27
|
+
[Tooltip(
|
|
28
|
+
"Registers an additive scene listener that hydrates relational fields for scenes loaded additively."
|
|
29
|
+
)]
|
|
30
|
+
private bool _listenForAdditiveScenes = true;
|
|
31
|
+
|
|
32
|
+
[SerializeField]
|
|
33
|
+
[Tooltip(
|
|
34
|
+
"Use a single-pass scan when assigning relational fields for improved performance."
|
|
35
|
+
)]
|
|
36
|
+
private bool _useSinglePassScan = true;
|
|
37
|
+
|
|
38
|
+
/// <inheritdoc />
|
|
39
|
+
public void InstallBindings(ContainerBuilder builder)
|
|
40
|
+
{
|
|
41
|
+
AttributeMetadataCache cacheInstance = AttributeMetadataCache.Instance;
|
|
42
|
+
if (cacheInstance != null && !builder.HasBinding(typeof(AttributeMetadataCache)))
|
|
43
|
+
{
|
|
44
|
+
builder.AddSingleton(cacheInstance, typeof(AttributeMetadataCache));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!builder.HasBinding(typeof(IRelationalComponentAssigner)))
|
|
48
|
+
{
|
|
49
|
+
builder.AddSingleton(
|
|
50
|
+
typeof(RelationalComponentAssigner),
|
|
51
|
+
typeof(IRelationalComponentAssigner),
|
|
52
|
+
typeof(RelationalComponentAssigner)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
RelationalSceneAssignmentOptions options = new(
|
|
57
|
+
_includeInactiveObjects,
|
|
58
|
+
_useSinglePassScan
|
|
59
|
+
);
|
|
60
|
+
if (!builder.HasBinding(typeof(RelationalSceneAssignmentOptions)))
|
|
61
|
+
{
|
|
62
|
+
builder.AddSingleton(options);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
Scene installerScene = gameObject.scene;
|
|
66
|
+
|
|
67
|
+
builder.OnContainerBuilt += container =>
|
|
68
|
+
{
|
|
69
|
+
RelationalSceneAssignmentOptions assignmentOptions = options;
|
|
70
|
+
if (container.HasBinding<RelationalSceneAssignmentOptions>())
|
|
71
|
+
{
|
|
72
|
+
assignmentOptions = container.Resolve<RelationalSceneAssignmentOptions>();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
RelationalReflexSceneBootstrapper.ConfigureScene(
|
|
76
|
+
container,
|
|
77
|
+
installerScene,
|
|
78
|
+
assignmentOptions,
|
|
79
|
+
_assignSceneOnInitialize,
|
|
80
|
+
_listenForAdditiveScenes
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
#endif
|