├── .github └── workflows │ └── Generate Documentation.yml ├── .gitignore ├── .viewer └── data.json ├── Assets ├── XRI.meta └── XRI │ ├── Settings.meta │ └── Settings │ ├── Resources.meta │ ├── Resources │ ├── InteractionLayerSettings.asset │ ├── InteractionLayerSettings.asset.meta │ ├── XRDeviceSimulatorSettings.asset │ └── XRDeviceSimulatorSettings.asset.meta │ ├── XRInteractionEditorSettings.asset │ └── XRInteractionEditorSettings.asset.meta ├── Documentation ├── Documentation.iml ├── TocGeneration.bat ├── docfx.json ├── filterConfig.yml ├── index.md ├── resources │ ├── ExampleManual.png │ └── ExampleScriptingApi.png ├── templates │ └── unity │ │ ├── partials │ │ ├── head.tmpl.partial │ │ └── toc.yml │ │ ├── styles │ │ ├── docfx.js │ │ ├── main.css │ │ └── toc.yml │ │ └── toc.yml └── toc.yml ├── Logs └── Packages-Update.log ├── Packages ├── Unity_Extensions │ ├── Scripts.meta │ ├── Scripts │ │ ├── AspectRatio.cs │ │ ├── AspectRatio.cs.meta │ │ ├── AwaitExtensions.cs │ │ ├── AwaitExtensions.cs.meta │ │ ├── ByteExtensions.cs │ │ ├── ByteExtensions.cs.meta │ │ ├── CameraExtensions.cs │ │ ├── CameraExtensions.cs.meta │ │ ├── ColorExtensions.cs │ │ ├── ColorExtensions.cs.meta │ │ ├── Colors.cs │ │ ├── Colors.cs.meta │ │ ├── DateTimeExtensions.cs │ │ ├── DateTimeExtensions.cs.meta │ │ ├── DebugExtension.cs │ │ ├── DebugExtension.cs.meta │ │ ├── DictionaryExtensions.cs │ │ ├── DictionaryExtensions.cs.meta │ │ ├── EditorExtensions.cs │ │ ├── EditorExtensions.cs.meta │ │ ├── EnumExtensions.cs │ │ ├── EnumExtensions.cs.meta │ │ ├── EnumerableExtensions.cs │ │ ├── EnumerableExtensions.cs.meta │ │ ├── FileExtensions.cs │ │ ├── FileExtensions.cs.meta │ │ ├── GameObjectExtensions.cs │ │ ├── GameObjectExtensions.cs.meta │ │ ├── ImageExtensions.cs │ │ ├── ImageExtensions.cs.meta │ │ ├── Input.meta │ │ ├── Input │ │ │ ├── InputExtensions.cs │ │ │ ├── InputExtensions.cs.meta │ │ │ ├── gg.extensions.Input.asmdef │ │ │ └── gg.extensions.Input.asmdef.meta │ │ ├── LayerMaskExtensions.cs │ │ ├── LayerMaskExtensions.cs.meta │ │ ├── MathsExtensions.cs │ │ ├── MathsExtensions.cs.meta │ │ ├── MiscExtensions.cs │ │ ├── MiscExtensions.cs.meta │ │ ├── NumberExtensions.cs │ │ ├── NumberExtensions.cs.meta │ │ ├── RectTramsformExtensions.cs │ │ ├── RectTramsformExtensions.cs.meta │ │ ├── RendererExtensions.cs │ │ ├── RendererExtensions.cs.meta │ │ ├── SecurityExtensions.cs │ │ ├── SecurityExtensions.cs.meta │ │ ├── StringExtensions.cs │ │ ├── StringExtensions.cs.meta │ │ ├── TransformExtensions.cs │ │ ├── TransformExtensions.cs.meta │ │ ├── UIExtensions.cs │ │ ├── UIExtensions.cs.meta │ │ ├── VectorExtensions.cs │ │ ├── VectorExtensions.cs.meta │ │ ├── VersionExtension.cs │ │ ├── VersionExtension.cs.meta │ │ ├── WebExtensions.cs │ │ ├── WebExtensions.cs.meta │ │ ├── XR.meta │ │ ├── XR │ │ │ ├── LayerMaskExtensions.cs │ │ │ ├── LayerMaskExtensions.cs.meta │ │ │ ├── XrExtensions.cs │ │ │ ├── XrExtensions.cs.meta │ │ │ ├── gg.extensions.Xr.asmdef │ │ │ └── gg.extensions.Xr.asmdef.meta │ │ ├── gg.extensions.asmdef │ │ └── gg.extensions.asmdef.meta │ ├── package.json │ └── package.json.meta ├── manifest.json └── packages-lock.json ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── MemorySettings.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── PackageManagerSettings.asset ├── Physics2DSettings.asset ├── PresetManager.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset ├── UnityConnectSettings.asset ├── VFXManager.asset ├── VersionControlSettings.asset └── XRSettings.asset ├── README.MD └── UserSettings └── EditorUserSettings.asset /.github/workflows/Generate Documentation.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: Generate Documentation 4 | 5 | # Controls when the action will run. 6 | on: 7 | push: 8 | tags: 9 | - '*' 10 | 11 | # Allows you to run this workflow manually from the Actions tab 12 | workflow_dispatch: 13 | 14 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 15 | jobs: 16 | # This workflow contains a single job called "build" 17 | build: 18 | runs-on: ubuntu-latest 19 | env: 20 | UNITY_LICENSE: ${{ secrets.UNITY_LICENCE_2019_4_12F1 }} 21 | steps: 22 | - name: Checkout 23 | uses: actions/checkout@v2 24 | # with: 25 | # submodules: true 26 | 27 | - uses: game-ci/unity-builder@v2.0-alpha-6 28 | with: 29 | buildMethod: UnityEditor.SyncVS.SyncSolution 30 | targetPlatform: StandaloneWindows 31 | 32 | - name: Build 33 | uses: nikeee/docfx-action@v1.0.0 34 | with: 35 | args: Documentation/docfx.json 36 | 37 | # Upload the generated documentation 38 | - name: Upload site artifact 39 | uses: actions/upload-artifact@v2 40 | with: 41 | name: _site 42 | path: _site # Must equals the 'build.dest' value on your docfx.json 43 | 44 | # Deploy the generated documentation to the gh-pages branch 45 | deploy: 46 | needs: build 47 | runs-on: ubuntu-latest 48 | steps: 49 | - name: Checkout 50 | uses: actions/checkout@v2 51 | # with: 52 | # submodules: true 53 | 54 | # Download the generated documentation 55 | - name: Download site artifact 56 | uses: actions/download-artifact@v2 57 | with: 58 | name: _site 59 | path: _site 60 | 61 | - name: Deploy 62 | uses: peaceiris/actions-gh-pages@v3 63 | with: 64 | github_token: ${{ secrets.GITHUB_TOKEN }} 65 | publish_branch: gh-pages 66 | publish_dir: _site -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Bb]uild/ 5 | [Bb]uilds/ 6 | [Ll]ogs/ 7 | Assets/AssetStoreTools* 8 | 9 | # Jetbrain Rider Cache 10 | .idea/ 11 | Assets/Plugins/Editor/JetBrains* 12 | 13 | # Visual Studio cache directory 14 | .vs/ 15 | 16 | # Autogenerated VS/MD/Consulo solution and project files 17 | ExportedObj/ 18 | .consulo/ 19 | *.csproj 20 | *.unityproj 21 | *.sln 22 | *.suo 23 | *.tmp 24 | *.user 25 | *.userprefs 26 | *.pidb 27 | *.booproj 28 | *.svd 29 | *.pdb 30 | *.opendb 31 | *.log 32 | 33 | # Unity3D generated meta files 34 | *.pidb.meta 35 | *.pdb.meta 36 | 37 | # Unity3D Generated File On Crash Reports 38 | sysinfo.txt 39 | 40 | # Builds 41 | *.apk 42 | *.unitypackage 43 | 44 | # Pointclouds 45 | /[Pp]ointcloud/ 46 | /[Pp]ointclouds/ 47 | 48 | # Misc 49 | Dev/ 50 | Screenshots/ 51 | Docs/ 52 | Logs/ 53 | *ProjectSettings/ProjectVersion.txt 54 | Logs 55 | UserSettings 56 | -------------------------------------------------------------------------------- /.viewer/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "image_url": 3 | [ 4 | "https://i.redd.it/tu3gt6ysfxq71.png", 5 | "http://www.ikozmik.com/Content/Images/uploaded/its-free-featured.jpg" 6 | ], 7 | "description": "This is a description to see how it pulls though into the website", 8 | "path": "Unity/Utilities" 9 | } 10 | -------------------------------------------------------------------------------- /Assets/XRI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 771d42a9ca295ab4ca46204fce1a4f80 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/XRI/Settings.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1914785bdded58d4b96db9559f9fa9b3 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/XRI/Settings/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4994a1c1c705869478b49293dc647aa8 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/XRI/Settings/Resources/InteractionLayerSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: 191492db6e452eb468b95433ec162164, type: 3} 13 | m_Name: InteractionLayerSettings 14 | m_EditorClassIdentifier: 15 | m_LayerNames: 16 | - Default 17 | - 18 | - 19 | - 20 | - 21 | - 22 | - 23 | - 24 | - 25 | - 26 | - 27 | - 28 | - 29 | - 30 | - 31 | - 32 | - 33 | - 34 | - 35 | - 36 | - 37 | - 38 | - 39 | - 40 | - 41 | - 42 | - 43 | - 44 | - 45 | - 46 | - 47 | - 48 | -------------------------------------------------------------------------------- /Assets/XRI/Settings/Resources/InteractionLayerSettings.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2490dedba365bf14a929d9bb022fe19e 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/XRI/Settings/Resources/XRDeviceSimulatorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: 690929a59dc7a42da9030305190d391f, type: 3} 13 | m_Name: XRDeviceSimulatorSettings 14 | m_EditorClassIdentifier: 15 | m_AutomaticallyInstantiateSimulatorPrefab: 0 16 | m_AutomaticallyInstantiateInEditorOnly: 1 17 | m_SimulatorPrefab: {fileID: 0} 18 | -------------------------------------------------------------------------------- /Assets/XRI/Settings/Resources/XRDeviceSimulatorSettings.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 80baa52e50397d14c8903c08960aa1dd 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/XRI/Settings/XRInteractionEditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: 2d38fb1463c5c804b8847c20e8873623, type: 3} 13 | m_Name: XRInteractionEditorSettings 14 | m_EditorClassIdentifier: 15 | m_InteractionLayerUpdaterShown: 1 16 | m_ShowOldInteractionLayerMaskInInspector: 0 17 | -------------------------------------------------------------------------------- /Assets/XRI/Settings/XRInteractionEditorSettings.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a39036753e5b6e740bb40a97daa52ddf 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Documentation/Documentation.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Documentation/TocGeneration.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | SET mypath=%~dp0 3 | echo %mypath:~0,-1% 4 | pwsh.exe -Command "& {import-module docfx-toc-generator;Build-TocHereRecursive;}" 5 | PAUSE -------------------------------------------------------------------------------- /Documentation/docfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": [ 3 | { 4 | "src": 5 | [ 6 | { 7 | "src": "../", 8 | "files": [ "**.csproj" ] 9 | } 10 | ], 11 | "globalNamespaceId": "Global", 12 | "filter": "filterConfig.yml", 13 | "dest": "api" 14 | } 15 | ], 16 | "build": { 17 | "globalMetadata": { 18 | "_appTitle": "Documentation", 19 | "_appFooter": "Documentation", 20 | "_enableSearch": true 21 | }, 22 | "content": [ 23 | { 24 | "files": [ "toc.yml", "index.md" ] 25 | }, 26 | { 27 | "src": "api", 28 | "files": [ "*.yml" ], 29 | "dest": "api" 30 | } 31 | ], 32 | "resource": [ 33 | { 34 | "files": [ "resources/**/*" ] 35 | } 36 | ], 37 | "xref": [ "https://nicoco007.github.io/UnityXRefMap/2019.4/xrefmap.yml" ], 38 | "xrefService": [ "https://xref.docs.microsoft.com/query?uid={uid}" ], 39 | "dest": "../_site" 40 | } 41 | } -------------------------------------------------------------------------------- /Documentation/filterConfig.yml: -------------------------------------------------------------------------------- 1 | apiRules: 2 | - include: 3 | uidRegex: ^Global 4 | type: Namespace 5 | - include: 6 | uidRegex: ^GG 7 | type: Namespace 8 | - exclude: 9 | uidRegex: .* # Every other namespaces are ignored 10 | type: Namespace -------------------------------------------------------------------------------- /Documentation/index.md: -------------------------------------------------------------------------------- 1 | # Title 2 | 3 | content content 4 | -------------------------------------------------------------------------------- /Documentation/resources/ExampleManual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Greener-Games/Unity_Extensions/3aee50d54739f70b7eb474ec691c0a29ba9c2e66/Documentation/resources/ExampleManual.png -------------------------------------------------------------------------------- /Documentation/resources/ExampleScriptingApi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Greener-Games/Unity_Extensions/3aee50d54739f70b7eb474ec691c0a29ba9c2e66/Documentation/resources/ExampleScriptingApi.png -------------------------------------------------------------------------------- /Documentation/templates/unity/partials/head.tmpl.partial: -------------------------------------------------------------------------------- 1 | {{!Copyright (c) Marvin Neurath. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.}} 2 | 3 | 4 | 5 | 6 | {{#title}}{{title}}{{/title}}{{^title}}{{>partials/title}}{{/title}} {{#_appTitle}}| {{_appTitle}} {{/_appTitle}} 7 | 8 | 9 | 10 | {{#_description}}{{/_description}} 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | {{#_noindex}}{{/_noindex}} 19 | {{#_enableSearch}}{{/_enableSearch}} 20 | {{#_enableNewTab}}{{/_enableNewTab}} 21 | -------------------------------------------------------------------------------- /Documentation/templates/unity/partials/toc.yml: -------------------------------------------------------------------------------- 1 | [] 2 | 3 | -------------------------------------------------------------------------------- /Documentation/templates/unity/styles/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: #465563; 3 | font-family: 'Roboto', sans-serif; 4 | line-height: 1.5; 5 | font-size: 16px; 6 | -ms-text-size-adjust: 100%; 7 | -webkit-text-size-adjust: 100%; 8 | word-wrap: break-word 9 | } 10 | 11 | #wrapper { 12 | min-height: 100%; 13 | position: absolute; 14 | width: -webkit-fill-available; 15 | } 16 | 17 | /* HEADINGS */ 18 | 19 | h1 { 20 | font-weight: 600; 21 | font-size: 32px; 22 | color: #000; 23 | } 24 | 25 | h2 { 26 | font-weight: 600; 27 | font-size: 24px; 28 | line-height: 1.8; 29 | color: #000; 30 | } 31 | 32 | h3 { 33 | font-weight: 600; 34 | font-size: 20px; 35 | line-height: 1.8; 36 | color: #000; 37 | } 38 | 39 | h5 { 40 | font-size: 14px; 41 | padding: 10px 0px; 42 | color: #000; 43 | font-weight: bold; 44 | } 45 | 46 | article h1, article h2, article h3, article h4 { 47 | margin-top: 35px; 48 | margin-bottom: 15px; 49 | } 50 | 51 | article h4 { 52 | padding-bottom: 8px; 53 | border-bottom: 2px solid #ddd; 54 | } 55 | 56 | /* NAVBAR */ 57 | 58 | .navbar-brand>img { 59 | color: #fff; 60 | } 61 | 62 | .navbar { 63 | border: none; 64 | /* Both navbars use box-shadow */ 65 | -webkit-box-shadow: 0px 1px 3px 0px rgba(100, 100, 100, 0.5); 66 | -moz-box-shadow: 0px 1px 3px 0px rgba(100, 100, 100, 0.5); 67 | box-shadow: 0px 1px 3px 0px rgba(100, 100, 100, 0.5); 68 | } 69 | 70 | .subnav { 71 | border-top: 1px solid #ddd; 72 | background-color: #fff; 73 | } 74 | 75 | .navbar-inverse { 76 | background-color: #262f39; 77 | z-index: 100; 78 | } 79 | 80 | ul.level1.breadcrumb>li>a { 81 | color: #d54473; 82 | } 83 | 84 | .navbar-inverse .navbar-nav>li>a, .navbar-inverse .navbar-text { 85 | color: #fff; 86 | background-color: #262f39; 87 | border-bottom: 3px solid transparent; 88 | padding-bottom: 12px; 89 | text-decoration: none; 90 | } 91 | 92 | .navbar-inverse .navbar-nav>li>a:focus, .navbar-inverse .navbar-nav>li>a:hover { 93 | color: #00cccc; 94 | background-color: #262f39; 95 | border-bottom: 3px solid white; 96 | } 97 | 98 | .navbar-inverse .navbar-nav>.active>a, .navbar-inverse .navbar-nav>.active>a:focus, .navbar-inverse .navbar-nav>.active>a:hover { 99 | color: #00cccc; 100 | background-color: #262f39; 101 | border-bottom: 3px solid white; 102 | text-decoration: underline; 103 | } 104 | 105 | .navbar-form .form-control { 106 | border: none; 107 | border-radius: 20px; 108 | } 109 | 110 | /* SIDEBAR */ 111 | 112 | .toc { 113 | margin: 0px 1px 0px 0px; 114 | padding: 0 20px; 115 | } 116 | 117 | .toc .level1>li { 118 | font-weight: 400; 119 | } 120 | 121 | .toc .nav>li>a { 122 | color: #455463; 123 | text-decoration: none; 124 | } 125 | 126 | .toc .nav>li>a:hover { 127 | color: #455463; 128 | text-decoration: underline; 129 | } 130 | 131 | /*selected element in sidebar at level 2*/ 132 | ul.nav.level2>li.active.in>a.active { 133 | background: #222c37; 134 | color: #fff; 135 | padding: 5px 8px; 136 | text-decoration: none; 137 | font-weight: normal; 138 | } 139 | 140 | .toc .nav>li.active>.expand-stub::before, .toc .nav>li.in>.expand-stub::before, .toc .nav>li.in.active>.expand-stub::before, .toc .nav>li.filtered>.expand-stub::before { 141 | width: 12px; 142 | height: 12px; 143 | cursor: pointer; 144 | border: #19e3b1 1px solid; 145 | font-size: 8px; 146 | background: #19e3b1; 147 | color: #fff; 148 | content: "-"; 149 | display: table; 150 | margin-top: 3px; 151 | text-align: center; 152 | } 153 | 154 | .toc .nav>li>.expand-stub::before, .toc .nav>li.active>.expand-stub::before { 155 | width: 12px; 156 | height: 12px; 157 | cursor: pointer; 158 | border: #19e3b1 1px solid; 159 | font-size: 8px; 160 | background: #19e3b1; 161 | color: #fff; 162 | content: "+"; 163 | display: table; 164 | margin-top: 3px; 165 | text-align: center; 166 | } 167 | 168 | .sidefilter { 169 | background-color: #fff; 170 | border-left: none; 171 | border-right: none; 172 | } 173 | 174 | .sidefilter { 175 | background-color: #fff; 176 | border-left: none; 177 | border-right: none; 178 | } 179 | 180 | .toc-filter { 181 | padding: 10px; 182 | margin: 0; 183 | } 184 | 185 | .toc-filter>input { 186 | border: 2px solid #ddd; 187 | border-radius: 20px; 188 | } 189 | 190 | .toc-filter>.filter-icon { 191 | display: none; 192 | } 193 | 194 | .sidetoc>.toc { 195 | background-color: #fff; 196 | overflow-x: hidden; 197 | height: 100%; 198 | } 199 | 200 | .sidetoc { 201 | background-color: #ccf5f5; 202 | border: none; 203 | color: #ccf5f5; 204 | padding-right: 8px; 205 | height: 100%; 206 | } 207 | 208 | /* ALERTS */ 209 | 210 | .alert { 211 | padding: 0px 0px 5px 0px; 212 | color: inherit; 213 | background-color: inherit; 214 | border: none; 215 | box-shadow: 0px 2px 2px 0px rgba(100, 100, 100, 0.4); 216 | } 217 | 218 | .alert>p { 219 | margin-bottom: 0; 220 | padding: 5px 10px; 221 | } 222 | 223 | .alert>ul { 224 | margin-bottom: 0; 225 | padding: 5px 40px; 226 | } 227 | 228 | .alert>h5 { 229 | padding: 10px 15px; 230 | margin-top: 0; 231 | text-transform: uppercase; 232 | font-weight: bold; 233 | border-radius: 4px 4px 0 0; 234 | } 235 | 236 | .alert-info>h5 { 237 | color: #1976d2; 238 | border-bottom: 4px solid #1976d2; 239 | background-color: #e3f2fd; 240 | } 241 | 242 | /*custom tip alert*/ 243 | .alert-tip>h5 { 244 | color: #d54473; 245 | border-bottom: 4px solid #d54473; 246 | background-color: #ffdfe9; 247 | content: "\e162"; 248 | } 249 | 250 | .alert-tip h5:before { 251 | content: "\e162"; 252 | } 253 | 254 | .alert-warning>h5 { 255 | color: #f57f17; 256 | border-bottom: 4px solid #f57f17; 257 | background-color: #fff3e0; 258 | } 259 | 260 | .alert-danger>h5 { 261 | color: #d32f2f; 262 | border-bottom: 4px solid #d32f2f; 263 | background-color: #ffebee; 264 | } 265 | 266 | .toc .nav>li.active>a { 267 | color: #000; 268 | text-decoration: none; 269 | font-weight: bold; 270 | } 271 | 272 | .toc .nav>li.active>a:hover { 273 | color: #000; 274 | text-decoration: underline; 275 | } 276 | 277 | .toc .nav>li.active>a:focus { 278 | color: #000; 279 | text-decoration: underline; 280 | } 281 | 282 | button, a { 283 | color: #d54473; 284 | cursor: pointer; 285 | text-decoration: underline; 286 | } 287 | 288 | button:hover, button:focus, a:hover, a:focus { 289 | color: #d54473; 290 | text-decoration: none; 291 | } 292 | 293 | .affix>ul>li.active>a, .affix>ul>li.active>a:before { 294 | color: #d54473; 295 | font-weight: bold; 296 | } 297 | 298 | .affix ul>li.active>a, .affix ul>li.active>a:before { 299 | color: #d54473; 300 | } 301 | 302 | /* CODE HIGHLIGHT */ 303 | 304 | pre { 305 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 306 | padding: 20px; 307 | margin: 0 0 30px 0; 308 | border: #ddd 1px solid; 309 | background: #fff; 310 | font-size: 0.9375em; 311 | color: #455463; 312 | overflow: auto; 313 | border-radius: 0px; 314 | } 315 | 316 | /* Full width */ 317 | @media (min-width:992px) { 318 | .container { 319 | width: 970px 320 | } 321 | } 322 | 323 | @media (min-width:1200px) { 324 | .container { 325 | width: 100%; 326 | } 327 | } -------------------------------------------------------------------------------- /Documentation/templates/unity/styles/toc.yml: -------------------------------------------------------------------------------- 1 | [] 2 | 3 | -------------------------------------------------------------------------------- /Documentation/templates/unity/toc.yml: -------------------------------------------------------------------------------- 1 | [] 2 | 3 | -------------------------------------------------------------------------------- /Documentation/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Home 2 | href: index.md 3 | - name: API 4 | href: api/ -------------------------------------------------------------------------------- /Logs/Packages-Update.log: -------------------------------------------------------------------------------- 1 | 2 | === Thu Jan 21 10:25:26 2021 3 | 4 | Packages were changed. 5 | Update Mode: mergeDefaultDependencies 6 | 7 | The following packages were added: 8 | com.unity.collab-proxy@1.2.16 9 | com.unity.ide.rider@1.1.4 10 | com.unity.ide.vscode@1.2.1 11 | com.unity.modules.ai@1.0.0 12 | com.unity.modules.androidjni@1.0.0 13 | com.unity.modules.animation@1.0.0 14 | com.unity.modules.assetbundle@1.0.0 15 | com.unity.modules.audio@1.0.0 16 | com.unity.modules.cloth@1.0.0 17 | com.unity.modules.director@1.0.0 18 | com.unity.modules.imageconversion@1.0.0 19 | com.unity.modules.imgui@1.0.0 20 | com.unity.modules.jsonserialize@1.0.0 21 | com.unity.modules.particlesystem@1.0.0 22 | com.unity.modules.physics@1.0.0 23 | com.unity.modules.physics2d@1.0.0 24 | com.unity.modules.screencapture@1.0.0 25 | com.unity.modules.terrain@1.0.0 26 | com.unity.modules.terrainphysics@1.0.0 27 | com.unity.modules.tilemap@1.0.0 28 | com.unity.modules.ui@1.0.0 29 | com.unity.modules.uielements@1.0.0 30 | com.unity.modules.umbra@1.0.0 31 | com.unity.modules.unityanalytics@1.0.0 32 | com.unity.modules.unitywebrequest@1.0.0 33 | com.unity.modules.unitywebrequestassetbundle@1.0.0 34 | com.unity.modules.unitywebrequestaudio@1.0.0 35 | com.unity.modules.unitywebrequesttexture@1.0.0 36 | com.unity.modules.unitywebrequestwww@1.0.0 37 | com.unity.modules.vehicles@1.0.0 38 | com.unity.modules.video@1.0.0 39 | com.unity.modules.vr@1.0.0 40 | com.unity.modules.wind@1.0.0 41 | com.unity.modules.xr@1.0.0 42 | com.unity.test-framework@1.1.16 43 | com.unity.textmeshpro@2.1.1 44 | com.unity.timeline@1.2.17 45 | com.unity.ugui@1.0.0 46 | The following packages were updated: 47 | com.unity.2d.animation from version 3.2.4 to 3.2.5 48 | com.unity.2d.psdimporter from version 2.1.5 to 2.1.6 49 | com.unity.2d.spriteshape from version 3.0.13 to 3.0.14 50 | 51 | === Tue Sep 7 13:41:40 2021 52 | 53 | Packages were changed. 54 | Update Mode: updateDependencies 55 | 56 | The following packages were added: 57 | com.unity.ide.visualstudio@2.0.8 58 | The following packages were updated: 59 | com.unity.2d.animation from version 3.2.5 to 5.0.5 60 | com.unity.2d.pixel-perfect from version 2.0.4 to 4.0.1 61 | com.unity.2d.psdimporter from version 2.1.6 to 4.0.2 62 | com.unity.2d.spriteshape from version 3.0.14 to 5.1.2 63 | com.unity.collab-proxy from version 1.2.16 to 1.5.7 64 | com.unity.ide.rider from version 1.1.4 to 2.0.7 65 | com.unity.ide.vscode from version 1.2.1 to 1.2.3 66 | com.unity.test-framework from version 1.1.16 to 1.1.24 67 | com.unity.textmeshpro from version 2.1.1 to 3.0.6 68 | com.unity.timeline from version 1.2.17 to 1.4.8 69 | 70 | === Fri Feb 11 15:16:22 2022 71 | 72 | Packages were changed. 73 | Update Mode: updateDependencies 74 | 75 | The following packages were updated: 76 | com.unity.2d.animation from version 5.0.5 to 5.0.10 77 | com.unity.2d.psdimporter from version 4.0.2 to 4.1.3 78 | com.unity.2d.spriteshape from version 5.1.2 to 5.1.7 79 | com.unity.collab-proxy from version 1.5.7 to 1.15.7 80 | com.unity.ide.visualstudio from version 2.0.8 to 2.0.12 81 | com.unity.ide.vscode from version 1.2.3 to 1.2.4 82 | com.unity.test-framework from version 1.1.24 to 1.1.29 83 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ea771803c307960488d91cc224ebcd33 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/AspectRatio.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | namespace GG.Extensions 5 | { 6 | /// 7 | /// Provides utility methods for calculating aspect ratios. 8 | /// 9 | public static class AspectRatio 10 | { 11 | /// 12 | /// Calculates the aspect ratio from given width and height integers. 13 | /// 14 | /// The width component of the resolution. 15 | /// The height component of the resolution. 16 | /// If true, logs the calculated aspect ratio to the console. 17 | /// A Vector2 representing the aspect ratio (x:y). 18 | public static Vector2 GetAspectRatio(int x, int y, bool debug = false) 19 | { 20 | return GetAspectRatio(new Vector2(x, y), debug); 21 | } 22 | 23 | /// 24 | /// Calculates the aspect ratio from a Vector2 representing width and height. 25 | /// 26 | /// A Vector2 where x is width and y is height. 27 | /// If true, logs the calculated aspect ratio to the console. 28 | /// A Vector2 representing the aspect ratio (x:y). 29 | public static Vector2 GetAspectRatio(Vector2 xy, bool debug = false) 30 | { 31 | float f = xy.x / xy.y; 32 | int i = 0; 33 | while (true) 34 | { 35 | i++; 36 | if (System.Math.Round(f * i, 2) == Mathf.RoundToInt(f * i)) 37 | break; 38 | } 39 | 40 | if (debug) 41 | Debug.Log($"Aspect ratio is {f * i}:{i} (Resolution: {xy.x}x{xy.y})"); 42 | return new Vector2((float)System.Math.Round(f * i, 2), i); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/AspectRatio.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71b41e8576ed0de45b781463ff4d813a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/AwaitExtensions.cs: -------------------------------------------------------------------------------- 1 | #region 2 | 3 | using System; 4 | using System.Collections.Concurrent; 5 | using System.Collections.Generic; 6 | using System.Diagnostics; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | using UnityEngine; 12 | 13 | #endregion 14 | 15 | namespace GG.Extensions 16 | { 17 | public static class AwaitExtensions 18 | { 19 | /// 20 | /// Blocks while condition is true or timeout occurs. 21 | /// 22 | /// The condition that will perpetuate the block. 23 | /// The frequency at which the condition will be check, in milliseconds. 24 | /// Timeout in milliseconds. 25 | /// 26 | /// 27 | public static async Task WaitWhile(Func condition, int frequency = 25, int timeout = -1) 28 | { 29 | var waitTask = Task.Run(async () => 30 | { 31 | while (condition()) await Task.Delay(frequency); 32 | }); 33 | 34 | if(waitTask != await Task.WhenAny(waitTask, Task.Delay(timeout))) 35 | throw new TimeoutException(); 36 | } 37 | 38 | /// 39 | /// Blocks until condition is true or timeout occurs. 40 | /// 41 | /// The break condition. 42 | /// The frequency at which the condition will be checked. 43 | /// The timeout in milliseconds. 44 | /// 45 | public static async Task WaitUntil(Func condition, int frequency = 25, int timeout = -1) 46 | { 47 | #if UNITY_WEBGL 48 | while (!condition.Invoke()) 49 | { 50 | await new WaitForSeconds(frequency / 1000); 51 | } 52 | #else 53 | var waitTask = Task.Run(async () => 54 | { 55 | while (!condition()) await Task.Delay(frequency); 56 | }); 57 | 58 | if (waitTask != await Task.WhenAny(waitTask, 59 | Task.Delay(timeout))) 60 | throw new TimeoutException(); 61 | #endif 62 | } 63 | 64 | // Adapted from https://blogs.msdn.microsoft.com/pfxteam/2012/03/05/implementing-a-simple-foreachasync-part-2/ 65 | public static Task ForEachAsync(this IEnumerable source, int degreeOfParallelism, Func body, 66 | IProgress progress = null) 67 | { 68 | return Task.WhenAll 69 | ( 70 | Partitioner.Create(source).GetPartitions(degreeOfParallelism) 71 | .Select(partition => Task.Run(async () => 72 | { 73 | using (partition) 74 | { 75 | while (partition.MoveNext()) 76 | { 77 | await body(partition.Current); 78 | progress?.Report(partition.Current); 79 | } 80 | } 81 | })) 82 | ); 83 | } 84 | 85 | /// 86 | /// Yield for all events to complete passing back the index from the list 87 | /// 88 | /// 89 | /// 90 | /// 91 | /// 92 | /// 93 | /// 94 | public static Task ForEachAsync(this IEnumerable source, int degreeOfParallelism, Func body, IProgress progress = null) 95 | { 96 | int index = 0; 97 | return Task.WhenAll 98 | ( 99 | Partitioner.Create(source).GetPartitions(degreeOfParallelism).Select(partition => Task.Run(async () => 100 | { 101 | using (partition) 102 | { 103 | while (partition.MoveNext()) 104 | { 105 | index++; 106 | await body(partition.Current, index); 107 | progress?.Report(partition.Current); 108 | } 109 | } 110 | })) 111 | ); 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/AwaitExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a44105d847e7c96428c258c6651c7700 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/ByteExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GG.Extensions 4 | { 5 | /// 6 | /// Byte Extensions class 7 | /// 8 | public static class ByteExtensions 9 | { 10 | /// 11 | /// Is a bit set? 12 | /// 13 | /// The byte to compare 14 | /// The bit position to check 15 | /// True if bit is set 16 | public static bool IsBitSet(this byte b, int pos) 17 | { 18 | if (pos < 0 || pos > 7) 19 | throw new ArgumentOutOfRangeException(nameof(pos), "Index must be in the range of 0-7."); 20 | 21 | return (b & (1 << pos)) != 0; 22 | } 23 | 24 | /// 25 | /// Set the bit (it's unclear if this works properly so i've not been using it currently). 26 | /// 27 | /// The byte to change 28 | /// The bit position to set 29 | /// The new byte 30 | public static byte SetBit(this byte b, int pos) 31 | { 32 | if (pos < 0 || pos > 7) 33 | throw new ArgumentOutOfRangeException(nameof(pos), "Index must be in the range of 0-7."); 34 | 35 | return (byte)(b | (1 << pos)); 36 | } 37 | 38 | /// 39 | /// Unset a bit 40 | /// 41 | /// The byte to change 42 | /// The bit position to set 43 | /// The new byte 44 | public static byte UnsetBit(this byte b, int pos) 45 | { 46 | if (pos < 0 || pos > 7) 47 | throw new ArgumentOutOfRangeException(nameof(pos), "Index must be in the range of 0-7."); 48 | 49 | return (byte)(b & ~(1 << pos)); 50 | } 51 | 52 | /// 53 | /// Toggles a bit 54 | /// 55 | /// The byte to toggle 56 | /// The positon to toggle 57 | /// The new byte 58 | public static byte ToggleBit(this byte b, int pos) 59 | { 60 | if (pos < 0 || pos > 7) 61 | throw new ArgumentOutOfRangeException(nameof(pos), "Index must be in the range of 0-7."); 62 | 63 | return (byte)(b ^ (1 << pos)); 64 | } 65 | 66 | /// 67 | /// Converts to a binary string 68 | /// 69 | /// The byte to compare 70 | /// Byte in string format 71 | public static string ToBinaryString(this byte b) 72 | { 73 | return Convert.ToString(b, 2).PadLeft(8, '0'); 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/ByteExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ee87b4abfe1b6234ea983fee964fd069 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/CameraExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | 4 | namespace GG.Extensions 5 | { 6 | public static class CameraExtensions 7 | { 8 | /// 9 | /// Shows layers specified by a bitmask on the camera's culling mask. 10 | /// 11 | /// The camera to modify. 12 | /// The layer mask to show. 13 | public static void LayerCullingShow(this Camera cam, int layerMask) 14 | { 15 | cam.cullingMask |= layerMask; 16 | } 17 | 18 | /// 19 | /// Shows a single layer specified by name on the camera's culling mask. 20 | /// 21 | /// The camera to modify. 22 | /// The name of the layer to show. 23 | public static void LayerCullingShow(this Camera cam, string layer) 24 | { 25 | LayerCullingShow(cam, 1 << LayerMask.NameToLayer(layer)); 26 | } 27 | 28 | /// 29 | /// Shows multiple layers specified by names on the camera's culling mask. 30 | /// 31 | /// The camera to modify. 32 | /// The names of the layers to show. 33 | public static void LayerCullingShow(this Camera camera, params string[] layerNames) 34 | { 35 | foreach (string layerName in layerNames) 36 | { 37 | LayerCullingShow(camera, layerName); 38 | } 39 | } 40 | 41 | /// 42 | /// Hides layers specified by a bitmask from the camera's culling mask. 43 | /// 44 | /// The camera to modify. 45 | /// The layer mask to hide. 46 | public static void LayerCullingHide(this Camera cam, int layerMask) 47 | { 48 | cam.cullingMask &= ~layerMask; 49 | } 50 | 51 | /// 52 | /// Hides a single layer specified by name from the camera's culling mask. 53 | /// 54 | /// The camera to modify. 55 | /// The name of the layer to hide. 56 | public static void LayerCullingHide(this Camera cam, string layer) 57 | { 58 | LayerCullingHide(cam, 1 << LayerMask.NameToLayer(layer)); 59 | } 60 | 61 | /// 62 | /// Hides multiple layers specified by names from the camera's culling mask. 63 | /// 64 | /// The camera to modify. 65 | /// The names of the layers to hide. 66 | public static void LayerCullingHide(this Camera camera, params string[] layerNames) 67 | { 68 | foreach (string layerName in layerNames) 69 | { 70 | LayerCullingHide(camera, layerName); 71 | } 72 | } 73 | 74 | /// 75 | /// Toggles the visibility of layers specified by a bitmask on the camera's culling mask. 76 | /// 77 | /// The camera to modify. 78 | /// The layer mask to toggle. 79 | public static void LayerCullingToggle(this Camera cam, int layerMask) 80 | { 81 | cam.cullingMask ^= layerMask; 82 | } 83 | 84 | /// 85 | /// Toggles the visibility of a single layer specified by name on the camera's culling mask. 86 | /// 87 | /// The camera to modify. 88 | /// The name of the layer to toggle. 89 | public static void LayerCullingToggle(this Camera cam, string layer) 90 | { 91 | LayerCullingToggle(cam, 1 << LayerMask.NameToLayer(layer)); 92 | } 93 | 94 | /// 95 | /// Checks if the camera's culling mask includes layers specified by a bitmask. 96 | /// 97 | /// The camera to check. 98 | /// The layer mask to check for inclusion. 99 | /// True if the layer mask is included in the camera's culling mask; otherwise, false. 100 | public static bool LayerCullingIncludes(this Camera cam, int layerMask) 101 | { 102 | return (cam.cullingMask & layerMask) > 0; 103 | } 104 | 105 | /// 106 | /// Checks if the camera's culling mask includes a single layer specified by name. 107 | /// 108 | /// The camera to check. 109 | /// The name of the layer to check for inclusion. 110 | /// True if the layer is included in the camera's culling mask; otherwise, false. 111 | public static bool LayerCullingIncludes(this Camera cam, string layer) 112 | { 113 | return LayerCullingIncludes(cam, 1 << LayerMask.NameToLayer(layer)); 114 | } 115 | 116 | /// 117 | /// Toggles the visibility of layers specified by a bitmask on the camera's culling mask, with an option to force visibility on or off. 118 | /// 119 | /// The camera to modify. 120 | /// The layer mask to toggle. 121 | /// If true, forces the layer(s) to be visible; if false, forces the layer(s) to be hidden. 122 | public static void LayerCullingToggle(this Camera cam, int layerMask, bool isOn) 123 | { 124 | bool included = LayerCullingIncludes(cam, layerMask); 125 | if (isOn && !included) 126 | { 127 | LayerCullingShow(cam, layerMask); 128 | } 129 | else if (!isOn && included) 130 | { 131 | LayerCullingHide(cam, layerMask); 132 | } 133 | } 134 | 135 | /// 136 | /// Toggles the visibility of a single layer specified by name on the camera's culling mask, with an option to force visibility on or off. 137 | /// 138 | /// The camera to modify. 139 | /// The name of the layer to toggle. 140 | /// If true, forces the layer to be visible; if false, forces the layer to be hidden. 141 | public static void LayerCullingToggle(this Camera cam, string layer, bool isOn) 142 | { 143 | LayerCullingToggle(cam, 1 << LayerMask.NameToLayer(layer), isOn); 144 | } 145 | 146 | /// 147 | /// Sets the camera's culling mask to show only the specified layers. 148 | /// 149 | /// The camera to modify. 150 | /// A list of layer names to be made visible. 151 | public static void SetCullingMask(this Camera cam, List layers) 152 | { 153 | cam.cullingMask = 0; 154 | foreach (string layer in layers) 155 | { 156 | cam.LayerCullingShow(layer); 157 | } 158 | } 159 | 160 | /// 161 | /// Sets the camera's culling mask to show only the specified layer. 162 | /// This method resets the camera's culling mask before showing the specified layer, 163 | /// effectively making only the specified layer visible. 164 | /// 165 | /// The camera to modify. 166 | /// The name of the layer to be made visible. 167 | public static void SetCullingMask(this Camera cam, string layer) 168 | { 169 | cam.cullingMask = 0; 170 | cam.LayerCullingShow(layer); 171 | } 172 | } 173 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/CameraExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fbf2d0e8e4611274aa50042439ae2a4d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/ColorExtensions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace GG.Extensions 4 | { 5 | public static class ColorExtensions 6 | { 7 | /// 8 | /// Converts a Color32 to a hexadecimal string representation. 9 | /// 10 | /// The Color32 to convert. 11 | /// A hexadecimal string representing the color. 12 | public static string ColorToHex(this Color32 color) 13 | { 14 | string hex = color.r.ToString("X2") + color.g.ToString("X2") + color.b.ToString("X2"); 15 | return hex; 16 | } 17 | 18 | /// 19 | /// Converts a hexadecimal string to a Color. 20 | /// 21 | /// The hexadecimal string to convert. Can be prefixed with "0x" or "#". 22 | /// A Color represented by the hexadecimal string. 23 | /// 24 | /// Assumes the color is fully opaque unless an alpha value is specified in the hex string. 25 | /// 26 | public static Color HexToColor(string hex) 27 | { 28 | hex = hex.Replace("0x", ""); //in case the string is formatted 0xFFFFFF 29 | hex = hex.Replace("#", ""); //in case the string is formatted #FFFFFF 30 | byte a = 255; //assume fully visible unless specified in hex 31 | byte r = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); 32 | byte g = byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); 33 | byte b = byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); 34 | //Only use alpha if the string has enough characters 35 | if (hex.Length == 8) 36 | { 37 | a = byte.Parse(hex.Substring(6, 2), System.Globalization.NumberStyles.HexNumber); 38 | } 39 | 40 | return new Color32(r, g, b, a); 41 | } 42 | 43 | /// 44 | /// Creates color with corrected brightness. 45 | /// 46 | /// Color to correct. 47 | /// The brightness correction factor. Must be between -1 and 1. 48 | /// Negative values produce darker colors. 49 | /// 50 | /// Corrected structure. 51 | /// 52 | public static Color ChangeColorBrightness(this Color color, float correctionFactor) 53 | { 54 | float red = (float)color.r; 55 | float green = (float)color.g; 56 | float blue = (float)color.b; 57 | 58 | if (correctionFactor < 0) 59 | { 60 | correctionFactor = 1 + correctionFactor; 61 | red *= correctionFactor; 62 | green *= correctionFactor; 63 | blue *= correctionFactor; 64 | } 65 | else 66 | { 67 | red = (255 - red) * correctionFactor + red; 68 | green = (255 - green) * correctionFactor + green; 69 | blue = (255 - blue) * correctionFactor + blue; 70 | } 71 | 72 | return new Color(red/255, green/255, blue/255, color.a); 73 | } 74 | 75 | #region GameLogic Extensions 76 | 77 | /// 78 | /// Returns whether the color is black or almost black. 79 | /// 80 | /// 81 | /// 82 | public static bool IsApproximatelyBlack(this Color color) 83 | { 84 | return color.r + color.g + color.b <= Mathf.Epsilon; 85 | } 86 | 87 | /// 88 | /// Returns whether the color is white or almost white. 89 | /// 90 | /// 91 | /// 92 | public static bool IsApproximatelyWhite(this Color color) 93 | { 94 | return color.r + color.g + color.b >= 1 - Mathf.Epsilon; 95 | } 96 | 97 | /// 98 | /// Returns an opaque version of the given color. 99 | /// 100 | /// 101 | /// 102 | public static Color Opaque(this Color color) 103 | { 104 | return new Color(color.r, color.g, color.b); 105 | } 106 | 107 | /// 108 | /// Returns a new color that is this color inverted. 109 | /// 110 | /// The color to invert. 111 | /// 112 | public static Color Invert(this Color color) 113 | { 114 | return new Color(1 - color.r, 1 - color.g, 1 - color.b, color.a); 115 | } 116 | 117 | /// 118 | /// Returns the same color, but with the specified alpha. 119 | /// 120 | /// The color. 121 | /// The alpha. 122 | /// Color. 123 | public static Color WithAlpha(this Color color, float alpha) 124 | { 125 | return new Color(color.r, color.g, color.b, alpha); 126 | } 127 | 128 | #endregion 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/ColorExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 65e1d6b15af6f964180b7293371f76bf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/Colors.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace GG.Extensions 4 | { 5 | public class Colors 6 | { 7 | /// 8 | /// Generates a random color with each RGB component ranging from 0 to 1. 9 | /// 10 | /// A new Color instance with random RGB values. 11 | public static Color Random 12 | { 13 | get 14 | { 15 | System.Random r = new System.Random(); 16 | 17 | return new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)); 18 | } 19 | } 20 | 21 | #region colours by https://github.com/LotteMakesStuff 22 | 23 | public static readonly Color AliceBlue = new Color32(240, 248, 255, 255); 24 | public static readonly Color AntiqueWhite = new Color32(250, 235, 215, 255); 25 | public static readonly Color Aqua = new Color32(0, 255, 255, 255); 26 | public static readonly Color Aquamarine = new Color32(127, 255, 212, 255); 27 | public static readonly Color Azure = new Color32(240, 255, 255, 255); 28 | public static readonly Color Beige = new Color32(245, 245, 220, 255); 29 | public static readonly Color Bisque = new Color32(255, 228, 196, 255); 30 | public static readonly Color Black = new Color32(0, 0, 0, 255); 31 | public static readonly Color BlanchedAlmond = new Color32(255, 235, 205, 255); 32 | public static readonly Color Blue = new Color32(0, 0, 255, 255); 33 | public static readonly Color BlueViolet = new Color32(138, 43, 226, 255); 34 | public static readonly Color Brown = new Color32(165, 42, 42, 255); 35 | public static readonly Color Burlywood = new Color32(222, 184, 135, 255); 36 | public static readonly Color CadetBlue = new Color32(95, 158, 160, 255); 37 | public static readonly Color Chartreuse = new Color32(127, 255, 0, 255); 38 | public static readonly Color Chocolate = new Color32(210, 105, 30, 255); 39 | public static readonly Color Coral = new Color32(255, 127, 80, 255); 40 | public static readonly Color CornflowerBlue = new Color32(100, 149, 237, 255); 41 | public static readonly Color Cornsilk = new Color32(255, 248, 220, 255); 42 | public static readonly Color Crimson = new Color32(220, 20, 60, 255); 43 | public static readonly Color Cyan = new Color32(0, 255, 255, 255); 44 | public static readonly Color DarkBlue = new Color32(0, 0, 139, 255); 45 | public static readonly Color DarkCyan = new Color32(0, 139, 139, 255); 46 | public static readonly Color DarkGoldenrod = new Color32(184, 134, 11, 255); 47 | public static readonly Color DarkGray = new Color32(169, 169, 169, 255); 48 | public static readonly Color DarkGreen = new Color32(0, 100, 0, 255); 49 | public static readonly Color DarkKhaki = new Color32(189, 183, 107, 255); 50 | public static readonly Color DarkMagenta = new Color32(139, 0, 139, 255); 51 | public static readonly Color DarkOliveGreen = new Color32(85, 107, 47, 255); 52 | public static readonly Color DarkOrange = new Color32(255, 140, 0, 255); 53 | public static readonly Color DarkOrchid = new Color32(153, 50, 204, 255); 54 | public static readonly Color DarkRed = new Color32(139, 0, 0, 255); 55 | public static readonly Color DarkSalmon = new Color32(233, 150, 122, 255); 56 | public static readonly Color DarkSeaGreen = new Color32(143, 188, 143, 255); 57 | public static readonly Color DarkSlateBlue = new Color32(72, 61, 139, 255); 58 | public static readonly Color DarkSlateGray = new Color32(47, 79, 79, 255); 59 | public static readonly Color DarkTurquoise = new Color32(0, 206, 209, 255); 60 | public static readonly Color DarkViolet = new Color32(148, 0, 211, 255); 61 | public static readonly Color DeepPink = new Color32(255, 20, 147, 255); 62 | public static readonly Color DeepSkyBlue = new Color32(0, 191, 255, 255); 63 | public static readonly Color DimGray = new Color32(105, 105, 105, 255); 64 | public static readonly Color DodgerBlue = new Color32(30, 144, 255, 255); 65 | public static readonly Color FireBrick = new Color32(178, 34, 34, 255); 66 | public static readonly Color FloralWhite = new Color32(255, 250, 240, 255); 67 | public static readonly Color ForestGreen = new Color32(34, 139, 34, 255); 68 | public static readonly Color Fuchsia = new Color32(255, 0, 255, 255); 69 | public static readonly Color Gainsboro = new Color32(220, 220, 220, 255); 70 | public static readonly Color GhostWhite = new Color32(248, 248, 255, 255); 71 | public static readonly Color Gold = new Color32(255, 215, 0, 255); 72 | public static readonly Color Goldenrod = new Color32(218, 165, 32, 255); 73 | public static readonly Color Gray = new Color32(128, 128, 128, 255); 74 | public static readonly Color Green = new Color32(0, 128, 0, 255); 75 | public static readonly Color GreenYellow = new Color32(173, 255, 47, 255); 76 | public static readonly Color Honeydew = new Color32(240, 255, 240, 255); 77 | public static readonly Color HotPink = new Color32(255, 105, 180, 255); 78 | public static readonly Color IndianRed = new Color32(205, 92, 92, 255); 79 | public static readonly Color Indigo = new Color32(75, 0, 130, 255); 80 | public static readonly Color Ivory = new Color32(255, 255, 240, 255); 81 | public static readonly Color Khaki = new Color32(240, 230, 140, 255); 82 | public static readonly Color Lavender = new Color32(230, 230, 250, 255); 83 | public static readonly Color Lavenderblush = new Color32(255, 240, 245, 255); 84 | public static readonly Color LawnGreen = new Color32(124, 252, 0, 255); 85 | public static readonly Color LemonChiffon = new Color32(255, 250, 205, 255); 86 | public static readonly Color LightBlue = new Color32(173, 216, 230, 255); 87 | public static readonly Color LightCoral = new Color32(240, 128, 128, 255); 88 | public static readonly Color LightCyan = new Color32(224, 255, 255, 255); 89 | public static readonly Color LightGoldenodYellow = new Color32(250, 250, 210, 255); 90 | public static readonly Color LightGray = new Color32(211, 211, 211, 255); 91 | public static readonly Color LightGreen = new Color32(144, 238, 144, 255); 92 | public static readonly Color LightPink = new Color32(255, 182, 193, 255); 93 | public static readonly Color LightSalmon = new Color32(255, 160, 122, 255); 94 | public static readonly Color LightSeaGreen = new Color32(32, 178, 170, 255); 95 | public static readonly Color LightSkyBlue = new Color32(135, 206, 250, 255); 96 | public static readonly Color LightSlateGray = new Color32(119, 136, 153, 255); 97 | public static readonly Color LightSteelBlue = new Color32(176, 196, 222, 255); 98 | public static readonly Color LightYellow = new Color32(255, 255, 224, 255); 99 | public static readonly Color Lime = new Color32(0, 255, 0, 255); 100 | public static readonly Color LimeGreen = new Color32(50, 205, 50, 255); 101 | public static readonly Color Linen = new Color32(250, 240, 230, 255); 102 | public static readonly Color Magenta = new Color32(255, 0, 255, 255); 103 | public static readonly Color Maroon = new Color32(128, 0, 0, 255); 104 | public static readonly Color MediumAquamarine = new Color32(102, 205, 170, 255); 105 | public static readonly Color MediumBlue = new Color32(0, 0, 205, 255); 106 | public static readonly Color MediumOrchid = new Color32(186, 85, 211, 255); 107 | public static readonly Color MediumPurple = new Color32(147, 112, 219, 255); 108 | public static readonly Color MediumSeaGreen = new Color32(60, 179, 113, 255); 109 | public static readonly Color MediumSlateBlue = new Color32(123, 104, 238, 255); 110 | public static readonly Color MediumSpringGreen = new Color32(0, 250, 154, 255); 111 | public static readonly Color MediumTurquoise = new Color32(72, 209, 204, 255); 112 | public static readonly Color MediumVioletRed = new Color32(199, 21, 133, 255); 113 | public static readonly Color MidnightBlue = new Color32(25, 25, 112, 255); 114 | public static readonly Color Mintcream = new Color32(245, 255, 250, 255); 115 | public static readonly Color MistyRose = new Color32(255, 228, 225, 255); 116 | public static readonly Color Moccasin = new Color32(255, 228, 181, 255); 117 | public static readonly Color NavajoWhite = new Color32(255, 222, 173, 255); 118 | public static readonly Color Navy = new Color32(0, 0, 128, 255); 119 | public static readonly Color OldLace = new Color32(253, 245, 230, 255); 120 | public static readonly Color Olive = new Color32(128, 128, 0, 255); 121 | public static readonly Color Olivedrab = new Color32(107, 142, 35, 255); 122 | public static readonly Color Orange = new Color32(255, 165, 0, 255); 123 | public static readonly Color Orangered = new Color32(255, 69, 0, 255); 124 | public static readonly Color Orchid = new Color32(218, 112, 214, 255); 125 | public static readonly Color PaleGoldenrod = new Color32(238, 232, 170, 255); 126 | public static readonly Color PaleGreen = new Color32(152, 251, 152, 255); 127 | public static readonly Color PaleTurquoise = new Color32(175, 238, 238, 255); 128 | public static readonly Color PaleVioletred = new Color32(219, 112, 147, 255); 129 | public static readonly Color PapayaWhip = new Color32(255, 239, 213, 255); 130 | public static readonly Color PeachPuff = new Color32(255, 218, 185, 255); 131 | public static readonly Color Peru = new Color32(205, 133, 63, 255); 132 | public static readonly Color Pink = new Color32(255, 192, 203, 255); 133 | public static readonly Color Plum = new Color32(221, 160, 221, 255); 134 | public static readonly Color PowderBlue = new Color32(176, 224, 230, 255); 135 | public static readonly Color Purple = new Color32(128, 0, 128, 255); 136 | public static readonly Color Red = new Color32(255, 0, 0, 255); 137 | public static readonly Color RosyBrown = new Color32(188, 143, 143, 255); 138 | public static readonly Color RoyalBlue = new Color32(65, 105, 225, 255); 139 | public static readonly Color SaddleBrown = new Color32(139, 69, 19, 255); 140 | public static readonly Color Salmon = new Color32(250, 128, 114, 255); 141 | public static readonly Color SandyBrown = new Color32(244, 164, 96, 255); 142 | public static readonly Color SeaGreen = new Color32(46, 139, 87, 255); 143 | public static readonly Color Seashell = new Color32(255, 245, 238, 255); 144 | public static readonly Color Sienna = new Color32(160, 82, 45, 255); 145 | public static readonly Color Silver = new Color32(192, 192, 192, 255); 146 | public static readonly Color SkyBlue = new Color32(135, 206, 235, 255); 147 | public static readonly Color SlateBlue = new Color32(106, 90, 205, 255); 148 | public static readonly Color SlateGray = new Color32(112, 128, 144, 255); 149 | public static readonly Color Snow = new Color32(255, 250, 250, 255); 150 | public static readonly Color SpringGreen = new Color32(0, 255, 127, 255); 151 | public static readonly Color SteelBlue = new Color32(70, 130, 180, 255); 152 | public static readonly Color Tan = new Color32(210, 180, 140, 255); 153 | public static readonly Color Teal = new Color32(0, 128, 128, 255); 154 | public static readonly Color Thistle = new Color32(216, 191, 216, 255); 155 | public static readonly Color Tomato = new Color32(255, 99, 71, 255); 156 | public static readonly Color Turquoise = new Color32(64, 224, 208, 255); 157 | public static readonly Color Violet = new Color32(238, 130, 238, 255); 158 | public static readonly Color Wheat = new Color32(245, 222, 179, 255); 159 | public static readonly Color White = new Color32(255, 255, 255, 255); 160 | public static readonly Color WhiteSmoke = new Color32(245, 245, 245, 255); 161 | public static readonly Color Yellow = new Color32(255, 255, 0, 255); 162 | public static readonly Color YellowGreen = new Color32(154, 205, 50, 255); 163 | 164 | #endregion 165 | 166 | } 167 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/Colors.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1beb9f04c4bdf6e4aad79985ed212926 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/DateTimeExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 658dfcaf33014ea42b1c561ad661686e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/DebugExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: da79be7e8dd56f14c8c818f3175912f3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/DictionaryExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace GG.Extensions 4 | { 5 | public static class DictionaryExtensions 6 | { 7 | /// 8 | /// Change the key of a dictionary entry 9 | /// 10 | /// 11 | /// 12 | /// 13 | /// 14 | /// 15 | /// 16 | public static bool ChangeKey(this IDictionary dict, 17 | TKey oldKey, TKey newKey) 18 | { 19 | if (!dict.TryGetValue(oldKey, out TValue value)) 20 | return false; 21 | 22 | dict.Remove(oldKey); // do not change order 23 | dict[newKey] = value; // or dict.Add(newKey, value) depending on ur comfort 24 | return true; 25 | } 26 | 27 | /// 28 | /// Checks if a dictionary value exists, if not creates it, if so updates it 29 | /// 30 | /// 31 | /// 32 | /// 33 | /// 34 | /// 35 | public static void AddOrUpdate(this Dictionary dic, TKey key, TValue newValue) 36 | { 37 | if (dic.TryGetValue(key, out TValue val)) 38 | { 39 | // yay, value exists! 40 | dic[key] = newValue; 41 | } 42 | else 43 | { 44 | // darn, lets add the value 45 | dic.Add(key, newValue); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/DictionaryExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2086d2ce7ad7acb45af3491f150162f3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/EditorExtensions.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.IO; 3 | using UnityEditor; 4 | using UnityEngine; 5 | 6 | namespace GG.Extensions 7 | { 8 | public static class EditorExtensions 9 | { 10 | /// 11 | /// Return the location of this script 12 | /// 13 | /// 14 | /// 15 | static string GetMonoScriptFilePath(ScriptableObject scriptableObject) 16 | { 17 | MonoScript ms = MonoScript.FromScriptableObject(scriptableObject); 18 | 19 | string filePath = AssetDatabase.GetAssetPath(ms); 20 | 21 | FileInfo fi = new FileInfo(filePath); 22 | 23 | if (fi.Directory != null) 24 | { 25 | filePath = fi.Directory.ToString(); 26 | 27 | return filePath.Replace 28 | ( 29 | oldChar: '\\', 30 | newChar: '/' 31 | ); 32 | } 33 | return null; 34 | } 35 | } 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/EditorExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 57d50d8cc66d14f44b40ae5e4d1f041f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/EnumExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Reflection; 6 | 7 | namespace GG.Extensions 8 | { 9 | public static class EnumExtensions 10 | { 11 | /// 12 | /// Returns the description assigned to the enum value throguh system.componentmodel 13 | /// 14 | /// 15 | /// 16 | /// 17 | public static string GetDescription(this T value) 18 | { 19 | CheckIsEnum(false); 20 | string name = Enum.GetName(typeof(T), value); 21 | if (name != null) 22 | { 23 | FieldInfo field = typeof(T).GetField(name); 24 | if (field != null) 25 | { 26 | DescriptionAttribute attr = 27 | Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute; 28 | if (attr != null) 29 | { 30 | return attr.Description; 31 | } 32 | } 33 | } 34 | 35 | return null; 36 | } 37 | 38 | /// 39 | /// Returns the description assigned to the enum value throguh system.componentmodel, 40 | /// Use this when passing a generic object though thats an enum 41 | /// 42 | /// 43 | /// 44 | /// 45 | public static string GetDescriptionFromObject(this object o) 46 | { 47 | if (!o.GetType().IsEnum) 48 | { 49 | throw new ArgumentException(string.Format("Type '{0}' is not an enum", o.GetType())); 50 | } 51 | 52 | string name = Enum.GetName(o.GetType(), o); 53 | if (name != null) 54 | { 55 | FieldInfo field = o.GetType().GetField(name); 56 | if (field != null) 57 | { 58 | DescriptionAttribute attr = 59 | Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute; 60 | if (attr != null) 61 | { 62 | return attr.Description; 63 | } 64 | } 65 | } 66 | 67 | return null; 68 | } 69 | 70 | /// 71 | /// Retrieves descriptions for all enum values of a specified type. 72 | /// 73 | /// The enum type. 74 | /// An enumerable of descriptions for each enum value. 75 | public static IEnumerable GetDescriptions() 76 | { 77 | List descs = new List(); 78 | foreach (T item in Enum.GetValues(typeof(T))) 79 | { 80 | descs.Add(GetDescription(item)); 81 | } 82 | 83 | return descs; 84 | } 85 | 86 | /// 87 | /// Finds an enum value by its description. 88 | /// 89 | /// The enum type. 90 | /// The description to search for. 91 | /// The enum value associated with the given description, or the default value if not found. 92 | /// Thrown if T is not an enum type. 93 | public static T GetEnumValueFromDescription(string description) 94 | { 95 | var type = typeof(T); 96 | if (!type.IsEnum) 97 | throw new ArgumentException(); 98 | FieldInfo[] fields = type.GetFields(); 99 | var field = fields 100 | .SelectMany(f => f.GetCustomAttributes( 101 | typeof(DescriptionAttribute), false), ( 102 | f, a) => new { Field = f, Att = a }).SingleOrDefault(a => ((DescriptionAttribute)a.Att) 103 | .Description == description); 104 | return field == null ? default(T) : (T)field.Field.GetRawConstantValue(); 105 | } 106 | 107 | /// 108 | /// Validates that a type is an enum and optionally checks for the Flags attribute. 109 | /// 110 | /// The type to check. 111 | /// Whether to check for the Flags attribute. 112 | /// Thrown if T is not an enum or doesn't have the Flags attribute when required. 113 | private static void CheckIsEnum(bool withFlags) 114 | { 115 | if (!typeof(T).IsEnum) 116 | throw new ArgumentException(string.Format("Type '{0}' is not an enum", typeof(T).FullName)); 117 | if (withFlags && !Attribute.IsDefined(typeof(T), typeof(FlagsAttribute))) 118 | throw new ArgumentException(string.Format("Type '{0}' doesn't have the 'Flags' attribute", 119 | typeof(T).FullName)); 120 | } 121 | 122 | /// 123 | /// Checks if a specific flag is set in an enum value. 124 | /// 125 | /// The enum type. 126 | /// The enum value to check. 127 | /// The flag to check for. 128 | /// True if the flag is set, false otherwise. 129 | public static bool IsFlagSet(this T value, T flag) where T : struct 130 | { 131 | CheckIsEnum(true); 132 | long lValue = Convert.ToInt64(value); 133 | long lFlag = Convert.ToInt64(flag); 134 | return (lValue & lFlag) != 0; 135 | } 136 | 137 | /// 138 | /// Retrieves all flags that are set in an enum value. 139 | /// 140 | /// The enum type. 141 | /// The enum value to check. 142 | /// An enumerable of all set flags. 143 | public static IEnumerable GetFlags(this T value) where T : struct 144 | { 145 | CheckIsEnum(true); 146 | foreach (T flag in Enum.GetValues(typeof(T)).Cast()) 147 | { 148 | if (value.IsFlagSet(flag)) 149 | yield return flag; 150 | } 151 | } 152 | 153 | public static T SetFlags(this T value, T flags, bool on) where T : struct 154 | { 155 | CheckIsEnum(true); 156 | long lValue = Convert.ToInt64(value); 157 | long lFlag = Convert.ToInt64(flags); 158 | if (on) 159 | { 160 | lValue |= lFlag; 161 | } 162 | else 163 | { 164 | lValue &= (~lFlag); 165 | } 166 | 167 | return (T)Enum.ToObject(typeof(T), lValue); 168 | } 169 | 170 | /// 171 | /// Joins the specified flags with the current value, setting the specified flags to true. 172 | /// 173 | /// The enum type. 174 | /// The current enum value. 175 | /// The flags to join with the current value. 176 | /// The result of joining the specified flags with the current value. 177 | public static T JoinFlags(this T value, T flags) where T : struct => value.SetFlags(flags, true); 178 | 179 | /// 180 | /// Sets the specified flags on the current value. 181 | /// 182 | /// The enum type. 183 | /// The current enum value. 184 | /// The flags to set. 185 | /// The result of setting the specified flags on the current value. 186 | public static T SetFlags(this T value, T flags) where T : struct 187 | { 188 | return value.SetFlags(flags, true); 189 | } 190 | 191 | /// 192 | /// Clears the specified flags from the current value. 193 | /// 194 | /// The enum type. 195 | /// The current enum value. 196 | /// The flags to clear. 197 | /// The result of clearing the specified flags from the current value. 198 | public static T ClearFlags(this T value, T flags) where T : struct 199 | { 200 | return value.SetFlags(flags, false); 201 | } 202 | 203 | /// 204 | /// Combines multiple enum flags into a single value. 205 | /// 206 | /// The enum type. 207 | /// The collection of enum flags to combine. 208 | /// The combined enum value. 209 | public static T CombineFlags(this IEnumerable flags) where T : struct 210 | { 211 | CheckIsEnum(true); 212 | long lValue = 0; 213 | foreach (T flag in flags) 214 | { 215 | long lFlag = Convert.ToInt64(flag); 216 | lValue |= lFlag; 217 | } 218 | 219 | return (T)Enum.ToObject(typeof(T), lValue); 220 | } 221 | 222 | /// 223 | /// Cycles through the values of an enum, moving to the next value, and wrapping back to the first value after the last. 224 | /// 225 | /// The enum type. 226 | /// The current enum value. 227 | /// The next enum value, or the first enum value if the current value is the last. 228 | public static T CycleEnum(this T enumerable) where T : struct, IConvertible 229 | { 230 | int enumLength = Enum.GetValues(typeof(T)).Length; 231 | 232 | int val = (int)(IConvertible)enumerable; 233 | val++; 234 | 235 | if (val == enumLength) 236 | { 237 | val = 0; 238 | } 239 | 240 | T returnVal = (T)(IConvertible)val; 241 | 242 | return returnVal; 243 | } 244 | 245 | /// 246 | /// Converts the enum values to a list of their names. 247 | /// 248 | /// The enum type. 249 | /// A list of the names of the enum values. 250 | public static List AsList() where T : struct, Enum 251 | { 252 | return Enum.GetNames(typeof(T)).ToList(); 253 | } 254 | } 255 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/EnumExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f2cd38bb064c52499c697635ef22d08 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/EnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using UnityEngine.Assertions; 6 | 7 | namespace GG.Extensions 8 | { 9 | public static class EnumerableExtensions 10 | { 11 | /// 12 | /// Returns a list of ever X entry in an IEnumerable 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | public static List GetEveryXEntry(this IEnumerable source, int nth) 19 | { 20 | return source.Every(nth).ToList(); 21 | } 22 | 23 | /// 24 | /// Iterates though every X entry in an IEnumerable 25 | /// 26 | /// 27 | /// 28 | /// 29 | /// 30 | public static IEnumerable Every(this IEnumerable source, int count) 31 | { 32 | int cnt = 0; 33 | foreach(T item in source) 34 | { 35 | cnt++; 36 | if (cnt == count) 37 | { 38 | cnt = 0; 39 | yield return item; 40 | } 41 | } 42 | } 43 | 44 | /// 45 | /// Moves the item matching the to the in a list. 46 | /// 47 | public static void Move(this List list, T itemSelector, int newIndex) where T : class 48 | { 49 | Assert.IsNotNull(list, "list"); 50 | Assert.IsNotNull(itemSelector, "itemSelector"); 51 | Assert.IsTrue(newIndex >= 0, "New index must be greater than or equal to zero."); 52 | 53 | int currentIndex = list.IndexOf(itemSelector); 54 | Assert.IsTrue(currentIndex >= 0, "No item was found that matches the specified selector."); 55 | 56 | // Copy the current item 57 | T item = list[currentIndex]; 58 | 59 | // Remove the item 60 | list.RemoveAt(currentIndex); 61 | 62 | // Finally add the item at the new index 63 | list.Insert(newIndex, item); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/EnumerableExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ea7fb832b5c1d7440a95e9d846de800c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/FileExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using UnityEngine; 4 | 5 | namespace GG.Extensions 6 | { 7 | public static class FileExtensions 8 | { 9 | /// 10 | /// Checks if the specified file is currently in use by another process. 11 | /// 12 | /// The FileInfo object representing the file to check. 13 | /// True if the file is in use; otherwise, false. 14 | /// 15 | /// This method attempts to open the file with read/write access and no sharing. 16 | /// If an IOException is caught, it is assumed the file is in use. 17 | /// The file stream is closed immediately in the finally block if it was successfully opened. 18 | /// 19 | public static bool IsFileInUse(FileInfo file) 20 | { 21 | FileStream stream = null; 22 | 23 | try 24 | { 25 | // Attempt to open the file with exclusive access. 26 | stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None); 27 | } 28 | catch (IOException) 29 | { 30 | // IOException caught indicates the file is in use or does not exist. 31 | return true; 32 | } 33 | finally 34 | { 35 | // Ensure the file stream is closed if it was opened. 36 | stream?.Close(); 37 | } 38 | return false; 39 | } 40 | 41 | /// 42 | /// Copy a whole directory with option to copy all sub folders 43 | /// 44 | /// 45 | /// 46 | /// 47 | /// 48 | public static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs) 49 | { 50 | // Get the subdirectories for the specified directory. 51 | DirectoryInfo dir = new DirectoryInfo(sourceDirName); 52 | 53 | if (!dir.Exists) 54 | { 55 | throw new DirectoryNotFoundException( 56 | "Source directory does not exist or could not be found: " 57 | + sourceDirName); 58 | } 59 | 60 | DirectoryInfo[] dirs = dir.GetDirectories(); 61 | // If the destination directory doesn't exist, create it. 62 | if (!Directory.Exists(destDirName)) 63 | { 64 | Directory.CreateDirectory(destDirName); 65 | } 66 | 67 | // Get the files in the directory and copy them to the new location. 68 | FileInfo[] files = dir.GetFiles(); 69 | foreach (FileInfo file in files) 70 | { 71 | string temppath = Path.Combine(destDirName, file.Name); 72 | file.CopyTo(temppath, false); 73 | } 74 | 75 | // If copying subdirectories, copy them and their contents to new location. 76 | if (copySubDirs) 77 | { 78 | foreach (DirectoryInfo subdir in dirs) 79 | { 80 | string temppath = Path.Combine(destDirName, subdir.Name); 81 | DirectoryCopy(subdir.FullName, temppath, copySubDirs); 82 | } 83 | } 84 | } 85 | 86 | /// 87 | /// Removes the file extension from a given file path. 88 | /// 89 | /// The full path of the file including its extension. 90 | /// The file path without its extension. 91 | public static string RemoveFileExtension(string filePath) 92 | { 93 | return Path.ChangeExtension(filePath, null); 94 | } 95 | 96 | /// 97 | /// Determine whether a given path is a directory. 98 | /// 99 | public static bool PathIsDirectory (string absolutePath) 100 | { 101 | FileAttributes attr = File.GetAttributes(absolutePath); 102 | if ((attr & FileAttributes.Directory) == FileAttributes.Directory) 103 | return true; 104 | else 105 | return false; 106 | } 107 | 108 | 109 | /// 110 | /// Given an absolute path, return a path rooted at the Assets folder. 111 | /// 112 | /// 113 | /// Asset relative paths can only be used in the editor. They will break in builds. 114 | /// 115 | /// 116 | /// /Folder/UnityProject/Assets/resources/music returns Assets/resources/music 117 | /// 118 | public static string AssetsRelativePath (string absolutePath) 119 | { 120 | if (absolutePath.StartsWith(Application.dataPath)) { 121 | return "Assets" + absolutePath.Substring(Application.dataPath.Length); 122 | } 123 | else { 124 | throw new System.ArgumentException("Full path does not contain the current project's Assets folder", "absolutePath"); 125 | } 126 | } 127 | 128 | 129 | /// 130 | /// Get all available Resources directory paths within the current project. 131 | /// 132 | public static string[] GetResourcesDirectories () 133 | { 134 | List result = new List(); 135 | 136 | foreach (string dir in Directory.GetDirectories(Application.dataPath, "*", SearchOption.AllDirectories)) 137 | { 138 | if (Path.GetFileName(dir).Equals("Resources")) 139 | { 140 | // If one of the found directories is a Resources dir, add it to the result 141 | result.Add(dir); 142 | } 143 | } 144 | return result.ToArray(); 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/FileExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 055079162f6706146ada6cb21ecf79e0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/GameObjectExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using UnityEngine; 4 | 5 | namespace GG.Extensions 6 | { 7 | public static class GameObjectExtensions 8 | { 9 | static List dontDestoryOnLoadObjects = new List(); 10 | 11 | /// 12 | /// Gets an existing component of type T from the child or adds one if it doesn't exist. 13 | /// 14 | /// The type of the component to get or add. 15 | /// The component from which to get or add the component. 16 | /// The existing or newly added component. 17 | static public T GetOrAddComponent(this Component child) where T : Component 18 | { 19 | T result = child.GetComponent(); 20 | if (result == null) 21 | { 22 | result = child.gameObject.AddComponent(); 23 | } 24 | return result; 25 | } 26 | 27 | /// 28 | /// Gets an existing component of type T from the GameObject or adds one if it doesn't exist. 29 | /// 30 | /// The type of the component to get or add. 31 | /// The GameObject from which to get or add the component. 32 | /// The existing or newly added component. 33 | static public T GetOrAddComponent(this GameObject child) where T : Component 34 | { 35 | return GetOrAddComponent(child.transform); 36 | } 37 | 38 | /// 39 | /// Changes the material of all Renderer components in the GameObject and its children. 40 | /// 41 | /// The GameObject whose materials to change. 42 | /// The new material to apply. 43 | public static void ChangeMaterial(this GameObject go, Material newMat) 44 | { 45 | Renderer[] children = go.GetComponentsInChildren(true); 46 | foreach (Renderer rend in children) 47 | { 48 | Material[] mats = new Material[rend.materials.Length]; 49 | for (int j = 0; j < rend.materials.Length; j++) 50 | { 51 | mats[j] = newMat; 52 | } 53 | rend.materials = mats; 54 | } 55 | } 56 | 57 | /// 58 | /// Gets a component of type T from the parent of the GameObject, ignoring any components of type T on the GameObject itself. 59 | /// 60 | /// The type of the component to get. 61 | /// The GameObject from which to start the search. 62 | /// The component of type T from the parent GameObject. 63 | public static T GetComponentInParentIgnoreSelf(this GameObject go) 64 | { 65 | return go.transform.parent.GetComponentInParent(); 66 | } 67 | 68 | /// 69 | /// Marks the specified GameObject to not be destroyed when loading a new scene. 70 | /// 71 | /// The GameObject to preserve across scenes. 72 | /// 73 | /// Adds the GameObject to a static list to keep track of objects that shouldn't be destroyed on load. 74 | /// 75 | public static void DontDestroyOnLoad(this GameObject obj) 76 | { 77 | dontDestoryOnLoadObjects.Add(obj); 78 | Object.DontDestroyOnLoad(obj); 79 | } 80 | 81 | /// 82 | /// Destroys a GameObject that was previously marked with DontDestroyOnLoad. 83 | /// 84 | /// The GameObject to destroy. 85 | /// 86 | /// Removes the GameObject from the static list that tracks objects preserved across scenes before destroying it. 87 | /// 88 | public static void DestoryDontDestroyOnLoad(this GameObject obj) 89 | { 90 | dontDestoryOnLoadObjects.Remove(obj); 91 | Object.Destroy(obj); 92 | } 93 | 94 | /// 95 | /// Retrieves a list of all GameObjects that have been marked to not be destroyed on scene loads. 96 | /// 97 | /// A list of GameObjects that are preserved across scenes. 98 | /// 99 | /// Filters out any null references in the static list before returning it to ensure all returned objects are valid. 100 | /// 101 | public static List GetDontDestroyOnLoadObjects() 102 | { 103 | dontDestoryOnLoadObjects = dontDestoryOnLoadObjects.Where(x => x != null).ToList(); 104 | return new List(dontDestoryOnLoadObjects); 105 | } 106 | 107 | /// 108 | /// Returns a list of all child GameObjects of the specified GameObject. 109 | /// 110 | /// The parent GameObject. 111 | /// A list of all child GameObjects. 112 | /// 113 | /// Does not include the parent GameObject in the list, only its children. 114 | /// 115 | public static List GetAllChildren(this GameObject gameObject) 116 | { 117 | Transform[] childTransforms = gameObject.GetComponentsInChildren(); 118 | List allChildren = new List(childTransforms.Length); 119 | 120 | foreach(Transform child in childTransforms) 121 | { 122 | if(child.gameObject != gameObject) allChildren.Add(child.gameObject); 123 | } 124 | 125 | return allChildren; 126 | } 127 | 128 | /// 129 | /// Returns a list of all child GameObjects of the specified GameObject, including the GameObject itself. 130 | /// 131 | /// The GameObject to retrieve children from. 132 | /// A list of GameObjects representing all children and the GameObject itself. 133 | public static List GetAllChildrenAndSelf(this GameObject gameObject) 134 | { 135 | Transform[] childTransforms = gameObject.GetComponentsInChildren(); 136 | List allChildren = new List(childTransforms.Length); 137 | 138 | for (int transformIndex = 0; transformIndex < childTransforms.Length; ++transformIndex) 139 | { 140 | allChildren.Add(childTransforms[transformIndex].gameObject); 141 | } 142 | 143 | return allChildren; 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/GameObjectExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ccda96e850f95194fad404c711824b0c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/ImageExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using UnityEngine; 6 | 7 | namespace GG.Extensions 8 | { 9 | public static class ImageExtensions 10 | { 11 | /// 12 | /// Generates a Texture2D object from a base64 encoded string. 13 | /// 14 | /// The base64 encoded string representing the image data. 15 | /// Optional name to assign to the texture. Defaults to an empty string. 16 | /// A new Texture2D object created from the base64 string. 17 | /// 18 | /// The texture is created with a default size of 16x16 pixels, ARGB32 format, no mipmaps, and bilinear filtering. 19 | /// The texture is also marked with HideFlags.HideAndDontSave to avoid it being saved with the scene. 20 | /// 21 | public static Texture2D CreateTextureFromBase64(string base64, string name = "") 22 | { 23 | byte[] data = Convert.FromBase64String(base64); 24 | Texture2D tex = new Texture2D(16, 16, TextureFormat.ARGB32, false, true) {hideFlags = HideFlags.HideAndDontSave, name = name, filterMode = FilterMode.Bilinear}; 25 | tex.LoadImage(data); 26 | return tex; 27 | } 28 | 29 | /// 30 | /// Creates a Sprite from a base64 encoded string. 31 | /// 32 | /// The base64 encoded string representing the image data. 33 | /// A new Sprite created from the base64 string. 34 | /// 35 | /// This method first converts the base64 string into a Texture2D object, then creates a sprite from the entire texture. 36 | /// The sprite's pivot is set to the center (0.5, 0.5) and pixels per unit to 100. 37 | /// 38 | public static Sprite CreateSpriteFromBase64(string base64) 39 | { 40 | Texture2D tex = CreateTextureFromBase64(base64); 41 | return Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f); 42 | } 43 | 44 | /// 45 | /// Converts a Texture2D object to a base64 encoded string. 46 | /// 47 | /// The Texture2D object to convert. 48 | /// A base64 encoded string representing the image data of the Texture2D. 49 | /// 50 | /// The texture is first encoded to PNG format before being converted to a base64 string. 51 | /// 52 | public static string ToBase64Image(Texture2D texture2D) 53 | { 54 | byte[] imageData = texture2D.EncodeToPNG(); 55 | return Convert.ToBase64String(imageData); 56 | } 57 | 58 | /// 59 | /// Converts an image file to a base64 encoded string. 60 | /// 61 | /// The file path of the image to convert. 62 | /// A base64 encoded string representing the image data. 63 | /// 64 | /// The image file is read as a byte array before being converted to a base64 string. 65 | /// 66 | public static string ToBase64Image(string path) 67 | { 68 | byte[] asBytes = File.ReadAllBytes(path); 69 | return Convert.ToBase64String(asBytes); 70 | } 71 | 72 | /// 73 | /// Loads an image file as a byte array. 74 | /// 75 | /// The file path of the image to load. 76 | /// A byte array containing the image data. 77 | /// 78 | /// This method directly reads the file content into a byte array without any conversion. 79 | /// 80 | public static byte[] LoadImageAsBytes(string path) 81 | { 82 | return File.ReadAllBytes(path); 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/ImageExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a7487f820741ba04189a163549076ddf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/Input.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e22ac2b732db5d42bc8066e22dd9fdd 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/Input/InputExtensions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine.InputSystem; 2 | 3 | namespace GG.Extensions 4 | { 5 | /// 6 | /// Defines the types of input devices. 7 | /// 8 | public enum DeviceType 9 | { 10 | Gamepad, 11 | Keyboard, 12 | Mouse, 13 | Touchscreen, 14 | Joystick, 15 | Pen, 16 | Sensor, 17 | Unknown 18 | } 19 | 20 | /// 21 | /// Provides extension methods for input-related functionalities. 22 | /// 23 | public static class InputExtensions 24 | { 25 | /// 26 | /// Determines the type of device from an input action callback context. 27 | /// 28 | /// The callback context from which to determine the device type. 29 | /// The determined device type. 30 | public static DeviceType GetDeviceType(InputAction.CallbackContext context) 31 | { 32 | InputDevice device = context.control.device; 33 | 34 | if (device is Gamepad) 35 | { 36 | return DeviceType.Gamepad; 37 | } 38 | else if (device is Keyboard) 39 | { 40 | return DeviceType.Keyboard; 41 | } 42 | else if (device is Mouse) 43 | { 44 | return DeviceType.Mouse; 45 | } 46 | else if (device is Touchscreen) 47 | { 48 | return DeviceType.Touchscreen; 49 | } 50 | else if (device is Joystick) 51 | { 52 | return DeviceType.Joystick; 53 | } 54 | else if (device is Pen) 55 | { 56 | return DeviceType.Pen; 57 | } 58 | else if (device is Sensor) 59 | { 60 | return DeviceType.Sensor; 61 | } 62 | else 63 | { 64 | return DeviceType.Unknown; 65 | } 66 | } 67 | 68 | /// 69 | /// Tries to read the value of the specified type from an input action callback context. 70 | /// 71 | /// The type of the value to read. 72 | /// The callback context from which to read the value. 73 | /// The output parameter that will contain the read value if successful. 74 | /// True if the value was successfully read; otherwise, false. 75 | public static bool TryReadValue(this InputAction.CallbackContext context, out T value) where T : struct 76 | { 77 | // Initialize the output value to the default 78 | value = default; 79 | 80 | // Check if the control is not null and the value type is correct 81 | if (context.control != null && context.control.valueType == typeof(T)) 82 | { 83 | // Read the value from the context 84 | value = context.ReadValue(); 85 | return true; 86 | } 87 | 88 | // If the control is null or the value type does not match, return false 89 | return false; 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/Input/InputExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8d8f3f3704a34c33b35e68c365158c84 3 | timeCreated: 1720019834 -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/Input/gg.extensions.Input.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GG.Extensions.Input", 3 | "rootNamespace": "", 4 | "references": [ 5 | "Unity.InputSystem" 6 | ], 7 | "includePlatforms": [], 8 | "excludePlatforms": [], 9 | "allowUnsafeCode": false, 10 | "overrideReferences": false, 11 | "precompiledReferences": [], 12 | "autoReferenced": true, 13 | "defineConstraints": [ 14 | "ENABLE_INPUT_SYSTEM" 15 | ], 16 | "versionDefines": [], 17 | "noEngineReferences": false 18 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/Input/gg.extensions.Input.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 15c3a644a6fede04396ff514de6b6bd8 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/LayerMaskExtensions.cs: -------------------------------------------------------------------------------- 1 | #region 2 | 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | #endregion 7 | 8 | namespace GG.Extensions 9 | { 10 | public static class LayerMaskExtensions 11 | { 12 | /// 13 | /// Creates a LayerMask from an array of layer names. 14 | /// 15 | /// Array of layer names to include in the mask. 16 | /// A LayerMask composed of the specified layers. 17 | public static LayerMask CreateLayerMask(params string[] layerNames) 18 | { 19 | return NamesToMask(layerNames); 20 | } 21 | 22 | /// 23 | /// Creates a LayerMask from an array of layer numbers. 24 | /// 25 | /// Array of layer numbers to include in the mask. 26 | /// A LayerMask composed of the specified layers. 27 | public static LayerMask CreateLayerMask(params int[] layerNumbers) 28 | { 29 | return LayerNumbersToMask(layerNumbers); 30 | } 31 | 32 | /// 33 | /// Converts an array of layer names into a LayerMask. 34 | /// 35 | /// Array of layer names to convert. 36 | /// A LayerMask representing the given layer names. 37 | public static LayerMask NamesToMask(params string[] layerNames) 38 | { 39 | LayerMask ret = 0; 40 | foreach (string name in layerNames) 41 | { 42 | ret |= 1 << LayerMask.NameToLayer(name); 43 | } 44 | 45 | return ret; 46 | } 47 | 48 | /// 49 | /// Converts an array of layer numbers into a LayerMask. 50 | /// 51 | /// Array of layer numbers to convert. 52 | /// A LayerMask representing the given layer numbers. 53 | public static LayerMask LayerNumbersToMask(params int[] layerNumbers) 54 | { 55 | LayerMask ret = 0; 56 | foreach (int layer in layerNumbers) 57 | { 58 | ret |= 1 << layer; 59 | } 60 | 61 | return ret; 62 | } 63 | 64 | /// 65 | /// Inverts the given LayerMask. 66 | /// 67 | /// The original LayerMask to invert. 68 | /// An inverted LayerMask. 69 | public static LayerMask Inverse(this LayerMask original) 70 | { 71 | return ~original; 72 | } 73 | 74 | /// 75 | /// Adds layers to the given LayerMask. 76 | /// 77 | /// The original LayerMask to add layers to. 78 | /// Array of layer names to add. 79 | /// A LayerMask with the specified layers added. 80 | public static LayerMask AddToMask(this LayerMask original, params string[] layerNames) 81 | { 82 | return original | NamesToMask(layerNames); 83 | } 84 | 85 | /// 86 | /// Removes layers from the given LayerMask. 87 | /// 88 | /// The original LayerMask to remove layers from. 89 | /// Array of layer names to remove. 90 | /// A LayerMask with the specified layers removed. 91 | public static LayerMask RemoveFromMask(this LayerMask original, params string[] layerNames) 92 | { 93 | LayerMask invertedOriginal = ~original; 94 | return ~(invertedOriginal | NamesToMask(layerNames)); 95 | } 96 | 97 | /// 98 | /// Converts a LayerMask to an array of layer names. 99 | /// 100 | /// The LayerMask to convert. 101 | /// An array of layer names included in the LayerMask. 102 | public static string[] MaskToNames(this LayerMask original) 103 | { 104 | List output = new List(); 105 | 106 | for (int i = 0; i < 32; ++i) 107 | { 108 | int shifted = 1 << i; 109 | if ((original & shifted) == shifted) 110 | { 111 | string layerName = LayerMask.LayerToName(i); 112 | if (!string.IsNullOrEmpty(layerName)) 113 | { 114 | output.Add(layerName); 115 | } 116 | } 117 | } 118 | 119 | return output.ToArray(); 120 | } 121 | 122 | /// 123 | /// Converts a LayerMask to a string representation using a default delimiter. 124 | /// 125 | /// The LayerMask to convert. 126 | /// A string representation of the LayerMask. 127 | public static string MaskToString(this LayerMask original) 128 | { 129 | return MaskToString(original, ", "); 130 | } 131 | 132 | /// 133 | /// Converts a LayerMask to a string representation using a specified delimiter. 134 | /// 135 | /// The LayerMask to convert. 136 | /// The delimiter to use between layer names. 137 | /// A string representation of the LayerMask. 138 | public static string MaskToString(this LayerMask original, string delimiter) 139 | { 140 | return string.Join(delimiter, MaskToNames(original)); 141 | } 142 | 143 | /// 144 | /// Moves the GameObject associated with the given Transform to a specified layer, optionally applying the change recursively to all children. 145 | /// 146 | /// The root Transform whose GameObject is to be moved to a new layer. 147 | /// The name of the layer to move the GameObject to. 148 | /// Whether to apply the layer change to all child Transforms recursively. 149 | public static void MoveToLayer(this Transform root, string layer, bool recursive = true) 150 | { 151 | MoveToLayer(root, LayerMask.NameToLayer(layer), recursive); 152 | } 153 | 154 | /// 155 | /// Moves the GameObject associated with the given Transform to a specified layer, optionally applying the change recursively to all children. 156 | /// 157 | /// The root Transform whose GameObject is to be moved to a new layer. 158 | /// The layer number to move the GameObject to. 159 | /// Whether to apply the layer change to all child Transforms recursively. 160 | public static void MoveToLayer(this Transform root, int layer, bool recursive = true) 161 | { 162 | root.gameObject.layer = layer; 163 | 164 | if (recursive) 165 | { 166 | foreach (Transform child in root) 167 | { 168 | MoveToLayer(child, layer); 169 | } 170 | } 171 | } 172 | 173 | /// 174 | /// Moves all GameObjects associated with the given Transform and its children of type T to a specified layer. 175 | /// 176 | /// The component type to filter the children by. 177 | /// The root Transform whose children are to be moved to a new layer. 178 | /// The name of the layer to move the GameObjects to. 179 | public static void MoveToLayer(this Transform root, string layer) where T : Component 180 | { 181 | MoveToLayer(root, LayerMask.NameToLayer(layer)); 182 | } 183 | 184 | /// 185 | /// Moves all GameObjects associated with the given Transform and its children of type T to a specified layer. 186 | /// 187 | /// The component type to filter the children by. 188 | /// The root Transform whose children are to be moved to a new layer. 189 | /// The layer number to move the GameObjects to. 190 | public static void MoveToLayer(this Transform root, int layerNumber) where T : Component 191 | { 192 | foreach (T trans in root.GetComponentsInChildren(true)) 193 | { 194 | trans.gameObject.layer = layerNumber; 195 | } 196 | } 197 | 198 | /// 199 | /// Checks if a LayerMask contains a specific layer number. 200 | /// 201 | /// The LayerMask to check. 202 | /// The layer number to check for. 203 | /// True if the LayerMask contains the layer, false otherwise. 204 | public static bool ContainsLayer(this LayerMask mask, int layer) 205 | { 206 | return ((1 << layer) & mask) > 0; 207 | } 208 | 209 | /// 210 | /// Checks if a LayerMask contains a specific layer by name. 211 | /// 212 | /// The LayerMask to check. 213 | /// The name of the layer to check for. 214 | public static bool ContainsLayer(this LayerMask mask, string layer) 215 | { 216 | return ((1 << LayerMask.NameToLayer(layer)) & mask) > 0; 217 | } 218 | } 219 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/LayerMaskExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dd9b6767328d167488ee990ab304180a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/MathsExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | namespace GG.Extensions 7 | { 8 | public static class MathsExtensions 9 | { 10 | #region Constants 11 | 12 | public static readonly float Sqrt3 = Mathf.Sqrt(3); 13 | 14 | #endregion 15 | 16 | #region Static Methods 17 | 18 | /// 19 | /// Linearly interpolates between two values between 0 and 1 if values wrap around from 1 back to 0. 20 | /// 21 | /// This is useful, for example, in lerping between angles. 22 | /// 23 | /// float angleInRad1 = 1; 24 | /// float angleInRad2 = 5; 25 | /// float revolution = Mathf.PI * 2; 26 | /// float interpolation = WLerp(angleInRad1 / revolution, angleInRad2 / revolution, 0.5f); 27 | /// 28 | /// //interpolation == (5 + 1 + Mathf.PI * 2)/2 = 3 + Mathf.PI 29 | /// 30 | /// 31 | public static float Wlerp01(float v1, float v2, float t) 32 | { 33 | if (Mathf.Abs(v1 - v2) <= 0.5f) 34 | { 35 | return Mathf.Lerp(v1, v2, t); 36 | } 37 | else if (v1 <= v2) 38 | { 39 | return Frac(Mathf.Lerp(v1 + 1, v2, t)); 40 | } 41 | else 42 | { 43 | return Frac(Mathf.Lerp(v1, v2 + 1, t)); 44 | } 45 | } 46 | 47 | /// 48 | /// Tests whether the given value lies in the range [0, 1). 49 | /// 50 | /// The value to check. 51 | /// true if the given value is equal or greater than 0 and smaller than 1, false otherwise. 52 | public static bool InRange01(float value) 53 | { 54 | return InRange(value, 0, 1); 55 | } 56 | 57 | /// 58 | /// Tests whether the given value lies in the half-open interval specified by its endpoints, that is, whether the value 59 | /// lies in the interval [closedLeft, openRight). 60 | /// 61 | /// The value to check. 62 | /// The left end of the interval. 63 | /// The right end of the interval. 64 | /// true if the given value is equal or greater than closedLeft and smaller than openRight, false otherwise. 65 | public static bool InRange(float value, float closedLeft, float openRight) 66 | { 67 | return value >= closedLeft && value < openRight; 68 | } 69 | 70 | /// 71 | /// Mod operator that also works for negative m. 72 | /// 73 | /// The m. 74 | /// The n. 75 | /// System.Int32. 76 | public static int FloorMod(int m, int n) 77 | { 78 | if (m >= 0) 79 | { 80 | return m % n; 81 | } 82 | 83 | return (m - 2 * m * n) % n; 84 | } 85 | 86 | /// 87 | /// Mod operator that also works for negative m. 88 | /// 89 | /// The m. 90 | /// The n. 91 | /// System.Int32. 92 | public static float FloorMod(float m, float n) 93 | { 94 | if (m >= 0) 95 | { 96 | return m % n; 97 | } 98 | 99 | return (m % n) + n; 100 | } 101 | 102 | /// 103 | /// Floor division that also work for negative m. 104 | /// 105 | /// The m. 106 | /// The n. 107 | /// System.Int32. 108 | public static int FloorDiv(int m, int n) 109 | { 110 | if (m >= 0) 111 | { 112 | return m / n; 113 | } 114 | 115 | int t = m / n; 116 | 117 | if (t * n == m) 118 | { 119 | return t; 120 | } 121 | 122 | return t - 1; 123 | } 124 | 125 | /// 126 | /// Returns the fractional part of a floating point number. 127 | /// 128 | /// The number to get the fractional part of. 129 | /// The fractional part of the given number. 130 | /// The result is always the number minus the number's floor. 131 | public static float Frac(float x) 132 | { 133 | return x - Mathf.Floor(x); 134 | } 135 | 136 | /// 137 | /// Returns the sign function evaluated at the given value. 138 | /// 139 | /// 1 if the given value is positive, -1 if it is negative, and 0 if it is 0. 140 | public static int Sign(float x) 141 | { 142 | if (x > 0) return 1; 143 | if (x < 0) return -1; 144 | 145 | return 0; 146 | } 147 | 148 | /// 149 | /// Returns the sign function evaluated at the given value. 150 | /// 151 | /// 1 if the given value is positive, -1 if it is negative, and 0 if it is 0. 152 | public static int Sign(int p) 153 | { 154 | if (p > 0) return 1; 155 | if (p < 0) return -1; 156 | 157 | return 0; 158 | } 159 | 160 | #endregion 161 | 162 | #region Obsolete 163 | 164 | [Obsolete("Use FloorDiv instead")] 165 | public static int Div(int m, int n) 166 | { 167 | return FloorDiv(m, n); 168 | } 169 | 170 | [Obsolete("Use FloorMod instead")] 171 | public static int Mod(int m, int n) 172 | { 173 | return FloorMod(m, n); 174 | } 175 | 176 | [Obsolete("Use FloorMod instead")] 177 | public static float Mod(float m, float n) 178 | { 179 | return FloorMod(m, n); 180 | } 181 | 182 | /// 183 | /// Returns the highest integer equal to the given float. 184 | /// 185 | [Obsolete("Use Mathf.FloorToInt")] 186 | public static int FloorToInt(float x) 187 | { 188 | return Mathf.FloorToInt(x); 189 | } 190 | 191 | [Obsolete("Use Frac instead.")] 192 | public static float Wrap01(float value) 193 | { 194 | int n = Mathf.FloorToInt(value); 195 | float result = value - n; 196 | 197 | return result; 198 | } 199 | 200 | #endregion 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/MathsExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3361cd00fad177945b8f0d46d31c1fd8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/MiscExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Reflection; 6 | using System.Runtime.Serialization; 7 | using UnityEngine; 8 | using UnityEngine.Events; 9 | using UnityEngine.SceneManagement; 10 | using UnityEngine.UI; 11 | 12 | namespace GG.Extensions 13 | { 14 | public static class MiscExtensions 15 | { 16 | public delegate void UnityAction(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4); 17 | 18 | /// 19 | /// An actual quit that will stop play mode in editor as well 20 | /// 21 | public static void Quit() 22 | { 23 | #if UNITY_EDITOR 24 | UnityEditor.EditorApplication.isPlaying = false; 25 | #else 26 | Application.Quit(); 27 | #endif 28 | } 29 | 30 | /// 31 | /// Ensure the resources directory lives at 'Assets' level 32 | /// 33 | public static void EnsureResourcesExists() 34 | { 35 | string path = Path.Combine("Assets", "Resources"); 36 | 37 | if (!Directory.Exists(path)) 38 | { 39 | Directory.CreateDirectory(path); 40 | } 41 | } 42 | 43 | /// 44 | /// Finds all objects of type T in all loaded scenes, including inactive objects. 45 | /// This method is an alternative to Resources.FindObjectsOfTypeAll (which returns project assets, including prefabs), 46 | /// and GameObject.FindObjectsOfTypeAll (which is deprecated). 47 | /// 48 | /// The type of the objects to find. 49 | /// A list of objects of type T found in all loaded scenes. 50 | public static List FindObjectsOfTypeAll() 51 | { 52 | List results = new List(); 53 | for (int i = 0; i < SceneManager.sceneCount; i++) 54 | { 55 | var s = SceneManager.GetSceneAt(i); 56 | results.AddRange(FindObjectsOfTypeAllInScene(s, false)); 57 | } 58 | 59 | foreach (GameObject savedObject in GameObjectExtensions.GetDontDestroyOnLoadObjects()) 60 | { 61 | results.AddRange(savedObject.GetComponentsInChildren(true)); 62 | } 63 | 64 | return results; 65 | } 66 | 67 | /// 68 | /// Finds all objects of type T in a specific scene, including inactive objects. 69 | /// Optionally includes objects marked as DontDestroyOnLoad. 70 | /// 71 | /// The type of the objects to find. 72 | /// The scene to search within. 73 | /// Whether to include objects marked as DontDestroyOnLoad. 74 | /// A list of objects of type T found in the specified scene. 75 | public static List FindObjectsOfTypeAllInScene(Scene scene, bool includeDontDestroyOnLoad = true) 76 | { 77 | List results = new List(); 78 | 79 | var allGameObjects = scene.GetRootGameObjects(); 80 | for (int j = 0; j < allGameObjects.Length; j++) 81 | { 82 | var go = allGameObjects[j]; 83 | results.AddRange(go.GetComponentsInChildren(true)); 84 | } 85 | 86 | if (includeDontDestroyOnLoad) 87 | { 88 | foreach (GameObject savedObject in GameObjectExtensions.GetDontDestroyOnLoadObjects()) 89 | { 90 | results.AddRange(savedObject.GetComponentsInChildren(true)); 91 | } 92 | } 93 | 94 | return results; 95 | } 96 | 97 | /// 98 | /// Asynchronously loads a scene by name and provides progress updates and a completion callback. 99 | /// 100 | /// The name of the scene to load. 101 | /// Specifies whether to load the scene additively or replace the current scene. 102 | /// An action to perform with the loading progress (0.0 to 0.9). 103 | /// An action to perform once the scene is fully loaded and activated. 104 | /// An IEnumerator for coroutine support, allowing this method to yield until the scene has loaded. 105 | public static IEnumerator WaitForSceneToLoad(string sceneName, LoadSceneMode loadSceneMode, 106 | UnityAction updateAction, UnityAction OnComplete) 107 | { 108 | AsyncOperation async = SceneManager.LoadSceneAsync(sceneName, loadSceneMode); 109 | async.allowSceneActivation = false; 110 | 111 | while (async.progress < 0.9f) 112 | { 113 | updateAction?.Invoke(async.progress); 114 | yield return null; 115 | } 116 | 117 | async.allowSceneActivation = true; 118 | 119 | while (!SceneManager.GetSceneByName(sceneName).isLoaded) 120 | { 121 | yield return new WaitForSeconds(0.1f); 122 | } 123 | 124 | OnComplete?.Invoke(); 125 | } 126 | 127 | /// 128 | /// Clone data from an object into a new version of it 129 | /// 130 | /// 131 | /// 132 | /// 133 | public static T Clone(T obj) 134 | { 135 | DataContractSerializer dcSer = new DataContractSerializer(obj.GetType()); 136 | MemoryStream memoryStream = new MemoryStream(); 137 | 138 | dcSer.WriteObject(memoryStream, obj); 139 | memoryStream.Position = 0; 140 | 141 | T newObject = (T)dcSer.ReadObject(memoryStream); 142 | Color32 c = new Color32(); 143 | c.ColorToHex(); 144 | return newObject; 145 | } 146 | 147 | /// 148 | /// Use Reflection from a source class to an inhearated class 149 | /// 150 | /// 151 | /// 152 | /// 153 | /// 154 | public static void CopyAll(this T source, T2 target) 155 | { 156 | Type type = typeof(T); 157 | foreach (FieldInfo sourceField in type.GetFields()) 158 | { 159 | FieldInfo targetField = type.GetField(sourceField.Name); 160 | targetField.SetValue(target, sourceField.GetValue(source)); 161 | } 162 | } 163 | 164 | /// 165 | /// Calculates the number of columns and rows in a vertical grid layout based on the active children. 166 | /// 167 | /// The GridLayoutGroup for which to calculate columns and rows. 168 | /// The number of columns in the grid. Output parameter. 169 | /// The number of rows in the grid. Output parameter. 170 | /// 171 | /// This method assumes that the grid starts with at least one column and one row. 172 | /// It iterates through all child objects of the GridLayoutGroup, counting the number of columns and rows 173 | /// based on the positions of the child objects. It only considers active child objects. 174 | /// 175 | public static void GetColumnAndRowForVerticalGrid(this GridLayoutGroup glg, out int column, out int row) 176 | { 177 | column = 0; 178 | row = 0; 179 | 180 | if (glg.transform.childCount == 0) 181 | return; 182 | 183 | //Column and row are now 1 184 | column = 1; 185 | row = 1; 186 | 187 | //Get the first child GameObject of the GridLayoutGroup 188 | RectTransform firstChildObj = glg.transform.GetChild(0).GetComponent(); 189 | 190 | float currentY = firstChildObj.anchoredPosition.y; 191 | 192 | //Loop through the rest of the child object 193 | for (int i = 1; i < glg.transform.childCount; i++) 194 | { 195 | if (!glg.transform.GetChild(i).gameObject.activeSelf) 196 | { 197 | continue; 198 | } 199 | 200 | //Get the next child 201 | RectTransform currentChildObj = glg.transform.GetChild(i).GetComponent(); 202 | 203 | Vector2 currentChildPos = currentChildObj.anchoredPosition; 204 | 205 | //if first child.x == otherchild.x, it is a row, else it's a column 206 | if (Math.Abs(currentY - currentChildPos.y) > Mathf.Epsilon) 207 | { 208 | row++; 209 | currentY = currentChildPos.y; 210 | } 211 | else 212 | { 213 | column++; 214 | } 215 | } 216 | } 217 | 218 | /// 219 | /// Finds the index of the first occurrence of an object in an array. 220 | /// 221 | /// The array to search. 222 | /// The object to find the index of. 223 | /// The type of the objects in the array. 224 | /// The index of the first occurrence of the object in the array; -1 if not found. 225 | public static int IndexOf(this T[] array, T obj) 226 | { 227 | return Array.IndexOf(array, obj); 228 | } 229 | 230 | /// 231 | /// Trims the milliseconds from a DateTime object, returning a new DateTime object. 232 | /// 233 | /// The DateTime object to trim milliseconds from. 234 | /// A new DateTime object with the milliseconds set to 0. 235 | public static DateTime TrimMilliseconds(this DateTime dt) 236 | { 237 | return new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, 0, dt.Kind); 238 | } 239 | 240 | /// 241 | /// Wait a set number of frames in a coroutine 242 | /// 243 | /// 244 | /// 245 | public static IEnumerator Frames(int frameCount) 246 | { 247 | WaitForEndOfFrame frame = new WaitForEndOfFrame(); 248 | while (frameCount > 0) 249 | { 250 | frameCount--; 251 | yield return frame; 252 | } 253 | } 254 | 255 | /// 256 | /// Creates a runtime sprite from a texture2D 257 | /// 258 | /// 259 | /// 260 | public static Sprite CreateSprite(this Texture2D t) 261 | { 262 | Rect r = new Rect(0, 0, t.width, t.height); 263 | Sprite s = Sprite.Create(t, r, Vector2.zero); 264 | return s; 265 | } 266 | } 267 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/MiscExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a9adae05b2cb62f49927d4f8b9c932d5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/NumberExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace GG.Extensions 5 | { 6 | /// 7 | /// Provides extension methods for numeric types to perform various rounding operations and checks. 8 | /// 9 | public static class NumberExtensions 10 | { 11 | /// 12 | /// Defines the rounding mode to be used. 13 | /// 14 | public enum RoundMode 15 | { 16 | /// 17 | /// Round to the nearest multiple. 18 | /// 19 | UpDown, 20 | /// 21 | /// Always round up to the nearest multiple. 22 | /// 23 | Up, 24 | /// 25 | /// Always round down to the nearest multiple. 26 | /// 27 | Down 28 | } 29 | 30 | /// 31 | /// Rounds an integer to the nearest multiple of a specified number, with an optional rounding mode. 32 | /// 33 | /// The integer to round. 34 | /// The multiple to round to. 35 | /// The rounding mode to use. Defaults to UpDown. 36 | /// The rounded integer. 37 | public static int NearestMultipleOf(this int x, int multiple, RoundMode rm = RoundMode.UpDown) 38 | { 39 | return Mathf.RoundToInt(((float)x).NearestMultipleOf((float)multiple, rm)); 40 | } 41 | 42 | /// 43 | /// Rounds a float to the nearest multiple of a specified number, with an optional rounding mode. 44 | /// 45 | /// The float to round. 46 | /// The multiple to round to. 47 | /// The rounding mode to use. Defaults to UpDown. 48 | /// The rounded float. 49 | public static float NearestMultipleOf(this float x, float multiple, RoundMode rm = RoundMode.UpDown) 50 | { 51 | float mod = x % multiple; 52 | float midPoint = multiple / 2.0f; 53 | 54 | if (rm == RoundMode.UpDown) 55 | { 56 | if (mod > midPoint) 57 | { 58 | return x + (multiple - mod); 59 | } 60 | else 61 | { 62 | return x - mod; 63 | } 64 | } 65 | else if (rm == RoundMode.Up) 66 | { 67 | return x + (multiple - mod); 68 | } 69 | else // (rm == RoundMode.Down) 70 | { 71 | return x - mod; 72 | } 73 | } 74 | 75 | /// 76 | /// Checks if a float value falls within a specified range, inclusive of the range boundaries. 77 | /// 78 | /// The float value to check. 79 | /// The lower boundary of the range. 80 | /// The upper boundary of the range. 81 | /// True if the value falls within the range, false otherwise. 82 | public static bool FallsBetween(this float numberToCheck, float bottom, float top) 83 | { 84 | return (numberToCheck >= bottom && numberToCheck <= top); 85 | } 86 | 87 | /// 88 | /// Rounds a float value to a specified number of decimal places. 89 | /// 90 | /// The float value to round. 91 | /// The number of decimal places to round to. 92 | /// The rounded float value. 93 | public static float Round(this float value, int digits) 94 | { 95 | return (float)Math.Round(value, digits); 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/NumberExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 802fe70f0b21b734a84a0f05edc887b3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/RectTramsformExtensions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace GG.Extensions 4 | { 5 | /// 6 | /// Defines preset anchor positions for RectTransforms. 7 | /// 8 | public enum AnchorPresets 9 | { 10 | TopLeft, 11 | TopCenter, 12 | TopRight, 13 | 14 | MiddleLeft, 15 | MiddleCenter, 16 | MiddleRight, 17 | 18 | BottomLeft, 19 | BottonCenter, 20 | BottomRight, 21 | BottomStretch, 22 | 23 | VertStretchLeft, 24 | VertStretchRight, 25 | VertStretchCenter, 26 | 27 | HorStretchTop, 28 | HorStretchMiddle, 29 | HorStretchBottom, 30 | 31 | StretchAll 32 | } 33 | /// 34 | /// Defines preset pivot positions for RectTransforms. 35 | /// 36 | public enum PivotPresets 37 | { 38 | TopLeft, 39 | TopCenter, 40 | TopRight, 41 | 42 | MiddleLeft, 43 | MiddleCenter, 44 | MiddleRight, 45 | 46 | BottomLeft, 47 | BottomCenter, 48 | BottomRight, 49 | } 50 | 51 | public static class RectTransformExtensions 52 | { 53 | /// 54 | /// Sets the anchor of a RectTransform to a predefined preset. 55 | /// 56 | /// The RectTransform to modify. 57 | /// The AnchorPresets value to apply. 58 | /// Optional X offset from the anchor position. 59 | /// Optional Y offset from the anchor position. 60 | public static void SetAnchor(this RectTransform source, AnchorPresets allign, int offsetX=0, int offsetY=0) 61 | { 62 | source.anchoredPosition = new Vector3(offsetX, offsetY, 0); 63 | 64 | switch (allign) 65 | { 66 | case(AnchorPresets.TopLeft): 67 | { 68 | source.anchorMin = new Vector2(0, 1); 69 | source.anchorMax = new Vector2(0, 1); 70 | break; 71 | } 72 | case (AnchorPresets.TopCenter): 73 | { 74 | source.anchorMin = new Vector2(0.5f, 1); 75 | source.anchorMax = new Vector2(0.5f, 1); 76 | break; 77 | } 78 | case (AnchorPresets.TopRight): 79 | { 80 | source.anchorMin = new Vector2(1, 1); 81 | source.anchorMax = new Vector2(1, 1); 82 | break; 83 | } 84 | 85 | case (AnchorPresets.MiddleLeft): 86 | { 87 | source.anchorMin = new Vector2(0, 0.5f); 88 | source.anchorMax = new Vector2(0, 0.5f); 89 | break; 90 | } 91 | case (AnchorPresets.MiddleCenter): 92 | { 93 | source.anchorMin = new Vector2(0.5f, 0.5f); 94 | source.anchorMax = new Vector2(0.5f, 0.5f); 95 | break; 96 | } 97 | case (AnchorPresets.MiddleRight): 98 | { 99 | source.anchorMin = new Vector2(1, 0.5f); 100 | source.anchorMax = new Vector2(1, 0.5f); 101 | break; 102 | } 103 | 104 | case (AnchorPresets.BottomLeft): 105 | { 106 | source.anchorMin = new Vector2(0, 0); 107 | source.anchorMax = new Vector2(0, 0); 108 | break; 109 | } 110 | case (AnchorPresets.BottonCenter): 111 | { 112 | source.anchorMin = new Vector2(0.5f, 0); 113 | source.anchorMax = new Vector2(0.5f,0); 114 | break; 115 | } 116 | case (AnchorPresets.BottomRight): 117 | { 118 | source.anchorMin = new Vector2(1, 0); 119 | source.anchorMax = new Vector2(1, 0); 120 | break; 121 | } 122 | 123 | case (AnchorPresets.HorStretchTop): 124 | { 125 | source.anchorMin = new Vector2(0, 1); 126 | source.anchorMax = new Vector2(1, 1); 127 | break; 128 | } 129 | case (AnchorPresets.HorStretchMiddle): 130 | { 131 | source.anchorMin = new Vector2(0, 0.5f); 132 | source.anchorMax = new Vector2(1, 0.5f); 133 | break; 134 | } 135 | case (AnchorPresets.HorStretchBottom): 136 | { 137 | source.anchorMin = new Vector2(0, 0); 138 | source.anchorMax = new Vector2(1, 0); 139 | break; 140 | } 141 | 142 | case (AnchorPresets.VertStretchLeft): 143 | { 144 | source.anchorMin = new Vector2(0, 0); 145 | source.anchorMax = new Vector2(0, 1); 146 | break; 147 | } 148 | case (AnchorPresets.VertStretchCenter): 149 | { 150 | source.anchorMin = new Vector2(0.5f, 0); 151 | source.anchorMax = new Vector2(0.5f, 1); 152 | break; 153 | } 154 | case (AnchorPresets.VertStretchRight): 155 | { 156 | source.anchorMin = new Vector2(1, 0); 157 | source.anchorMax = new Vector2(1, 1); 158 | break; 159 | } 160 | 161 | case (AnchorPresets.StretchAll): 162 | { 163 | source.anchorMin = new Vector2(0, 0); 164 | source.anchorMax = new Vector2(1, 1); 165 | break; 166 | } 167 | } 168 | } 169 | 170 | /// 171 | /// Sets the pivot of a RectTransform to a predefined preset. 172 | /// 173 | /// The RectTransform to modify. 174 | /// The PivotPresets value to apply. 175 | public static void SetPivot(this RectTransform source, PivotPresets preset) 176 | { 177 | 178 | switch (preset) 179 | { 180 | case (PivotPresets.TopLeft): 181 | { 182 | source.pivot = new Vector2(0, 1); 183 | break; 184 | } 185 | case (PivotPresets.TopCenter): 186 | { 187 | source.pivot = new Vector2(0.5f, 1); 188 | break; 189 | } 190 | case (PivotPresets.TopRight): 191 | { 192 | source.pivot = new Vector2(1, 1); 193 | break; 194 | } 195 | 196 | case (PivotPresets.MiddleLeft): 197 | { 198 | source.pivot = new Vector2(0, 0.5f); 199 | break; 200 | } 201 | case (PivotPresets.MiddleCenter): 202 | { 203 | source.pivot = new Vector2(0.5f, 0.5f); 204 | break; 205 | } 206 | case (PivotPresets.MiddleRight): 207 | { 208 | source.pivot = new Vector2(1, 0.5f); 209 | break; 210 | } 211 | 212 | case (PivotPresets.BottomLeft): 213 | { 214 | source.pivot = new Vector2(0, 0); 215 | break; 216 | } 217 | case (PivotPresets.BottomCenter): 218 | { 219 | source.pivot = new Vector2(0.5f, 0); 220 | break; 221 | } 222 | case (PivotPresets.BottomRight): 223 | { 224 | source.pivot = new Vector2(1, 0); 225 | break; 226 | } 227 | } 228 | } 229 | 230 | } 231 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/RectTramsformExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 149c1b944751275418fc0ca64f31c397 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/RendererExtensions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace GG.Extensions 4 | { 5 | /// 6 | /// Provides extension methods for the Renderer component. 7 | /// 8 | public static class RendererExtensions 9 | { 10 | /// 11 | /// Sets a specific material to a renderer at the given index. 12 | /// 13 | /// The renderer to modify. 14 | /// The index at which to set the material. 15 | /// The new material to set. 16 | /// 17 | /// This method modifies the materials array of the renderer. It first copies the current materials into a new array, 18 | /// replaces the material at the specified index, and then sets the modified array back to the renderer. 19 | /// This is useful for dynamically changing materials of game objects at runtime. 20 | /// 21 | public static void SetMaterial(this Renderer renderer, int index, Material material) 22 | { 23 | Material[] mats = renderer.materials; 24 | mats[index] = material; 25 | renderer.materials = mats; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/RendererExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d869a700475c5224e9e908417e88d68e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/SecurityExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.IO; 5 | using System.Security.Cryptography; 6 | using System.Text; 7 | 8 | // ReSharper disable MemberCanBePrivate.Global 9 | // ReSharper disable ReturnTypeCanBeEnumerable.Global 10 | 11 | namespace GG.Extensions 12 | { 13 | /// 14 | /// Security Behaviour e.g. Hashing and the like 15 | /// 16 | public static class SecurityExtensions 17 | { 18 | const int Iterations = 10000; 19 | 20 | /// 21 | /// Convert a byte array into string 22 | /// 23 | /// 24 | /// 25 | public static string BytesToString(byte[] _in) 26 | { 27 | string s = string.Empty; 28 | foreach (byte b in _in) 29 | { 30 | s += (char) b; 31 | } 32 | 33 | return s; 34 | } 35 | 36 | /// 37 | /// convert a string into bytes 38 | /// 39 | /// 40 | /// 41 | public static byte[] StringToBytes(string _in) 42 | { 43 | List b = new List(); 44 | foreach (char c in _in) 45 | { 46 | b.Add((byte) c); 47 | } 48 | 49 | return b.ToArray(); 50 | } 51 | 52 | /// 53 | /// Get the SHA256 hash of the input 54 | /// 55 | /// Input String 56 | /// The SHA256 hash 57 | public static byte[] GetHash(this string input) 58 | { 59 | HashAlgorithm algorithm = SHA256.Create(); 60 | return algorithm.ComputeHash(Encoding.UTF8.GetBytes(input)); 61 | } 62 | 63 | /// 64 | /// Get the input string in a SHA256 hash format 65 | /// 66 | /// The string to hash 67 | /// The hashed version of the string 68 | public static string GetHashString(this string input) 69 | { 70 | StringBuilder sb = new StringBuilder(); 71 | foreach (byte b in GetHash(input)) 72 | { 73 | sb.Append(b.ToString("X2")); 74 | } 75 | return sb.ToString(); 76 | } 77 | 78 | #region Password Hash 79 | 80 | /// 81 | /// Encrypt the string using a randomly generated salt key 82 | /// 83 | /// 84 | /// 85 | public static string PasswordHashEncrypt(this string toEncrypt) 86 | { 87 | byte[] salt; 88 | new RNGCryptoServiceProvider().GetBytes(salt = new byte[16]); 89 | 90 | Rfc2898DeriveBytes pbkdf2 = new Rfc2898DeriveBytes(toEncrypt, salt, Iterations); 91 | 92 | byte[] hash = pbkdf2.GetBytes(20); 93 | byte[] hashBytes = new byte[36]; 94 | 95 | Array.Copy(salt,0,hashBytes, 0,16); 96 | Array.Copy(hash,0,hashBytes, 16,20); 97 | 98 | return Convert.ToBase64String(hashBytes); 99 | } 100 | 101 | /// 102 | /// Encrypt the data by the salt key of the source and compare the encrypted data 103 | /// 104 | /// 105 | /// 106 | /// 107 | public static bool PasswordHashCompare(this string password, string original) 108 | { 109 | string savedPassword = original; 110 | byte[] hashBytes = Convert.FromBase64String(savedPassword); 111 | 112 | byte[] salt = new byte[16]; 113 | Array.Copy(hashBytes,0,salt,0,16); 114 | 115 | Rfc2898DeriveBytes pbkdf2 = new Rfc2898DeriveBytes(password, salt, Iterations); 116 | byte[] hash = pbkdf2.GetBytes(20); 117 | 118 | bool b = true; 119 | for (int i = 0; i < 20; i++) 120 | { 121 | if (hashBytes[i + 16] != hash[i]) 122 | { 123 | b = false; 124 | } 125 | } 126 | 127 | return b; 128 | } 129 | 130 | #endregion 131 | 132 | #region Salt Key Encryption 133 | 134 | /// 135 | /// Encrypts the given data using HMAC SHA512 hashing with a specified salt key. 136 | /// 137 | /// The data to encrypt. 138 | /// The salt key to use for encryption. 139 | /// A list containing the base64 encoded payload and its HMAC SHA512 hash. 140 | public static List SaltKeyEncrypt(string data, string salt) 141 | { 142 | byte[] key = Encoding.UTF8.GetBytes(salt); 143 | using (HMACSHA512 sha512 = new HMACSHA512(key)) 144 | { 145 | byte[] payload = Encoding.UTF8.GetBytes(data); 146 | byte[] binaryHash = sha512.ComputeHash(payload); 147 | string stringHash = Convert.ToBase64String(binaryHash); 148 | 149 | List l = new List 150 | { 151 | Convert.ToBase64String(payload), 152 | stringHash 153 | }; 154 | 155 | return l; 156 | } 157 | } 158 | 159 | /// 160 | /// Decrypts the given data using HMAC SHA512 hashing with a specified salt key, comparing it against a known hash. 161 | /// 162 | /// An array where the first element is the base64 encoded payload and the second element is its hash. 163 | /// The salt key used during encryption. 164 | /// The decrypted data if the hash matches, otherwise an empty string. 165 | public static string SaltKeyDecrypt(string[] data, string salt) 166 | { 167 | string hash = data[1]; 168 | byte[] key = Encoding.UTF8.GetBytes(salt); 169 | using (HMACSHA512 sha512 = new HMACSHA512(key)) 170 | { 171 | byte[] payload = Convert.FromBase64String(data[0]); 172 | byte[] binaryHash = sha512.ComputeHash(payload); 173 | string stringHash = Convert.ToBase64String(binaryHash); 174 | 175 | if (hash == stringHash) 176 | { 177 | string d = Encoding.UTF8.GetString(payload); 178 | return d; 179 | } 180 | } 181 | 182 | return ""; 183 | } 184 | 185 | #endregion 186 | 187 | #region AES 188 | /// 189 | /// Encrypts a given string using AES encryption with a specified key and initialization vector (IV). 190 | /// 191 | /// The string to encrypt. 192 | /// The encryption key as a string. It will be converted to bytes internally. 193 | /// The initialization vector as a string. It will be converted to bytes internally. 194 | /// The encrypted string, converted from bytes to a string representation. 195 | public static string AesEncryption(string rawValue, string key, string iv) 196 | { 197 | byte[] keyByte = StringToBytes(key); // Convert the key from string to bytes 198 | byte[] ivByte = StringToBytes(iv); // Convert the IV from string to bytes 199 | 200 | byte[] encrypted; // To hold the encrypted data bytes 201 | string s = string.Empty; // Initialize an empty string to hold the final encrypted string 202 | using (Aes aesAlg = Aes.Create()) // Create a new instance of the Aes class 203 | { 204 | aesAlg.Key = keyByte; // Set the encryption key 205 | aesAlg.IV = ivByte; // Set the initialization vector 206 | 207 | // Create an encryptor to perform the stream transform. 208 | ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); 209 | 210 | // Create the streams used for encryption. 211 | using (MemoryStream msEncrypt = new MemoryStream()) 212 | { 213 | using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) 214 | { 215 | using (StreamWriter swEncrypt = new StreamWriter(csEncrypt)) 216 | { 217 | //Write all data to the stream. 218 | swEncrypt.Write(rawValue); 219 | } 220 | 221 | encrypted = msEncrypt.ToArray(); // Convert the encrypted data stream to a byte array 222 | 223 | s = BytesToString(encrypted); // Convert the encrypted bytes to a string 224 | } 225 | } 226 | } 227 | 228 | return s; // Return the encrypted string 229 | } 230 | 231 | /// 232 | /// Decrypt the byte array into a ascii readable string 233 | /// 234 | /// 235 | /// 236 | /// 237 | /// 238 | public static string AesDecryption(byte[] rawValue, string key, string iv) 239 | { 240 | byte[] keyByte = StringToBytes(key); 241 | byte[] ivByte = StringToBytes(iv); 242 | 243 | // Declare the string used to hold 244 | // the decrypted text. 245 | string plaintext = null; 246 | 247 | // Create an Aes object 248 | // with the specified key and IV. 249 | using (Aes aesAlg = Aes.Create()) 250 | { 251 | aesAlg.Key = keyByte; 252 | aesAlg.IV = ivByte; 253 | 254 | // Create a decryptor to perform the stream transform. 255 | ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); 256 | 257 | // Create the streams used for decryption. 258 | using (MemoryStream msDecrypt = new MemoryStream(rawValue)) 259 | { 260 | using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) 261 | { 262 | using (StreamReader srDecrypt = new StreamReader(csDecrypt)) 263 | { 264 | // Read the decrypted bytes from the decrypting stream 265 | // and place them in a string. 266 | plaintext = srDecrypt.ReadToEnd(); 267 | } 268 | } 269 | } 270 | } 271 | 272 | return plaintext; 273 | } 274 | #endregion 275 | } 276 | } 277 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/SecurityExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 49743f728c4eb0a44a4b059c106e5369 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.Text.RegularExpressions; 3 | using UnityEngine; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | 7 | namespace GG.Extensions 8 | { 9 | public static class StringExtensions 10 | { 11 | /// 12 | /// Given a person's first and last name, we'll make our best guess to extract up to two initials, hopefully 13 | /// representing their first and last name, skipping any middle initials, Jr/Sr/III suffixes, etc. The letters 14 | /// will be returned together in ALL CAPS, e.g. "TW". 15 | /// 16 | /// The way it parses names for many common styles: 17 | /// 18 | /// Mason Zhwiti -> MZ 19 | /// mason lowercase zhwiti -> MZ 20 | /// Mason G Zhwiti -> MZ 21 | /// Mason G. Zhwiti -> MZ 22 | /// John Queue Public -> JP 23 | /// John Q. Public, Jr. -> JP 24 | /// John Q Public Jr. -> JP 25 | /// Thurston Howell III -> TH 26 | /// Thurston Howell, III -> TH 27 | /// Malcolm X -> MX 28 | /// A Ron -> AR 29 | /// A A Ron -> AR 30 | /// Madonna -> M 31 | /// Chris O'Donnell -> CO 32 | /// Malcolm McDowell -> MM 33 | /// Robert "Rocky" Balboa, Sr. -> RB 34 | /// 1Bobby 2Tables -> BT 35 | /// Éric Ígor -> ÉÍ 36 | /// 행운의 복숭아 -> 행복 37 | /// 38 | /// 39 | /// The full name of a person. 40 | /// One to two uppercase initials, without punctuation. 41 | public static string ExtractInitialsFromName(string name) 42 | { 43 | // first remove all: punctuation, separator chars, control chars, and numbers (unicode style regexes) 44 | string initials = Regex.Replace(name, @"[\p{P}\p{S}\p{C}\p{N}]+", ""); 45 | 46 | // Replacing all possible whitespace/separator characters (unicode style), with a single, regular ascii space. 47 | initials = Regex.Replace(initials, @"\p{Z}+", " "); 48 | 49 | // Remove all Sr, Jr, I, II, III, IV, V, VI, VII, VIII, IX at the end of names 50 | initials = Regex.Replace(initials.Trim(), @"\s+(?:[JS]R|I{1,3}|I[VX]|VI{0,3})$", "", 51 | RegexOptions.IgnoreCase); 52 | 53 | // Extract up to 2 initials from the remaining cleaned name. 54 | initials = Regex.Replace(initials, @"^(\p{L})[^\s]*(?:\s+(?:\p{L}+\s+(?=\p{L}))?(?:(\p{L})\p{L}*)?)?$", 55 | "$1$2").Trim(); 56 | 57 | if (initials.Length > 2) 58 | { 59 | // Worst case scenario, everything failed, just grab the first two letters of what we have left. 60 | initials = initials.Substring(0, 2); 61 | } 62 | 63 | return initials.ToUpperInvariant(); 64 | } 65 | 66 | /// 67 | /// Extracts the first name and the initial of the last name from a full name. 68 | /// 69 | /// The full name from which to extract the first name and initial. 70 | /// A string containing the first name and the initial of the last name. 71 | public static string FirstNameAndInitial(string name) 72 | { 73 | name = Regex.Match(name, @"[A-Za-z]+\s+[A-Za-z]").Value; 74 | 75 | return name; 76 | } 77 | 78 | /// 79 | /// Converts a string to title case using the current thread's culture info. 80 | /// 81 | /// The string to convert to title case. 82 | /// The converted string in title case. 83 | public static string TitleCase(this string str) 84 | { 85 | CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture; 86 | return cultureInfo.TextInfo.ToTitleCase(str.ToLower()); 87 | } 88 | 89 | /// 90 | /// Converts a string to title case using a specified culture info by name. 91 | /// 92 | /// The string to convert to title case. 93 | /// The name of the culture info to use for conversion. 94 | /// The converted string in title case. 95 | public static string TitleCase(this string str, string cultureInfoName) 96 | { 97 | CultureInfo cultureInfo = new CultureInfo(cultureInfoName); 98 | return cultureInfo.TextInfo.ToTitleCase(str.ToLower()); 99 | } 100 | 101 | /// 102 | /// Converts a string to title case using a specified culture info. 103 | /// 104 | /// The string to convert to title case. 105 | /// The culture info to use for conversion. 106 | /// The converted string in title case. 107 | public static string TitleCase(this string str, CultureInfo cultureInfo) 108 | { 109 | return cultureInfo.TextInfo.ToTitleCase(str.ToLower()); 110 | } 111 | 112 | /// 113 | /// Splits a string at specified indices. 114 | /// 115 | /// The source string to split. 116 | /// An array of indices where the string should be split. 117 | /// An array of substrings created by splitting the source string. 118 | public static string[] SplitAtIndexs(this string source, params int[] index) 119 | { 120 | var indices = new[] { 0 }.Union(index).Union(new[] { source.Length }); 121 | 122 | return indices 123 | .Zip(indices.Skip(1), (a, b) => (a, b)) 124 | .Select(_ => source.Substring(_.a, _.b - _.a)).ToArray(); 125 | } 126 | 127 | /// 128 | /// Splits a string into two parts at the nearest space to the middle, ensuring that neither part exceeds a specified maximum length. 129 | /// 130 | /// The source string to split. 131 | /// The maximum length of each part after splitting. 132 | /// The source string split into two parts, if necessary, at the nearest space to the middle. 133 | public static string SliceString(this string source, int maxCharacterLengthInLine) 134 | { 135 | if (source.Length >= maxCharacterLengthInLine) 136 | { 137 | //get half way number 138 | int half = source.Length / 2; 139 | bool startOfWord = false; 140 | 141 | while (!startOfWord) 142 | { 143 | //while not space, go back a letter 144 | char c = source[half]; 145 | if (c == ' ' || half == 0) 146 | { 147 | startOfWord = true; 148 | } 149 | else 150 | { 151 | half++; 152 | } 153 | } 154 | 155 | string[] a = source.SplitAtIndexs(half); 156 | source = a[0] + "\n" + a[1].TrimStart(); 157 | } 158 | 159 | return source; 160 | } 161 | } 162 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/StringExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4eb1b397baf2edb428200d19045a5dcf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/TransformExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a74cdd7866e1e849a5ffd7bbda48438 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/UIExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using UnityEngine; 3 | using UnityEngine.UI; 4 | 5 | namespace GG.Extensions 6 | { 7 | public static class UiExtensions 8 | { 9 | #region ToggleGroups 10 | 11 | public static Toggle GetActive(this ToggleGroup aGroup) 12 | { 13 | return aGroup.ActiveToggles().FirstOrDefault(); 14 | } 15 | 16 | #endregion 17 | 18 | static Slider.SliderEvent emptySliderEvent = new Slider.SliderEvent(); 19 | public static void SetValue(this Slider instance, float value) 20 | { 21 | var originalEvent = instance.onValueChanged; 22 | instance.onValueChanged = emptySliderEvent; 23 | instance.value = value; 24 | instance.onValueChanged = originalEvent; 25 | } 26 | 27 | static Toggle.ToggleEvent emptyToggleEvent = new Toggle.ToggleEvent(); 28 | public static void SetValue(this Toggle instance, bool value) 29 | { 30 | var originalEvent = instance.onValueChanged; 31 | instance.onValueChanged = emptyToggleEvent; 32 | instance.isOn = value; 33 | instance.onValueChanged = originalEvent; 34 | } 35 | 36 | static InputField.OnChangeEvent emptyInputFieldEvent = new InputField.OnChangeEvent(); 37 | public static void SetValue(this InputField instance, string value) 38 | { 39 | var originalEvent = instance.onValueChanged; 40 | instance.onValueChanged = emptyInputFieldEvent; 41 | instance.text = value; 42 | instance.onValueChanged = originalEvent; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/UIExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1723e34048866584cbf64220a92d99e6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/VectorExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2dfe4902e02485d4ba2be00b0825bab7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/VersionExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GG.Extensions 4 | { 5 | public static class VersionExtension { 6 | 7 | public static Version IncrementRevision(this Version version) { 8 | return AddVersion(version, 0, 0, 0, 1); 9 | } 10 | public static Version IncrementBuild(this Version version) { 11 | return IncrementBuild(version, true); 12 | } 13 | public static Version IncrementBuild(this Version version, bool resetLowerNumbers) { 14 | return AddVersion(version, 0, 0, 1, resetLowerNumbers ? -version.Revision : 0); 15 | } 16 | public static Version IncrementMinor(this Version version) { 17 | return IncrementMinor(version, true); 18 | } 19 | public static Version IncrementMinor(this Version version, bool resetLowerNumbers) { 20 | return AddVersion(version, 0, 1, resetLowerNumbers ? -version.Build : 0, resetLowerNumbers ? -version.Revision : 0); 21 | } 22 | public static Version IncrementMajor(this Version version) { 23 | return IncrementMajor(version, true); 24 | } 25 | public static Version IncrementMajor(this Version version, bool resetLowerNumbers) { 26 | return AddVersion(version, 1, resetLowerNumbers ? -version.Minor : 0, resetLowerNumbers ? -version.Build : 0, resetLowerNumbers ? -version.Revision : 0); 27 | } 28 | 29 | public static Version AddVersion(this Version version, string addVersion) { 30 | return AddVersion(version, new Version(addVersion)); 31 | } 32 | public static Version AddVersion(this Version version, Version addVersion) { 33 | return AddVersion(version, addVersion.Major, addVersion.Minor, addVersion.Build, addVersion.Revision); 34 | } 35 | public static Version AddVersion(this Version version, int major, int minor, int build, int revision) { 36 | return SetVersion(version, version.Major + major, version.Minor + minor, version.Build + build, version.Revision + revision); 37 | } 38 | public static Version SetVersion(this Version version, int major, int minor, int build, int revision) { 39 | return new Version(major, minor, build);//, revision); 40 | } 41 | 42 | /* 43 | //one day we may even be able to do something like this... 44 | //https://github.com/dotnet/csharplang/issues/192 45 | public static Version operator +(Version version, int revision) { 46 | return AddVersion(version, 0, 0, 0, revision); 47 | } 48 | public static Version operator ++(Version version) { 49 | return IncrementVersion(version); 50 | } 51 | */ 52 | } 53 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/VersionExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 981917db65d2fa04abc595b3f98ac67e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/WebExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using System.Threading.Tasks; 3 | using UnityEngine; 4 | using UnityEngine.Networking; 5 | 6 | namespace GG.Extensions 7 | { 8 | public static class WebExtensions 9 | { 10 | /// 11 | /// Quickly pings a URL and returns if it is accessible 12 | /// Defaults to ping google, cause if you cant reach google then the world has already ended. 13 | /// 14 | /// 15 | public static async Task CanReachInternet(string toPing = "http://google.com") 16 | { 17 | UnityWebRequest request = new UnityWebRequest(toPing); 18 | await request.SendWebRequest(); 19 | 20 | return !request.isNetworkError; 21 | } 22 | 23 | /// 24 | /// Setup a web request to send a JSON in the body 25 | /// 26 | /// The json to send 27 | /// The URI to send to 28 | public static UnityWebRequest SetupPostWebRequest(string json, string uri) 29 | { 30 | UnityWebRequest request = UnityWebRequest.PostWwwForm(uri, ""); 31 | byte[] bodyRaw = new UTF8Encoding().GetBytes(json); 32 | request.uploadHandler = new UploadHandlerRaw(bodyRaw) {contentType = "application/json"}; 33 | request.downloadHandler = new DownloadHandlerBuffer(); 34 | return request; 35 | } 36 | 37 | /// 38 | /// Adds a Parameter value to the url 39 | /// 40 | /// 41 | /// 42 | /// 43 | public static void AddParameter(this UnityWebRequest request, string parameter, string value) 44 | { 45 | if (request.url.Contains("?")) 46 | { 47 | request.url += $"&{parameter}={value}"; 48 | } 49 | else 50 | { 51 | request.url += $"?{parameter}={value}"; 52 | } 53 | } 54 | 55 | /// 56 | /// Download texture from a urlImagePath 57 | /// 58 | /// 59 | /// 60 | public static async Task GetTexture(string urlToImage) 61 | { 62 | UnityWebRequest www = UnityWebRequestTexture.GetTexture(urlToImage); 63 | await www.SendWebRequest(); 64 | 65 | if(www.isNetworkError || www.isHttpError) 66 | { 67 | Debug.Log(www.error); 68 | } 69 | else 70 | { 71 | Texture2D myTexture = DownloadHandlerTexture.GetContent(www); 72 | return myTexture; 73 | } 74 | 75 | return null; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/WebExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b436824a9b941174fbbcc4a792d05479 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/XR.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 686ad1d4b11391c46adbc042bbe815f1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/XR/LayerMaskExtensions.cs: -------------------------------------------------------------------------------- 1 | #if Interaction_Toolkit 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.XR.Interaction.Toolkit; 5 | 6 | namespace GG.Extensions.Vr 7 | { 8 | public static class InteractionLayerMaskExtensions 9 | { 10 | /// 11 | /// Creates a layer mask from the specified layer names. 12 | /// 13 | /// The layer names to include in the mask. 14 | /// An InteractionLayerMask representing the specified layers. 15 | public static InteractionLayerMask CreateLayerMask(params string[] layerNames) 16 | { 17 | return NamesToMask(layerNames); 18 | } 19 | 20 | /// 21 | /// Creates a layer mask from the specified layer numbers. 22 | /// 23 | /// The layer numbers to include in the mask. 24 | /// An InteractionLayerMask representing the specified layers. 25 | public static InteractionLayerMask CreateLayerMask(params int[] layerNumbers) 26 | { 27 | return LayerNumbersToMask(layerNumbers); 28 | } 29 | 30 | /// 31 | /// Converts an array of layer names into an InteractionLayerMask. 32 | /// 33 | /// The layer names to convert. 34 | /// An InteractionLayerMask representing the specified layers. 35 | public static InteractionLayerMask NamesToMask(params string[] layerNames) 36 | { 37 | InteractionLayerMask ret = 0; 38 | foreach (string name in layerNames) 39 | { 40 | ret |= 1 << InteractionLayerMask.NameToLayer(name); 41 | } 42 | 43 | return ret; 44 | } 45 | 46 | /// 47 | /// Converts an array of layer numbers into an InteractionLayerMask. 48 | /// 49 | /// The layer numbers to convert. 50 | /// An InteractionLayerMask representing the specified layers. 51 | public static InteractionLayerMask LayerNumbersToMask(params int[] layerNumbers) 52 | { 53 | InteractionLayerMask ret = 0; 54 | foreach (int layer in layerNumbers) 55 | { 56 | ret |= 1 << layer; 57 | } 58 | 59 | return ret; 60 | } 61 | 62 | /// 63 | /// Inverts the specified InteractionLayerMask. 64 | /// 65 | /// The original InteractionLayerMask to invert. 66 | /// An inverted InteractionLayerMask. 67 | public static InteractionLayerMask Inverse(this InteractionLayerMask original) 68 | { 69 | return ~original; 70 | } 71 | 72 | /// 73 | /// Adds layers to the specified InteractionLayerMask. 74 | /// 75 | /// The original InteractionLayerMask. 76 | /// The layer names to add. 77 | /// An InteractionLayerMask with the specified layers added. 78 | public static InteractionLayerMask AddToMask(this InteractionLayerMask original, params string[] layerNames) 79 | { 80 | return original | NamesToMask(layerNames); 81 | } 82 | 83 | /// 84 | /// Removes layers from the specified InteractionLayerMask. 85 | /// 86 | /// The original InteractionLayerMask. 87 | /// The layer names to remove. 88 | /// An InteractionLayerMask with the specified layers removed. 89 | public static InteractionLayerMask RemoveFromMask(this InteractionLayerMask original, 90 | params string[] layerNames) 91 | { 92 | InteractionLayerMask invertedOriginal = ~original; 93 | return ~(invertedOriginal | NamesToMask(layerNames)); 94 | } 95 | 96 | /// 97 | /// Converts an InteractionLayerMask to an array of layer names. 98 | /// 99 | /// The InteractionLayerMask to convert. 100 | /// An array of layer names represented by the InteractionLayerMask. 101 | public static string[] MaskToNames(this InteractionLayerMask original) 102 | { 103 | List output = new List(); 104 | 105 | for (int i = 0; i < 32; ++i) 106 | { 107 | int shifted = 1 << i; 108 | if ((original & shifted) == shifted) 109 | { 110 | string layerName = InteractionLayerMask.LayerToName(i); 111 | if (!string.IsNullOrEmpty(layerName)) 112 | { 113 | output.Add(layerName); 114 | } 115 | } 116 | } 117 | 118 | return output.ToArray(); 119 | } 120 | 121 | /// 122 | /// Converts an InteractionLayerMask to a string representation, using a specified delimiter. 123 | /// 124 | /// The InteractionLayerMask to convert. 125 | /// The delimiter to use between layer names. 126 | /// A string representation of the InteractionLayerMask. 127 | public static string MaskToString(this InteractionLayerMask original, string delimiter) 128 | { 129 | return string.Join(delimiter, MaskToNames(original)); 130 | } 131 | 132 | /// 133 | /// Converts an InteractionLayerMask to a string representation with a default delimiter. 134 | /// 135 | /// The InteractionLayerMask to convert. 136 | /// A string representation of the InteractionLayerMask, separated by ", ". 137 | public static string MaskToString(this InteractionLayerMask original) 138 | { 139 | return MaskToString(original, ", "); 140 | } 141 | 142 | /// 143 | /// Moves the GameObject associated with the specified Transform to a new layer, optionally applying the change recursively to all children. 144 | /// 145 | /// The root Transform whose GameObject's layer will be changed. 146 | /// The name of the layer to move the GameObject to. 147 | /// Whether to apply the layer change to all child GameObjects recursively. 148 | public static void MoveToLayer(this Transform root, string layer, bool recursive = true) 149 | { 150 | MoveToLayer(root, InteractionLayerMask.NameToLayer(layer), recursive); 151 | } 152 | 153 | /// 154 | /// Moves the GameObject associated with the specified Transform to a new layer, optionally applying the change recursively to all children. 155 | /// 156 | /// The root Transform whose GameObject's layer will be changed. 157 | /// The layer number to move the GameObject to. 158 | /// Whether to apply the layer change to all child GameObjects recursively. 159 | public static void MoveToLayer(this Transform root, int layer, bool recursive = true) 160 | { 161 | root.gameObject.layer = layer; 162 | 163 | if (recursive) 164 | { 165 | foreach (Transform child in root) 166 | { 167 | MoveToLayer(child, layer); 168 | } 169 | } 170 | } 171 | 172 | /// 173 | /// Moves all GameObjects of a specific component type within the children of the specified Transform to a new layer. 174 | /// 175 | /// The component type to filter the GameObjects by. 176 | /// The root Transform to search within. 177 | /// The name of the layer to move the GameObjects to. 178 | public static void MoveToLayer(this Transform root, string layer) where T : Component 179 | { 180 | MoveToLayer(root, InteractionLayerMask.NameToLayer(layer)); 181 | } 182 | 183 | /// 184 | /// Moves all GameObjects of a specific component type within the children of the specified Transform to a new layer. 185 | /// 186 | /// The component type to filter the GameObjects by. 187 | /// The root Transform to search within. 188 | /// The layer number to move the GameObjects to. 189 | public static void MoveToLayer(this Transform root, int layerNumber) where T : Component 190 | { 191 | foreach (T trans in root.GetComponentsInChildren(true)) 192 | { 193 | trans.gameObject.layer = layerNumber; 194 | } 195 | } 196 | 197 | /// 198 | /// Checks if the specified InteractionLayerMask contains a specific layer number. 199 | /// 200 | /// The InteractionLayerMask to check. 201 | /// The layer number to check for. 202 | /// True if the mask contains the layer, otherwise false. 203 | public static bool ContainsLayer(this InteractionLayerMask mask, int layer) 204 | { 205 | return ((1 << layer) & mask) > 0; 206 | } 207 | 208 | /// 209 | /// Checks if the specified InteractionLayerMask contains a specific layer name. 210 | /// 211 | /// The InteractionLayerMask to check. 212 | /// The name of the layer to check for. 213 | /// True if the mask contains the layer, otherwise false. 214 | public static bool ContainsLayer(this InteractionLayerMask mask, string layer) 215 | { 216 | return ((1 << InteractionLayerMask.NameToLayer(layer)) & mask) > 0; 217 | } 218 | } 219 | } 220 | #endif -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/XR/LayerMaskExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e297f2fff9449ecb7a37e83d9ee69fb 3 | timeCreated: 1647957605 -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/XR/XrExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | using UnityEngine.XR; 4 | 5 | namespace GG.Extensions.Vr 6 | { 7 | /// 8 | /// Provides extension methods for XR (Extended Reality) functionalities. 9 | /// 10 | public static class XrExtensions 11 | { 12 | /// 13 | /// Checks if an XR headset is currently present and running. 14 | /// 15 | /// True if an XR headset is present and running; otherwise, false. 16 | public static bool IsHeadsetPresent() 17 | { 18 | // Create a list to hold XR display subsystems 19 | List xrDisplaySubsystems = new List(); 20 | // Populate the list with the current XR display subsystem instances 21 | SubsystemManager.GetInstances(xrDisplaySubsystems); 22 | // Iterate through each XR display subsystem 23 | foreach (XRDisplaySubsystem xrDisplay in xrDisplaySubsystems) 24 | { 25 | // Check if the XR display subsystem is running 26 | if (xrDisplay.running) 27 | { 28 | // If running, return true indicating a headset is present 29 | return true; 30 | } 31 | } 32 | // If no running XR display subsystem is found, return false 33 | return false; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/XR/XrExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 98669a04d18c4a33893d5cef087dc17b 3 | timeCreated: 1644592779 -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/XR/gg.extensions.Xr.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GG.Extensions.Xr", 3 | "rootNamespace": "", 4 | "references": [ 5 | "Unity.XR.Interaction.Toolkit" 6 | ], 7 | "includePlatforms": [], 8 | "excludePlatforms": [], 9 | "allowUnsafeCode": false, 10 | "overrideReferences": false, 11 | "precompiledReferences": [], 12 | "autoReferenced": true, 13 | "defineConstraints": [], 14 | "versionDefines": [ 15 | { 16 | "name": "com.unity.xr.interaction.toolkit", 17 | "expression": "2.0.1", 18 | "define": "Interaction_Toolkit" 19 | } 20 | ], 21 | "noEngineReferences": false 22 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/XR/gg.extensions.Xr.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a692bdab0c6a929448dd522756ce4d0d 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/gg.extensions.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GG.Extensions", 3 | "references": [ 4 | "GUID:6f099b00ee0d34f4eb8ef168f15e5087" 5 | ], 6 | "includePlatforms": [], 7 | "excludePlatforms": [], 8 | "allowUnsafeCode": false, 9 | "overrideReferences": false, 10 | "precompiledReferences": [], 11 | "autoReferenced": true, 12 | "defineConstraints": [], 13 | "versionDefines": [], 14 | "noEngineReferences": false 15 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/Scripts/gg.extensions.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 91018aa887077a148a9037b4dfd0338a 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/Unity_Extensions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.greener-games.unity-extensions", 3 | "displayName": "Unity Extensions", 4 | "description": "Collection of extensions for use in unity", 5 | "version": "1.2.0", 6 | "unity": "2018.1", 7 | "license": "MIT", 8 | "author": { 9 | "name": "Greener Games" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/Greener-Games/Unity_Extensions" 14 | }, 15 | "dependencies": { 16 | "com.svermeulen.asyncawaitutil": "0.1.3" 17 | } 18 | } -------------------------------------------------------------------------------- /Packages/Unity_Extensions/package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3541648546faf3c4cae2309f061964ab 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Packages/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "com.svermeulen.asyncawaitutil": "0.1.3", 4 | "com.unity.2d.animation": "9.1.0", 5 | "com.unity.2d.pixel-perfect": "5.0.3", 6 | "com.unity.2d.psdimporter": "8.0.4", 7 | "com.unity.2d.sprite": "1.0.0", 8 | "com.unity.2d.spriteshape": "9.0.2", 9 | "com.unity.2d.tilemap": "1.0.0", 10 | "com.unity.ai.navigation": "1.1.5", 11 | "com.unity.collab-proxy": "2.3.1", 12 | "com.unity.ide.rider": "3.0.28", 13 | "com.unity.ide.visualstudio": "2.0.22", 14 | "com.unity.ide.vscode": "1.2.5", 15 | "com.unity.test-framework": "1.1.33", 16 | "com.unity.textmeshpro": "3.0.6", 17 | "com.unity.timeline": "1.7.6", 18 | "com.unity.ugui": "1.0.0", 19 | "com.unity.xr.interaction.toolkit": "2.5.4", 20 | "com.unity.modules.ai": "1.0.0", 21 | "com.unity.modules.androidjni": "1.0.0", 22 | "com.unity.modules.animation": "1.0.0", 23 | "com.unity.modules.assetbundle": "1.0.0", 24 | "com.unity.modules.audio": "1.0.0", 25 | "com.unity.modules.cloth": "1.0.0", 26 | "com.unity.modules.director": "1.0.0", 27 | "com.unity.modules.imageconversion": "1.0.0", 28 | "com.unity.modules.imgui": "1.0.0", 29 | "com.unity.modules.jsonserialize": "1.0.0", 30 | "com.unity.modules.particlesystem": "1.0.0", 31 | "com.unity.modules.physics": "1.0.0", 32 | "com.unity.modules.physics2d": "1.0.0", 33 | "com.unity.modules.screencapture": "1.0.0", 34 | "com.unity.modules.terrain": "1.0.0", 35 | "com.unity.modules.terrainphysics": "1.0.0", 36 | "com.unity.modules.tilemap": "1.0.0", 37 | "com.unity.modules.ui": "1.0.0", 38 | "com.unity.modules.uielements": "1.0.0", 39 | "com.unity.modules.umbra": "1.0.0", 40 | "com.unity.modules.unityanalytics": "1.0.0", 41 | "com.unity.modules.unitywebrequest": "1.0.0", 42 | "com.unity.modules.unitywebrequestassetbundle": "1.0.0", 43 | "com.unity.modules.unitywebrequestaudio": "1.0.0", 44 | "com.unity.modules.unitywebrequesttexture": "1.0.0", 45 | "com.unity.modules.unitywebrequestwww": "1.0.0", 46 | "com.unity.modules.vehicles": "1.0.0", 47 | "com.unity.modules.video": "1.0.0", 48 | "com.unity.modules.vr": "1.0.0", 49 | "com.unity.modules.wind": "1.0.0", 50 | "com.unity.modules.xr": "1.0.0" 51 | }, 52 | "scopedRegistries": [ 53 | { 54 | "name": "OpenUpm", 55 | "url": "https://package.openupm.com", 56 | "scopes": [ 57 | "com.svermeulen", 58 | "com.firenero" 59 | ] 60 | } 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Volume: 1 8 | Rolloff Scale: 1 9 | Doppler Factor: 1 10 | Default Speaker Mode: 2 11 | m_SampleRate: 0 12 | m_DSPBufferSize: 1024 13 | m_VirtualVoiceCount: 512 14 | m_RealVoiceCount: 32 15 | m_SpatializerPlugin: 16 | m_AmbisonicDecoderPlugin: 17 | m_DisableAudio: 0 18 | m_VirtualizeEffects: 1 19 | m_RequestedDSPBufferSize: 1024 20 | -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!236 &1 4 | ClusterInputManager: 5 | m_ObjectHideFlags: 0 6 | m_Inputs: [] 7 | -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 11 7 | m_Gravity: {x: 0, y: -9.81, z: 0} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_BounceThreshold: 2 10 | m_SleepThreshold: 0.005 11 | m_DefaultContactOffset: 0.01 12 | m_DefaultSolverIterations: 6 13 | m_DefaultSolverVelocityIterations: 1 14 | m_QueriesHitBackfaces: 0 15 | m_QueriesHitTriggers: 1 16 | m_EnableAdaptiveForce: 0 17 | m_ClothInterCollisionDistance: 0 18 | m_ClothInterCollisionStiffness: 0 19 | m_ContactsGeneration: 1 20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 21 | m_AutoSimulation: 1 22 | m_AutoSyncTransforms: 0 23 | m_ReuseCollisionCallbacks: 1 24 | m_ClothInterCollisionSettingsToggle: 0 25 | m_ContactPairsMode: 0 26 | m_BroadphaseType: 0 27 | m_WorldBounds: 28 | m_Center: {x: 0, y: 0, z: 0} 29 | m_Extent: {x: 250, y: 250, z: 250} 30 | m_WorldSubdivisions: 8 31 | m_FrictionType: 0 32 | m_EnableEnhancedDeterminism: 0 33 | m_EnableUnifiedHeightmaps: 1 34 | m_DefaultMaxAngluarSpeed: 7 35 | -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: [] 8 | m_configObjects: {} 9 | -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 9 7 | m_ExternalVersionControlSupport: Visible Meta Files 8 | m_SerializationMode: 2 9 | m_LineEndingsForNewScripts: 0 10 | m_DefaultBehaviorMode: 1 11 | m_PrefabRegularEnvironment: {fileID: 0} 12 | m_PrefabUIEnvironment: {fileID: 0} 13 | m_SpritePackerMode: 4 14 | m_SpritePackerPaddingPower: 1 15 | m_EtcTextureCompressorBehavior: 1 16 | m_EtcTextureFastCompressor: 1 17 | m_EtcTextureNormalCompressor: 2 18 | m_EtcTextureBestCompressor: 4 19 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;rsp;asmref 20 | m_ProjectGenerationRootNamespace: 21 | m_CollabEditorSettings: 22 | inProgressEnabled: 1 23 | m_EnableTextureStreamingInEditMode: 1 24 | m_EnableTextureStreamingInPlayMode: 1 25 | m_AsyncShaderCompilation: 1 26 | m_EnterPlayModeOptionsEnabled: 0 27 | m_EnterPlayModeOptions: 3 28 | m_ShowLightmapResolutionOverlay: 1 29 | m_UseLegacyProbeSampleCount: 1 30 | m_AssetPipelineMode: 1 31 | m_CacheServerMode: 0 32 | m_CacheServerEndpoint: 33 | m_CacheServerNamespacePrefix: default 34 | m_CacheServerEnableDownload: 1 35 | m_CacheServerEnableUpload: 1 36 | -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!30 &1 4 | GraphicsSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 12 7 | m_Deferred: 8 | m_Mode: 1 9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} 10 | m_DeferredReflections: 11 | m_Mode: 1 12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0} 13 | m_ScreenSpaceShadows: 14 | m_Mode: 1 15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0} 16 | m_LegacyDeferred: 17 | m_Mode: 1 18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} 19 | m_DepthNormals: 20 | m_Mode: 1 21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0} 22 | m_MotionVectors: 23 | m_Mode: 1 24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0} 25 | m_LightHalo: 26 | m_Mode: 1 27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0} 28 | m_LensFlare: 29 | m_Mode: 1 30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0} 31 | m_AlwaysIncludedShaders: 32 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} 33 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} 34 | m_PreloadedShaders: [] 35 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, 36 | type: 0} 37 | m_CustomRenderPipeline: {fileID: 0} 38 | m_TransparencySortMode: 0 39 | m_TransparencySortAxis: {x: 0, y: 0, z: 1} 40 | m_DefaultRenderingPath: 1 41 | m_DefaultMobileRenderingPath: 1 42 | m_TierSettings: [] 43 | m_LightmapStripping: 0 44 | m_FogStripping: 0 45 | m_InstancingStripping: 0 46 | m_LightmapKeepPlain: 1 47 | m_LightmapKeepDirCombined: 1 48 | m_LightmapKeepDynamicPlain: 1 49 | m_LightmapKeepDynamicDirCombined: 1 50 | m_LightmapKeepShadowMask: 1 51 | m_LightmapKeepSubtractive: 1 52 | m_FogKeepLinear: 1 53 | m_FogKeepExp: 1 54 | m_FogKeepExp2: 1 55 | m_AlbedoSwatchInfos: [] 56 | m_LightsUseLinearIntensity: 0 57 | m_LightsUseColorTemperature: 0 58 | -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!13 &1 4 | InputManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Axes: 8 | - serializedVersion: 3 9 | m_Name: Horizontal 10 | descriptiveName: 11 | descriptiveNegativeName: 12 | negativeButton: left 13 | positiveButton: right 14 | altNegativeButton: a 15 | altPositiveButton: d 16 | gravity: 3 17 | dead: 0.001 18 | sensitivity: 3 19 | snap: 1 20 | invert: 0 21 | type: 0 22 | axis: 0 23 | joyNum: 0 24 | - serializedVersion: 3 25 | m_Name: Vertical 26 | descriptiveName: 27 | descriptiveNegativeName: 28 | negativeButton: down 29 | positiveButton: up 30 | altNegativeButton: s 31 | altPositiveButton: w 32 | gravity: 3 33 | dead: 0.001 34 | sensitivity: 3 35 | snap: 1 36 | invert: 0 37 | type: 0 38 | axis: 0 39 | joyNum: 0 40 | - serializedVersion: 3 41 | m_Name: Fire1 42 | descriptiveName: 43 | descriptiveNegativeName: 44 | negativeButton: 45 | positiveButton: left ctrl 46 | altNegativeButton: 47 | altPositiveButton: mouse 0 48 | gravity: 1000 49 | dead: 0.001 50 | sensitivity: 1000 51 | snap: 0 52 | invert: 0 53 | type: 0 54 | axis: 0 55 | joyNum: 0 56 | - serializedVersion: 3 57 | m_Name: Fire2 58 | descriptiveName: 59 | descriptiveNegativeName: 60 | negativeButton: 61 | positiveButton: left alt 62 | altNegativeButton: 63 | altPositiveButton: mouse 1 64 | gravity: 1000 65 | dead: 0.001 66 | sensitivity: 1000 67 | snap: 0 68 | invert: 0 69 | type: 0 70 | axis: 0 71 | joyNum: 0 72 | - serializedVersion: 3 73 | m_Name: Fire3 74 | descriptiveName: 75 | descriptiveNegativeName: 76 | negativeButton: 77 | positiveButton: left shift 78 | altNegativeButton: 79 | altPositiveButton: mouse 2 80 | gravity: 1000 81 | dead: 0.001 82 | sensitivity: 1000 83 | snap: 0 84 | invert: 0 85 | type: 0 86 | axis: 0 87 | joyNum: 0 88 | - serializedVersion: 3 89 | m_Name: Jump 90 | descriptiveName: 91 | descriptiveNegativeName: 92 | negativeButton: 93 | positiveButton: space 94 | altNegativeButton: 95 | altPositiveButton: 96 | gravity: 1000 97 | dead: 0.001 98 | sensitivity: 1000 99 | snap: 0 100 | invert: 0 101 | type: 0 102 | axis: 0 103 | joyNum: 0 104 | - serializedVersion: 3 105 | m_Name: Mouse X 106 | descriptiveName: 107 | descriptiveNegativeName: 108 | negativeButton: 109 | positiveButton: 110 | altNegativeButton: 111 | altPositiveButton: 112 | gravity: 0 113 | dead: 0 114 | sensitivity: 0.1 115 | snap: 0 116 | invert: 0 117 | type: 1 118 | axis: 0 119 | joyNum: 0 120 | - serializedVersion: 3 121 | m_Name: Mouse Y 122 | descriptiveName: 123 | descriptiveNegativeName: 124 | negativeButton: 125 | positiveButton: 126 | altNegativeButton: 127 | altPositiveButton: 128 | gravity: 0 129 | dead: 0 130 | sensitivity: 0.1 131 | snap: 0 132 | invert: 0 133 | type: 1 134 | axis: 1 135 | joyNum: 0 136 | - serializedVersion: 3 137 | m_Name: Mouse ScrollWheel 138 | descriptiveName: 139 | descriptiveNegativeName: 140 | negativeButton: 141 | positiveButton: 142 | altNegativeButton: 143 | altPositiveButton: 144 | gravity: 0 145 | dead: 0 146 | sensitivity: 0.1 147 | snap: 0 148 | invert: 0 149 | type: 1 150 | axis: 2 151 | joyNum: 0 152 | - serializedVersion: 3 153 | m_Name: Horizontal 154 | descriptiveName: 155 | descriptiveNegativeName: 156 | negativeButton: 157 | positiveButton: 158 | altNegativeButton: 159 | altPositiveButton: 160 | gravity: 0 161 | dead: 0.19 162 | sensitivity: 1 163 | snap: 0 164 | invert: 0 165 | type: 2 166 | axis: 0 167 | joyNum: 0 168 | - serializedVersion: 3 169 | m_Name: Vertical 170 | descriptiveName: 171 | descriptiveNegativeName: 172 | negativeButton: 173 | positiveButton: 174 | altNegativeButton: 175 | altPositiveButton: 176 | gravity: 0 177 | dead: 0.19 178 | sensitivity: 1 179 | snap: 0 180 | invert: 1 181 | type: 2 182 | axis: 1 183 | joyNum: 0 184 | - serializedVersion: 3 185 | m_Name: Fire1 186 | descriptiveName: 187 | descriptiveNegativeName: 188 | negativeButton: 189 | positiveButton: joystick button 0 190 | altNegativeButton: 191 | altPositiveButton: 192 | gravity: 1000 193 | dead: 0.001 194 | sensitivity: 1000 195 | snap: 0 196 | invert: 0 197 | type: 0 198 | axis: 0 199 | joyNum: 0 200 | - serializedVersion: 3 201 | m_Name: Fire2 202 | descriptiveName: 203 | descriptiveNegativeName: 204 | negativeButton: 205 | positiveButton: joystick button 1 206 | altNegativeButton: 207 | altPositiveButton: 208 | gravity: 1000 209 | dead: 0.001 210 | sensitivity: 1000 211 | snap: 0 212 | invert: 0 213 | type: 0 214 | axis: 0 215 | joyNum: 0 216 | - serializedVersion: 3 217 | m_Name: Fire3 218 | descriptiveName: 219 | descriptiveNegativeName: 220 | negativeButton: 221 | positiveButton: joystick button 2 222 | altNegativeButton: 223 | altPositiveButton: 224 | gravity: 1000 225 | dead: 0.001 226 | sensitivity: 1000 227 | snap: 0 228 | invert: 0 229 | type: 0 230 | axis: 0 231 | joyNum: 0 232 | - serializedVersion: 3 233 | m_Name: Jump 234 | descriptiveName: 235 | descriptiveNegativeName: 236 | negativeButton: 237 | positiveButton: joystick button 3 238 | altNegativeButton: 239 | altPositiveButton: 240 | gravity: 1000 241 | dead: 0.001 242 | sensitivity: 1000 243 | snap: 0 244 | invert: 0 245 | type: 0 246 | axis: 0 247 | joyNum: 0 248 | - serializedVersion: 3 249 | m_Name: Submit 250 | descriptiveName: 251 | descriptiveNegativeName: 252 | negativeButton: 253 | positiveButton: return 254 | altNegativeButton: 255 | altPositiveButton: joystick button 0 256 | gravity: 1000 257 | dead: 0.001 258 | sensitivity: 1000 259 | snap: 0 260 | invert: 0 261 | type: 0 262 | axis: 0 263 | joyNum: 0 264 | - serializedVersion: 3 265 | m_Name: Submit 266 | descriptiveName: 267 | descriptiveNegativeName: 268 | negativeButton: 269 | positiveButton: enter 270 | altNegativeButton: 271 | altPositiveButton: space 272 | gravity: 1000 273 | dead: 0.001 274 | sensitivity: 1000 275 | snap: 0 276 | invert: 0 277 | type: 0 278 | axis: 0 279 | joyNum: 0 280 | - serializedVersion: 3 281 | m_Name: Cancel 282 | descriptiveName: 283 | descriptiveNegativeName: 284 | negativeButton: 285 | positiveButton: escape 286 | altNegativeButton: 287 | altPositiveButton: joystick button 1 288 | gravity: 1000 289 | dead: 0.001 290 | sensitivity: 1000 291 | snap: 0 292 | invert: 0 293 | type: 0 294 | axis: 0 295 | joyNum: 0 296 | -------------------------------------------------------------------------------- /ProjectSettings/MemorySettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!387306366 &1 4 | MemorySettings: 5 | m_ObjectHideFlags: 0 6 | m_EditorMemorySettings: 7 | m_MainAllocatorBlockSize: -1 8 | m_ThreadAllocatorBlockSize: -1 9 | m_MainGfxBlockSize: -1 10 | m_ThreadGfxBlockSize: -1 11 | m_CacheBlockSize: -1 12 | m_TypetreeBlockSize: -1 13 | m_ProfilerBlockSize: -1 14 | m_ProfilerEditorBlockSize: -1 15 | m_BucketAllocatorGranularity: -1 16 | m_BucketAllocatorBucketsCount: -1 17 | m_BucketAllocatorBlockSize: -1 18 | m_BucketAllocatorBlockCount: -1 19 | m_ProfilerBucketAllocatorGranularity: -1 20 | m_ProfilerBucketAllocatorBucketsCount: -1 21 | m_ProfilerBucketAllocatorBlockSize: -1 22 | m_ProfilerBucketAllocatorBlockCount: -1 23 | m_TempAllocatorSizeMain: -1 24 | m_JobTempAllocatorBlockSize: -1 25 | m_BackgroundJobTempAllocatorBlockSize: -1 26 | m_JobTempAllocatorReducedBlockSize: -1 27 | m_TempAllocatorSizeGIBakingWorker: -1 28 | m_TempAllocatorSizeNavMeshWorker: -1 29 | m_TempAllocatorSizeAudioWorker: -1 30 | m_TempAllocatorSizeCloudWorker: -1 31 | m_TempAllocatorSizeGfx: -1 32 | m_TempAllocatorSizeJobWorker: -1 33 | m_TempAllocatorSizeBackgroundWorker: -1 34 | m_TempAllocatorSizePreloadManager: -1 35 | m_PlatformMemorySettings: {} 36 | -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshProjectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | m_LastAgentTypeID: -887442657 73 | m_Settings: 74 | - serializedVersion: 2 75 | agentTypeID: 0 76 | agentRadius: 0.5 77 | agentHeight: 2 78 | agentSlope: 45 79 | agentClimb: 0.75 80 | ledgeDropHeight: 0 81 | maxJumpAcrossDistance: 0 82 | minRegionArea: 2 83 | manualCellSize: 0 84 | cellSize: 0.16666667 85 | manualTileSize: 0 86 | tileSize: 256 87 | accuratePlacement: 0 88 | debug: 89 | m_Flags: 0 90 | m_SettingNames: 91 | - Humanoid 92 | -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!149 &1 4 | NetworkManager: 5 | m_ObjectHideFlags: 0 6 | m_DebugLevel: 0 7 | m_Sendrate: 15 8 | m_AssetToPrefab: {} 9 | -------------------------------------------------------------------------------- /ProjectSettings/PackageManagerSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &1 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 61 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0} 13 | m_Name: 14 | m_EditorClassIdentifier: 15 | m_EnablePreReleasePackages: 0 16 | m_AdvancedSettingsExpanded: 1 17 | m_ScopedRegistriesSettingsExpanded: 1 18 | m_SeeAllPackageVersions: 0 19 | m_DismissPreviewPackagesInUse: 0 20 | oneTimeWarningShown: 0 21 | m_Registries: 22 | - m_Id: main 23 | m_Name: 24 | m_Url: https://packages.unity.com 25 | m_Scopes: [] 26 | m_IsDefault: 1 27 | m_Capabilities: 7 28 | m_ConfigSource: 0 29 | - m_Id: scoped:project:OpenUpm 30 | m_Name: OpenUpm 31 | m_Url: https://package.openupm.com 32 | m_Scopes: 33 | - com.svermeulen 34 | - com.firenero 35 | m_IsDefault: 0 36 | m_Capabilities: 0 37 | m_ConfigSource: 4 38 | m_UserSelectedRegistryName: OpenUpm 39 | m_UserAddingNewScopedRegistry: 0 40 | m_RegistryInfoDraft: 41 | m_Modified: 0 42 | m_ErrorMessage: 43 | m_UserModificationsInstanceId: -840 44 | m_OriginalInstanceId: -844 45 | m_LoadAssets: 0 46 | -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 4 7 | m_Gravity: {x: 0, y: -9.81} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_VelocityIterations: 8 10 | m_PositionIterations: 3 11 | m_VelocityThreshold: 1 12 | m_MaxLinearCorrection: 0.2 13 | m_MaxAngularCorrection: 8 14 | m_MaxTranslationSpeed: 100 15 | m_MaxRotationSpeed: 360 16 | m_BaumgarteScale: 0.2 17 | m_BaumgarteTimeOfImpactScale: 0.75 18 | m_TimeToSleep: 0.5 19 | m_LinearSleepTolerance: 0.01 20 | m_AngularSleepTolerance: 2 21 | m_DefaultContactOffset: 0.01 22 | m_JobOptions: 23 | serializedVersion: 2 24 | useMultithreading: 0 25 | useConsistencySorting: 0 26 | m_InterpolationPosesPerJob: 100 27 | m_NewContactsPerJob: 30 28 | m_CollideContactsPerJob: 100 29 | m_ClearFlagsPerJob: 200 30 | m_ClearBodyForcesPerJob: 200 31 | m_SyncDiscreteFixturesPerJob: 50 32 | m_SyncContinuousFixturesPerJob: 50 33 | m_FindNearestContactsPerJob: 100 34 | m_UpdateTriggerContactsPerJob: 100 35 | m_IslandSolverCostThreshold: 100 36 | m_IslandSolverBodyCostScale: 1 37 | m_IslandSolverContactCostScale: 10 38 | m_IslandSolverJointCostScale: 10 39 | m_IslandSolverBodiesPerJob: 50 40 | m_IslandSolverContactsPerJob: 50 41 | m_AutoSimulation: 1 42 | m_QueriesHitTriggers: 1 43 | m_QueriesStartInColliders: 1 44 | m_CallbacksOnDisable: 1 45 | m_ReuseCollisionCallbacks: 1 46 | m_AutoSyncTransforms: 0 47 | m_AlwaysShowColliders: 0 48 | m_ShowColliderSleep: 1 49 | m_ShowColliderContacts: 0 50 | m_ShowColliderAABB: 0 51 | m_ContactArrowScale: 0.2 52 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} 53 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} 54 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} 55 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} 56 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 57 | -------------------------------------------------------------------------------- /ProjectSettings/PresetManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1386491679 &1 4 | PresetManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_DefaultPresets: {} 8 | -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2022.3.29f1 2 | m_EditorVersionWithRevision: 2022.3.29f1 (8d510ca76d2b) 3 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!47 &1 4 | QualitySettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 5 7 | m_CurrentQuality: 3 8 | m_QualitySettings: 9 | - serializedVersion: 2 10 | name: Very Low 11 | pixelLightCount: 0 12 | shadows: 0 13 | shadowResolution: 0 14 | shadowProjection: 1 15 | shadowCascades: 1 16 | shadowDistance: 15 17 | shadowNearPlaneOffset: 3 18 | shadowCascade2Split: 0.33333334 19 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 20 | shadowmaskMode: 0 21 | blendWeights: 1 22 | textureQuality: 1 23 | anisotropicTextures: 0 24 | antiAliasing: 0 25 | softParticles: 0 26 | softVegetation: 0 27 | realtimeReflectionProbes: 0 28 | billboardsFaceCameraPosition: 0 29 | vSyncCount: 0 30 | lodBias: 0.3 31 | maximumLODLevel: 0 32 | particleRaycastBudget: 4 33 | asyncUploadTimeSlice: 2 34 | asyncUploadBufferSize: 16 35 | resolutionScalingFixedDPIFactor: 1 36 | excludedTargetPlatforms: [] 37 | - serializedVersion: 2 38 | name: Low 39 | pixelLightCount: 0 40 | shadows: 0 41 | shadowResolution: 0 42 | shadowProjection: 1 43 | shadowCascades: 1 44 | shadowDistance: 20 45 | shadowNearPlaneOffset: 3 46 | shadowCascade2Split: 0.33333334 47 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 48 | shadowmaskMode: 0 49 | blendWeights: 2 50 | textureQuality: 0 51 | anisotropicTextures: 0 52 | antiAliasing: 0 53 | softParticles: 0 54 | softVegetation: 0 55 | realtimeReflectionProbes: 0 56 | billboardsFaceCameraPosition: 0 57 | vSyncCount: 0 58 | lodBias: 0.4 59 | maximumLODLevel: 0 60 | particleRaycastBudget: 16 61 | asyncUploadTimeSlice: 2 62 | asyncUploadBufferSize: 16 63 | resolutionScalingFixedDPIFactor: 1 64 | excludedTargetPlatforms: [] 65 | - serializedVersion: 2 66 | name: Medium 67 | pixelLightCount: 1 68 | shadows: 0 69 | shadowResolution: 0 70 | shadowProjection: 1 71 | shadowCascades: 1 72 | shadowDistance: 20 73 | shadowNearPlaneOffset: 3 74 | shadowCascade2Split: 0.33333334 75 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 76 | shadowmaskMode: 0 77 | blendWeights: 2 78 | textureQuality: 0 79 | anisotropicTextures: 0 80 | antiAliasing: 0 81 | softParticles: 0 82 | softVegetation: 0 83 | realtimeReflectionProbes: 0 84 | billboardsFaceCameraPosition: 0 85 | vSyncCount: 1 86 | lodBias: 0.7 87 | maximumLODLevel: 0 88 | particleRaycastBudget: 64 89 | asyncUploadTimeSlice: 2 90 | asyncUploadBufferSize: 16 91 | resolutionScalingFixedDPIFactor: 1 92 | excludedTargetPlatforms: [] 93 | - serializedVersion: 2 94 | name: High 95 | pixelLightCount: 2 96 | shadows: 0 97 | shadowResolution: 1 98 | shadowProjection: 1 99 | shadowCascades: 2 100 | shadowDistance: 40 101 | shadowNearPlaneOffset: 3 102 | shadowCascade2Split: 0.33333334 103 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 104 | shadowmaskMode: 1 105 | blendWeights: 2 106 | textureQuality: 0 107 | anisotropicTextures: 0 108 | antiAliasing: 0 109 | softParticles: 0 110 | softVegetation: 1 111 | realtimeReflectionProbes: 0 112 | billboardsFaceCameraPosition: 0 113 | vSyncCount: 1 114 | lodBias: 1 115 | maximumLODLevel: 0 116 | particleRaycastBudget: 256 117 | asyncUploadTimeSlice: 2 118 | asyncUploadBufferSize: 16 119 | resolutionScalingFixedDPIFactor: 1 120 | excludedTargetPlatforms: [] 121 | - serializedVersion: 2 122 | name: Very High 123 | pixelLightCount: 3 124 | shadows: 0 125 | shadowResolution: 2 126 | shadowProjection: 1 127 | shadowCascades: 2 128 | shadowDistance: 70 129 | shadowNearPlaneOffset: 3 130 | shadowCascade2Split: 0.33333334 131 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 132 | shadowmaskMode: 1 133 | blendWeights: 4 134 | textureQuality: 0 135 | anisotropicTextures: 0 136 | antiAliasing: 0 137 | softParticles: 0 138 | softVegetation: 1 139 | realtimeReflectionProbes: 0 140 | billboardsFaceCameraPosition: 0 141 | vSyncCount: 1 142 | lodBias: 1.5 143 | maximumLODLevel: 0 144 | particleRaycastBudget: 1024 145 | asyncUploadTimeSlice: 2 146 | asyncUploadBufferSize: 16 147 | resolutionScalingFixedDPIFactor: 1 148 | excludedTargetPlatforms: [] 149 | - serializedVersion: 2 150 | name: Ultra 151 | pixelLightCount: 4 152 | shadows: 0 153 | shadowResolution: 0 154 | shadowProjection: 1 155 | shadowCascades: 4 156 | shadowDistance: 150 157 | shadowNearPlaneOffset: 3 158 | shadowCascade2Split: 0.33333334 159 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 160 | shadowmaskMode: 1 161 | blendWeights: 4 162 | textureQuality: 0 163 | anisotropicTextures: 0 164 | antiAliasing: 0 165 | softParticles: 0 166 | softVegetation: 1 167 | realtimeReflectionProbes: 0 168 | billboardsFaceCameraPosition: 0 169 | vSyncCount: 1 170 | lodBias: 2 171 | maximumLODLevel: 0 172 | particleRaycastBudget: 4096 173 | asyncUploadTimeSlice: 2 174 | asyncUploadBufferSize: 16 175 | resolutionScalingFixedDPIFactor: 1 176 | excludedTargetPlatforms: [] 177 | m_PerPlatformDefaultQuality: 178 | Android: 2 179 | Nintendo 3DS: 5 180 | Nintendo Switch: 5 181 | PS4: 5 182 | PSM: 5 183 | PSP2: 2 184 | Stadia: 5 185 | Standalone: 5 186 | Tizen: 2 187 | WebGL: 3 188 | WiiU: 5 189 | Windows Store Apps: 5 190 | XboxOne: 5 191 | iPhone: 2 192 | tvOS: 2 193 | -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 14 | - 15 | - 16 | - 17 | - 18 | - 19 | - 20 | - 21 | - 22 | - 23 | - 24 | - 25 | - 26 | - 27 | - 28 | - 29 | - 30 | - 31 | - 32 | - 33 | - 34 | - 35 | - 36 | - 37 | - 38 | - 39 | - 40 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: 0.02 7 | Maximum Allowed Timestep: 0.1 8 | m_TimeScale: 1 9 | Maximum Particle Timestep: 0.03 10 | -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!310 &1 4 | UnityConnectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 1 7 | m_Enabled: 0 8 | m_TestMode: 0 9 | m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events 10 | m_EventUrl: https://cdp.cloud.unity3d.com/v1/events 11 | m_ConfigUrl: https://config.uca.cloud.unity3d.com 12 | m_TestInitMode: 0 13 | CrashReportingSettings: 14 | m_EventUrl: https://perf-events.cloud.unity3d.com 15 | m_Enabled: 0 16 | m_LogBufferSize: 10 17 | m_CaptureEditorExceptions: 1 18 | UnityPurchasingSettings: 19 | m_Enabled: 0 20 | m_TestMode: 0 21 | UnityAnalyticsSettings: 22 | m_Enabled: 0 23 | m_TestMode: 0 24 | m_InitializeOnStartup: 1 25 | UnityAdsSettings: 26 | m_Enabled: 0 27 | m_InitializeOnStartup: 1 28 | m_TestMode: 0 29 | m_IosGameId: 30 | m_AndroidGameId: 31 | m_GameIds: {} 32 | m_GameId: 33 | PerformanceReportingSettings: 34 | m_Enabled: 0 35 | -------------------------------------------------------------------------------- /ProjectSettings/VFXManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!937362698 &1 4 | VFXManager: 5 | m_ObjectHideFlags: 0 6 | m_IndirectShader: {fileID: 0} 7 | m_CopyBufferShader: {fileID: 0} 8 | m_SortShader: {fileID: 0} 9 | m_StripUpdateShader: {fileID: 0} 10 | m_RenderPipeSettingsPath: 11 | m_FixedTimeStep: 0.016666668 12 | m_MaxDeltaTime: 0.05 13 | -------------------------------------------------------------------------------- /ProjectSettings/VersionControlSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!890905787 &1 4 | VersionControlSettings: 5 | m_ObjectHideFlags: 0 6 | m_Mode: Visible Meta Files 7 | m_CollabEditorSettings: 8 | inProgressEnabled: 1 9 | -------------------------------------------------------------------------------- /ProjectSettings/XRSettings.asset: -------------------------------------------------------------------------------- 1 | { 2 | "m_SettingKeys": [ 3 | "VR Device Disabled", 4 | "VR Device User Alert" 5 | ], 6 | "m_SettingValues": [ 7 | "False", 8 | "False" 9 | ] 10 | } -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | [![openupm](https://img.shields.io/npm/v/com.greener-games.unity-extensions?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.greener-games.unity-extensions/) 2 | 3 | Collection of Unity extension methods. 4 | 5 | Have been gathered from multiple sources to have them all in one place 6 | 7 | Please free free to request additional extentions though the issues board/post any useful ones that can be added to the collection. 8 | 9 | Further Docs avaiable here https://greener-games.github.io/Unity_Extensions/ 10 | -------------------------------------------------------------------------------- /UserSettings/EditorUserSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!162 &1 4 | EditorUserSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 4 7 | m_ConfigSettings: 8 | vcSharedLogLevel: 9 | value: 0d5e400f0650 10 | flags: 0 11 | m_VCAutomaticAdd: 1 12 | m_VCDebugCom: 0 13 | m_VCDebugCmd: 0 14 | m_VCDebugOut: 0 15 | m_SemanticMergeMode: 2 16 | m_VCShowFailedCheckout: 1 17 | m_VCOverwriteFailedCheckoutAssets: 1 18 | m_VCOverlayIcons: 1 19 | m_VCAllowAsyncUpdate: 0 20 | --------------------------------------------------------------------------------