public void ProcessMesh() { rascal.CleanUpMeshes(); sw.Restart(); rascal.ProcessMesh(); double time = sw.LapTime(); meshGenText.text = "Mesh processed in: " + time.ToString("F2") + "ms"; }
public override void OnInspectorGUI() { serializedObject.Update(); RASCALSkinnedMeshCollider rascal = (RASCALSkinnedMeshCollider)target; EditorGUILayout.Space(); EditorGUILayout.LabelField("Generation", bold); if (GUILayout.Button(new GUIContent("Generate", "Generate collision meshes based on the current settings. THIS WILL UPDATE YOUR PREFAB if it is part of one, otherwise everything breaks."))) { rascal.ProcessMesh(); rascal.ImmediateUpdateColliders(true); if (!UpdatePrefab(rascal, true)) { rascal.UnserializeForPrefab(); } return; } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Clear", "Destroy all mesh colliders and data generated by this script. THIS WILL UPDATE YOUR PREFAB if it is part of one, otherwise everything breaks."), new GUIStyle(EditorStyles.miniButton) { fixedWidth = 120 })) { rascal.CleanUpMeshes(); UpdatePrefab(rascal); return; } EditorGUI.BeginChangeCheck(); bool clearAllMeshColliders = EditorGUILayout.Toggle(new GUIContent("All Mesh Colliders", GetTooltip("clearAllMeshColliders")), rascal.clearAllMeshColliders); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(rascal, "RASCAL Change Variable"); rascal.clearAllMeshColliders = clearAllMeshColliders; Undo.FlushUndoRecordObjects(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); bool generateOnStart = EditorGUILayout.ToggleLeft(GetContent("generateOnStart"), rascal.generateOnStart, label); bool immediateStartupCollision = rascal.immediateStartupCollision; if (rascal.generateOnStart) { immediateStartupCollision = EditorGUILayout.ToggleLeft(GetContent("immediateStartupCollision"), rascal.immediateStartupCollision, label); } EditorGUILayout.Space(); bool onlyUniqueTriangles = EditorGUILayout.ToggleLeft(GetContent("onlyUniqueTriangles"), rascal.onlyUniqueTriangles, label); bool splitCollisionMeshesByMaterial = EditorGUILayout.ToggleLeft(GetContent("splitCollisionMeshesByMaterial"), rascal.splitCollisionMeshesByMaterial, label); bool zeroBoneMeshAlternateTransform = EditorGUILayout.ToggleLeft(GetContent("zeroBoneMeshAlternateTransform"), rascal.zeroBoneMeshAlternateTransform, label); bool convexMeshColliders = EditorGUILayout.ToggleLeft(GetContent("convexMeshColliders"), rascal.convexMeshColliders, label); EditorGUILayout.Space(); EditorGUILayout.PropertyField(maxTris); PhysicMaterial physicsMaterial = EditorGUILayout.ObjectField(GetContent("physicsMaterial"), rascal.physicsMaterial, typeof(PhysicMaterial), true) as PhysicMaterial; EditorGUILayout.Space(); EditorGUILayout.LabelField("", new GUIStyle(GUI.skin.horizontalScrollbar) { fixedHeight = 1 }, GUILayout.Height(2)); EditorGUILayout.Space(); EditorGUILayout.LabelField("Updating", bold); bool enableUpdatingOnStart = EditorGUILayout.ToggleLeft(GetContent("enableUpdatingOnStart"), rascal.enableUpdatingOnStart, label); double idleCpuBudget = EditorGUILayout.DoubleField(GetContent("idleCpuBudget"), rascal.idleCpuBudget); double activeCpuBudget = EditorGUILayout.DoubleField(GetContent("activeCpuBudget"), rascal.activeCpuBudget); float meshUpdateThreshold = EditorGUILayout.FloatField(GetContent("meshUpdateThreshold"), rascal.meshUpdateThreshold); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(rascal, "RASCAL Change Variable"); rascal.generateOnStart = generateOnStart; rascal.immediateStartupCollision = immediateStartupCollision; rascal.onlyUniqueTriangles = onlyUniqueTriangles; rascal.splitCollisionMeshesByMaterial = splitCollisionMeshesByMaterial; rascal.zeroBoneMeshAlternateTransform = zeroBoneMeshAlternateTransform; rascal.convexMeshColliders = convexMeshColliders; rascal.physicsMaterial = physicsMaterial; rascal.enableUpdatingOnStart = enableUpdatingOnStart; rascal.idleCpuBudget = idleCpuBudget; rascal.activeCpuBudget = activeCpuBudget; rascal.meshUpdateThreshold = meshUpdateThreshold; Undo.FlushUndoRecordObjects(); } EditorGUILayout.Space(); EditorGUILayout.Space(); assocAndExcludeAnim.target = EditorGUILayout.Foldout(assocAndExcludeAnim.target, "Material Associations & Exclusions", new GUIStyle(EditorStyles.foldout) { fontStyle = FontStyle.Bold, fontSize = 12 }); if (EditorGUILayout.BeginFadeGroup(assocAndExcludeAnim.faded)) { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditorGUILayout.LabelField(new GUIContent("Material Associations", GetTooltip("materialAssociationList")), new GUIStyle(center) { fixedHeight = 18 }, GUILayout.Width(156)); if (GUILayout.Button("+", new GUIStyle(EditorStyles.miniButton) { fontSize = 13 }, GUILayout.Width(20), GUILayout.Height(20))) { Undo.RecordObject(rascal, "Add RASCAL Material Association"); rascal.materialAssociationList.Add(new RASCALSkinnedMeshCollider.PhysicsMaterialAssociation()); Undo.FlushUndoRecordObjects(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); matAssScrollPos = EditorGUILayout.BeginScrollView(matAssScrollPos, EditorStyles.helpBox, GUILayout.Height(rascal.materialAssociationList.Count * 26), GUILayout.MaxHeight(140)); for (int i = 0; i < rascal.materialAssociationList.Count;) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("X", new GUIStyle(EditorStyles.miniButton) { }, GUILayout.Width(19), GUILayout.Height(16))) { Undo.RecordObject(rascal, "Remove RASCAL Material Association"); rascal.materialAssociationList.Remove(rascal.materialAssociationList[i]); Undo.FlushUndoRecordObjects(); continue; } EditorGUI.BeginChangeCheck(); Material material = EditorGUILayout.ObjectField(rascal.materialAssociationList[i].material, typeof(Material), true) as Material; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(rascal, "RASCAL MA Set Material"); rascal.materialAssociationList[i].material = material; Undo.FlushUndoRecordObjects(); } EditorGUILayout.LabelField(" -> ", GUILayout.Width(28)); EditorGUI.BeginChangeCheck(); PhysicMaterial physMat = EditorGUILayout.ObjectField(rascal.materialAssociationList[i].physicsMaterial, typeof(PhysicMaterial), true) as PhysicMaterial; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(rascal, "RASCAL MA Set PhysMat"); rascal.materialAssociationList[i].physicsMaterial = physMat; Undo.FlushUndoRecordObjects(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("", new GUIStyle(GUI.skin.horizontalScrollbar) { fixedHeight = 1 }, GUILayout.Height(2)); i++; } EditorGUILayout.EndScrollView(); //exclusion stuff EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); EditorGUILayout.LabelField(new GUIContent("Add Exclusions", "Drag either a skinned mesh, bone-transform, or material into the slots below to add them to the exclusion list. " + "This will make it so collision meshes will not be generated for the given meshes, bone-transforms, and materials."), center); EditorGUILayout.BeginHorizontal(); SkinnedMeshRenderer exSkin = EditorGUILayout.ObjectField(null, typeof(SkinnedMeshRenderer), true) as SkinnedMeshRenderer; Transform exBone = EditorGUILayout.ObjectField(null, typeof(Transform), true) as Transform; Material exMat = EditorGUILayout.ObjectField(null, typeof(Material), true) as Material; EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { //New Obj was assigned if (exSkin && !rascal.excludedSkins.Contains(exSkin)) { Undo.RecordObject(rascal, "RASCAL Add Excluded SkinnedMesh"); rascal.excludedSkins.Add(exSkin); Undo.FlushUndoRecordObjects(); } if (exMat && !rascal.excludedMaterials.Contains(exMat)) { Undo.RecordObject(rascal, "RASCAL Add Excluded Material"); rascal.excludedMaterials.Add(exMat); Undo.FlushUndoRecordObjects(); } if (exBone && !rascal.excludedBones.Contains(exBone)) { Undo.RecordObject(rascal, "RASCAL Add Excluded Bone"); rascal.excludedBones.Add(exBone); Undo.FlushUndoRecordObjects(); } } const bool useDisabledLook = false; excludeScrollPos = EditorGUILayout.BeginScrollView(excludeScrollPos, EditorStyles.helpBox, GUILayout.Height(excludeCount(rascal) * 27), GUILayout.MaxHeight(160)); for (int i = 0; i < rascal.excludedSkins.Count;) { EditorGUILayout.BeginHorizontal(new GUIStyle() { margin = new RectOffset(0, 0, 0, 0) }); if (GUILayout.Button("X", GUILayout.Width(18), GUILayout.Height(16))) { Undo.RecordObject(rascal, "Remove RASCAL Excluded SkinnedMesh"); rascal.excludedSkins.Remove(rascal.excludedSkins[i]); Undo.FlushUndoRecordObjects(); continue; } EditorGUI.BeginDisabledGroup(useDisabledLook); rascal.excludedSkins[i] = EditorGUILayout.ObjectField(rascal.excludedSkins[i], typeof(SkinnedMeshRenderer), true, GUILayout.Height(17)) as SkinnedMeshRenderer; EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); //EditorGUILayout.LabelField("", new GUIStyle(GUI.skin.horizontalScrollbar) { fixedHeight = 1 }, GUILayout.Height(2)); i++; } for (int i = 0; i < rascal.excludedBones.Count;) { EditorGUILayout.BeginHorizontal(new GUIStyle() { margin = new RectOffset(0, 0, 0, 0) }); if (GUILayout.Button("X", GUILayout.Width(18), GUILayout.Height(16))) { Undo.RecordObject(rascal, "Remove RASCAL Excluded Bone"); rascal.excludedBones.Remove(rascal.excludedBones[i]); Undo.FlushUndoRecordObjects(); continue; } EditorGUI.BeginDisabledGroup(useDisabledLook); rascal.excludedBones[i] = EditorGUILayout.ObjectField(rascal.excludedBones[i], typeof(Transform), true, GUILayout.Height(17)) as Transform; EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); //EditorGUILayout.LabelField("", new GUIStyle(GUI.skin.horizontalScrollbar) { fixedHeight = 1 }, GUILayout.Height(2)); i++; } for (int i = 0; i < rascal.excludedMaterials.Count;) { EditorGUILayout.BeginHorizontal(new GUIStyle() { margin = new RectOffset(0, 0, 0, 0) }); if (GUILayout.Button("X", GUILayout.Width(18), GUILayout.Height(16))) { Undo.RecordObject(rascal, "Remove RASCAL Excluded Material"); rascal.excludedMaterials.Remove(rascal.excludedMaterials[i]); Undo.FlushUndoRecordObjects(); continue; } EditorGUI.BeginDisabledGroup(useDisabledLook); rascal.excludedMaterials[i] = EditorGUILayout.ObjectField(rascal.excludedMaterials[i], typeof(Material), true, GUILayout.Height(17)) as Material; EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); //EditorGUILayout.LabelField("", new GUIStyle(GUI.skin.horizontalScrollbar) { fixedHeight = 1 }, GUILayout.Height(2)); i++; } EditorGUILayout.EndScrollView(); } EditorGUILayout.EndFadeGroup(); serializedObject.ApplyModifiedProperties(); }