├── Editor ├── TagGenerator.cs.meta ├── Utilities.cs.meta ├── ICodeGenerator.cs.meta ├── LayerGenerator.cs.meta ├── ICodeGenerator.cs ├── TNRD.LayerTagsGenerator.Editor.asmdef.meta ├── TNRD.LayerTagsGenerator.Editor.asmdef ├── TagGenerator.cs ├── LayerGenerator.cs └── Utilities.cs ├── Documentation~ ├── menu_items.png └── generated_files.png ├── CHANGELOG.md.meta ├── LICENSE.md.meta ├── README.md.meta ├── package.json.meta ├── Editor.meta ├── CHANGELOG.md ├── package.json ├── .github └── FUNDING.yml ├── LICENSE.md └── README.md /Editor/TagGenerator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c31099fa62b24989953dd316008a18de 3 | timeCreated: 1594471242 -------------------------------------------------------------------------------- /Editor/Utilities.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f67ca0b8ac2647e389e0f2c55121ec58 3 | timeCreated: 1594471251 -------------------------------------------------------------------------------- /Editor/ICodeGenerator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f865e04d31f94d31860e50bb03046a79 3 | timeCreated: 1594471516 -------------------------------------------------------------------------------- /Editor/LayerGenerator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 318ca1054c6842b7bc30ba49355153e2 3 | timeCreated: 1594471238 -------------------------------------------------------------------------------- /Documentation~/menu_items.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Thundernerd/Unity3D-LayersTagsGenerator/HEAD/Documentation~/menu_items.png -------------------------------------------------------------------------------- /Documentation~/generated_files.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Thundernerd/Unity3D-LayersTagsGenerator/HEAD/Documentation~/generated_files.png -------------------------------------------------------------------------------- /Editor/ICodeGenerator.cs: -------------------------------------------------------------------------------- 1 | namespace TNRD.CodeGeneration 2 | { 3 | public interface ICodeGenerator 4 | { 5 | void Generate(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /CHANGELOG.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e52485ef875aee4a9aff3f6e99f68bf 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f2e526334ef59d4ea2343b28694ef42 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b9f9a38f0f2d164893b437b22669b20 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7791e0110fd0f2049a93f36de8ca3eb6 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6d5e5b1775c566948ba40e1b5518f114 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/TNRD.LayerTagsGenerator.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 586fb755b756bee40a4741b3342d2a5b 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [2.0.0] - 2021-02-16 4 | ### Changed 5 | - Code generation happens through CodeDom instead of custom generation 6 | 7 | ### Removed 8 | - Sorting Layer generator 9 | 10 | ## [1.0.2] - 2020-07-14 11 | ### Fixed 12 | - Missing meta file 13 | 14 | ## [1.0.1] - 2020-07-14 15 | ### Fixed 16 | - Dependency 17 | 18 | ## [1.0.0] - 2020-07-11 19 | ### Added 20 | - Layers Generator 21 | - Sorting Layers Generator 22 | - Tags Generator 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "net.tnrd.layertagsgenerator", 3 | "displayName": "Layer Tags Generator", 4 | "version": "2.0.0", 5 | "unity": "2019.1", 6 | "description": "A simple tool to generate files that contain the project's Layers and Tags.", 7 | "keywords": [ 8 | "layer", 9 | "layers", 10 | "tag", 11 | "tags", 12 | "generator" 13 | ], 14 | "author": { 15 | "name": "TNRD", 16 | "email": "unity3d@tnrd.net", 17 | "url": "https://www.tnrd.net" 18 | } 19 | } -------------------------------------------------------------------------------- /Editor/TNRD.LayerTagsGenerator.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TNRD.LayerTagsGenerator.Editor", 3 | "references": [ 4 | "TNRD.CodeGenerator.Editor" 5 | ], 6 | "includePlatforms": [ 7 | "Editor" 8 | ], 9 | "excludePlatforms": [], 10 | "allowUnsafeCode": false, 11 | "overrideReferences": false, 12 | "precompiledReferences": [], 13 | "autoReferenced": true, 14 | "defineConstraints": [], 15 | "versionDefines": [], 16 | "noEngineReferences": false 17 | } -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: thundernerd 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Christiaan Bloemendaal 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 | -------------------------------------------------------------------------------- /Editor/TagGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using System.Linq; 3 | using System.Reflection; 4 | using UnityEditor; 5 | using UnityEditorInternal; 6 | using UnityEngine; 7 | 8 | namespace TNRD.CodeGeneration.Tags 9 | { 10 | public class TagGenerator : ICodeGenerator 11 | { 12 | [MenuItem("TNRD/Code Generation/Tags")] 13 | private static void Execute() 14 | { 15 | TagGenerator generator = new TagGenerator(); 16 | generator.Generate(); 17 | } 18 | 19 | public void Generate() 20 | { 21 | string[] tags = InternalEditorUtility.tags 22 | .OrderBy(x => x) 23 | .ToArray(); 24 | 25 | CodeCompileUnit compileUnit = new CodeCompileUnit(); 26 | CodeNamespace codeNamespace = new CodeNamespace(); 27 | CodeTypeDeclaration classDeclaration = new CodeTypeDeclaration("Tags") 28 | { 29 | IsClass = true, 30 | TypeAttributes = TypeAttributes.Public | TypeAttributes.Sealed 31 | }; 32 | 33 | foreach (string tag in tags) 34 | { 35 | CodeMemberField field = new CodeMemberField 36 | { 37 | Attributes = MemberAttributes.Public | MemberAttributes.Const, 38 | Name = Utilities.GetScreamName(tag), 39 | Type = new CodeTypeReference(typeof(string)), 40 | InitExpression = new CodePrimitiveExpression(tag) 41 | }; 42 | classDeclaration.Members.Add(field); 43 | } 44 | 45 | codeNamespace.Types.Add(classDeclaration); 46 | compileUnit.Namespaces.Add(codeNamespace); 47 | 48 | Utilities.GenerateToFile(compileUnit, Application.dataPath + "/Generated", "Tags.cs"); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Editor/LayerGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.CodeDom; 2 | using System.Linq; 3 | using System.Reflection; 4 | using UnityEditor; 5 | using UnityEditorInternal; 6 | using UnityEngine; 7 | 8 | namespace TNRD.CodeGeneration.Layers 9 | { 10 | public class LayerGenerator : ICodeGenerator 11 | { 12 | [MenuItem("TNRD/Code Generation/Layers")] 13 | private static void Execute() 14 | { 15 | LayerGenerator generator = new LayerGenerator(); 16 | generator.Generate(); 17 | } 18 | 19 | public void Generate() 20 | { 21 | string[] layers = InternalEditorUtility.layers 22 | .OrderBy(x => x) 23 | .ToArray(); 24 | 25 | CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); 26 | CodeNamespace codeNamespace = new CodeNamespace(); 27 | CodeTypeDeclaration classDeclaration = new CodeTypeDeclaration("Layers") 28 | { 29 | IsClass = true, 30 | TypeAttributes = TypeAttributes.Public | TypeAttributes.Sealed 31 | }; 32 | 33 | for (int i = 0; i < layers.Length; i++) 34 | { 35 | string layer = layers[i]; 36 | string layerName = Utilities.GetScreamName(layer); 37 | string maskName = layerName + "_MASK"; 38 | int layerValue = LayerMask.NameToLayer(layer); 39 | 40 | CodeMemberField layerField = new CodeMemberField(typeof(int), layerName) 41 | { 42 | Attributes = MemberAttributes.Public | MemberAttributes.Const, 43 | InitExpression = new CodePrimitiveExpression(layerValue) 44 | }; 45 | 46 | CodeMemberField maskField = new CodeMemberField(typeof(int), maskName) 47 | { 48 | Attributes = MemberAttributes.Public | MemberAttributes.Const, 49 | InitExpression = new CodePrimitiveExpression(1 << layerValue) 50 | }; 51 | 52 | classDeclaration.Members.Add(layerField); 53 | classDeclaration.Members.Add(maskField); 54 | } 55 | 56 | codeNamespace.Types.Add(classDeclaration); 57 | codeCompileUnit.Namespaces.Add(codeNamespace); 58 | 59 | Utilities.GenerateToFile(codeCompileUnit, Application.dataPath + "/Generated", "Layers.cs"); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Layers & Tags Generator 2 | 3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |