Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from GVR Audio to Unity Audio #551

Merged
merged 6 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions Assets/Editor/ReplaceGvr.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;

public class ReplaceGvr : Editor
{

// Only used for console logging
private static string currentSceneOrPrefabName;

[MenuItem("Open Brush/Replace GoogleVR Audio")]
public static void Run()
{
// Iterate through all scenes
for (int i = 0; i < SceneManager.sceneCount; i++)
{
var scene = SceneManager.GetSceneAt(i);
EditorSceneManager.OpenScene(scene.path);

currentSceneOrPrefabName = scene.name;
foreach (GameObject obj in FindObjectsOfType<GameObject>(includeInactive: true))
{
FixAllGvr(obj);
}
}

// Iterate through all prefabs
string[] prefabGUIDs = AssetDatabase.FindAssets("t:Prefab");
foreach (string prefabGuid in prefabGUIDs)
{
string prefabPath = AssetDatabase.GUIDToAssetPath(prefabGuid);
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
IteratePrefab(prefab.transform);
}
}

private static void IteratePrefab(Transform transform)
{
currentSceneOrPrefabName = transform.name;
FixAllGvr(transform.gameObject);

foreach (Transform child in transform)
{
IteratePrefab(child);
}
}

public static void FixAllGvr(GameObject go)
{
FixGvrSource(go);
FixGvrSoundfield(go);
FixGvrRoom(go);
FixGvrListener(go);
}

public static void FixGvrSoundfield(GameObject go)
{
var gvr = go.GetComponent<GvrAudioSoundfield>();
if (gvr == null) return;

// Disable Resonance for now
// if (go.GetComponent<ResonanceAudioSource>() == null)
// {
// go.AddComponent<ResonanceAudioSource>();
// Debug.Log($"Added ResonanceAudioSource to {currentSceneOrPrefabName}.{go.name}");
// }
}

public static void FixGvrRoom(GameObject go)
{
var gvr = go.GetComponent<GvrAudioRoom>();
if (gvr == null) return;

// Disable Resonance for now
// ResonanceAudioRoom resAudioRoom = null;
// if (go.GetComponent<ResonanceAudioRoom>() == null)
// {
// resAudioRoom = go.AddComponent<ResonanceAudioRoom>();
// Debug.Log($"Added ResonanceAudioRoom to {currentSceneOrPrefabName}.{go.name}");
// }

// resAudioRoom.leftWall = (ResonanceAudioRoomManager.SurfaceMaterial)gvr.leftWall;
// resAudioRoom.rightWall = (ResonanceAudioRoomManager.SurfaceMaterial)gvr.rightWall;
// resAudioRoom.floor = (ResonanceAudioRoomManager.SurfaceMaterial)gvr.floor;
// resAudioRoom.ceiling = (ResonanceAudioRoomManager.SurfaceMaterial)gvr.ceiling;
// resAudioRoom.backWall = (ResonanceAudioRoomManager.SurfaceMaterial)gvr.backWall;
// resAudioRoom.frontWall = (ResonanceAudioRoomManager.SurfaceMaterial)gvr.frontWall;
// resAudioRoom.reflectivity = gvr.reflectivity;
// resAudioRoom.reverbGainDb = gvr.reverbGainDb;
// resAudioRoom.reverbBrightness = gvr.reverbBrightness;
// resAudioRoom.reverbTime = gvr.reverbTime;
// resAudioRoom.size = gvr.size;
}

public static void FixGvrListener(GameObject go)
{
var gvr = go.GetComponent<GvrAudioListener>();
if (gvr == null) return;

// Disable Resonance for now
// ResonanceAudioListener resAudioListener = null;
// if (go.GetComponent<ResonanceAudioListener>() == null)
// {
// resAudioListener = go.AddComponent<ResonanceAudioListener>();
// Debug.Log($"Added ResonanceAudioListener to {currentSceneOrPrefabName}.{go.name}");
// }

// resAudioListener.occlusionMask = gvr.occlusionMask;
// resAudioListener.globalGainDb = gvr.globalGainDb;
// // resAudioListener.??? = gvr.quality;
}

public static void FixGvrSource(GameObject go)
{
var gvr = go.GetComponent<GvrAudioSource>();
if (gvr == null) return;

var audioSource = go.GetComponent<AudioSource>();
if (audioSource == null)
{
audioSource = go.AddComponent<AudioSource>();
Debug.Log($"Added AudioSource to {currentSceneOrPrefabName}.{go.name}");
}

audioSource.bypassEffects = gvr.bypassRoomEffects;
audioSource.bypassListenerEffects = gvr.bypassRoomEffects;
audioSource.clip = gvr.sourceClip;
audioSource.loop = gvr.sourceLoop;
audioSource.mute = gvr.sourceMute;
audioSource.pitch = gvr.sourcePitch;
audioSource.priority = gvr.sourcePriority;
audioSource.spatialBlend = gvr.sourceSpatialBlend;
audioSource.dopplerLevel = gvr.sourceDopplerLevel;
audioSource.spread = gvr.sourceSpread;
audioSource.volume = gvr.sourceVolume;
audioSource.rolloffMode = gvr.sourceRolloffMode;
audioSource.maxDistance = gvr.sourceMaxDistance;
audioSource.minDistance = gvr.sourceMinDistance;

// Disable Resonance for now
// ResonanceAudioSource resAudioSource = null;
// if (go.GetComponent<ResonanceAudioSource>() == null)
// {
// resAudioSource = go.AddComponent<ResonanceAudioSource>();
// Debug.Log($"Added ResonanceAudioSource to {currentSceneOrPrefabName}.{go.name}");
// }

// resAudioSource.directivityAlpha = gvr.directivityAlpha;
// resAudioSource.directivitySharpness = gvr.directivitySharpness;
// resAudioSource.listenerDirectivityAlpha = gvr.listenerDirectivityAlpha;
// resAudioSource.listenerDirectivitySharpness = gvr.listenerDirectivitySharpness;
// resAudioSource.gainDb = gvr.gainDb;
// resAudioSource.occlusionEnabled = gvr.occlusionEnabled;
// audioSource.playOnAwake = gvr.playOnAwake;
// // resAudioSource.disableOnStop = gvr.disableOnStop;
// // resAudioSource.hrtfEnabled = gvr.hrtfEnabled;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions Assets/Prefabs/AudioLoop.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GameObject:
m_Component:
- component: {fileID: 446936}
- component: {fileID: 114000012757747538}
- component: {fileID: -8006449586877461498}
m_Layer: 0
m_Name: AudioLoop
m_TagString: Untagged
Expand All @@ -27,6 +28,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
Expand Down Expand Up @@ -66,3 +68,99 @@ MonoBehaviour:
sourceMinDistance: 1
hrtfEnabled: 1
audioSource: {fileID: 0}
--- !u!82 &-8006449586877461498
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 166670}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_PlayOnAwake: 1
m_Volume: 1
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 10
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
98 changes: 98 additions & 0 deletions Assets/Prefabs/AudioOneShot.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GameObject:
m_Component:
- component: {fileID: 446936}
- component: {fileID: 114000012757747538}
- component: {fileID: 343108808504654218}
m_Layer: 0
m_Name: AudioOneShot
m_TagString: Untagged
Expand All @@ -27,6 +28,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
Expand Down Expand Up @@ -66,3 +68,99 @@ MonoBehaviour:
sourceMinDistance: 1
hrtfEnabled: 1
audioSource: {fileID: 0}
--- !u!82 &343108808504654218
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 166670}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_PlayOnAwake: 1
m_Volume: 1
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 10
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
Loading