SuperCombinerSettingsEditor.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace LunarCatsStudio.SuperCombiner
  6. {
  7. [CustomEditor(typeof(SuperCombinerSettings))]
  8. public class SuperCombinerSettingsEditor : Editor
  9. {
  10. SuperCombinerSettings _sc_settings;
  11. // flag used for show or hide sub-settings
  12. bool _show_instructions = true;
  13. bool _show_general_settings = true;
  14. bool _show_texture_settings = true;
  15. bool _show_material_settings = true;
  16. bool _show_mesh_settings = true;
  17. bool _showMultipleMaterials = false;
  18. Vector2 _pos_material_list;
  19. // Serialized
  20. private SerializedObject _serializedSettings;
  21. private SerializedProperty _customShaderProperties;
  22. private List<SerializedProperty> _multiMaterialsSC = new List<SerializedProperty>();
  23. public void OnEnable()
  24. {
  25. _sc_settings = (SuperCombinerSettings)target;
  26. _serializedSettings = new SerializedObject(_sc_settings);
  27. _customShaderProperties = _serializedSettings.FindProperty("_material_settings._customShaderProperties");
  28. for (int i = 0; i < SuperCombinerEditor.MAX_MULTI_MATERIAL_COUNT; i++)
  29. {
  30. _multiMaterialsSC.Add(_serializedSettings.FindProperty("_material_settings.multiMaterials" + i));
  31. }
  32. }
  33. public override void OnInspectorGUI()
  34. {
  35. base.OnInspectorGUI(); //utilisation de la methode de base
  36. GUI.enabled = false;
  37. DisplayHelp();
  38. EditorGUILayout.Space();
  39. DisplayGeneralSettings();
  40. EditorGUILayout.Space();
  41. DisplayTextureSettings();
  42. EditorGUILayout.Space();
  43. DisplayMaterialSettings();
  44. EditorGUILayout.Space();
  45. DisplayMeshSettings();
  46. EditorGUILayout.Space();
  47. GUI.enabled = true;
  48. EditorUtility.SetDirty(_sc_settings); // tag SC setting as modified and Save it
  49. }
  50. private void DisplayHelp()
  51. {
  52. _show_instructions = EditorGUILayout.Foldout(_show_instructions, "Instructions for Super Combiner (v " + _sc_settings.generalSettings.versionNumber + ")");
  53. if (_show_instructions)
  54. {
  55. GUILayout.Label("Put all you prefabs to combine as children of me. " +
  56. "Select your session name, the texture atlas size and whether or not to combine meshes. " +
  57. "When you are ready click 'Combine' button to start the process (it may take a while depending on the quantity of different assets). " +
  58. "When the process is finished you'll see the result on the scene (all original mesh renderers will be deactivated). " +
  59. "If you want to save the combined assets, select your saving options and click 'Save' button. " +
  60. "To revert the process just click 'Uncombine' button.", EditorStyles.helpBox);
  61. }
  62. }
  63. private void DisplayGeneralSettings()
  64. {
  65. _show_general_settings = EditorGUILayout.Foldout(_show_general_settings, "General Settings:");
  66. if (_show_general_settings)
  67. {
  68. _sc_settings.generalSettings.sessionName = EditorGUILayout.TextField(new GUIContent("Session name", "Your session name should be different for every SuperCombiner instance. Avoid using special characters."), _sc_settings.generalSettings.sessionName, GUILayout.ExpandWidth(true));
  69. _sc_settings.generalSettings.combineAtRuntime = EditorGUILayout.Toggle(new GUIContent("Combine at runtime?", "Set to true if you want the process to combine at startup during runtime (beware that combining is a complex task that may takes some time to process)"), _sc_settings.generalSettings.combineAtRuntime);
  70. _sc_settings.generalSettings.targetGameObject = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Target GameObject", "The GameObject into which the combined GameObject(s) will be created. If you leave it empty, a new GameObject will be created under this GameObject with the name of you session name."), _sc_settings.generalSettings.targetGameObject, typeof(GameObject), true);
  71. }
  72. }
  73. private void DisplayTextureSettings()
  74. {
  75. _show_texture_settings = EditorGUILayout.Foldout(_show_texture_settings, "Texture Atlas Settings:");
  76. if (_show_texture_settings)
  77. {
  78. _sc_settings.textureSettings.atlasSize = EditorGUILayout.IntPopup("Texture Atlas size", _sc_settings.textureSettings.atlasSize, _sc_settings.textureSettings.textureAtlasSizesLabels.ToArray(), _sc_settings.textureSettings.textureAtlasSizesValues.ToArray(), GUILayout.ExpandWidth(true));
  79. _sc_settings.textureSettings.tilingFactor = EditorGUILayout.Slider(new GUIContent("tiling factor", "Apply a tiling factor on the textures. This may be helpfull if you observe strange artifacts after combining materials with heightmap"), _sc_settings.textureSettings.tilingFactor, TextureSettings.MIN_TILING_FACTOR, TextureSettings.MAX_TILING_FACTOR, GUILayout.ExpandWidth(true));
  80. _sc_settings.textureSettings.padding = EditorGUILayout.IntField(new GUIContent("padding", "Padding between textures in the atlas"), _sc_settings.textureSettings.padding, GUILayout.ExpandWidth(true));
  81. }
  82. }
  83. private void DisplayMaterialSettings()
  84. {
  85. _show_material_settings = EditorGUILayout.Foldout(_show_material_settings, "Materials and Shaders Settings:");
  86. if (_show_material_settings)
  87. {
  88. _sc_settings.materialSettings.multipleMaterialsMode = EditorGUILayout.Toggle(new GUIContent("Multiple materials", "The multi material feature lets you combine to several materials (up to 10) from the listed source materials. This is usually usefull when combining meshes that have various materials (submeshes) that cannot be combined together."), _sc_settings.materialSettings.multipleMaterialsMode);
  89. // Multiple Material
  90. if (_sc_settings.materialSettings.multipleMaterialsMode)
  91. {
  92. _sc_settings.materialSettings.combineEachGroupAsSubmesh = EditorGUILayout.Toggle(new GUIContent("Set as submesh", "If set to true, each combined mesh for each material source group will be a submesh of the final combine mesh. If set to false, each material source group will be a separate mesh in a separate GameObject."), _sc_settings.materialSettings.combineEachGroupAsSubmesh);
  93. _showMultipleMaterials = EditorGUILayout.Foldout(_showMultipleMaterials, "Materials group");
  94. if (_showMultipleMaterials)
  95. {
  96. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  97. for (int i = 0; i < _sc_settings.materialSettings.multipleMaterialsCount; i++)
  98. {
  99. EditorGUILayout.BeginHorizontal();
  100. // Source materials
  101. EditorGUILayout.PropertyField(_multiMaterialsSC[i], new GUIContent("source materials (group " + i + ")", "Define here all the source material to be included in combined material " + i), true);
  102. EditorGUILayout.EndHorizontal();
  103. }
  104. EditorGUILayout.EndVertical();
  105. }
  106. }
  107. // Custom Shader propertues
  108. EditorGUILayout.PropertyField(_customShaderProperties, new GUIContent("Custom shader properties", "Super Combiner uses the list of texture properties from standard shader. If you are using custom shader with different texture properties, add their exact name in the list."), true);
  109. }
  110. }
  111. private void DisplayMeshSettings()
  112. {
  113. _show_mesh_settings = EditorGUILayout.Foldout(_show_mesh_settings, "Meshs Settings");
  114. if (_show_mesh_settings)
  115. {
  116. _sc_settings.meshSettings.combineMeshs = EditorGUILayout.Toggle(new GUIContent("Combine meshes?", "If set to false, only materials and textures will be combined, all meshes will remain separated. If set to true, all meshes will be combined into a unique combined mesh."), _sc_settings.meshSettings.combineMeshs);
  117. if (_sc_settings.meshSettings.combineMeshs)
  118. {
  119. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  120. _sc_settings.meshSettings.generateUv2 = EditorGUILayout.Toggle(new GUIContent("Generate UV2?", "If set to true, Super Combiner will generate UV2 for the combined mesh."), _sc_settings.meshSettings.generateUv2);
  121. _sc_settings.meshSettings.meshOutputType = (MeshSettings.MeshOutputType)EditorGUILayout.EnumPopup(new GUIContent("Mesh output", "Chose to combine into a Mesh or a SkinnedMesh. Combining into SkinnedMesh is in alpha release, it will only works properly if there are only SkinnedMeshes as input. Combining Meshes and SkinnedMeshes into a SkinnedMesh is not supported yet."), _sc_settings.meshSettings.meshOutputType, GUILayout.ExpandWidth(true));
  122. _sc_settings.meshSettings.manageColliders = EditorGUILayout.Toggle(new GUIContent("Include colliders", "If set to true, SuperCombiner will integrate all colliders into the combined GameObject"), _sc_settings.meshSettings.manageColliders);
  123. EditorGUILayout.EndVertical();
  124. }
  125. EditorGUILayout.BeginHorizontal();
  126. _sc_settings.meshSettings.manageLODs = EditorGUILayout.Toggle(new GUIContent("Manage LOD level", "If set to true, SuperCombiner will only take into account the specified LOD level for each LODGroup in the list of GameObjects to combine."), _sc_settings.meshSettings.manageLODs);
  127. if (_sc_settings.meshSettings.manageLODs)
  128. {
  129. _sc_settings.meshSettings.managedLODLevel = EditorGUILayout.IntField(new GUIContent("LOD level to take into account", "LOD Level to take into account"), _sc_settings.meshSettings.managedLODLevel, GUILayout.ExpandWidth(true));
  130. }
  131. EditorGUILayout.EndHorizontal();
  132. _sc_settings.meshSettings.targetGameObject = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Target GameObject", "The GameObject into which the combined GameObject(s) will be created. If you leave it empty, a new GameObject will be created under this GameObject with the name of you session name."), _sc_settings.meshSettings.targetGameObject, typeof(GameObject), true);
  133. }
  134. }
  135. }
  136. }