Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.6 KiB

  1. /************************************************************************************
  2. Filename : ONSPPropagationSerializationManager.cs
  3. Content : Functionality for serializing Oculus Audio geometry
  4. Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
  5. Licensed under the Oculus SDK Version 3.5 (the "License");
  6. you may not use the Oculus SDK except in compliance with the License,
  7. which is provided at the time of installation or download, or which
  8. otherwise accompanies this software in either electronic or hard copy form.
  9. You may obtain a copy of the License at
  10. https://developer.oculus.com/licenses/sdk-3.5/
  11. Unless required by applicable law or agreed to in writing, the Oculus SDK
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. ************************************************************************************/
  17. using UnityEditor;
  18. using UnityEditor.Build;
  19. using UnityEngine;
  20. using UnityEditor.SceneManagement;
  21. using UnityEngine.SceneManagement;
  22. using System.Collections.Generic;
  23. public enum PlayModeState
  24. {
  25. Stopped,
  26. Playing,
  27. Paused
  28. }
  29. class ONSPPropagationSerializationManager
  30. {
  31. static ONSPPropagationSerializationManager()
  32. {
  33. EditorSceneManager.sceneSaving += OnSceneSaving;
  34. }
  35. public int callbackOrder { get { return 0; } }
  36. public void OnPreprocessBuild(BuildTarget target, string path)
  37. {
  38. Debug.Log("ONSPPropagationSerializationManager.OnPreprocessBuild for target " + target + " at path " + path);
  39. }
  40. [MenuItem("Oculus/Spatializer/Build audio geometry for current scene")]
  41. public static void BuildAudioGeometryForCurrentScene()
  42. {
  43. BuildAudioGeometryForScene(EditorSceneManager.GetActiveScene());
  44. }
  45. [MenuItem("Oculus/Spatializer/Rebuild audio geometry all scenes")]
  46. public static void RebuildAudioGeometryForAllScenes()
  47. {
  48. Debug.Log("Rebuilding geometry for all scenes");
  49. System.IO.Directory.Delete(ONSPPropagationGeometry.GeometryAssetPath, true);
  50. for (int i = 0; i < EditorSceneManager.sceneCount; ++i)
  51. {
  52. BuildAudioGeometryForScene(EditorSceneManager.GetSceneAt(i));
  53. }
  54. }
  55. public static void OnSceneSaving(Scene scene, string path)
  56. {
  57. BuildAudioGeometryForScene(scene);
  58. }
  59. private static void BuildAudioGeometryForScene(Scene scene)
  60. {
  61. Debug.Log("Building audio geometry for scene " + scene.name);
  62. List<GameObject> rootObjects = new List<GameObject>();
  63. scene.GetRootGameObjects(rootObjects);
  64. HashSet<string> fileNames = new HashSet<string>();
  65. foreach (GameObject go in rootObjects)
  66. {
  67. var geometryComponents = go.GetComponentsInChildren<ONSPPropagationGeometry>();
  68. foreach (ONSPPropagationGeometry geo in geometryComponents)
  69. {
  70. if (geo.fileEnabled)
  71. {
  72. if (!geo.WriteFile())
  73. {
  74. Debug.LogError("Failed writing geometry for " + geo.gameObject.name);
  75. }
  76. else
  77. {
  78. if (!fileNames.Add(geo.filePathRelative))
  79. {
  80. Debug.LogWarning("Duplicate file name detected: " + geo.filePathRelative);
  81. }
  82. }
  83. }
  84. }
  85. }
  86. Debug.Log("Successfully built " + fileNames.Count + " geometry objects");
  87. }
  88. }