BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / Spatializer / editor / ONSPPropagationSerializationManager.cs

ONSPPropagationSerializationManager.cs

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