private static void UpdateGeneratedConstants() { string[] sortingLayerNames = (string[])(typeof(UnityEditorInternal.InternalEditorUtility)).GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null, new object[0]);; string[] layerNames = UnityEditorInternal.InternalEditorUtility.layers; List <string> sceneNames = new List <string>(); List <string> santitizedSceneNames = new List <string>(); int[] sortingLayerValues = (int[])(typeof(UnityEditorInternal.InternalEditorUtility)).GetProperty("sortingLayerUniqueIDs", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null, new object[0]); int[] layerValues = new int[layerNames.Length]; LayerMask[] layerMaskValues = new LayerMask[layerNames.Length]; string[] collisionMatrixNames = new string[layerNames.Length]; LayerMask[] collisionMatrixValues = new LayerMask[layerNames.Length]; string[] tagNames = UnityEditorInternal.InternalEditorUtility.tags; string[] tagValues = new string[tagNames.Length]; for (int i = 0; i < layerNames.Length; i++) { layerNames[i] = StringUtils.Santise(layerNames[i], false, false); layerValues[i] = LayerMask.NameToLayer(layerNames[i]); layerMaskValues[i] = 1 << layerValues[i]; collisionMatrixNames[i] = layerNames[i] + "CollisionMask"; collisionMatrixValues[i] = PhysicsUtils.GetCollisionMatrixMask(i); } for (int i = 0; i < sortingLayerNames.Length; i++) { sortingLayerNames[i] = StringUtils.Santise(sortingLayerNames[i], false, false); } for (int i = 0; i < EditorBuildSettings.scenes.Length; i++) { string path = EditorBuildSettings.scenes[i].path; if (!string.IsNullOrEmpty(path)) { int slashIndex = path.LastIndexOf('/') + 1; string sceneName = path.Substring(slashIndex, path.Length - slashIndex - 6); string sanitizedName = StringUtils.Santise(StringUtils.Titelize(sceneName), false, false); if (!sceneNames.Contains(sceneName) && File.Exists(path)) { sceneNames.Add(sceneName); santitizedSceneNames.Add(sanitizedName); } } } for (int i = 0; i < tagNames.Length; i++) { tagValues[i] = tagNames[i]; tagNames[i] = StringUtils.Santise(tagNames[i], false, false); } List <CodeGenerator.CodeDefintion> definitions = new List <CodeGenerator.CodeDefintion>(); definitions.Add(CodeGenerator.CreateEnumDefinition("LayerName", layerNames, layerValues)); definitions.Add(CodeGenerator.CreateEnumDefinition("SortingLayerName", sortingLayerNames, sortingLayerValues)); definitions.Add(CodeGenerator.CreateClass("Layer", CodeGenerator.CreateConstantInts(layerNames, layerValues), true, false)); definitions.Add(CodeGenerator.CreateClass("SortingLayer", CodeGenerator.CreateConstantInts(sortingLayerNames, sortingLayerValues), true, false)); definitions.Add(CodeGenerator.CreateClass("Tag", CodeGenerator.CreateConstantStrings(tagNames, tagValues), true, false)); definitions.Add(CodeGenerator.CreateClass("LayerMasks", CodeGenerator.CreateConstantLayerMasks(layerNames, layerMaskValues, true), true, true)); definitions.Add(CodeGenerator.CreateClass("CollisionMatrix", CodeGenerator.CreateConstantLayerMasks(collisionMatrixNames, collisionMatrixValues, true), true, false)); definitions.Add(CodeGenerator.CreateClass("SceneNames", CodeGenerator.CreateConstantStrings(santitizedSceneNames, sceneNames), true, false)); Type[] scriptableEnumTypes = typeof(ScriptableEnum).GetAllSubtypesInUnityAssemblies(); for (int i = 0; i < scriptableEnumTypes.Length; i++) { CodeGenerator.CodeDefintion enumClass = CodeGenerator.CreateClass(scriptableEnumTypes[i].Name, CodeGenerator.CreateScriptableEnumConstants(scriptableEnumTypes[i]), false, true); string titleName = StringUtils.Titelize(scriptableEnumTypes[i].Name); enumClass.AppendAttribute("CreateAssetMenu", "fileName = \"" + titleName + "\"", "menuName = \"Scriptable Enum/" + titleName + "\""); definitions.Add(enumClass); } for (int i = 0; i < scriptableEnumTypes.Length; i++) { definitions.Add(CodeGenerator.CreateScriptableEnumMaskClass(scriptableEnumTypes[i])); } CodeGenerator.CreateSourceFile("AutoGeneratedConstants", definitions); }