├── .gitignore ├── CHANGELOG.md ├── CHANGELOG.md.meta ├── Editor.meta ├── Editor ├── CoreMenus.cs ├── CoreMenus.cs.meta ├── FronkonGames.GameWork.Core.Editor.asmdef └── FronkonGames.GameWork.Core.Editor.asmdef.meta ├── LICENSE.md ├── LICENSE.md.meta ├── Media.meta ├── Media ├── banner.png ├── banner.png.meta ├── banner.psd └── banner.psd.meta ├── README.md ├── README.md.meta ├── Runtime.meta ├── Runtime ├── Async.meta ├── Async │ ├── Awaiters.cs │ ├── Awaiters.cs.meta │ ├── CallbackAwaiter.cs │ ├── CallbackAwaiter.cs.meta │ ├── CallbackTask.cs │ ├── CallbackTask.cs.meta │ ├── IAwaitable.cs │ ├── IAwaitable.cs.meta │ ├── IAwaiter.cs │ └── IAwaiter.cs.meta ├── DI.meta ├── DI │ ├── DependencyContainer.cs │ ├── DependencyContainer.cs.meta │ ├── IDependencyContainer.cs │ ├── IDependencyContainer.cs.meta │ ├── IInjector.cs │ ├── IInjector.cs.meta │ ├── InjectAttribute.cs │ ├── InjectAttribute.cs.meta │ ├── Injector.cs │ ├── Injector.cs.meta │ ├── SearchIn.cs │ └── SearchIn.cs.meta ├── Events.meta ├── Events │ ├── Event.cs │ ├── Event.cs.meta │ ├── Events.cs │ ├── Events.cs.meta │ ├── ScriptableEvent.cs │ └── ScriptableEvent.cs.meta ├── FronkonGames.GameWork.Core.asmdef ├── FronkonGames.GameWork.Core.asmdef.meta ├── Game.Injection.cs ├── Game.Injection.cs.meta ├── Game.Modules.cs ├── Game.Modules.cs.meta ├── Game.MonoBehaviour.cs ├── Game.MonoBehaviour.cs.meta ├── Game.cs ├── Game.cs.meta ├── Modules.meta └── Modules │ ├── IActivable.cs │ ├── IActivable.cs.meta │ ├── IDestructible.cs │ ├── IDestructible.cs.meta │ ├── IGUI.cs │ ├── IGUI.cs.meta │ ├── IInitializable.cs │ ├── IInitializable.cs.meta │ ├── ILowMemory.cs │ ├── ILowMemory.cs.meta │ ├── IModule.cs │ ├── IModule.cs.meta │ ├── IRenderObject.cs │ ├── IRenderObject.cs.meta │ ├── ISceneLoad.cs │ ├── ISceneLoad.cs.meta │ ├── IUpdatable.cs │ ├── IUpdatable.cs.meta │ ├── MonoBehaviourModule.cs │ ├── MonoBehaviourModule.cs.meta │ ├── ScriptableModule.cs │ └── ScriptableModule.cs.meta ├── Test.meta ├── Test ├── Async.meta ├── Async │ ├── Async.Test.cs │ ├── Async.Test.cs.meta │ ├── FronkonGames.GameWork.Core.Async.Test.asmdef │ └── FronkonGames.GameWork.Core.Async.Test.asmdef.meta ├── DI.meta ├── DI │ ├── FronkonGames.GameWork.Core.DI.Test.asmdef │ ├── FronkonGames.GameWork.Core.DI.Test.asmdef.meta │ ├── Injection.Test.cs │ └── Injection.Test.cs.meta ├── Events.meta ├── Events │ ├── Events.Test.cs │ ├── Events.Test.cs.meta │ ├── FronkonGames.GameWork.Core.Events.Test.asmdef │ └── FronkonGames.GameWork.Core.Events.Test.asmdef.meta ├── Modules.meta └── Modules │ ├── FronkonGames.GameWork.Core.Modules.Test.asmdef │ ├── FronkonGames.GameWork.Core.Modules.Test.asmdef.meta │ ├── Modules.Test.cs │ └── Modules.Test.cs.meta ├── package.json └── package.json.meta /.gitignore: -------------------------------------------------------------------------------- 1 | ############################### 2 | # Unity. 3 | ############################### 4 | [Ll]ibrary/ 5 | [Tt]emp/ 6 | [Oo]bj/ 7 | [Ll]ogs/ 8 | [Ll]ibrary/ 9 | [Bb]uilds/ 10 | UnityGenerated/ 11 | UnityPackageManager/ 12 | ProBuilderPreferences.* 13 | [Rr]ecordings/ 14 | sysinfo.txt 15 | Assets/AssetStoreTools* 16 | *.pidb.meta 17 | *.pdb.meta 18 | *.stackdump 19 | project.json 20 | project.lock.json 21 | package-lock.json 22 | 23 | ############################### 24 | # Visual Studio. 25 | ############################### 26 | [Ee]xported[Oo]bj/ 27 | .vs/ 28 | *.userprefs 29 | *.csproj 30 | *.pidb 31 | *.suo 32 | *.sln* 33 | *.user 34 | *.unityproj 35 | *.booproj 36 | 37 | ############################### 38 | # Visual Studio Code. 39 | ############################### 40 | .vscode 41 | 42 | ############################### 43 | # JetBrains Rider. 44 | ############################### 45 | .idea/ 46 | /.idea 47 | JetBrains/ 48 | Unity/.idea/ 49 | JetBrains.* 50 | 51 | ############################### 52 | # DocFX. 53 | ############################### 54 | .cache 55 | /**/_site/ 56 | Documentation/api/ 57 | Documentation/index.* 58 | 59 | ############################### 60 | # OS. 61 | ############################### 62 | .DS_Store* 63 | ._* 64 | .Spotlight-V100 65 | .Trashes 66 | Icon? 67 | ehthumbs.db 68 | [Tt]humbs.db 69 | [Dd]esktop.ini 70 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.0.3 - 2024-07-09 9 | 10 | ### Added 11 | - Update to Game:Work Foundation 0.0.13. 12 | 13 | ## 0.0.2 - 2023-04-29 14 | 15 | ### Added 16 | - Changelog. 17 | - Comments. 18 | 19 | ### Changed 20 | - Game inherits from PersistentMonoBehaviourSingleton. 21 | - Module lists are ArrayList. 22 | - All tests moved to the same folder. 23 | -------------------------------------------------------------------------------- /CHANGELOG.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 59f30b7c5a963fc4d9b1222fc42e6857 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 80441a8a95733934690d5da94df7f33e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/CoreMenus.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using UnityEngine; 18 | using UnityEditor; 19 | 20 | namespace FronkonGames.GameWork.Core 21 | { 22 | /// Core menus. 23 | public static class CoreMenus 24 | { 25 | /// Open the repository. 26 | [MenuItem("Help/Fronkon Games/Game:Work/Core/Open repository")] 27 | public static void OpenRepository() => Application.OpenURL("https://github.com/FronkonGames/GameWork-Core"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Editor/CoreMenus.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c9b6df37ac09a64f92c9aad01510a6d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/FronkonGames.GameWork.Core.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FronkonGames.GameWork.Core.Editor", 3 | "references": 4 | [ 5 | "FronkonGames.GameWork.Core", 6 | "FronkonGames.Gamework.Foundation.Editor" 7 | ], 8 | "optionalUnityReferences": [], 9 | "includePlatforms": [], 10 | "excludePlatforms": [], 11 | "allowUnsafeCode": false, 12 | "overrideReferences": false, 13 | "precompiledReferences": [], 14 | "autoReferenced": true, 15 | "defineConstraints": [] 16 | } 17 | -------------------------------------------------------------------------------- /Editor/FronkonGames.GameWork.Core.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f32ed59491945147bc8c58a90bf5728 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2022 Martin Bustos 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fd775320274934448a99226cb31eac95 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Media.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b095c5bbce6c35b449175cba00834460 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Media/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FronkonGames/GameWork-Core/1f10436e9a6da88d332f10e9b2f85cb3d6709845/Media/banner.png -------------------------------------------------------------------------------- /Media/banner.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4aefafc881c928a45b93ecbd25787a4e 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 11 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | vTOnly: 0 27 | grayScaleToAlpha: 0 28 | generateCubemap: 6 29 | cubemapConvolution: 0 30 | seamlessCubemap: 0 31 | textureFormat: 1 32 | maxTextureSize: 2048 33 | textureSettings: 34 | serializedVersion: 2 35 | filterMode: 1 36 | aniso: 1 37 | mipBias: 0 38 | wrapU: 0 39 | wrapV: 0 40 | wrapW: 0 41 | nPOTScale: 1 42 | lightmap: 0 43 | compressionQuality: 50 44 | spriteMode: 0 45 | spriteExtrude: 1 46 | spriteMeshType: 1 47 | alignment: 0 48 | spritePivot: {x: 0.5, y: 0.5} 49 | spritePixelsToUnits: 100 50 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 51 | spriteGenerateFallbackPhysicsShape: 1 52 | alphaUsage: 1 53 | alphaIsTransparency: 0 54 | spriteTessellationDetail: -1 55 | textureType: 0 56 | textureShape: 1 57 | singleChannelComponent: 0 58 | flipbookRows: 1 59 | flipbookColumns: 1 60 | maxTextureSizeSet: 0 61 | compressionQualitySet: 0 62 | textureFormatSet: 0 63 | ignorePngGamma: 0 64 | applyGammaDecoding: 0 65 | platformSettings: 66 | - serializedVersion: 3 67 | buildTarget: DefaultTexturePlatform 68 | maxTextureSize: 2048 69 | resizeAlgorithm: 0 70 | textureFormat: -1 71 | textureCompression: 1 72 | compressionQuality: 50 73 | crunchedCompression: 0 74 | allowsAlphaSplitting: 0 75 | overridden: 0 76 | androidETC2FallbackOverride: 0 77 | forceMaximumCompressionQuality_BC6H_BC7: 0 78 | spriteSheet: 79 | serializedVersion: 2 80 | sprites: [] 81 | outline: [] 82 | physicsShape: [] 83 | bones: [] 84 | spriteID: 85 | internalID: 0 86 | vertices: [] 87 | indices: 88 | edges: [] 89 | weights: [] 90 | secondaryTextures: [] 91 | spritePackingTag: 92 | pSDRemoveMatte: 0 93 | pSDShowRemoveMatteOption: 0 94 | userData: 95 | assetBundleName: 96 | assetBundleVariant: 97 | -------------------------------------------------------------------------------- /Media/banner.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FronkonGames/GameWork-Core/1f10436e9a6da88d332f10e9b2f85cb3d6709845/Media/banner.psd -------------------------------------------------------------------------------- /Media/banner.psd.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c27d458542fa0d44da0bf1b7e5e73b19 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 11 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | vTOnly: 0 27 | grayScaleToAlpha: 0 28 | generateCubemap: 6 29 | cubemapConvolution: 0 30 | seamlessCubemap: 0 31 | textureFormat: 1 32 | maxTextureSize: 2048 33 | textureSettings: 34 | serializedVersion: 2 35 | filterMode: 1 36 | aniso: 1 37 | mipBias: 0 38 | wrapU: 0 39 | wrapV: 0 40 | wrapW: 0 41 | nPOTScale: 1 42 | lightmap: 0 43 | compressionQuality: 50 44 | spriteMode: 0 45 | spriteExtrude: 1 46 | spriteMeshType: 1 47 | alignment: 0 48 | spritePivot: {x: 0.5, y: 0.5} 49 | spritePixelsToUnits: 100 50 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 51 | spriteGenerateFallbackPhysicsShape: 1 52 | alphaUsage: 1 53 | alphaIsTransparency: 0 54 | spriteTessellationDetail: -1 55 | textureType: 0 56 | textureShape: 1 57 | singleChannelComponent: 0 58 | flipbookRows: 1 59 | flipbookColumns: 1 60 | maxTextureSizeSet: 0 61 | compressionQualitySet: 0 62 | textureFormatSet: 0 63 | ignorePngGamma: 0 64 | applyGammaDecoding: 0 65 | platformSettings: 66 | - serializedVersion: 3 67 | buildTarget: DefaultTexturePlatform 68 | maxTextureSize: 2048 69 | resizeAlgorithm: 0 70 | textureFormat: -1 71 | textureCompression: 1 72 | compressionQuality: 50 73 | crunchedCompression: 0 74 | allowsAlphaSplitting: 0 75 | overridden: 0 76 | androidETC2FallbackOverride: 0 77 | forceMaximumCompressionQuality_BC6H_BC7: 0 78 | spriteSheet: 79 | serializedVersion: 2 80 | sprites: [] 81 | outline: [] 82 | physicsShape: [] 83 | bones: [] 84 | spriteID: 85 | internalID: 0 86 | vertices: [] 87 | indices: 88 | edges: [] 89 | weights: [] 90 | secondaryTextures: [] 91 | spritePackingTag: 92 | pSDRemoveMatte: 0 93 | pSDShowRemoveMatteOption: 0 94 | userData: 95 | assetBundleName: 96 | assetBundleVariant: 97 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

