public IEnumerator SceneTest() { const string basePath = "Assets/UniEnum.Tests/Editor/Scenes"; var sceneFiles = Directory.EnumerateFiles(basePath, "*.unity", SearchOption.AllDirectories) .Select(v => new EditorBuildSettingsScene(v, true)) .ToArray(); var setting = new GenerateSetting() { Namespace = "UniEnumEditorTests", OutputDir = "Assets/UniEnum.Tests/Editor/TestOutput", }; AssetDatabase.DeleteAsset($"{setting.OutputDir}/SceneValues.Generated.cs"); UnityConstantValuesGenerator.UpdateSceneValues(setting, sceneFiles); yield return(new RecompileScripts()); Assert.AreEqual("UniEnumTest_100", SceneName.UniEnumTest_100); Assert.AreEqual("UniEnumTest_101", SceneName.UniEnumTest_101); Assert.AreEqual("UniEnumTest_102", SceneName.UniEnumTest_102); Assert.AreEqual(0, SceneId.UniEnumTest_100); Assert.AreEqual(1, SceneId.UniEnumTest_101); Assert.AreEqual(2, SceneId.UniEnumTest_102); Assert.AreEqual($"{basePath}/UniEnumTest_100.unity", ScenePath.UniEnumTest_100); Assert.AreEqual($"{basePath}/UniEnumTest_101.unity", ScenePath.UniEnumTest_101); Assert.AreEqual($"{basePath}/UniEnumTest_102.unity", ScenePath.UniEnumTest_102); }
public IEnumerator UnityConstantsTest() { var setting = new GenerateSetting() { Namespace = "UniEnumEditorTests", OutputDir = "Assets/UniEnum.Tests/Editor/TestOutput", }; AssetDatabase.DeleteAsset($"{setting.OutputDir}/TagValues.Generated.cs"); AssetDatabase.DeleteAsset($"{setting.OutputDir}/LayerValues.Generated.cs"); AssetDatabase.DeleteAsset($"{setting.OutputDir}/SortingLayerValues.Generated.cs"); UnityConstantValuesGenerator.UpdateUnityConstants(setting); yield return(new RecompileScripts()); Assert.AreEqual("12@hoge -##A", TagName._12hogeA); Assert.AreEqual(17, (int)LayerId.アイウエオ); Assert.AreEqual((1 << 17), (int)LayerMaskValue.アイウエオ); Assert.AreEqual(21, (int)LayerId._123abcWXZ11); Assert.AreEqual((1 << 21), (int)LayerMaskValue._123abcWXZ11); Assert.AreEqual(SortingLayer.NameToID("Default"), SortingLayerId.Default); }
public IEnumerator SceneTest() { var sceneFiles = Directory.EnumerateFiles(SceneDirPath, "*.unity", SearchOption.AllDirectories) .Select(v => new EditorBuildSettingsScene(v, true)) .ToArray(); var setting = new GenerateSetting() { @namespace = "UniEnumEditorTests", outputDir = OutputDirPath, }; AssetDatabase.DeleteAsset($"{setting.outputDir}/SceneValues.Generated.cs"); UnityConstantValuesGenerator.UpdateSceneValues(setting, sceneFiles); yield return(new RecompileScripts()); #if CHECK_GENERATE_CLASS Assert.AreEqual("UniEnumTest_100", SceneName.UniEnumTest_100); Assert.AreEqual("UniEnumTest_101", SceneName.UniEnumTest_101); Assert.AreEqual("UniEnumTest_102", SceneName.UniEnumTest_102); Assert.AreEqual(0, SceneId.UniEnumTest_100); Assert.AreEqual(1, SceneId.UniEnumTest_101); Assert.AreEqual(2, SceneId.UniEnumTest_102); Assert.AreEqual($"{SceneDirPath}/UniEnumTest_100.unity", ScenePath.UniEnumTest_100); Assert.AreEqual($"{SceneDirPath}/UniEnumTest_101.unity", ScenePath.UniEnumTest_101); Assert.AreEqual($"{SceneDirPath}/UniEnumTest_102.unity", ScenePath.UniEnumTest_102); #endif }
public override void OnGUI(string searchContext) { _serializedObject.UpdateIfRequiredOrScript(); using (new LabeledScope(Styles.SourceGenerationLabel)) { EditorGUILayout.PropertyField(_namespaceProp, new GUIContent("Namespace")); EditorGUILayout.PropertyField(_outputPathProp, new GUIContent("Output Directory")); using (new LabeledScope(Styles.GenerateTargetsLabel)) { EditorGUILayout.PropertyField(_generateSceneProp, new GUIContent("Scene")); EditorGUILayout.PropertyField(_generateSortingLayerProp, new GUIContent("SortingLayer")); EditorGUILayout.PropertyField(_generateLayerProp, new GUIContent("Layer")); EditorGUILayout.PropertyField(_generateTagProp, new GUIContent("Tag")); } EditorGUILayout.Space(); if (GUILayout.Button("Generate", EditorStyles.miniButtonRight)) { using (AssetEditing.Scope()) { UnityConstantValuesGenerator.UpdateUnityConstants(); UnityConstantValuesGenerator.UpdateSceneValues(); } AssetDatabase.Refresh(); } } _serializedObject.ApplyModifiedProperties(); }
public override void OnGUI(string searchContext) { using (new LabeledScope(Styles.SourceGenerationLabel)) { EditorGUI.BeginChangeCheck(); _generateSetting.@namespace = EditorGUILayout.TextField(new GUIContent("Namespace"), _generateSetting.@namespace); _generateSetting.outputDir = EditorGUILayout.TextField(new GUIContent("Output Directory"), _generateSetting.outputDir); using (new LabeledScope(Styles.GenerateTargetsLabel)) { _generateSetting.generateSceneValues = EditorGUILayout.Toggle(new GUIContent("Scene"), _generateSetting.generateSceneValues); _generateSetting.generateSortingLayerValues = EditorGUILayout.Toggle(new GUIContent("SortingLayer"), _generateSetting.generateSortingLayerValues); _generateSetting.generateLayerValues = EditorGUILayout.Toggle(new GUIContent("Layer"), _generateSetting.generateLayerValues); _generateSetting.generateTagValues = EditorGUILayout.Toggle(new GUIContent("Tag"), _generateSetting.generateTagValues); } EditorGUILayout.Space(); if (EditorGUI.EndChangeCheck()) { UnityConstantsGeneratorSettings.Save(); } if (GUILayout.Button("Generate", EditorStyles.miniButtonRight)) { using (AssetEditing.Scope()) { UnityConstantValuesGenerator.UpdateUnityConstants(); UnityConstantValuesGenerator.UpdateSceneValues(); } AssetDatabase.Refresh(); } } }