PXR_Audio_Spatializer_ContextEditor.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4. [CustomEditor(typeof(PXR_Audio_Spatializer_Context))]
  5. [CanEditMultipleObjects]
  6. public class PXR_Audio_Spatializer_ContextEditor : Editor
  7. {
  8. private SerializedProperty meshBakingLayerMask;
  9. private bool showMeshBakingUtilsFlag = true;
  10. private string showMeshBakingUtilities = "Static mesh baking utilities";
  11. private void OnEnable()
  12. {
  13. meshBakingLayerMask = serializedObject.FindProperty("meshBakingLayerMask");
  14. }
  15. public override void OnInspectorGUI()
  16. {
  17. base.OnInspectorGUI();
  18. // Static mesh baking utilities
  19. serializedObject.Update();
  20. showMeshBakingUtilsFlag = EditorGUILayout.Foldout(showMeshBakingUtilsFlag, showMeshBakingUtilities);
  21. if (showMeshBakingUtilsFlag)
  22. {
  23. EditorGUI.indentLevel++;
  24. EditorGUILayout.PropertyField(meshBakingLayerMask);
  25. serializedObject.ApplyModifiedProperties();
  26. EditorGUILayout.BeginHorizontal();
  27. GUILayout.Space(EditorGUI.indentLevel * 15);
  28. if (GUILayout.Button("Bake all"))
  29. {
  30. var start = Time.realtimeSinceStartup;
  31. Undo.IncrementCurrentGroup();
  32. var undoGroupIndex = Undo.GetCurrentGroup();
  33. string bakedObjectNames = "";
  34. int meshCount = 0;
  35. var sceneGeometries = FindObjectsOfType<PXR_Audio_Spatializer_SceneGeometry>();
  36. foreach (PXR_Audio_Spatializer_SceneGeometry geometry in sceneGeometries)
  37. {
  38. bakedObjectNames += geometry.name + ", ";
  39. Undo.RecordObject(geometry, "");
  40. meshCount += geometry.BakeStaticMesh(meshBakingLayerMask.intValue);
  41. PrefabUtility.RecordPrefabInstancePropertyModifications(geometry);
  42. }
  43. Undo.SetCurrentGroupName("Bake static meshes for gameObject: " + bakedObjectNames);
  44. Undo.CollapseUndoOperations(undoGroupIndex);
  45. var durationMs = (Time.realtimeSinceStartup - start) * 1000;
  46. Debug.LogFormat("Baked static {0} meshes for gameObject: {1}in {2:f4} ms", meshCount, bakedObjectNames,
  47. durationMs);
  48. }
  49. if (GUILayout.Button("Clear all"))
  50. {
  51. Undo.IncrementCurrentGroup();
  52. var undoGroupIndex = Undo.GetCurrentGroup();
  53. string bakedObjectNames = "";
  54. var sceneGeometries = FindObjectsOfType<PXR_Audio_Spatializer_SceneGeometry>();
  55. foreach (PXR_Audio_Spatializer_SceneGeometry geometry in sceneGeometries)
  56. {
  57. bakedObjectNames += geometry.name + ", ";
  58. Undo.RecordObject(geometry, "");
  59. geometry.ClearBakeStaticMesh();
  60. PrefabUtility.RecordPrefabInstancePropertyModifications(geometry);
  61. }
  62. Undo.SetCurrentGroupName("Clear baked static meshes for gameObject: " + bakedObjectNames);
  63. Undo.CollapseUndoOperations(undoGroupIndex);
  64. Debug.LogFormat("Cleared baked static meshes for gameObject: {0}", bakedObjectNames);
  65. }
  66. GUILayout.Space(EditorGUI.indentLevel * 15 - 15);
  67. EditorGUILayout.EndHorizontal();
  68. EditorGUI.indentLevel--;
  69. }
  70. else
  71. {
  72. serializedObject.ApplyModifiedProperties();
  73. }
  74. }
  75. }
粤ICP备19079148号