├── .gitignore ├── Editor.meta ├── Editor ├── AssetModificationProcessor.cs ├── AssetModificationProcessor.cs.meta ├── AssetPostprocessor.cs ├── AssetPostprocessor.cs.meta ├── Generator.cs ├── Generator.cs.meta ├── UnityTagsGenerator.Editor.asmdef └── UnityTagsGenerator.Editor.asmdef.meta ├── LICENSE ├── LICENSE.meta ├── README.md ├── README.md.meta ├── Runtime.meta ├── Runtime ├── LayerExtensions.cs ├── LayerExtensions.cs.meta ├── UnityTagsGenerator.asmdef └── UnityTagsGenerator.asmdef.meta ├── Template~ └── Tags.template.cs ├── Tests.meta ├── Tests ├── Editor.meta └── Editor │ ├── LayerExtensionsTest.cs │ ├── LayerExtensionsTest.cs.meta │ ├── UnityTagsGenerator.Tests.Editor.asmdef │ └── UnityTagsGenerator.Tests.Editor.asmdef.meta ├── package.json └── package.json.meta /.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Mm]emoryCaptures/ 12 | 13 | # Asset meta data should only be ignored when the corresponding asset is also ignored 14 | !/[Aa]ssets/**/*.meta 15 | 16 | # Uncomment this line if you wish to ignore the asset store tools plugin 17 | # /[Aa]ssets/AssetStoreTools* 18 | 19 | # Autogenerated Jetbrains Rider plugin 20 | [Aa]ssets/Plugins/Editor/JetBrains* 21 | 22 | # Visual Studio cache directory 23 | .vs/ 24 | 25 | # Gradle cache directory 26 | .gradle/ 27 | 28 | # Autogenerated VS/MD/Consulo solution and project files 29 | ExportedObj/ 30 | .consulo/ 31 | *.csproj 32 | *.unityproj 33 | *.sln 34 | *.suo 35 | *.tmp 36 | *.user 37 | *.userprefs 38 | *.pidb 39 | *.booproj 40 | *.svd 41 | *.pdb 42 | *.mdb 43 | *.opendb 44 | *.VC.db 45 | 46 | # Unity3D generated meta files 47 | *.pidb.meta 48 | *.pdb.meta 49 | *.mdb.meta 50 | 51 | # Unity3D generated file on crash reports 52 | sysinfo.txt 53 | 54 | # Builds 55 | *.apk 56 | *.unitypackage 57 | 58 | # Crashlytics generated file 59 | crashlytics-build.properties 60 | 61 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab3245bec6d21924c90e351e7386f918 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/AssetModificationProcessor.cs: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2022 - 2023 Alexander Pluzhnikov 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | using System.Linq; 24 | 25 | namespace UnityTagsGenerator.Editor 26 | { 27 | internal class AssetModificationProcessor : UnityEditor.AssetModificationProcessor 28 | { 29 | private static string[] OnWillSaveAssets(string[] paths) 30 | { 31 | if (paths.Contains("ProjectSettings/TagManager.asset")) 32 | Generator.Run(); 33 | 34 | return paths; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Editor/AssetModificationProcessor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 940ca453f96247b686940b01f983357d 3 | timeCreated: 1653255102 -------------------------------------------------------------------------------- /Editor/AssetPostprocessor.cs: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2022 - 2023 Alexander Pluzhnikov 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | namespace UnityTagsGenerator.Editor 24 | { 25 | internal class AssetPostprocessor : UnityEditor.AssetPostprocessor 26 | { 27 | private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, 28 | string[] movedFromAssetPaths) 29 | { 30 | Generator.Run(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Editor/AssetPostprocessor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7951ec1a9d2a42249260f6be3dab85fe 3 | timeCreated: 1653255042 -------------------------------------------------------------------------------- /Editor/Generator.cs: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2022 - 2023 Alexander Pluzhnikov 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.IO; 26 | using System.Runtime.CompilerServices; 27 | using System.Text.RegularExpressions; 28 | using UnityEditor.Compilation; 29 | using UnityEngine; 30 | 31 | namespace UnityTagsGenerator.Editor 32 | { 33 | internal static class Generator 34 | { 35 | internal static void Run() 36 | { 37 | var tags = UnityEditorInternal.InternalEditorUtility.tags; 38 | var layers = GetLayers(); 39 | 40 | CreateSourceFile(tags, layers); 41 | CompilationPipeline.RequestScriptCompilation(); 42 | } 43 | 44 | private static void CreateSourceFile(IEnumerable tags, IReadOnlyDictionary layers) 45 | { 46 | var currentDirectory = Path.GetDirectoryName(GetCallerPath()); 47 | 48 | if (string.IsNullOrEmpty(currentDirectory)) 49 | throw new Exception("Can't get parent directory of caller path"); 50 | 51 | var generatedDirectoryPath = Path.Combine(Application.dataPath, "generated"); 52 | var templateText = File.ReadAllText(Path.Combine(currentDirectory, "../Template~/Tags.template.cs")); 53 | var compiledTags = ""; 54 | var compiledLayers = ""; 55 | 56 | if (!Directory.Exists(generatedDirectoryPath)) 57 | Directory.CreateDirectory(generatedDirectoryPath); 58 | 59 | foreach (var tag in tags) 60 | { 61 | var varName = ValidateVariableName(tag); 62 | compiledTags += $"\tpublic const string {varName} = \"{tag}\";\n"; 63 | } 64 | 65 | foreach (var pair in layers) 66 | { 67 | var varName = ValidateVariableName(pair.Value); 68 | compiledLayers += $"\tpublic const int {varName} = {pair.Key};\n"; 69 | } 70 | 71 | var compiledTemplateText = string.Format(templateText, compiledTags, compiledLayers); 72 | File.WriteAllText(Path.Combine(generatedDirectoryPath, "Tags.cs"), compiledTemplateText); 73 | } 74 | 75 | private static string ValidateVariableName(string name) 76 | { 77 | var varName = ""; 78 | var matches = Regex.Matches(name, "[A-Za-z0-9_]+"); 79 | 80 | for (var i = 0; i < matches.Count; i++) 81 | { 82 | if (i > 0) 83 | varName += "_"; 84 | varName += matches[i].Value; 85 | } 86 | 87 | return varName; 88 | } 89 | 90 | private static IReadOnlyDictionary GetLayers() 91 | { 92 | const int layersCount = 32; 93 | var layers = new Dictionary(); 94 | var equalKeys = new List(); 95 | 96 | for (var i = 0; i < layersCount; i++) 97 | { 98 | var name = LayerMask.LayerToName(i); 99 | 100 | if (!string.IsNullOrEmpty(name)) 101 | layers.Add(i, name); 102 | } 103 | 104 | foreach (var pair in layers) 105 | { 106 | var equalFound = false; 107 | 108 | if (equalKeys.Contains(pair.Key)) 109 | continue; 110 | 111 | foreach (var innerPair in layers) 112 | { 113 | if (pair.Key == innerPair.Key) 114 | continue; 115 | 116 | if (pair.Value != innerPair.Value) 117 | continue; 118 | 119 | if (!equalFound) 120 | { 121 | equalKeys.Add(pair.Key); 122 | equalFound = true; 123 | } 124 | 125 | equalKeys.Add(innerPair.Key); 126 | } 127 | } 128 | 129 | foreach (var key in equalKeys) 130 | layers[key] += $"_{key}"; 131 | 132 | return layers; 133 | } 134 | 135 | private static string GetCallerPath([CallerFilePath] string path = "") 136 | { 137 | if (string.IsNullOrEmpty(path)) 138 | throw new Exception("Caller path can't be empty or null"); 139 | 140 | return path; 141 | } 142 | } 143 | } -------------------------------------------------------------------------------- /Editor/Generator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e8cb6fe3b21f464a9000454f16e9417 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/UnityTagsGenerator.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "UnityTagsGenerator.Editor", 3 | "references": [], 4 | "includePlatforms": [ 5 | "Editor" 6 | ], 7 | "excludePlatforms": [], 8 | "allowUnsafeCode": false, 9 | "overrideReferences": false, 10 | "precompiledReferences": [], 11 | "autoReferenced": true, 12 | "defineConstraints": [], 13 | "versionDefines": [], 14 | "noEngineReferences": false 15 | } -------------------------------------------------------------------------------- /Editor/UnityTagsGenerator.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f1b853b6c7a54360bc3f9366075be815 3 | timeCreated: 1653254758 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Alexander Pluzhnikov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a6a1872d21409145a70446b7b20096f 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityTagsGenerator 2 | 3 | [![Made with Unity](https://img.shields.io/badge/Made%20with-Unity-57b9d3.svg?style=flat&logo=unity)](https://unity3d.com) 4 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 5 | ![GitHub release (latest by date)](https://img.shields.io/github/v/release/CheeryLee/UnityTagsGenerator?display_name=tag) 6 | 7 | This tool allows to generate compile time source file with tag names and layer values of your Unity project. 8 | 9 | Tested with Unity 2019+, but it should work from 2017.3+ too. 10 | 11 | ## Getting started 12 | You can install the package directly from GitHub by using Package Manager: 13 | 14 | ![image](https://user-images.githubusercontent.com/11297752/233580399-45635f58-c37d-447d-b497-99cf05fc87d1.png) 15 | 16 | ![image](https://user-images.githubusercontent.com/11297752/233580798-0097314f-98b8-42a6-8cd5-7731c5e059c5.png) 17 | 18 | ... or add the URL to `Packages/manifest.json`: 19 | 20 | `"com.cheerylee.unity-tags-generator": "https://github.com/CheeryLee/UnityTagsGenerator.git#1.0.0"` 21 | 22 | This project uses the `*.*.*` release tags. So after the hashtag in URL you can specify a target version to install. For example, it may be `#1.0.0`. 23 | 24 | ## How to use 25 | 26 | By default there are some tags and layers that Unity provides out-of-box. They will be created even if you don't set something in Tag Manager. 27 | 28 | After every asset related operation there would be automatically writed a new file called Tags.cs in folder **Assets/generated** with **Tags** and **Layers** classes inside: 29 | 30 | ```csharp 31 | public static class Tags 32 | { 33 | public const string Untagged = "Untagged"; 34 | public const string Respawn = "Respawn"; 35 | ... 36 | } 37 | 38 | public static class Layers 39 | { 40 | public const int Default = 0; 41 | public const int TransparentFX = 1; 42 | ... 43 | } 44 | ``` 45 | 46 | Use it wherever you want instead of string literals: 47 | 48 | ```csharp 49 | void OnTriggerEnter(Collider other) 50 | { 51 | // whoa, what a mess ... 52 | if (other.gameObject.CompareTag("Player")) { ... } 53 | 54 | // let's do it with our new killing spree feature 55 | if (other.gameObject.CompareTag(Tags.Player)) { ... } 56 | } 57 | ``` 58 | 59 | ... or instead of bitwise operations for layer mask: 60 | 61 | ```csharp 62 | // Layers.UI returns an appropriate value 63 | if (Physics.Raycast(transform.position, Vector3.forward, out hit, 10, Layers.UI)) 64 | { 65 | Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow); 66 | Debug.Log("Did Hit"); 67 | } 68 | ``` 69 | 70 | In addition there are some tricky useful methods in **LayerExtensions** class: 71 | ```csharp 72 | // don't write 1 << 3 | 1 << 5, just do this: 73 | LayersExtensions.Where(Layers.Third, Layers.Fifth); 74 | ``` 75 | 76 | ## How does it work? 77 | 78 | Everything is pretty simple. After every asset importing operation (save and load are also included) the generator will create an appropriate source file that contains tag IDs. The variables names correspond to real tag names, except spaces and some service chars. 79 | 80 | ## Pros & cons 81 | 82 | The main reason why it was created is take into account the proof-of-concept that this feature is possible to do. 83 | 84 | ### Pros: 85 | 86 | 1. it works like the ID generator in Android native Java projects. It means you should not use string literals to work with tags functionality in Unity. Just take what you've got from development environment; 87 | 2. based on the previous one, you now can see compile time errors if there are missing tags after they were changed in Tag Manager; 88 | 3. IDE hints (who doesn't love IntelliSense? :upside_down_face: ); 89 | 4. small memory footprint: every variables are const like. 90 | 91 | ### Cons: 92 | 93 | 1. tags are still strings under the hood. There is no any magic way to change the basic behaviour of Unity. The rule of using **CompareTag** method instead of direct comparing is still actual. 94 | 2. even if you can type every tag name what you want, you can't use it as variable name. That's why we have restrictions to letters, digits and underscore char. -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1046bfd0f76a88f4e87f01c70318f0de 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7d24c2211a654274bcd96aaf1b6d35ad 3 | timeCreated: 1682016673 -------------------------------------------------------------------------------- /Runtime/LayerExtensions.cs: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2022 - 2023 Alexander Pluzhnikov 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | using System.Runtime.CompilerServices; 24 | using UnityEngine; 25 | 26 | namespace UnityTagsGenerator 27 | { 28 | public static class LayerExtensions 29 | { 30 | private const int LayersCount = 32; 31 | 32 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 33 | public static LayerMask All() 34 | { 35 | var mask = 0; 36 | for (var i = 0; i < LayersCount; i++) 37 | mask |= 1 << i; 38 | 39 | return mask; 40 | } 41 | 42 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 43 | public static LayerMask Except(params int[] layerNumbers) 44 | { 45 | var mask = (int)All(); 46 | foreach (var layer in layerNumbers) 47 | mask ^= 1 << layer; 48 | 49 | return mask; 50 | } 51 | 52 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 53 | public static LayerMask Except(LayerMask layerMask) 54 | { 55 | var mask1 = (int)All(); 56 | var mask2 = (int)layerMask; 57 | return mask1 ^ mask2; 58 | } 59 | 60 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 61 | public static LayerMask Where(params int[] layerNumbers) 62 | { 63 | var mask = 0; 64 | foreach (var layer in layerNumbers) 65 | mask |= 1 << layer; 66 | 67 | return mask; 68 | } 69 | 70 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 71 | public static LayerMask Union(this LayerMask mask1, LayerMask mask2) 72 | { 73 | var intMask1 = (int)mask1; 74 | var intMask2 = (int)mask2; 75 | return intMask1 | intMask2; 76 | } 77 | 78 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 79 | public static LayerMask Union(this LayerMask mask1, params int[] layerNumbers) 80 | { 81 | return Union(mask1, Where(layerNumbers)); 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /Runtime/LayerExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 39617bbd54ec4c45847f966414b8b48a 3 | timeCreated: 1654026893 -------------------------------------------------------------------------------- /Runtime/UnityTagsGenerator.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "UnityTagsGenerator" 3 | } 4 | -------------------------------------------------------------------------------- /Runtime/UnityTagsGenerator.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a3871aa0d90b7ae4f84fabb6008d9026 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Template~/Tags.template.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by UnityTagsGenerator. 4 | // 5 | // Changes to this file may cause incorrect behavior and will be lost if 6 | // the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | // MIT License 10 | // 11 | // Copyright (c) 2022 - 2023 Alexander Pluzhnikov 12 | // 13 | // Permission is hereby granted, free of charge, to any person obtaining a copy 14 | // of this software and associated documentation files (the "Software"), to deal 15 | // in the Software without restriction, including without limitation the rights 16 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | // copies of the Software, and to permit persons to whom the Software is 18 | // furnished to do so, subject to the following conditions: 19 | // 20 | // The above copyright notice and this permission notice shall be included in all 21 | // copies or substantial portions of the Software. 22 | // 23 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 29 | // SOFTWARE. 30 | 31 | public static class Tags 32 | {{ 33 | {0} 34 | }} 35 | 36 | public static class Layers 37 | {{ 38 | {1} 39 | }} -------------------------------------------------------------------------------- /Tests.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df29ef638f4b4dd5a99f3fff1cc5a46b 3 | timeCreated: 1682020933 -------------------------------------------------------------------------------- /Tests/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2e56f137c79d488bbe1296bf640fc0f4 3 | timeCreated: 1682020976 -------------------------------------------------------------------------------- /Tests/Editor/LayerExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2022 - 2023 Alexander Pluzhnikov 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | using NUnit.Framework; 24 | using UnityEngine; 25 | 26 | namespace UnityTagsGenerator.Tests.Editor 27 | { 28 | public class LayerExtensionsTest 29 | { 30 | [Test] 31 | public void LayerExtensions_AllLayersTest() 32 | { 33 | var all = LayerExtensions.All(); 34 | Assert.AreEqual(-1, all.value); 35 | } 36 | 37 | [Test] 38 | public void LayerExtensions_ExceptLayerNumbersTest() 39 | { 40 | var except = LayerExtensions.Except(1); 41 | Assert.AreEqual(-3, except.value); 42 | } 43 | 44 | [Test] 45 | public void LayerExtensions_ExceptLayerMaskTest() 46 | { 47 | var intMask = 1 << 1; 48 | var except = LayerExtensions.Except((LayerMask)intMask); 49 | Assert.AreEqual(-3, except.value); 50 | } 51 | 52 | [Test] 53 | public void LayerExtensions_WhereTest() 54 | { 55 | // mask value: 10 56 | var where = LayerExtensions.Where(1, 3); 57 | Assert.AreEqual(10, where.value); 58 | } 59 | 60 | [Test] 61 | public void LayerExtensions_UnionLayerMaskTest() 62 | { 63 | // mask value: 3 64 | var mask1 = LayerExtensions.Where(0, 1); 65 | // mask value: 24 66 | var mask2 = LayerExtensions.Where(3, 4); 67 | var union = mask1.Union(mask2); 68 | Assert.AreEqual(27, union.value); 69 | } 70 | 71 | [Test] 72 | public void LayerExtensions_UnionLayerNumbersTest() 73 | { 74 | // mask value: 3 75 | var mask1 = LayerExtensions.Where(0, 1); 76 | // mask value: 24 77 | var union = mask1.Union(3, 4); 78 | Assert.AreEqual(27, union.value); 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /Tests/Editor/LayerExtensionsTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2c4609cd99664f40b613e1200a2e7c42 3 | timeCreated: 1682021002 -------------------------------------------------------------------------------- /Tests/Editor/UnityTagsGenerator.Tests.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "UnityTagsGenerator.Tests.Editor", 3 | "references": [ 4 | "GUID:a3871aa0d90b7ae4f84fabb6008d9026" 5 | ], 6 | "includePlatforms": [ 7 | "Editor" 8 | ], 9 | "excludePlatforms": [], 10 | "allowUnsafeCode": false, 11 | "overrideReferences": true, 12 | "precompiledReferences": [ 13 | "nunit.framework.dll" 14 | ], 15 | "autoReferenced": true, 16 | "defineConstraints": [ 17 | "UNITY_INCLUDE_TESTS" 18 | ], 19 | "versionDefines": [], 20 | "noEngineReferences": false 21 | } -------------------------------------------------------------------------------- /Tests/Editor/UnityTagsGenerator.Tests.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b0dcb8526b6b3854ca9e23e1b519f2ab 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.cheerylee.unity-tags-generator", 3 | "displayName": "UnityTagsGenerator", 4 | "version": "1.0.0", 5 | "unity": "2019.1", 6 | "description": "This tool allows to generate compile time source file with tag names and layer values of your Unity project", 7 | "documentationUrl": "https://github.com/CheeryLee/UnityTagsGenerator/blob/master/README.md", 8 | "license": "MIT", 9 | "licensesUrl": "https://github.com/CheeryLee/UnityTagsGenerator/blob/master/LICENSE", 10 | "author": { 11 | "name": "Alexander Pluzhnikov", 12 | "url": "https://github.com/CheeryLee" 13 | }, 14 | "keywords": [ 15 | "tag", 16 | "layer", 17 | "generator", 18 | "extension" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 98b4d936654045ae815cc122ea364023 3 | timeCreated: 1682017797 --------------------------------------------------------------------------------