{"id":13662219,"url":"https://github.com/INFGameDev/ConstGen","last_synced_at":"2025-04-25T07:30:54.687Z","repository":{"id":189488757,"uuid":"340622909","full_name":"INFGameDev/ConstGen","owner":"INFGameDev","description":"Unity Constants Generator","archived":false,"fork":false,"pushed_at":"2022-09-02T13:48:08.000Z","size":146,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T13:15:18.103Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/INFGameDev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-02-20T10:10:20.000Z","updated_at":"2024-06-07T07:40:03.000Z","dependencies_parsed_at":"2023-08-20T12:24:20.979Z","dependency_job_id":"45e6bc2c-5c61-4c52-bfd4-7d30f3c2df43","html_url":"https://github.com/INFGameDev/ConstGen","commit_stats":null,"previous_names":["infgamedev/constgen"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/INFGameDev%2FConstGen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/INFGameDev%2FConstGen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/INFGameDev%2FConstGen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/INFGameDev%2FConstGen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/INFGameDev","download_url":"https://codeload.github.com/INFGameDev/ConstGen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250774603,"owners_count":21485175,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T05:01:52.566Z","updated_at":"2025-04-25T07:30:54.676Z","avatar_url":"https://github.com/INFGameDev.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# Const Generator \nUnity Constants Generator \n\n![ConstGen Window](https://github.com/INFGameDev/Project-ReadMe-Images/blob/master/ConstGen/ConstGenWIndow.PNG)\n\nTested on Unity Versions: \u003cbr/\u003e\n[ 2019.4.15f ] \u003cbr/\u003e [ 2018.4.14f ]\n\n#### Const Generator generates constant properties within static classes replacing the usage of magic strings by holding the value of those strings in the given constant property.\n.\u003cbr/\u003e\n.\u003cbr/\u003e\n.\u003cbr/\u003e\n.\u003cbr/\u003e\n.\u003cbr/\u003e\nbut why the use for this, you ask?\u003cbr/\u003e\nwhy not just use magic strings and simply write it like this:\u003cbr/\u003e\n\n `animator.SetFloat(\"XMove\", 5);`ノ( ゜-゜ノ)\n\nWell....\u003cbr/\u003e\nBecause screw this! (╯°□°）╯︵ `;(ϛ ',,ǝʌoWX,,)ʇɐolℲʇǝS˙ɹoʇɐɯᴉuɐ`\n\n\u003cbr/\u003e\n\nMagic strings are considered bad as they are very error-prone, they are non-performant and slow as no optimization is applied on them by the compiler as they are dynamically changing. The more you use them the more it will add up that will not only cause performance problems but will also make it harder to fix the bugs on your code.\n\nSo instead so we use constants, by this way we are fixing a variable's value so that it can be optimized, not only that it also eliminates the error of writing a typo in which the compiler has no whatsoever idea but will instead propagate an error at runtime causing annoying problems and bugs. \n\nIn here instead of typing out the string directly as an argument to a method, the constant property is used.\n\n![usage example](https://github.com/INFGameDev/Project-ReadMe-Images/blob/master/ConstGen/Usage_Example.png)\n\nBy this way you are sure there is no typos on the string you are passing. \u003cbr/\u003e\nPlus you got some of that neat pop up suggestions on other related constant properties and auto-completion :ok_hand:\n\n- - - -\n\n## Features ##\n\n### ( Constants Generation ) ###\n#### ConstGen can generate the type of unity constants for: ####\n- [x] Layers\n- [x] Tags\n- [x] Sorting Layers\n- [x] Scenes\n- [x] Nav Mesh Areas\n- [x] Input Axes\n- [x] Shader Properties\n- [x] Animator Controller Parameters\n- [x] Animator Controller Layers\n- [x] Animator Controller States \u003cbr/\u003e\n\n### ( Custom Generators ) ###\n#### ConstGen can also create custom generator for generating constants ####\n![generator creation](https://github.com/INFGameDev/Project-ReadMe-Images/blob/master/ConstGen/GeneratorCreation.png)\n\n### ( Generating Enums ) ###\n![Generated Enum](https://github.com/INFGameDev/Project-ReadMe-Images/blob/master/ConstGen/generated_enum.png)\n\n- - - -\n\n## Usage ##\n\nAccess the ConstGen window in the Main Menu \u003cbr/\u003e\n![accessing the window](https://github.com/INFGameDev/Project-ReadMe-Images/blob/master/ConstGen/Main_Menu.png)\n\n### ( Generating Constants ) ###\n![generating constants](https://github.com/INFGameDev/Project-ReadMe-Images/blob/master/ConstGen/GeneratingConstants.png)\n\n### | Settings | ###\n\n**[Close On Generate]** - You can treat the window like a pop up that when everytime you generate, the window will close automatically or leave this option off and you can dock the window and generate files without it closing.\n \n![indentifier](https://github.com/INFGameDev/Project-ReadMe-Images/blob/master/ConstGen/IdentifierFormat.png) \u003cbr/\u003e\n**[Identifier Format]** - Defines how the the class names of the generated constants are formatted.\n- Under_Score_Divider\n  - Filters the whitespaces and invalid charaters of the class names into underscores.\n- Pascal Case No Divider\n  - Removes the whitespaces and invalid charaters of the class and merge into a pascal case naming format.\n\n**[ReGen On Missing]** - Sets the generator to generate it's constants file if it detected none exists. \u003cbr/\u003e\n\nNOTE: [Force Generate] button depends on this setting as it will delete the constants file and let the generator create a new one.\n\n**[Update On Reload]** - Sets the generator to automatically generate/update it's constants file on editor recompile if any changes is detected within the unity editor, e.g adding new layers or deleting animator controller paramters. \u003cbr/\u003e\n\nNOTE: All generator update checks are are done upon editor recompile so the generator won't trigger script generate and recompile every after little change you want on the editor constants. \n\n### | Generation | ###\n\n**[Generate]** - Updates the constants or generates the constants file of the generator if none is present.\n\n**[Force Generate]** - Deletes the constants file and let the generator regenerate a new one.\n\n**[Generate ALL] \u0026 [Force Generate ALL]** - you know.....just like the generate \u0026 force generate buttons but instead triggers all generators.\n\n### | Constants Files/Generated Files | ###\n![generated files](https://github.com/INFGameDev/Project-ReadMe-Images/blob/master/ConstGen/generated_files.PNG)\n\n### Generation Output Directory Paths ###\n\n**Editor Constants** =\u003e Scripts/ConstGen Files/Generated Constants \u003cbr/\u003e\n**Custom Generators** =\u003e Scripts/ConstGen Files/Custom Generators \u003cbr/\u003e\n**Enums** (Default) =\u003e Scripts/ConstGen Files/Generated Enums \u003cbr/\u003e\n\nNOTE: DO NOT move around the files inside the ConstGen folder as it will break how the generators look for the files it needed inside ConstGen Folder BUT you can move the ConstGen folder itself at any directory in the assets. \u003cbr/\u003e\n\nANOTHER NOTE: Also DON'T change or move the folder of **Generated Constants** cause the generators look for that specific directory for the files inside when updating and generating files.\n\nAND ALSO ANOTHER ONE: In the event of for some reason the generated files has an error and [Force Generate] won't delete the file, you can manually delete the file itself in the it's folder with the **[ReGen On Missing]** turned on and the generator/s will try to generate a new file.\n\n\n### ( Creating Custom Generators ) ###\n![Creating generators](https://github.com/INFGameDev/Project-ReadMe-Images/blob/master/ConstGen/generator%20creation2.PNG)\n\nYou can also create custom generator scripts like the ones ConstGen use to generate the constants properties through script. \u003cbr/\u003e\nThis this will generate a custom generator template that you can modify and get started on.\n\n**Generated Name** - Already self explanatory, this will also be the name of the generator script. \u003cbr/\u003e\n**Output File Name** - The name of the generated file by the generator which is also the generated file's script name. \u003cbr/\u003e\n**Output Type** - The data type that the generated constants will store. \u003cbr/\u003e\n**Output Path** - The directory in which the generate constant/file is created at. \n\n- - - -\n\n## Using The Constants ##\n![how to use](https://github.com/INFGameDev/Project-ReadMe-Images/blob/master/ConstGen/namespaceImport.PNG)\n\nImport the `ConstGenConstants` namespace on which the constants are in and from there you can access them.\n\n- - - -\n\n## Generating Enum Constants ##\n![Generating Enums](https://github.com/INFGameDev/Project-ReadMe-Images/blob/master/ConstGen/GeneratingEnums.PNG)\n\n`List\u003cEnumConstant\u003e` - This is the list where you will add all the enums you want to generate. \u003cbr/\u003e\n`EnumConstant` - The enum data type that will hold all the constants you'll be generating, you pass the name of the enum to the object constructor at instance initialization. \u003cbr/\u003e\n`enum_.Add(\"Forward\", 0 );` - adds an constant into the enum, passing it's name and int value. \u003cbr/\u003e\n\nNOTE: if you don't want to assign a value to it, you can pass in `null` and none will be assigned thus the enum will instead have it's index as it's value.\n\nthen you add the `EnumConstant` variable into the `List\u003cEnumConstant\u003e` list. you can more than one enum in the list and the generator will generate those into the file.\n\n`ConstGen.ConstantGen.GenerateEnums(\"Directions\", enumList);` - Generates the enums into the default enum ouput directory with the file name of \"Directions\".\n\nNOTE: you shorten the method call by importing the `ConstGen` namespace and there are other `GenerateEnums` override methods you can utilize. \n\n- - - -\n\n![meme](https://github.com/INFGameDev/Project-ReadMe-Images/blob/master/ConstGen/no%20magic%20strings%20meme.png)\n\n- - - -\nThe code generation process is based from srndpty's CodeGen: https://github.com/srndpty/CodeGen\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FINFGameDev%2FConstGen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FINFGameDev%2FConstGen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FINFGameDev%2FConstGen/lists"}