public override void OnInspectorGUI() { serializedObject.Update(); var doReimport = false; string newReimportPath = null; GUILayout.Label("Import", EditorStyles.boldLabel); if (model.autoGenerated) { EditorGUILayout.HelpBox("This model was created by brick building. You cannot reimport it.", MessageType.Info); } else { EditorGUILayout.LabelField("Pivot", ObjectNames.NicifyVariableName(model.pivot.ToString())); EditorGUILayout.LabelField("Relative File Path", model.relativeFilePath, EditorStyles.wordWrappedLabel); GUILayout.Space(16); EditorGUILayout.LabelField("Absolute File Path", model.absoluteFilePath, EditorStyles.wordWrappedLabel); GUILayout.Space(16); // Check if part of prefab instance and prevent reimport. if (PrefabUtility.IsPartOfAnyPrefab(target)) { EditorGUILayout.HelpBox("You cannot reimport a prefab instance. Please perform reimporting on the prefab itself.", MessageType.Warning); } else { if (File.Exists(model.relativeFilePath) || File.Exists(model.absoluteFilePath)) { doReimport = GUILayout.Button("Reimport"); } else { EditorGUILayout.HelpBox("Could not find original file.", MessageType.Warning); } if (GUILayout.Button("Reimport From New File")) { var path = EditorUtility.OpenFilePanelWithFilters("Select model file", "Packages/com.unity.lego.modelimporter/Models", new string[] { "All model files", "ldr,io,lxfml,lxf", "LDraw files", "ldr", "Studio files", "io", "LXFML files", "lxfml", "LXF files", "lxf" }); if (path.Length != 0) { newReimportPath = path; doReimport = true; } } } } serializedObject.ApplyModifiedProperties(); if (doReimport) { ImportModel.ReimportModel(model, newReimportPath); } }
public override void OnInspectorGUI() { serializedObject.Update(); var doReimport = false; GUILayout.Label("Import", EditorStyles.boldLabel); if (modelGroup.autoGenerated) { EditorGUILayout.HelpBox("This group was changed by brick building since import. You can only reimport the entire model.", MessageType.Info); } else { EditorGUILayout.LabelField("Number", modelGroup.number.ToString()); EditorGUILayout.LabelField("Name", modelGroup.groupName); EditorGUILayout.LabelField("Colliders", modelGroup.importSettings.colliders.ToString()); EditorGUILayout.LabelField("Connectivity", modelGroup.importSettings.connectivity.ToString()); EditorGUILayout.LabelField("Static", modelGroup.importSettings.isStatic.ToString()); EditorGUILayout.LabelField("Lightmapped", modelGroup.importSettings.lightmapped.ToString()); EditorGUILayout.LabelField("Randomized Rotations", modelGroup.importSettings.randomizeRotation.ToString()); EditorGUILayout.LabelField("LOD", modelGroup.importSettings.lod.ToString()); GUILayout.Space(16); // Check if part of prefab instance and prevent reimport. if (PrefabUtility.IsPartOfAnyPrefab(target)) { EditorGUILayout.HelpBox("You cannot reimport a prefab instance. Please perform reimporting on the prefab itself.", MessageType.Warning); } else { if (File.Exists(modelGroup.relativeFilePath) || File.Exists(modelGroup.absoluteFilePath)) { doReimport = GUILayout.Button("Reimport"); } else { EditorGUILayout.HelpBox("Could not find original file. Select model and reimport from a new file.", MessageType.Warning); } } } var doProcessing = false; GUILayout.Space(16); GUILayout.Label("Processing", EditorStyles.boldLabel); if (processedProp.boolValue) { EditorGUILayout.HelpBox("Already Processed", MessageType.Info); } else { EditorGUILayout.PropertyField(optimizationsProp); // Backface culling and geometry removal UI, and sorting UI. if (((ModelGroup.Optimizations)optimizationsProp.intValue & (ModelGroup.CameraBasedGeometryRemovalOptimizations | ModelGroup.Optimizations.SortFrontToBack)) != 0) { var geometryRemoval = ((ModelGroup.Optimizations)optimizationsProp.intValue & ModelGroup.CameraBasedGeometryRemovalOptimizations) != 0; var sorting = ((ModelGroup.Optimizations)optimizationsProp.intValue & ModelGroup.Optimizations.SortFrontToBack) != 0; var message = ""; if (geometryRemoval) { message += "Backface culling and geometry removal are based on all the specified views.\n"; } if (sorting) { message += "Front-to-back geometry sorting is based on the first specified view."; } EditorGUILayout.HelpBox(message, MessageType.Info); if (viewsProp.arraySize == 0 && Camera.main) { var warning = "No views have been specified.\n"; if (geometryRemoval) { warning += "View from current main camera will be used when doing backface culling and geometry removal.\n"; } if (sorting) { warning += "View from current main camera will be used when sorting geometry."; } EditorGUILayout.HelpBox(warning, MessageType.Warning); } else if (viewsProp.arraySize == 0) { if (geometryRemoval || sorting) { var error = "No views have been specified.\n"; if (geometryRemoval) { error += "Could not find main camera to use when doing backface culling and geometry removal.\n"; } if (sorting) { error += "Could not find main camera to use when sorting geometry."; } EditorGUILayout.HelpBox(error, MessageType.Error); } } if (otherGroupViews.Count > 0) { showOtherGroups = EditorGUILayout.Foldout(showOtherGroups, "Views From Other Groups", true); if (showOtherGroups) { foreach (var group in otherGroupViews.Keys) { if (GUILayout.Button("Add Views From " + group.parentName + " " + group.groupName)) { foreach (var groupView in otherGroupViews[group]) { AddView(groupView); } } } } } if (lightViews.Count > 0) { showLights = EditorGUILayout.Foldout(showLights, "Views From Lights", true); if (showLights) { foreach (var light in lightViews.Keys) { if (GUILayout.Button("Add View From " + light.name)) { AddView(lightViews[light]); } } } } if (cameraViews.Count > 0) { showCameras = EditorGUILayout.Foldout(showCameras, "Views From Cameras", true); if (showCameras) { foreach (var camera in cameraViews.Keys) { if (GUILayout.Button("Add View From " + camera.name)) { AddView(cameraViews[camera]); } } } } if (GUILayout.Button("Add Current Scene Views")) { foreach (var sceneView in SceneView.sceneViews) { var sceneViewCamera = ((SceneView)sceneView).camera; viewsProp.arraySize++; var newEntry = viewsProp.GetArrayElementAtIndex(viewsProp.arraySize - 1); newEntry.FindPropertyRelative("name").stringValue = sceneViewCamera.name; newEntry.FindPropertyRelative("perspective").boolValue = !sceneViewCamera.orthographic; newEntry.FindPropertyRelative("position").vector3Value = sceneViewCamera.transform.position; newEntry.FindPropertyRelative("rotation").quaternionValue = sceneViewCamera.transform.rotation; newEntry.FindPropertyRelative("size").floatValue = sceneViewCamera.orthographicSize; newEntry.FindPropertyRelative("fov").floatValue = sceneViewCamera.fieldOfView; newEntry.FindPropertyRelative("aspect").floatValue = sceneViewCamera.aspect; newEntry.FindPropertyRelative("minRange").floatValue = sceneViewCamera.nearClipPlane; newEntry.FindPropertyRelative("maxRange").floatValue = sceneViewCamera.farClipPlane; } } if (viewsProp.arraySize > 0) { EditorList.Show(viewsProp, EditorListOption.All);//, new GUIContent[] { new GUIContent("Z", "View From") }, new System.Action<SerializedProperty>[] { (p) => ViewFrom(p) }); } } GUILayout.Space(16); EditorGUILayout.PropertyField(randomizeNormalsProp, new GUIContent("Add Noise To Normals", "A small amount of noise adds visual detail.")); /* GUILayout.Space(16); * EditorGUILayout.PropertyField(imperfectionsProp); * * // Imperfections UI. * if (((ModelGroup.Imperfections)imperfectionsProp.intValue & ModelGroup.Imperfections.UVDegradation) == ModelGroup.Imperfections.UVDegradation) * { * EditorGUILayout.HelpBox("UV degradation has not been implemented yet.", MessageType.Warning); * } * if (((ModelGroup.Imperfections)imperfectionsProp.intValue & ModelGroup.Imperfections.Scratches) == ModelGroup.Imperfections.Scratches) * { * EditorGUILayout.HelpBox("Scratches have not been implemented yet.", MessageType.Warning); * }*/ GUILayout.Space(16); if (PrefabUtility.IsPartOfAnyPrefab(target)) { EditorGUILayout.HelpBox("You cannot process a prefab instance. Please perform processing on the prefab itself.", MessageType.Warning); } else { // Process button. doProcessing = GUILayout.Button("Process"); if (doProcessing) { Undo.RegisterFullObjectHierarchyUndo(modelGroup.gameObject, "Process"); processedProp.boolValue = true; } } } serializedObject.ApplyModifiedProperties(); if (doReimport) { // FIXME Issue with finding the correct group when multiple groups have same name and group number has changed! ImportModel.ReimportModelGroup(modelGroup); } if (doProcessing) { Vector2Int vertCount = Vector2Int.zero; Vector2Int triCount = Vector2Int.zero; Vector2Int meshCount = Vector2Int.zero; Vector2Int boxColliderCount = Vector2Int.zero; ModelProcessor.ProcessModelGroup(modelGroup, ref vertCount, ref triCount, ref meshCount, ref boxColliderCount); Debug.Log($"Process result (before/after):\nVerts {vertCount.x}/{vertCount.y}, tris {triCount.x}/{triCount.y}, meshes {meshCount.x}/{meshCount.y}, box colliders {boxColliderCount.x}/{boxColliderCount.y}"); var prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { EditorSceneManager.MarkSceneDirty(prefabStage.scene); } } }