A micro-kernel framework with dependency injection and event-driven communication.

4 | 5 |
6 |

7 | 8 | version 9 | 10 | 11 | license 12 | 13 | 14 | top language 15 | 16 |

17 |

⚠️Still In Early Development ⚠️

18 | 19 | ## 🎇 Features 20 | 21 | - Highly configurable micro-kernel architecture. 22 | - Dependency management by Injection. 23 | - Event-driven communication. 24 | 25 | ## 🔧 Requisites 26 | 27 | - Unity 2021.2 or higher. 28 | - [Game:Work Foundation](https://github.com/FronkonGames/GameWork-Foundation). 29 | - Test Framework 1.1.31 or higher. 30 | 31 | ## ⚙️ Installation 32 | 33 | ### Editing your 'manifest.json' 34 | 35 | - Open the manifest.json file of your Unity project. 36 | - In the section "dependencies" add: 37 | 38 | ``` 39 | { 40 | ... 41 | "dependencies": 42 | { 43 | ... 44 | "FronkonGames.GameWork.Foundation": "git+https://github.com/FronkonGames/GameWork-Foundation.git", 45 | "FronkonGames.GameWork.Core": "git+https://github.com/FronkonGames/GameWork-Core.git" 46 | } 47 | ... 48 | } 49 | ``` 50 | 51 | ## 🚀 Use 52 | 53 | The functionality is divided into folders, this is its structure: 54 | 55 | ``` 56 | | 57 | |\_Runtime......................... Utilities for the game. 58 | | |\_Async....................... Custom async Awaiters. 59 | | |\_DI.......................... Dependency injection management. 60 | | |\_Events...................... Event-driven communication. 61 | | |\_Modules..................... Micro kernel architecture (aka plugin-based). 62 | | \_Test........................ Unit tests. 63 | | 64 | \_Editor.......................... Editor utilities. 65 | ``` 66 | 67 | Check the comments for each file for more information. 68 | 69 | ## 📜 License 70 | 71 | Code released under [MIT License](https://github.com/FronkonGames/GameWork-Core/blob/main/LICENSE.md). -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d066d05b331bc144a8f9f7d513fa338 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a5d27c95139eb7346820f3be343fa5bf 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Async.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 45af82f7716c9bf4c9380584efc0b66d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Async/Awaiters.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using UnityEngine; 18 | using System.Threading.Tasks; 19 | 20 | namespace FronkonGames.GameWork.Core 21 | { 22 | /// Custom async Awaiters. 23 | public static class Awaiters 24 | { 25 | /// Wait for the next Update. 26 | /// Task 27 | public static async Task NextUpdate() => await (Game.Instance.NextUpdate ??= new CallbackTask()); 28 | 29 | /// Wait for the next FixedUpdate. 30 | /// Task. 31 | public static async Task NextFixedUpdate() => await (Game.Instance.NextFixedUpdate ??= new CallbackTask()); 32 | 33 | /// Wait a few seconds. 34 | /// Seconds to wait. 35 | /// Task. 36 | public static async Task Seconds(float seconds) 37 | { 38 | while (seconds >= 0.0f) 39 | { 40 | await NextUpdate(); 41 | 42 | seconds -= Time.deltaTime; 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Runtime/Async/Awaiters.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 92b9cbcb46421414a9ff7f86e385c892 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Async/CallbackAwaiter.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using System; 18 | 19 | namespace FronkonGames.GameWork.Core 20 | { 21 | /// Awaiter callback. 22 | public class CallbackAwaiter : IAwaiter 23 | { 24 | private bool completed; 25 | private Action continuation; 26 | 27 | /// Is completed? 28 | public bool IsCompleted => completed; 29 | 30 | public void GetResult() { } 31 | 32 | /// Upon completion. 33 | /// Next action. 34 | public void OnCompleted(Action continuation) 35 | { 36 | if (completed) 37 | continuation(); 38 | else 39 | this.continuation += continuation; 40 | } 41 | 42 | /// Awaiter completed. 43 | public void Complete() 44 | { 45 | completed = true; 46 | continuation?.Invoke(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Runtime/Async/CallbackAwaiter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca9bf17bb47a03142bef55d1817f427a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Async/CallbackTask.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | 18 | namespace FronkonGames.GameWork.Core 19 | { 20 | /// Callback task. 21 | public class CallbackTask : IAwaitable 22 | { 23 | /// Get Awaiter. 24 | /// Awaiter. 25 | public CallbackAwaiter Awaiter { get; } = new CallbackAwaiter(); 26 | 27 | /// Get Awaiter. 28 | /// Awaiter interface 29 | public IAwaiter GetAwaiter() => Awaiter; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Runtime/Async/CallbackTask.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3ac7e779551f9b5488b09d8285515c7a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Async/IAwaitable.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | 18 | namespace FronkonGames.GameWork.Core 19 | { 20 | /// Awater interface. 21 | public interface IAwaitable 22 | { 23 | /// Get Awaiter. 24 | /// Awaiter interface 25 | IAwaiter GetAwaiter(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Runtime/Async/IAwaitable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 52f1fd2f9ae822545909ceef9e28d1bc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Async/IAwaiter.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using System.Runtime.CompilerServices; 18 | 19 | namespace FronkonGames.GameWork.Core 20 | { 21 | /// Awater interface. 22 | public interface IAwaiter : INotifyCompletion 23 | { 24 | /// Is completed? 25 | bool IsCompleted { get; } 26 | 27 | void GetResult(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Runtime/Async/IAwaiter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d604da6ff64912e42b653181d20fd6b7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/DI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 74547d0bbe2edc444a80e4c155d70662 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/DI/DependencyContainer.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using System; 18 | using System.Collections.Generic; 19 | using FronkonGames.GameWork.Foundation; 20 | 21 | namespace FronkonGames.GameWork.Core 22 | { 23 | /// Dependency container. 24 | public sealed class DependencyContainer : IDependencyContainer 25 | { 26 | private readonly Dictionary container = new(); 27 | 28 | /// The type is registered? 29 | /// Type 30 | /// true/false 31 | public bool Contains(Type type) => container.ContainsKey(type); 32 | 33 | /// Return the object, if the type is registered. 34 | /// Type 35 | /// Object or null 36 | public object Get(Type type) 37 | { 38 | object obj = Contains(type) == true ? container[type] : null; 39 | if (obj == null) 40 | Log.Error($"Type '{type}' not registered"); 41 | 42 | return obj; 43 | } 44 | 45 | /// Record the types of objects. 46 | /// Objects 47 | public void Register(params object[] objs) 48 | { 49 | for (int i = 0; i < objs.Length; ++i) 50 | Register(objs[i]); 51 | } 52 | 53 | /// Record the type of the object. 54 | /// Object 55 | public void Register(object obj) 56 | { 57 | Type type = obj.GetType(); 58 | if (Contains(type) == false && typeof(Game).IsAssignableFrom(type) == false) 59 | container.Add(type, obj); 60 | } 61 | 62 | /// Remove a type from the register. 63 | /// Type 64 | public void Remove(Type type) 65 | { 66 | if (Contains(type) == true) 67 | container.Remove(type); 68 | else 69 | Log.Error($"Type '{type}' not registered"); 70 | } 71 | 72 | /// Eliminate all types from the register. 73 | public void Clear() => container.Clear(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Runtime/DI/DependencyContainer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 162ae95e37f40df41b93bb7732a70c16 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/DI/IDependencyContainer.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using System; 18 | 19 | namespace FronkonGames.GameWork.Core 20 | { 21 | /// Dependency container interface. 22 | public interface IDependencyContainer 23 | { 24 | /// The type is registered? 25 | /// Type 26 | /// true/false 27 | bool Contains(Type type); 28 | 29 | /// Return the object, if the type is registered. 30 | /// Type 31 | /// Object or null 32 | object Get(Type type); 33 | 34 | /// Record the types of objects. 35 | /// Objects 36 | void Register(params object[] objs); 37 | 38 | /// Record the type of the object. 39 | /// Object 40 | void Register(object obj); 41 | 42 | /// Remove a type from the register. 43 | /// Type 44 | void Remove(Type type); 45 | 46 | /// Eliminate all types from the register. 47 | void Clear(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Runtime/DI/IDependencyContainer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab81f604ba27c464fa1caac966e94f65 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/DI/IInjector.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | 18 | namespace FronkonGames.GameWork.Core 19 | { 20 | /// Injector interface. 21 | public interface IInjector 22 | { 23 | /// Add a dependencies container. 24 | /// Dependency container 25 | void AddContainer(IDependencyContainer container); 26 | 27 | /// Remove a dependencies container. 28 | /// Dependency container 29 | void RemoveContainer(IDependencyContainer container); 30 | 31 | /// Remove all dependencies containers. 32 | void RemoveAllContainers(); 33 | 34 | /// Look for 'Inject' attributes and injects available objects in the container. 35 | /// Target. 36 | void Resolve(object target); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Runtime/DI/IInjector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b5429332fa7dfba4bad6698b43448bd7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/DI/InjectAttribute.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using System; 18 | 19 | namespace FronkonGames.GameWork.Core 20 | { 21 | /// Inject attribute. 22 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] 23 | public sealed class InjectAttribute : Attribute 24 | { 25 | public readonly SearchIn mode = SearchIn.Container; 26 | 27 | public InjectAttribute(SearchIn mode = SearchIn.Container) => this.mode = mode; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Runtime/DI/InjectAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: acf78ef0b9232304d9f0c34897148ddf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/DI/Injector.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using System.Collections.Generic; 18 | using System.Reflection; 19 | using UnityEngine; 20 | using FronkonGames.GameWork.Foundation; 21 | 22 | namespace FronkonGames.GameWork.Core 23 | { 24 | /// Dependencies injector. 25 | public sealed class Injector : IInjector 26 | { 27 | private readonly List containers = new(); 28 | 29 | /// Add a dependencies container. 30 | /// Dependency container 31 | public void AddContainer(IDependencyContainer container) 32 | { 33 | if (containers.Contains(container) == false) 34 | containers.Add(container); 35 | else 36 | Log.Error("The container is already added"); 37 | } 38 | 39 | /// Remove a dependencies container. 40 | /// Dependency container 41 | public void RemoveContainer(IDependencyContainer container) 42 | { 43 | if (containers.Contains(container) == true) 44 | containers.Remove(container); 45 | else 46 | Log.Error("Container not found"); 47 | } 48 | 49 | /// Remove all dependencies containers. 50 | public void RemoveAllContainers() => containers.Clear(); 51 | 52 | /// Look for 'Inject' attributes and injects available objects in the container. 53 | /// Target. 54 | public void Resolve(object target) 55 | { 56 | // Variables. 57 | FieldInfo[] fieldInfos = target.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); 58 | for (int i = 0; i < fieldInfos.Length; ++i) 59 | InjectField(target, fieldInfos[i]); 60 | 61 | // Properties. 62 | PropertyInfo[] propertyInfos = target.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); 63 | for (int i = 0; i < propertyInfos.Length; ++i) 64 | InjectProperty(target, propertyInfos[i]); 65 | } 66 | 67 | private void InjectField(object target, FieldInfo fieldInfo) 68 | { 69 | InjectAttribute injectAttribute = fieldInfo.GetCustomAttribute(); 70 | if (injectAttribute != null) 71 | { 72 | if (injectAttribute.mode == SearchIn.Container) 73 | { 74 | bool dependencyFound = false; 75 | for (int i = 0; i < containers.Count; i++) 76 | { 77 | if (containers[i].Contains(fieldInfo.FieldType) == true) 78 | { 79 | Log.Info($"'{target}' inject with {fieldInfo.FieldType}"); 80 | fieldInfo.SetValue(target, containers[i].Get(fieldInfo.FieldType)); 81 | dependencyFound = true; 82 | break; 83 | } 84 | } 85 | 86 | if (dependencyFound == false) 87 | Log.Error($"Type '{fieldInfo.FieldType}' not registered"); 88 | } 89 | else 90 | { 91 | CachedMonoBehaviour monoBehaviour = target as CachedMonoBehaviour; 92 | if (monoBehaviour != null) 93 | { 94 | Component component = null; 95 | if (injectAttribute.mode == SearchIn.Components) 96 | component = monoBehaviour.GetComponent(fieldInfo.FieldType); 97 | else if (injectAttribute.mode == SearchIn.Parent) 98 | component = monoBehaviour.GetComponentInParent(fieldInfo.FieldType); 99 | else if (injectAttribute.mode == SearchIn.Childrens) 100 | component = monoBehaviour.GetComponentInChildren(fieldInfo.FieldType); 101 | 102 | if (component != null) 103 | { 104 | Log.Info($"'{target}' inject with {component}"); 105 | fieldInfo.SetValue(target, component); 106 | } 107 | else 108 | Log.Error($"Type '{fieldInfo.FieldType}' not found in '{monoBehaviour.name}'"); 109 | } 110 | else 111 | Log.Error($"'{target}' is not a CachedMonoBehaviour"); 112 | } 113 | } 114 | } 115 | 116 | private void InjectProperty(object target, PropertyInfo propertyInfo) 117 | { 118 | InjectAttribute injectAttribute = propertyInfo.GetCustomAttribute(); 119 | if (injectAttribute != null) 120 | { 121 | Log.Info($"Injecting '{target}' {propertyInfo.PropertyType}"); 122 | 123 | if (injectAttribute.mode == SearchIn.Container) 124 | { 125 | bool dependencyFound = false; 126 | for (int i = 0; i < containers.Count; i++) 127 | { 128 | if (containers[i].Contains(propertyInfo.PropertyType) == true) 129 | { 130 | Log.Info($"'{target}' inject with {propertyInfo.PropertyType}"); 131 | propertyInfo.SetValue(target, containers[i].Get(propertyInfo.PropertyType)); 132 | dependencyFound = true; 133 | break; 134 | } 135 | } 136 | 137 | if (dependencyFound == false) 138 | Log.Error($"Type '{propertyInfo.PropertyType}' not registered"); 139 | } 140 | else 141 | { 142 | CachedMonoBehaviour monoBehaviour = target as CachedMonoBehaviour; 143 | if (monoBehaviour != null) 144 | { 145 | Component component = null; 146 | if (injectAttribute.mode == SearchIn.Components) 147 | component = monoBehaviour.GetComponent(propertyInfo.PropertyType); 148 | else if (injectAttribute.mode == SearchIn.Parent) 149 | component = monoBehaviour.GetComponentInParent(propertyInfo.PropertyType); 150 | else if (injectAttribute.mode == SearchIn.Childrens) 151 | component = monoBehaviour.GetComponentInChildren(propertyInfo.PropertyType); 152 | 153 | if (component != null) 154 | { 155 | Log.Info($"'{target}' inject with {component}"); 156 | propertyInfo.SetValue(target, component); 157 | } 158 | else 159 | Log.Error($"Type '{propertyInfo.PropertyType}' not found in '{monoBehaviour.name}'"); 160 | } 161 | else 162 | Log.Error($"'{target}' is not a CachedMonoBehaviour"); 163 | } 164 | } 165 | } 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /Runtime/DI/Injector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: da145712c11e89a4b9326e9ea487fc70 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/DI/SearchIn.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | 18 | namespace FronkonGames.GameWork.Core 19 | { 20 | /// Dependencies search modes. 21 | public enum SearchIn 22 | { 23 | ///Find dependencies registered in a container (default). 24 | Container, 25 | 26 | ///Find dependencies at the Components. Only available for CachedMonoBehaviour. 27 | Components, 28 | 29 | ///Find dependencies at the parent. Only available for CachedMonoBehaviour. 30 | Parent, 31 | 32 | ///Find dependencies at the childrens. Only available for CachedMonoBehaviour. 33 | Childrens, 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Runtime/DI/SearchIn.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ebc9bb635562ec8489b960f6f61ab65f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Events.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 699d00b03c4ff2046ba5587acd962ece 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Events/Event.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using UnityEngine; 18 | using UnityEngine.Events; 19 | using FronkonGames.GameWork.Foundation; 20 | 21 | namespace FronkonGames.GameWork.Core 22 | { 23 | /// Event without parameters. 24 | public class Event : ScriptableEvent 25 | { 26 | [SerializeField] 27 | private UnityEvent events = new(); 28 | 29 | /// Invokes the event. 30 | public override void Raise() => events.Invoke(); 31 | 32 | /// Subscribes call to the event. 33 | /// Action 34 | public void Subscribe(UnityAction call) 35 | { 36 | Check.IsNotNull(call); 37 | events.AddListener(call); 38 | } 39 | 40 | /// Unsubscribe call to the event. 41 | /// Action 42 | public void Unsubscribe(UnityAction call) 43 | { 44 | Check.IsNotNull(call); 45 | events.RemoveListener(call); 46 | } 47 | 48 | /// Remove all event subscriptions. 49 | public override void UnsubscribeAll() => events.RemoveAllListeners(); 50 | } 51 | 52 | /// Event with one parameter. 53 | public class Event : ScriptableEvent 54 | { 55 | /// First parameter. 56 | public T0 Value { get; set; } 57 | 58 | [SerializeField] 59 | private UnityEvent events = new(); 60 | 61 | /// Invokes the event. 62 | public override void Raise() => Raise(Value); 63 | 64 | /// Invokes the event. 65 | public void Raise(T0 value) 66 | { 67 | Value = value; 68 | 69 | events.Invoke(value); 70 | } 71 | 72 | /// Subscribes call to the event. 73 | /// Action 74 | public void Subscribe(UnityAction call) 75 | { 76 | Check.IsNotNull(call); 77 | events.AddListener(call); 78 | } 79 | 80 | /// Unsubscribe call to the event. 81 | /// Action 82 | public void Unsubscribe(UnityAction call) 83 | { 84 | Check.IsNotNull(call); 85 | events.RemoveListener(call); 86 | } 87 | 88 | /// Remove all event subscriptions. 89 | public override void UnsubscribeAll() => events.RemoveAllListeners(); 90 | } 91 | 92 | /// Event with two parameters. 93 | public class Event : ScriptableEvent 94 | { 95 | /// First parameter. 96 | public T0 Value0 { get; set; } 97 | 98 | /// Second parameter. 99 | public T1 Value1 { get; set; } 100 | 101 | [SerializeField] 102 | private UnityEvent events = new(); 103 | 104 | /// Invokes the event. 105 | public override void Raise() => Raise(Value0, Value1); 106 | 107 | /// Invokes the event. 108 | public void Raise(T0 value0, T1 value1) 109 | { 110 | Value0 = value0; 111 | Value1 = value1; 112 | 113 | events.Invoke(value0, value1); 114 | } 115 | 116 | /// Subscribes call to the event. 117 | /// Action 118 | public void Subscribe(UnityAction call) 119 | { 120 | Check.IsNotNull(call); 121 | events.AddListener(call); 122 | } 123 | 124 | /// Unsubscribe call to the event. 125 | /// Action 126 | public void Unsubscribe(UnityAction call) 127 | { 128 | Check.IsNotNull(call); 129 | events.RemoveListener(call); 130 | } 131 | 132 | /// Remove all event subscriptions. 133 | public override void UnsubscribeAll() => events.RemoveAllListeners(); 134 | } 135 | 136 | /// Event with three parameters. 137 | public class Event : ScriptableEvent 138 | { 139 | /// First parameter. 140 | public T0 Value0 { get; set; } 141 | 142 | /// Second parameter. 143 | public T1 Value1 { get; set; } 144 | 145 | /// Third parameter. 146 | public T2 Value2 { get; set; } 147 | 148 | [SerializeField] 149 | private UnityEvent events = new(); 150 | 151 | /// Invokes the event. 152 | public override void Raise() => Raise(Value0, Value1, Value2); 153 | 154 | /// Invokes the event. 155 | public void Raise(T0 value0, T1 value1, T2 value2) 156 | { 157 | Value0 = value0; 158 | Value1 = value1; 159 | Value2 = value2; 160 | 161 | events.Invoke(value0, value1, value2); 162 | } 163 | 164 | /// Subscribes call to the event. 165 | /// Action 166 | public void Subscribe(UnityAction call) 167 | { 168 | Check.IsNotNull(call); 169 | events.AddListener(call); 170 | } 171 | 172 | /// Unsubscribe call to the event. 173 | /// Action 174 | public void Unsubscribe(UnityAction call) 175 | { 176 | Check.IsNotNull(call); 177 | events.RemoveListener(call); 178 | } 179 | 180 | /// Remove all event subscriptions. 181 | public override void UnsubscribeAll() => events.RemoveAllListeners(); 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /Runtime/Events/Event.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5d057c6025dbb58459d97b66f3696afa 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Events/Events.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using UnityEngine; 18 | 19 | namespace FronkonGames.GameWork.Core 20 | { 21 | /// Event without parameters. 22 | [CreateAssetMenu(fileName = "VoidEvent", menuName = "Game:Work/Events/Void")] 23 | public class VoidEvent : Event { } 24 | 25 | /// Event with Byte parameter. 26 | [CreateAssetMenu(fileName = "ByteEvent", menuName = "Game:Work/Events/Byte")] 27 | public class ByteEvent : Event { } 28 | 29 | /// Event with Bool parameter. 30 | [CreateAssetMenu(fileName = "BoolEvent", menuName = "Game:Work/Events/Bool")] 31 | public class BoolEvent : Event 32 | { 33 | /// Invoke the event by changing the value. 34 | public void RaiseToggled() => Raise(!Value); 35 | } 36 | 37 | /// Event with int parameter. 38 | [CreateAssetMenu(fileName = "IntEvent", menuName = "Game:Work/Events/Int")] 39 | public class IntEvent : Event { } 40 | 41 | /// Event with float parameter. 42 | [CreateAssetMenu(fileName = "FloatEvent", menuName = "Game:Work/Events/Float")] 43 | public class FloatEvent : Event { } 44 | 45 | /// Event with string parameter. 46 | [CreateAssetMenu(fileName = "StringEvent", menuName = "Game:Work/Events/String")] 47 | public class StringEvent : Event { } 48 | 49 | /// Event with Vector2 parameter. 50 | [CreateAssetMenu(fileName = "Vector2Event", menuName = "Game:Work/Events/Vector2")] 51 | public class Vector2Event : Event { } 52 | 53 | /// Event with Vector3 parameter. 54 | [CreateAssetMenu(fileName = "Vector3Event", menuName = "Game:Work/Events/Vector3")] 55 | public class Vector3Event : Event { } 56 | 57 | /// Event with Quaternion parameter. 58 | [CreateAssetMenu(fileName = "QuaternionEvent", menuName = "Game:Work/Events/Quaternion")] 59 | public class QuaternionEvent : Event { } 60 | 61 | /// Event with GameObject parameter. 62 | [CreateAssetMenu(fileName = "GameObjectEvent", menuName = "Game:Work/Events/GameObject")] 63 | public class GameObjectEvent : Event { } 64 | 65 | /// Event with Component parameter. 66 | [CreateAssetMenu(fileName = "ComponentEvent", menuName = "Game:Work/Events/Component")] 67 | public class ComponentEvent : Event { } 68 | } 69 | -------------------------------------------------------------------------------- /Runtime/Events/Events.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 15caaa5da68a9bc4fb2c6fd3ee8d1a3f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Events/ScriptableEvent.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using UnityEngine; 18 | 19 | namespace FronkonGames.GameWork.Core 20 | { 21 | /// Scriptable event base. 22 | public abstract class ScriptableEvent : ScriptableObject 23 | { 24 | /// Invokes the event. 25 | public abstract void Raise(); 26 | 27 | /// Eliminate all event subscriptions. 28 | public abstract void UnsubscribeAll(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Runtime/Events/ScriptableEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 58af6b6c730a2c348a8c8c8ddb888fda 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/FronkonGames.GameWork.Core.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FronkonGames.GameWork.Core", 3 | "references": 4 | [ 5 | "FronkonGames.GameWork.Foundation" 6 | ], 7 | "optionalUnityReferences": [], 8 | "includePlatforms": [], 9 | "excludePlatforms": [], 10 | "allowUnsafeCode": false, 11 | "overrideReferences": false, 12 | "precompiledReferences": [], 13 | "autoReferenced": true, 14 | "defineConstraints": [] 15 | } 16 | -------------------------------------------------------------------------------- /Runtime/FronkonGames.GameWork.Core.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f55aacded615254a8ee20a156b43e4a 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/Game.Injection.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | //#define ENABLE_PROFILING 18 | using System.Collections.Generic; 19 | using UnityEngine; 20 | using UnityEngine.SceneManagement; 21 | using FronkonGames.GameWork.Foundation; 22 | 23 | namespace FronkonGames.GameWork.Core 24 | { 25 | /// Module manager and persistent singleton. 26 | public abstract partial class Game : PersistentMonoBehaviourSingleton, 27 | IInitializable, 28 | IUpdatable, 29 | IDestructible 30 | { 31 | protected IInjector injector; 32 | protected IDependencyContainer sceneDependencyContainer; 33 | protected IDependencyContainer childDependencyContainer; 34 | 35 | private void ResolveChildsDependencies() 36 | { 37 | #if ENABLE_PROFILING 38 | using (Profiling.Time("Resolve childs dependencies")) 39 | #endif 40 | { 41 | childDependencyContainer.Clear(); 42 | 43 | MonoBehaviour[] monoBehaviours = this.gameObject.GetComponentsInChildren(); 44 | 45 | for (int i = 0; i < monoBehaviours.Length; ++i) 46 | { 47 | if (typeof(IModule).IsAssignableFrom(monoBehaviours[i].GetType()) == true) 48 | { 49 | RegisterModule(monoBehaviours[i]); 50 | 51 | childDependencyContainer.Register(monoBehaviours[i]); 52 | } 53 | } 54 | 55 | for (int i = 0; i < monoBehaviours.Length; ++i) 56 | injector.Resolve(monoBehaviours[i]); 57 | } 58 | } 59 | 60 | private void ResolveLoadedSceneDependencies() 61 | { 62 | #if ENABLE_PROFILING 63 | using (Profiling.Time("Resolve scene dependencies")) 64 | #endif 65 | { 66 | sceneDependencyContainer.Clear(); 67 | 68 | List monoBehaviours = new(); 69 | for (int i = 0; i < SceneManager.sceneCount; ++i) 70 | { 71 | Scene scene = SceneManager.GetSceneAt(i); 72 | GameObject[] rootGameObjects = scene.GetRootGameObjects(); 73 | 74 | for (int j = 0; j < rootGameObjects.Length; ++j) 75 | { 76 | List gameObjects = rootGameObjects[j].GetAllChildrenAndSelf(); 77 | for (int k = 0; k < gameObjects.Count; ++k) 78 | monoBehaviours.AddRange(gameObjects[k].GetComponents()); 79 | } 80 | } 81 | 82 | for (int i = 0; i < monoBehaviours.Count; ++i) 83 | sceneDependencyContainer.Register(monoBehaviours[i]); 84 | 85 | for (int i = 0; i < monoBehaviours.Count; ++i) 86 | injector.Resolve(monoBehaviours[i]); 87 | } 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /Runtime/Game.Injection.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4da28bf8ffd60774aac530f4332eb9c0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Game.Modules.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using System; 18 | using System.Collections.Generic; 19 | using UnityEngine; 20 | using FronkonGames.GameWork.Foundation; 21 | 22 | namespace FronkonGames.GameWork.Core 23 | { 24 | /// Module manager and persistent singleton. 25 | public abstract partial class Game : PersistentMonoBehaviourSingleton, 26 | IInitializable, 27 | IUpdatable, 28 | IDestructible 29 | { 30 | private readonly ArrayList initializables = new(); 31 | private readonly ArrayList activables = new(); 32 | private readonly ArrayList updatables = new(); 33 | private readonly ArrayList GUIables = new(); 34 | private readonly ArrayList renderableObjects = new(); 35 | private readonly ArrayList destructibles = new(); 36 | private readonly ArrayList sceneLoads = new(); 37 | #if UNITY_ANDROID || UNITY_IOS 38 | private readonly ArrayList lowMemories = new(); 39 | #endif 40 | private readonly ArrayList allModules = new(); 41 | 42 | /// Register modules. 43 | /// Only allowed in OnInitialize. 44 | /// List of modules. 45 | public void RegisterModule(params object[] modules) 46 | { 47 | if (Initialized == true || sceneLoaded == true) 48 | Log.Error("Cannot to registered outsize of OnInitialize cycle"); 49 | 50 | for (int i = 0; i < modules.Length; ++i) 51 | RegisterModule(modules[i]); 52 | } 53 | 54 | /// Register modules by type and create them. 55 | /// Only allowed in OnInitialize. 56 | /// Types of modules. 57 | public void RegisterModule(params Type[] types) 58 | { 59 | if (Initialized == true || sceneLoaded == true) 60 | Log.Error("Cannot to registered outsize of OnInitialize cycle"); 61 | 62 | for (int i = 0; i < types.Length; ++i) 63 | { 64 | if (typeof(IModule).IsAssignableFrom(types[i]) == true) 65 | { 66 | IModule module = null; 67 | if (typeof(MonoBehaviourModule).IsAssignableFrom(types[i]) == false) 68 | module = Activator.CreateInstance(types[i]) as IModule; 69 | else 70 | { 71 | GameObject gameObject = new GameObject(types[i].Name); 72 | module = gameObject.AddComponent(types[i]) as IModule; 73 | } 74 | 75 | if (module != null) 76 | RegisterModule(module); 77 | else 78 | Log.Error($"'{types[i]}' null, not register to the Game"); 79 | } 80 | else 81 | Log.Error($"'{types[i]}' unknown, not register to the Game"); 82 | } 83 | } 84 | 85 | /// Unregister modules. 86 | /// Listado de modulos. 87 | public void UnregisterModule(params object[] modules) 88 | { 89 | for (int i = 0; i < modules.Length; ++i) 90 | UnregisterModule(modules[i]); 91 | } 92 | 93 | /// The module is registered? 94 | /// Type of module. 95 | /// True if you are registered. 96 | public bool HasModule() where T : IModule 97 | { 98 | for (int i = 0; i < allModules.Count; ++i) 99 | { 100 | if (allModules[i] is T) 101 | return true; 102 | } 103 | 104 | return false; 105 | } 106 | 107 | /// Returns the first module of a type (or null). 108 | /// Module type 109 | /// Module or null 110 | public T GetModule() where T : IModule 111 | { 112 | for (int i = 0; i < allModules.Count; ++i) 113 | { 114 | if (allModules[i] is T t) 115 | return t; 116 | } 117 | 118 | Log.Error($"Module {typeof(T).Name} not register"); 119 | 120 | return default; 121 | } 122 | 123 | /// Returns all modules of a type (or empty). 124 | /// Module type 125 | /// List of modules 126 | public List GetModules() where T : IModule 127 | { 128 | List modules = new(); 129 | for (int i = 0; i < allModules.Count; ++i) 130 | { 131 | if (allModules[i] is T t) 132 | modules.Add(t); 133 | } 134 | 135 | return modules; 136 | } 137 | 138 | private void RegisterModule(object obj) 139 | { 140 | Type type = obj.GetType(); 141 | 142 | if (typeof(IInitializable).IsAssignableFrom(type) == true) 143 | { 144 | IInitializable initializable = obj as IInitializable; 145 | initializable.OnInitialize(); 146 | 147 | initializables.Add(initializable); 148 | } 149 | 150 | if (typeof(IActivable).IsAssignableFrom(type) == true) 151 | activables.Add(obj as IActivable); 152 | 153 | if (typeof(IUpdatable).IsAssignableFrom(type) == true) 154 | updatables.Add(obj as IUpdatable); 155 | 156 | if (typeof(IGUI).IsAssignableFrom(type) == true) 157 | GUIables.Add(obj as IGUI); 158 | 159 | if (typeof(IRenderObject).IsAssignableFrom(type) == true) 160 | renderableObjects.Add(obj as IRenderObject); 161 | 162 | if (typeof(IDestructible).IsAssignableFrom(type) == true) 163 | destructibles.Add(obj as IDestructible); 164 | 165 | if (typeof(ISceneLoad).IsAssignableFrom(type) == true) 166 | sceneLoads.Add(obj as ISceneLoad); 167 | 168 | #if UNITY_ANDROID || UNITY_IOS 169 | if (typeof(ILowMemory).IsAssignableFrom(type) == true) 170 | lowMemories.Add(module as ILowMemory); 171 | #endif 172 | 173 | if (typeof(IModule).IsAssignableFrom(type) == true) 174 | allModules.Add(obj as IModule); 175 | else 176 | Log.Error($"Object '{type.Name}' is not a valid module"); 177 | } 178 | 179 | private void UnregisterModule(object module) 180 | { 181 | Type type = module.GetType(); 182 | if (allModules.Contains(module as IModule) == true) 183 | { 184 | if (typeof(IInitializable).IsAssignableFrom(type) == true) 185 | { 186 | IInitializable initializable = module as IInitializable; 187 | initializable.OnDeinitialize(); 188 | 189 | initializables.Remove(initializable); 190 | } 191 | 192 | if (typeof(IActivable).IsAssignableFrom(type) == true) 193 | activables.Remove(module as IActivable); 194 | 195 | if (typeof(IUpdatable).IsAssignableFrom(type) == true) 196 | updatables.Remove(module as IUpdatable); 197 | 198 | if (typeof(IGUI).IsAssignableFrom(type) == true) 199 | GUIables.Remove(module as IGUI); 200 | 201 | if (typeof(IRenderObject).IsAssignableFrom(type) == true) 202 | renderableObjects.Remove(module as IRenderObject); 203 | 204 | if (typeof(IDestructible).IsAssignableFrom(type) == true) 205 | destructibles.Remove(module as IDestructible); 206 | 207 | if (typeof(ISceneLoad).IsAssignableFrom(type) == true) 208 | sceneLoads.Remove(module as ISceneLoad); 209 | 210 | #if UNITY_ANDROID || UNITY_IOS 211 | if (typeof(ILowMemory).IsAssignableFrom(type) == true) 212 | lowMemories.Remove(module as ILowMemory); 213 | #endif 214 | 215 | allModules.Remove(module as IModule); 216 | } 217 | else 218 | Log.Error($"Object '{type.Name}' is not a valid module"); 219 | 220 | if (sceneDependencyContainer.Contains(type) == true) 221 | sceneDependencyContainer.Remove(type); 222 | } 223 | } 224 | } 225 | -------------------------------------------------------------------------------- /Runtime/Game.Modules.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0fbed50e9ad19ea4dbc506e358b40e91 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Game.MonoBehaviour.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using UnityEngine; 18 | using UnityEngine.SceneManagement; 19 | using FronkonGames.GameWork.Foundation; 20 | 21 | namespace FronkonGames.GameWork.Core 22 | { 23 | /// Module manager and persistent singleton. 24 | public abstract partial class Game : PersistentMonoBehaviourSingleton, 25 | IInitializable, 26 | IUpdatable, 27 | IDestructible 28 | { 29 | /// During the awake, this system will start the initialization. 30 | private void Awake() { } 31 | 32 | /// This function is called when the object becomes enabled and active. 33 | private void OnEnable() { } 34 | 35 | /// This function is called when the behaviour becomes disabled or inactive. 36 | private void OnDisable() 37 | { 38 | for (int i = 0; i < initializables.Count; ++i) 39 | { 40 | if (initializables[i].Initialized == true) 41 | { 42 | initializables[i].OnDeinitialize(); 43 | initializables[i].Initialized = false; 44 | } 45 | } 46 | 47 | if (this.Initialized == true) 48 | { 49 | this.OnDeinitialize(); 50 | this.Initialized = false; 51 | } 52 | } 53 | 54 | /// Update is called every frame, if the MonoBehaviour is enabled. 55 | private void Update() 56 | { 57 | if (this.Initialized == false || sceneLoaded == true) 58 | { 59 | if (this.Initialized == false) 60 | ResolveChildsDependencies(); 61 | 62 | ResolveLoadedSceneDependencies(); 63 | 64 | if (this.Initialized == false) 65 | { 66 | this.OnInitialized(); 67 | this.Initialized = true; 68 | } 69 | 70 | for (int i = 0; i < initializables.Count; ++i) 71 | { 72 | if (initializables[i].Initialized == false) 73 | { 74 | initializables[i].Initialized = true; 75 | initializables[i].OnInitialized(); 76 | } 77 | } 78 | 79 | sceneLoaded = false; 80 | } 81 | 82 | if (ShouldUpdate == true && this.WillDestroy == false) 83 | { 84 | this.OnUpdate(); 85 | 86 | for (int i = 0; i < updatables.Count; ++i) 87 | { 88 | if (updatables[i].ShouldUpdate == true) 89 | updatables[i].OnUpdate(); 90 | } 91 | } 92 | 93 | if (NextUpdate != null) 94 | { 95 | CallbackAwaiter awaiter = NextUpdate.Awaiter; 96 | NextUpdate = null; 97 | awaiter.Complete(); 98 | } 99 | } 100 | 101 | /// This function is called every fixed framerate frame, if the MonoBehaviour is enabled. 102 | private void FixedUpdate() 103 | { 104 | if (ShouldUpdate == true && this.WillDestroy == false) 105 | { 106 | this.OnFixedUpdate(); 107 | 108 | for (int i = 0; i < updatables.Count; ++i) 109 | { 110 | if (updatables[i].ShouldUpdate == true) 111 | updatables[i].OnFixedUpdate(); 112 | } 113 | } 114 | 115 | if (NextFixedUpdate != null) 116 | { 117 | CallbackAwaiter awaiter = NextFixedUpdate.Awaiter; 118 | NextFixedUpdate = null; 119 | awaiter.Complete(); 120 | } 121 | } 122 | 123 | /// 124 | /// LateUpdate is called every frame, if the Behaviour is enabled. 125 | /// It is called after all Update functions have been called. 126 | /// 127 | private void LateUpdate() 128 | { 129 | if (ShouldUpdate == true && this.WillDestroy == false) 130 | { 131 | this.OnLateUpdate(); 132 | 133 | for (int i = 0; i < updatables.Count; ++i) 134 | { 135 | if (updatables[i].ShouldUpdate == true) 136 | updatables[i].OnLateUpdate(); 137 | } 138 | } 139 | } 140 | 141 | /// OnRenderObject is called after camera has rendered the scene. 142 | private void OnRenderObject() 143 | { 144 | for (int i = 0; i < renderableObjects.Count; ++i) 145 | renderableObjects[i].OnRenderObject(); 146 | } 147 | 148 | /// This function is called when the MonoBehaviour will be destroyed. 149 | protected override void OnDestroy() 150 | { 151 | SceneManager.sceneLoaded -= OnSceneLoaded; 152 | SceneManager.sceneUnloaded -= OnSceneUnloaded; 153 | 154 | this.WillDestroy = true; 155 | 156 | for (int i = 0; i < destructibles.Count; ++i) 157 | { 158 | destructibles[i].WillDestroy = true; 159 | destructibles[i].OnWillDestroy(); 160 | } 161 | 162 | this.OnWillDestroy(); 163 | 164 | initializables.Clear(); 165 | activables.Clear(); 166 | updatables.Clear(); 167 | GUIables.Clear(); 168 | renderableObjects.Clear(); 169 | destructibles.Clear(); 170 | sceneLoads.Clear(); 171 | #if UNITY_ANDROID || UNITY_IOS 172 | lowMemories.Clear(); 173 | #endif 174 | allModules.Clear(); 175 | 176 | sceneDependencyContainer.Clear(); 177 | 178 | #if UNITY_ANDROID || UNITY_IOS 179 | Application.lowMemory -= OnLowMemory; 180 | #endif 181 | Application.wantsToQuit -= OnWantsToQuit; 182 | 183 | base.OnDestroy(); 184 | } 185 | 186 | #if UNITY_EDITOR 187 | /// Callback to draw gizmos that are pickable and always drawn. 188 | private void OnDrawGizmos() 189 | { 190 | for (int i = 0; i < GUIables.Count; ++i) 191 | GUIables[i].OnGizmos(); 192 | } 193 | #endif 194 | 195 | /// OnGUI is called for rendering and handling GUI events. 196 | private void OnGUI() 197 | { 198 | for (int i = 0; i < GUIables.Count; ++i) 199 | GUIables[i].OnGUI(); 200 | } 201 | 202 | /// Callback sent to all game objects before the application is quit. 203 | private void OnApplicationQuit() 204 | { 205 | this.WillDestroy = true; 206 | 207 | for (int i = 0; i < destructibles.Count; ++i) 208 | destructibles[i].WillDestroy = true; 209 | } 210 | 211 | #if UNITY_ANDROID || UNITY_IOS 212 | /// This event occurs when your app receives a low-memory notification from the device it is running on. 213 | private void OnLowMemory() 214 | { 215 | for (int i = 0; i < lowMemories.Count; ++i) 216 | lowMemories[i].OnLowMemory(); 217 | } 218 | #endif 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /Runtime/Game.MonoBehaviour.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fd880324af44cb04d85f600e26411eac 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Game.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using UnityEngine; 18 | using UnityEngine.SceneManagement; 19 | using FronkonGames.GameWork.Foundation; 20 | 21 | namespace FronkonGames.GameWork.Core 22 | { 23 | /// Module manager and persistent singleton. 24 | public abstract partial class Game : PersistentMonoBehaviourSingleton, 25 | IInitializable, 26 | IUpdatable, 27 | IDestructible 28 | { 29 | /// Initialized? 30 | /// True/false. 31 | public bool Initialized { get; set; } 32 | 33 | /// Should be updated? 34 | /// True/false. 35 | public bool ShouldUpdate { get; set; } = true; 36 | 37 | /// Will it be destroyed? 38 | /// True si va a destruirse. 39 | public bool WillDestroy { get; set; } 40 | 41 | public CallbackTask NextUpdate { get; set; } 42 | public CallbackTask NextFixedUpdate { get; set; } 43 | 44 | /// On initialize. 45 | public virtual void OnInitialize() { } 46 | 47 | /// 48 | /// At the end of initialization. 49 | /// Called in the first Update frame. 50 | /// 51 | public virtual void OnInitialized() { } 52 | 53 | /// On deinitialize. 54 | public virtual void OnDeinitialize() { } 55 | 56 | /// Update event. 57 | public virtual void OnUpdate() { } 58 | 59 | /// FixedUpdate event. 60 | public virtual void OnFixedUpdate() { } 61 | 62 | /// LateUpdate event. 63 | public virtual void OnLateUpdate() { } 64 | 65 | /// On destroy. 66 | public virtual void OnWillDestroy() { } 67 | 68 | private bool sceneLoaded; 69 | 70 | private void EntryPoint() 71 | { 72 | DontDestroyOnLoad(this.gameObject); 73 | 74 | SceneManager.sceneLoaded += OnSceneLoaded; 75 | SceneManager.sceneUnloaded += OnSceneUnloaded; 76 | 77 | sceneDependencyContainer = new DependencyContainer(); 78 | childDependencyContainer = new DependencyContainer(); 79 | 80 | injector = new Injector(); 81 | injector.AddContainer(sceneDependencyContainer); 82 | injector.AddContainer(childDependencyContainer); 83 | 84 | Application.wantsToQuit += OnWantsToQuit; 85 | #if UNITY_ANDROID || UNITY_IOS 86 | Application.lowMemory += OnLowMemory; 87 | #endif 88 | this.OnInitialize(); 89 | } 90 | 91 | [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)] 92 | private static void OnBeforeSplashScreen() 93 | { 94 | if (FindObjectOfType() != null) 95 | Game.Instance.EntryPoint(); 96 | } 97 | 98 | private void OnSceneLoaded(Scene current, LoadSceneMode mode) 99 | { 100 | sceneLoaded = true; 101 | 102 | for (int i = 0; i < sceneLoads.Count; ++i) 103 | sceneLoads[i].OnSceneLoad(current.buildIndex); 104 | } 105 | 106 | private void OnSceneUnloaded(Scene current) 107 | { 108 | for (int i = 0; i < sceneLoads.Count; ++i) 109 | sceneLoads[i].OnSceneUnload(); 110 | } 111 | 112 | private bool OnWantsToQuit() 113 | { 114 | // At the end of the execution, Unity calls OnDisable when there are already non valid objects. 115 | // Calling OnDeinitialize here ensures that objects are still valid and can be used. 116 | for (int i = 0; i < initializables.Count; ++i) 117 | { 118 | if (initializables[i].Initialized == true) 119 | { 120 | initializables[i].OnDeinitialize(); 121 | initializables[i].Initialized = false; 122 | } 123 | } 124 | 125 | if (this.Initialized == true) 126 | { 127 | this.OnDeinitialize(); 128 | this.Initialized = false; 129 | } 130 | 131 | this.WillDestroy = true; 132 | 133 | return true; 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /Runtime/Game.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1f487ff71c5249448e990a0677bdb48 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Modules.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ea7c2114dbdc89b498aa527285b65bab 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Modules/IActivable.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | namespace FronkonGames.GameWork.Core 18 | { 19 | /// It can be activated and deactivated. 20 | public interface IActivable : IModule 21 | { 22 | /// It is activated? 23 | /// True if it is activated 24 | bool Activated { get; set; } 25 | 26 | /// When activated. 27 | void OnActivated(); 28 | 29 | /// When deactivating. 30 | void OnDeactivated(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Runtime/Modules/IActivable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 10b2d4b79d6240449832ce666616ba80 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Modules/IDestructible.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | namespace FronkonGames.GameWork.Core 18 | { 19 | /// It can be destroyed. 20 | public interface IDestructible : IModule 21 | { 22 | /// Will it be destroyed? 23 | /// True if it is to be destroyed. 24 | bool WillDestroy { get; set; } 25 | 26 | /// When destroyed. 27 | void OnWillDestroy(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Runtime/Modules/IDestructible.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2f8931b1a4499324b916e4410f41de57 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Modules/IGUI.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | namespace FronkonGames.GameWork.Core 18 | { 19 | /// Draw in OnDrawGizmos and/or OnGUI. 20 | public interface IGUI : IModule 21 | { 22 | /// OnDrawGizmos event. 23 | void OnGizmos(); 24 | 25 | /// OnGUI event. 26 | void OnGUI(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Runtime/Modules/IGUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 29e1ce37d0b49a04f95bf79941ab0e0b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Modules/IInitializable.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | namespace FronkonGames.GameWork.Core 18 | { 19 | /// It can initialize and disincialize. 20 | public interface IInitializable : IModule 21 | { 22 | /// Is it initialized? 23 | /// Value 24 | bool Initialized { get; set; } 25 | 26 | /// When initialize. 27 | void OnInitialize(); 28 | 29 | /// 30 | /// At the end of initialization. 31 | /// Called in the first Update frame. 32 | /// 33 | void OnInitialized(); 34 | 35 | /// When deinitialize. 36 | void OnDeinitialize(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Runtime/Modules/IInitializable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f74c8eef845bba409d2b7a919445a45 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Modules/ILowMemory.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | namespace FronkonGames.GameWork.Core 18 | { 19 | /// 20 | /// When a low memory warning is received. 21 | /// Only in iOS and Android. 22 | /// 23 | public interface ILowMemory : IModule 24 | { 25 | /// Low memory event. 26 | void OnLowMemory(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Runtime/Modules/ILowMemory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed028ad04508c784cb642494c4634210 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Modules/IModule.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | namespace FronkonGames.GameWork.Core 18 | { 19 | /// Module interface. 20 | public interface IModule 21 | { 22 | } 23 | } -------------------------------------------------------------------------------- /Runtime/Modules/IModule.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6cec883a9961ec84da70c86078cfaaf2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Modules/IRenderObject.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | namespace FronkonGames.GameWork.Core 18 | { 19 | /// Use OnRenderObject. 20 | public interface IRenderObject : IModule 21 | { 22 | /// OnRenderObject event. 23 | void OnRenderObject(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Runtime/Modules/IRenderObject.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9ff9774f783c5714da6acffb114d4e9e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Modules/ISceneLoad.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | namespace FronkonGames.GameWork.Core 18 | { 19 | /// Scene un/loaded. 20 | public interface ISceneLoad : IModule 21 | { 22 | /// Scene is loaded. 23 | void OnSceneLoad(int sceneBuildIndex); 24 | 25 | /// Scene is unloaded. 26 | void OnSceneUnload(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Runtime/Modules/ISceneLoad.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 54e1ad95142e7304b9e77db6077a21f9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Modules/IUpdatable.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | namespace FronkonGames.GameWork.Core 18 | { 19 | /// It can be updated. 20 | public interface IUpdatable : IModule 21 | { 22 | /// Should be updated? 23 | /// True/false. 24 | bool ShouldUpdate { get; } 25 | 26 | /// Update event. 27 | void OnUpdate(); 28 | 29 | /// FixedUpdate event. 30 | void OnFixedUpdate(); 31 | 32 | /// LateUpdate event. 33 | void OnLateUpdate(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Runtime/Modules/IUpdatable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 32c6842df0d361c47a746fd9f12d9ebe 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Modules/MonoBehaviourModule.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using FronkonGames.GameWork.Foundation; 18 | 19 | namespace FronkonGames.GameWork.Core 20 | { 21 | /// CachedMonoBehaviour module. 22 | public abstract class MonoBehaviourModule : CachedMonoBehaviour, IModule 23 | { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Runtime/Modules/MonoBehaviourModule.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6be5262b7ae5ae4893b63be8ed7145a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Modules/ScriptableModule.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using UnityEngine; 18 | 19 | namespace FronkonGames.GameWork.Core 20 | { 21 | /// Serializable ScriptableObject module. 22 | public abstract class ScriptableModule : ScriptableObject, IModule 23 | { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Runtime/Modules/ScriptableModule.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bac5f88d39d4f754ab2451dd6196fb4b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Test.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cbb78861161e14b4ca956ea127f6aba9 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Test/Async.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1c90d9c61bcd07340a69910429bdb792 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Test/Async/Async.Test.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using System.Collections; 18 | using NUnit.Framework; 19 | using UnityEngine; 20 | using UnityEngine.Events; 21 | using UnityEngine.TestTools; 22 | using FronkonGames.GameWork.Core; 23 | 24 | /// Async test. 25 | public partial class AsyncTests 26 | { 27 | /// 28 | /// Async test. 29 | /// 30 | [UnityTest] 31 | public IEnumerator Async() 32 | { 33 | // @TODO: Wait to Unity Test Framework v2.0 34 | 35 | yield return null; 36 | } 37 | } -------------------------------------------------------------------------------- /Test/Async/Async.Test.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b99c5bfeb0cc80c4abbf26554daf35c3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Test/Async/FronkonGames.GameWork.Core.Async.Test.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FronkonGames.GameWork.Core.Async.Test", 3 | "references": [ 4 | "FronkonGames.GameWork.Core", 5 | "FronkonGames.GameWork.Foundation" 6 | ], 7 | "optionalUnityReferences": [ "TestAssemblies" ], 8 | "includePlatforms": [ "Editor" ], 9 | "excludePlatforms": [], 10 | "allowUnsafeCode": false 11 | } -------------------------------------------------------------------------------- /Test/Async/FronkonGames.GameWork.Core.Async.Test.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 297454a7217dbf54c9509c0dbce24388 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Test/DI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 834412d383c742549adeca07ab2557ca 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Test/DI/FronkonGames.GameWork.Core.DI.Test.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FronkonGames.GameWork.Core.DI.Test", 3 | "references": [ 4 | "FronkonGames.GameWork.Core", 5 | "FronkonGames.GameWork.Foundation" 6 | ], 7 | "optionalUnityReferences": [ "TestAssemblies" ], 8 | "includePlatforms": [ "Editor" ], 9 | "excludePlatforms": [], 10 | "allowUnsafeCode": false 11 | } -------------------------------------------------------------------------------- /Test/DI/FronkonGames.GameWork.Core.DI.Test.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e6387b89e36ed97468612ec642552f72 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Test/DI/Injection.Test.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using System.Collections; 18 | using NUnit.Framework; 19 | using UnityEngine; 20 | using UnityEngine.TestTools; 21 | using FronkonGames.GameWork.Foundation; 22 | using FronkonGames.GameWork.Core; 23 | 24 | /// Injection test. 25 | public partial class InjectionTests 26 | { 27 | public class ClassA { } 28 | public class ClassB { } 29 | 30 | public class TestInjection 31 | { 32 | public ClassA ClassA => testA; 33 | 34 | [Inject] 35 | public ClassB ClassB { get; set; } 36 | 37 | [Inject] 38 | private ClassA testA; 39 | } 40 | 41 | public class BehaviourA : MonoBehaviour { } 42 | 43 | public class BehaviourB : CachedMonoBehaviour 44 | { 45 | public BehaviourA BehaviourA => behaviourA; 46 | 47 | [Inject(SearchIn.Parent)] 48 | private BehaviourA behaviourA; 49 | } 50 | 51 | public class MonoBehaviourInjectionTest : CachedMonoBehaviour 52 | { 53 | public BehaviourA BehaviourA => behaviourA; 54 | 55 | public BehaviourB BehaviourB => behaviourB; 56 | 57 | [Inject(SearchIn.Components)] 58 | private BehaviourA behaviourA; 59 | 60 | [Inject(SearchIn.Childrens)] 61 | private BehaviourB behaviourB; 62 | } 63 | 64 | /// 65 | /// Injection test. 66 | /// 67 | [UnityTest] 68 | public IEnumerator Injection() 69 | { 70 | DependencyContainer dependencyContainer = new DependencyContainer(); 71 | Injector injector = new Injector(); 72 | injector.AddContainer(dependencyContainer); 73 | 74 | TestInjection testInjection = new TestInjection(); 75 | 76 | ClassA classA = new ClassA(); 77 | ClassB classB = new ClassB(); 78 | dependencyContainer.Register(classA, classB); 79 | 80 | injector.Resolve(testInjection); 81 | 82 | Assert.NotNull(testInjection.ClassA); 83 | Assert.NotNull(testInjection.ClassB); 84 | 85 | GameObject gameObject = new GameObject(); 86 | gameObject.AddComponent(); 87 | 88 | GameObject child = new GameObject(); 89 | child.transform.parent = gameObject.transform; 90 | BehaviourB behaviourB = child.AddComponent(); 91 | 92 | MonoBehaviourInjectionTest monoBehaviourInjectionTest = gameObject.AddComponent(); 93 | 94 | injector.Resolve(monoBehaviourInjectionTest); 95 | injector.Resolve(behaviourB); 96 | 97 | Assert.NotNull(monoBehaviourInjectionTest.BehaviourA); 98 | Assert.NotNull(monoBehaviourInjectionTest.BehaviourB); 99 | Assert.NotNull(behaviourB.BehaviourA); 100 | 101 | yield return null; 102 | } 103 | } -------------------------------------------------------------------------------- /Test/DI/Injection.Test.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1c588005542721a4cad933a3bb1223fa 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Test/Events.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f79f7db0d0c5aa64999c85e12d366751 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Test/Events/Events.Test.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using System.Collections; 18 | using NUnit.Framework; 19 | using UnityEngine; 20 | using UnityEngine.Events; 21 | using UnityEngine.TestTools; 22 | using FronkonGames.GameWork.Core; 23 | 24 | /// Events test. 25 | public partial class EventsTests 26 | { 27 | public class TestEvents 28 | { 29 | public UnityAction voidAction; 30 | public UnityAction byteAction; 31 | public UnityAction boolAction; 32 | public UnityAction intAction; 33 | public UnityAction floatAction; 34 | public UnityAction stringAction; 35 | public UnityAction vector2Action; 36 | public UnityAction vector3Action; 37 | public UnityAction quaternionAction; 38 | public UnityAction gameObjectAction; 39 | public UnityAction componentAction; 40 | 41 | public bool boolValue = false; 42 | public byte byteValue = 0; 43 | public int intValue = 0; 44 | public float floatValue = 0.0f; 45 | public string stringValue = string.Empty; 46 | public Vector2 vector2Value = Vector2.zero; 47 | public Vector3 vector3Value = Vector3.zero; 48 | public Quaternion quaternionValue = Quaternion.identity; 49 | public GameObject gameObjectValue = null; 50 | public Component componentValue = null; 51 | 52 | private void VoidFunc() => boolValue = !boolValue; 53 | private void ByteFunc(byte value) => byteValue = value; 54 | private void BoolFunc(bool value) => boolValue = value; 55 | private void IntFunc(int value) => intValue = value; 56 | private void FloatFunc(float value) => floatValue = value; 57 | private void StringFunc(string value) => stringValue = value; 58 | private void Vector2Func(Vector2 value) => vector2Value = value; 59 | private void Vector3Func(Vector3 value) => vector3Value = value; 60 | private void QuaternionFunc(Quaternion value) => quaternionValue = value; 61 | private void GameObjectFunc(GameObject value) => gameObjectValue = value; 62 | private void ComponentFunc(Component value) => componentValue = value; 63 | 64 | public TestEvents() 65 | { 66 | voidAction += VoidFunc; 67 | byteAction += ByteFunc; 68 | boolAction += BoolFunc; 69 | intAction += IntFunc; 70 | floatAction += FloatFunc; 71 | stringAction += StringFunc; 72 | vector2Action += Vector2Func; 73 | vector3Action += Vector3Func; 74 | quaternionAction += QuaternionFunc; 75 | gameObjectAction += GameObjectFunc; 76 | componentAction += ComponentFunc; 77 | } 78 | } 79 | 80 | /// 81 | /// Events test. 82 | /// 83 | [UnityTest] 84 | public IEnumerator Events() 85 | { 86 | TestEvents testEvents = new TestEvents(); 87 | 88 | VoidEvent voidEvent = ScriptableObject.CreateInstance(); 89 | ByteEvent byteEvent = ScriptableObject.CreateInstance(); 90 | BoolEvent boolEvent = ScriptableObject.CreateInstance(); 91 | IntEvent intEvent = ScriptableObject.CreateInstance(); 92 | FloatEvent floatEvent = ScriptableObject.CreateInstance(); 93 | StringEvent stringEvent = ScriptableObject.CreateInstance(); 94 | Vector2Event vector2Event = ScriptableObject.CreateInstance(); 95 | Vector3Event vector3Event = ScriptableObject.CreateInstance(); 96 | QuaternionEvent quaternionEvent = ScriptableObject.CreateInstance(); 97 | GameObjectEvent gameObjectEvent = ScriptableObject.CreateInstance(); 98 | ComponentEvent componentEvent = ScriptableObject.CreateInstance(); 99 | 100 | voidEvent.Subscribe(testEvents.voidAction); 101 | voidEvent.Raise(); 102 | Assert.IsTrue(testEvents.boolValue); 103 | voidEvent.Unsubscribe(testEvents.voidAction); 104 | voidEvent.Raise(); 105 | Assert.IsTrue(testEvents.boolValue); 106 | 107 | byteEvent.Subscribe(testEvents.byteAction); 108 | byteEvent.Raise(1); 109 | Assert.AreEqual(testEvents.byteValue, 1); 110 | byteEvent.Unsubscribe(testEvents.byteAction); 111 | 112 | boolEvent.Subscribe(testEvents.boolAction); 113 | boolEvent.Raise(false); 114 | Assert.IsFalse(testEvents.boolValue); 115 | boolEvent.Unsubscribe(testEvents.boolAction); 116 | 117 | intEvent.Subscribe(testEvents.intAction); 118 | intEvent.Raise(1); 119 | Assert.AreEqual(testEvents.intValue, 1); 120 | intEvent.Unsubscribe(testEvents.intAction); 121 | 122 | floatEvent.Subscribe(testEvents.floatAction); 123 | floatEvent.Raise(1.0f); 124 | Assert.AreEqual(testEvents.intValue, 1.0f); 125 | floatEvent.Unsubscribe(testEvents.floatAction); 126 | 127 | stringEvent.Subscribe(testEvents.stringAction); 128 | stringEvent.Raise("raised"); 129 | Assert.AreEqual(testEvents.stringValue, "raised"); 130 | stringEvent.Unsubscribe(testEvents.stringAction); 131 | 132 | vector2Event.Subscribe(testEvents.vector2Action); 133 | vector2Event.Raise(Vector2.one); 134 | Assert.AreEqual(testEvents.vector2Value, Vector2.one); 135 | vector2Event.Unsubscribe(testEvents.vector2Action); 136 | 137 | vector3Event.Subscribe(testEvents.vector3Action); 138 | vector3Event.Raise(Vector2.one); 139 | Assert.AreEqual(testEvents.vector2Value, Vector2.one); 140 | vector2Event.Unsubscribe(testEvents.vector2Action); 141 | 142 | quaternionEvent.Subscribe(testEvents.quaternionAction); 143 | quaternionEvent.Raise(Quaternion.Euler(90.0f, 0.0f, 0.0f)); 144 | Assert.AreEqual(testEvents.quaternionValue, Quaternion.Euler(90.0f, 0.0f, 0.0f)); 145 | quaternionEvent.Unsubscribe(testEvents.quaternionAction); 146 | 147 | GameObject gameObject = new GameObject(); 148 | gameObjectEvent.Subscribe(testEvents.gameObjectAction); 149 | gameObjectEvent.Raise(gameObject); 150 | Assert.AreEqual(testEvents.gameObjectValue, gameObject); 151 | gameObjectEvent.Unsubscribe(testEvents.gameObjectAction); 152 | 153 | Transform transform = gameObject.GetComponent(); 154 | componentEvent.Subscribe(testEvents.componentAction); 155 | componentEvent.Raise(transform); 156 | Assert.IsNotNull(testEvents.componentAction); 157 | componentEvent.Unsubscribe(testEvents.componentAction); 158 | 159 | yield return null; 160 | } 161 | } -------------------------------------------------------------------------------- /Test/Events/Events.Test.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 32ec60831e0d52644b3ad9cadfd0ef78 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Test/Events/FronkonGames.GameWork.Core.Events.Test.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FronkonGames.GameWork.Core.Events.Test", 3 | "references": [ 4 | "FronkonGames.GameWork.Core", 5 | "FronkonGames.GameWork.Foundation" 6 | ], 7 | "optionalUnityReferences": [ "TestAssemblies" ], 8 | "includePlatforms": [ "Editor" ], 9 | "excludePlatforms": [], 10 | "allowUnsafeCode": false 11 | } -------------------------------------------------------------------------------- /Test/Events/FronkonGames.GameWork.Core.Events.Test.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 03592410f4b58f8499e7b1056a563426 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Test/Modules.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3798f9569516542448c2c2964bf488b7 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Test/Modules/FronkonGames.GameWork.Core.Modules.Test.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FronkonGames.GameWork.Core.Modules.Test", 3 | "references": [ 4 | "FronkonGames.GameWork.Core", 5 | "FronkonGames.GameWork.Foundation" 6 | ], 7 | "optionalUnityReferences": [ "TestAssemblies" ], 8 | "includePlatforms": [ "Editor" ], 9 | "excludePlatforms": [], 10 | "allowUnsafeCode": false 11 | } -------------------------------------------------------------------------------- /Test/Modules/FronkonGames.GameWork.Core.Modules.Test.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a8f7ee45bde1faf48ad4cc9ee145d74f 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Test/Modules/Modules.Test.cs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Martin Bustos @FronkonGames 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 5 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | // permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // 9 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 10 | // the Software. 11 | // 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 13 | // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 14 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 15 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 16 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 17 | using System.Collections; 18 | using NUnit.Framework; 19 | using UnityEngine; 20 | using UnityEngine.Events; 21 | using UnityEngine.TestTools; 22 | using FronkonGames.GameWork.Core; 23 | 24 | /// Modules test. 25 | public partial class ModulesTests 26 | { 27 | /// 28 | /// Modules test. 29 | /// 30 | [UnityTest] 31 | public IEnumerator Modules() 32 | { 33 | // @TODO: Wait to Unity Test Framework v2.0 34 | 35 | yield return null; 36 | } 37 | } -------------------------------------------------------------------------------- /Test/Modules/Modules.Test.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 60a5d033b79637d48b42e298ee01bcfd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.frokongames.gamework.core", 3 | "version": "0.0.2", 4 | "displayName": "Game:Work Core", 5 | "decription": "A micro-kernel framework with dependency injection and event-driven communication.", 6 | "references": [ ], 7 | "unity": "2020.3", 8 | "unityRelease": "26f1", 9 | "optionalUnityReferences": [], 10 | "includePlatforms": [], 11 | "excludePlatforms": [], 12 | "allowUnsafeCode": false, 13 | "overrideReferences": false, 14 | "precompiledReferences": [], 15 | "autoReferenced": true, 16 | "defineConstraints": [], 17 | "dependencies": { }, 18 | "keywords": [ "unity", "gamedev", "framework", "game development", "gamework", "micro-kernel" ], 19 | "category": "Unity", 20 | "repository": 21 | { 22 | "type": "git", 23 | "url": "git+https://github.com/FronkonGames/GameWork-Core.git" 24 | }, 25 | "author": 26 | { 27 | "name": "Martin Bustos", 28 | "email": "fronkongames@gmail.com", 29 | "url": "https://fronkongames.github.io/" 30 | } 31 | } -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1a1991bb1b6960649930653b60cf12c9 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------