Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this is the editor script of the mesh combiner, put this script in a Editor folder, the combiner will not work if this script is missing
- using UnityEditor;
- using UnityEngine;
- [CustomEditor(typeof(MeshMerge))]
- [CanEditMultipleObjects]
- public class MeshMergeEditor : Editor
- {
- SerializedProperty material;
- SerializedProperty combineType;
- SerializedProperty subMeshesType;
- SerializedProperty use32BitsBuffer;
- SerializedProperty mesh;
- SerializedProperty colors;
- SerializedProperty range;
- SerializedProperty gridOffset;
- SerializedProperty gridMaxSize;
- SerializedProperty groupedItems;
- SerializedProperty items;
- SerializedProperty atlasTexture;
- SerializedProperty path;
- SerializedProperty newMat;
- bool showCombiner = false;
- bool showAtlas = false;
- bool showItems = false;
- bool showAtlasAndCombine = false;
- void OnEnable()
- {
- // Setup the SerializedProperties.
- material = serializedObject.FindProperty("material");
- combineType = serializedObject.FindProperty("combineType");
- subMeshesType = serializedObject.FindProperty("subMeshesType");
- use32BitsBuffer = serializedObject.FindProperty("use32BitsBuffer");
- mesh = serializedObject.FindProperty("mesh");
- colors = serializedObject.FindProperty("colors");
- range = serializedObject.FindProperty("range");
- gridOffset = serializedObject.FindProperty("gridOffset");
- gridMaxSize = serializedObject.FindProperty("gridMaxSize");
- groupedItems = serializedObject.FindProperty("groupedItems");
- items = serializedObject.FindProperty("items");
- atlasTexture = serializedObject.FindProperty("atlasTexture");
- path = serializedObject.FindProperty("path");
- newMat = serializedObject.FindProperty("newMat");
- }
- public override void OnInspectorGUI()
- {
- serializedObject.Update();
- MeshMerge meshMerge = (MeshMerge)target;
- GUILayout.Space(10);
- showCombiner = EditorGUILayout.Foldout(showCombiner, "COMBINER SETTINGS", true, new GUIStyle(EditorStyles.foldout) { fontStyle = FontStyle.Bold });
- if (showCombiner)
- {
- EditorGUILayout.BeginHorizontal();
- EditorGUILayout.PropertyField(material, new GUIContent("Material"));
- if (GUILayout.Button("Set with first mat."))
- material.objectReferenceValue = meshMerge.items[0].GetComponent<MeshRenderer>().sharedMaterial;
- if (GUILayout.Button("X")) material.objectReferenceValue = null;
- EditorGUILayout.EndHorizontal();
- EditorGUILayout.PropertyField(combineType, new GUIContent("Combine Type"));
- EditorGUILayout.PropertyField(subMeshesType, new GUIContent("SubMeshes Type"));
- EditorGUILayout.PropertyField(use32BitsBuffer, new GUIContent("Use 32 bits Buffer ?"));
- if (combineType.enumValueIndex == 1)
- EditorGUILayout.PropertyField(mesh, new GUIContent("Hexagon Mesh"));
- if (combineType.enumValueIndex == 0 || combineType.enumValueIndex == 1)
- {
- EditorGUILayout.PropertyField(colors, new GUIContent("Colors"));
- EditorGUILayout.BeginHorizontal();
- EditorGUILayout.PropertyField(range, new GUIContent("Range"));
- if (GUILayout.Button("Calculate perfect cell size")) meshMerge.CalculatePerfectCellSize();
- EditorGUILayout.EndHorizontal();
- EditorGUILayout.PropertyField(gridOffset, new GUIContent("Grid Offset"));
- if (GUILayout.Button("Set offset"))
- {
- gridOffset.vector3Value = new Vector3(range.intValue / 2, 0, range.intValue / 2);
- SceneView.RepaintAll();
- }
- EditorGUILayout.PropertyField(gridMaxSize, new GUIContent("Grid Max Size"));
- EditorGUILayout.PropertyField(groupedItems, new GUIContent("Items Into Cells"), true);
- if (GUILayout.Button("Group items to grid"))
- {
- meshMerge.SetGroupedList();
- meshMerge.GroupItems();
- }
- }
- GUILayout.Space(5);
- if (GUILayout.Button("Merge meshes")) meshMerge.CombineMeshes();
- }
- GUILayout.Space(10);
- showAtlas = EditorGUILayout.Foldout(showAtlas, "ATLAS SETTINGS", true, new GUIStyle(EditorStyles.foldout) { fontStyle = FontStyle.Bold });
- if (showAtlas)
- {
- EditorGUILayout.PropertyField(atlasTexture, new GUIContent("Final Atlas Texture"));
- path.stringValue = EditorGUILayout.TextField("Save Path", path.stringValue);
- EditorGUILayout.PropertyField(newMat, new GUIContent("Final Atlas Material"));
- EditorGUILayout.HelpBox("Warning, Atlas will not work correctly if one of the 3d objects have several submeshes/materials.\n Consider using \"Atlas & Combine\" property in this case.", MessageType.Warning);
- if (GUILayout.Button("Atlas")) meshMerge.AtlasUVS();
- }
- GUILayout.Space(10);
- EditorGUILayout.PropertyField(items, new GUIContent("Items"), true);
- EditorGUILayout.BeginHorizontal();
- if (GUILayout.Button("Get children"))
- for (int i = 0; i < meshMerge.transform.childCount; i++)
- meshMerge.items.Add(meshMerge.transform.GetChild(i).gameObject);
- if (GUILayout.Button("Clear list")) meshMerge.items.Clear();
- EditorGUILayout.EndHorizontal();
- GUILayout.Space(10);
- EditorGUILayout.BeginHorizontal();
- EditorGUILayout.LabelField("Atlas & Combine", EditorStyles.boldLabel);
- if (GUILayout.Button("Atlas & Combine")) meshMerge.AtlasAndCombine();
- EditorGUILayout.EndHorizontal();
- if (GUILayout.Button("Undo all")) meshMerge.Undo();
- serializedObject.ApplyModifiedProperties();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement