clean project

This commit is contained in:
Helar Jaadla
2022-03-07 17:52:41 +02:00
parent a174b45bd2
commit cbeb10ec35
5100 changed files with 837159 additions and 0 deletions

View File

@@ -0,0 +1,325 @@
/************************************************************************************
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Licensed under the Oculus SDK License Version 3.4.1 (the "License");
you may not use the Oculus SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
https://developer.oculus.com/licenses/sdk-3.4.1
Unless required by applicable law or agreed to in writing, the Oculus SDK
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
************************************************************************************/
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.IO;
using System.Diagnostics;
[InitializeOnLoad]
class ONSPAudioPluginUpdater
{
private static bool restartPending = false;
private static bool unityRunningInBatchmode = false;
private static System.Version invalidVersion = new System.Version("0.0.0");
static ONSPAudioPluginUpdater()
{
EditorApplication.delayCall += OnDelayCall;
}
static void OnDelayCall()
{
if (System.Environment.CommandLine.Contains("-batchmode"))
{
unityRunningInBatchmode = true;
}
if (ShouldAttemptPluginUpdate())
{
AttemptSpatializerPluginUpdate(true);
}
}
private static string GetCurrentProjectPath()
{
return Directory.GetParent(Application.dataPath).FullName;
}
private static string GetUtilitiesRootPath()
{
var so = ScriptableObject.CreateInstance(typeof(ONSPAudioPluginUpdaterStub));
var script = MonoScript.FromScriptableObject(so);
string assetPath = AssetDatabase.GetAssetPath(script);
string editorDir = Directory.GetParent(assetPath).FullName;
string ovrDir = Directory.GetParent(editorDir).FullName;
return ovrDir;
}
public static string GetVersionDescription(System.Version version)
{
bool isVersionValid = (version != invalidVersion);
return isVersionValid ? version.ToString() : "(Unknown)";
}
private static bool ShouldAttemptPluginUpdate()
{
if (unityRunningInBatchmode)
{
return false;
}
else
{
return (autoUpdateEnabled && !restartPending && !Application.isPlaying);
}
}
private static readonly string autoUpdateEnabledKey = "Oculus_Utilities_ONSPAudioPluginUpdater_AutoUpdate_" + 1.0;//PASOVRManager.utilitiesVersion;
private static bool autoUpdateEnabled
{
get
{
return PlayerPrefs.GetInt(autoUpdateEnabledKey, 1) == 1;
}
set
{
PlayerPrefs.SetInt(autoUpdateEnabledKey, value ? 1 : 0);
}
}
[MenuItem("Oculus/Tools/Update Spatializer Plugin")]
private static void RunSpatializerPluginUpdate()
{
autoUpdateEnabled = true;
AttemptSpatializerPluginUpdate(false);
}
// Separate entry point needed since "-executeMethod" does not support parameters or default parameter values
private static void BatchmodePluginUpdate()
{
OnDelayCall(); // manually invoke when running editor in batchmode
AttemptSpatializerPluginUpdate(false);
}
private static string GetSpatializerPluginsRootPath()
{
string ovrPath = GetUtilitiesRootPath();
string spatializerPluginsPath = Path.GetFullPath(Path.Combine(ovrPath, "../Spatializer/Plugins"));
return spatializerPluginsPath;
}
private static bool RenameSpatializerPluginToOld(string currentPluginPath)
{
if (File.Exists(currentPluginPath))
{
int index = 0;
string targetPluginPath;
string targetPluginMetaPath;
for (; ; )
{
targetPluginPath = currentPluginPath + ".old" + index.ToString();
targetPluginMetaPath = targetPluginPath + ".meta";
if (!File.Exists(targetPluginPath) && !File.Exists(targetPluginPath))
break;
++index;
}
try
{
File.Move(currentPluginPath, targetPluginPath);
File.Move(currentPluginPath + ".meta", targetPluginMetaPath);
UnityEngine.Debug.LogFormat("Spatializer plugin renamed: {0} to {1}", currentPluginPath, targetPluginPath);
return true;
}
catch (Exception e)
{
UnityEngine.Debug.LogWarningFormat("Unable to rename spatializer plugin: {0}, exception {1}", currentPluginPath, e.Message);
return false;
}
}
return false;
}
private static void AttemptSpatializerPluginUpdate(bool triggeredByAutoUpdate)
{
// We use a simplified path to update spatializer plugins:
// If there is a new AudioPluginOculusSpatializer.dll.new, we'll rename the original one to .old, and the new one to .dll, and restart the editor
string pluginsPath = GetSpatializerPluginsRootPath();
string newX86PluginPath = Path.GetFullPath(Path.Combine(pluginsPath, "x86/AudioPluginOculusSpatializer.dll.new"));
string newX64PluginPath = Path.GetFullPath(Path.Combine(pluginsPath, "x86_64/AudioPluginOculusSpatializer.dll.new"));
if (File.Exists(newX86PluginPath) || File.Exists(newX64PluginPath))
{
bool userAcceptsUpdate = false;
if (unityRunningInBatchmode)
{
userAcceptsUpdate = true;
}
else
{
int dialogResult = EditorUtility.DisplayDialogComplex("Update Spatializer Plugins",
"New spatializer plugin found. Do you want to upgrade? If you choose 'Upgrade', the old plugin will be renamed to AudioPluginOculusSpatializer.old",
"Upgrade", "Don't upgrade", "Delete new plugin");
if (dialogResult == 0)
{
userAcceptsUpdate = true;
}
else if (dialogResult == 1)
{
// do nothing
}
else if (dialogResult == 2)
{
try
{
File.Delete(newX86PluginPath);
File.Delete(newX86PluginPath + ".meta");
File.Delete(newX64PluginPath);
File.Delete(newX64PluginPath + ".meta");
}
catch (Exception e)
{
UnityEngine.Debug.LogWarning("Exception happened when deleting new spatializer plugin: " + e.Message);
}
}
}
if (userAcceptsUpdate)
{
bool upgradeDone = false;
string curX86PluginPath = Path.Combine(pluginsPath, "x86/AudioPluginOculusSpatializer.dll");
if (File.Exists(newX86PluginPath))
{
RenameSpatializerPluginToOld(curX86PluginPath);
try
{
File.Move(newX86PluginPath, curX86PluginPath);
File.Move(newX86PluginPath + ".meta", curX86PluginPath + ".meta");
// fix the platform
string curX86PluginPathRel = "Assets/Oculus/Spatializer/Plugins/x86/AudioPluginOculusSpatializer.dll";
UnityEngine.Debug.Log("path = " + curX86PluginPathRel);
AssetDatabase.ImportAsset(curX86PluginPathRel, ImportAssetOptions.ForceUpdate);
PluginImporter pi = PluginImporter.GetAtPath(curX86PluginPathRel) as PluginImporter;
pi.SetCompatibleWithEditor(false);
pi.SetCompatibleWithAnyPlatform(false);
pi.SetCompatibleWithPlatform(BuildTarget.Android, false);
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, false);
#if UNITY_2017_3_OR_NEWER
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSX, false);
#else
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXUniversal, false);
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel, false);
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel64, false);
#endif
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, true);
pi.SetCompatibleWithEditor(true);
pi.SetEditorData("CPU", "X86");
pi.SetEditorData("OS", "Windows");
pi.SetPlatformData("Editor", "CPU", "X86");
pi.SetPlatformData("Editor", "OS", "Windows");
AssetDatabase.ImportAsset(curX86PluginPathRel, ImportAssetOptions.ForceUpdate);
AssetDatabase.Refresh();
AssetDatabase.SaveAssets();
upgradeDone = true;
}
catch (Exception e)
{
UnityEngine.Debug.LogWarning("Unable to rename the new spatializer plugin: " + e.Message);
}
}
string curX64PluginPath = Path.Combine(pluginsPath, "x86_64/AudioPluginOculusSpatializer.dll");
if (File.Exists(newX64PluginPath))
{
RenameSpatializerPluginToOld(curX64PluginPath);
try
{
File.Move(newX64PluginPath, curX64PluginPath);
File.Move(newX64PluginPath + ".meta", curX64PluginPath + ".meta");
// fix the platform
string curX64PluginPathRel = "Assets/Oculus/Spatializer/Plugins/x86_64/AudioPluginOculusSpatializer.dll";
UnityEngine.Debug.Log("path = " + curX64PluginPathRel);
AssetDatabase.ImportAsset(curX64PluginPathRel, ImportAssetOptions.ForceUpdate);
PluginImporter pi = PluginImporter.GetAtPath(curX64PluginPathRel) as PluginImporter;
pi.SetCompatibleWithEditor(false);
pi.SetCompatibleWithAnyPlatform(false);
pi.SetCompatibleWithPlatform(BuildTarget.Android, false);
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, false);
#if UNITY_2017_3_OR_NEWER
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSX, false);
#else
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXUniversal, false);
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel, false);
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel64, false);
#endif
pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, true);
pi.SetCompatibleWithEditor(true);
pi.SetEditorData("CPU", "X86_64");
pi.SetEditorData("OS", "Windows");
pi.SetPlatformData("Editor", "CPU", "X86_64");
pi.SetPlatformData("Editor", "OS", "Windows");
AssetDatabase.ImportAsset(curX64PluginPathRel, ImportAssetOptions.ForceUpdate);
AssetDatabase.Refresh();
AssetDatabase.SaveAssets();
upgradeDone = true;
}
catch (Exception e)
{
UnityEngine.Debug.LogWarning("Unable to rename the new spatializer plugin: " + e.Message);
}
}
if (upgradeDone)
{
if (unityRunningInBatchmode
|| EditorUtility.DisplayDialog("Restart Unity",
"Spatializer plugins has been upgraded."
+ "\n\nPlease restart the Unity Editor to complete the update process."
#if !UNITY_2017_1_OR_NEWER
+ " You may need to manually relaunch Unity if you are using Unity 5.6 and higher."
#endif
,
"Restart",
"Not Now"))
{
RestartUnityEditor();
}
}
}
}
}
private static void RestartUnityEditor()
{
if (unityRunningInBatchmode)
{
EditorApplication.Exit(0);
}
else
{
restartPending = true;
EditorApplication.OpenProject(GetCurrentProjectPath());
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f7c56e5aebdd5864c9b3483178a00294
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
/************************************************************************************
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Licensed under the Oculus SDK License Version 3.4.1 (the "License");
you may not use the Oculus SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
https://developer.oculus.com/licenses/sdk-3.4.1
Unless required by applicable law or agreed to in writing, the Oculus SDK
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
************************************************************************************/
using UnityEngine;
using System.Collections;
public class ONSPAudioPluginUpdaterStub : ScriptableObject
{
// Stub helper class to locate OVR Utilities Path through Unity Editor API.
// Required to be a standalone class in a separate file or else MonoScript.FromScriptableObject() returns an empty string path.
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 12d7c28711479044c8a9610199f953b0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,100 @@
/************************************************************************************
Filename : ONSPAudioSourceEditor.cs
Content : This script adds editor functionality to OculusSpatializerUserParams script.
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Licensed under the Oculus SDK Version 3.5 (the "License");
you may not use the Oculus SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
https://developer.oculus.com/licenses/sdk-3.5/
Unless required by applicable law or agreed to in writing, the Oculus SDK
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
************************************************************************************/
#define CUSTOM_LAYOUT
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
[CustomEditor(typeof(ONSPAudioSource))]
public class OculusSpatializerUserParamsEditor : Editor
{
// target component
private ONSPAudioSource m_Component;
// OnEnable
void OnEnable()
{
m_Component = (ONSPAudioSource)target;
}
// OnInspectorGUI
public override void OnInspectorGUI()
{
GUI.color = Color.white;
Undo.RecordObject(m_Component, "OculusSpatializerUserParams");
{
#if CUSTOM_LAYOUT
m_Component.EnableSpatialization = EditorGUILayout.Toggle("Spatialization Enabled", m_Component.EnableSpatialization);
m_Component.EnableRfl = EditorGUILayout.Toggle("Reflections Enabled", m_Component.EnableRfl);
m_Component.Gain = EditorGUILayout.FloatField("Gain", m_Component.Gain);
Separator();
Label ("OCULUS ATTENUATION");
m_Component.UseInvSqr = EditorGUILayout.Toggle("Enabled", m_Component.UseInvSqr);
Label ("");
Label("RANGE (0.0 - 1000000.0 meters)");
m_Component.Near = EditorGUILayout.FloatField("Minimum", m_Component.Near);
m_Component.Far = EditorGUILayout.FloatField("Maximum", m_Component.Far);
Label("");
Label("VOLUMETRIC RADIUS (0.0 - 1000.0 meters)");
m_Component.VolumetricRadius = EditorGUILayout.FloatField("Radius", m_Component.VolumetricRadius);
Separator();
Label("REVERB SEND LEVEL (-60.0 - 20.0 decibels)");
m_Component.ReverbSend = EditorGUILayout.FloatField(" ", m_Component.ReverbSend);
Separator();
#else
DrawDefaultInspector ();
#endif
}
if (GUI.changed)
{
EditorUtility.SetDirty(m_Component);
}
}
// Utilities, move out of here (or copy over to other editor script)
// Separator
void Separator()
{
GUI.color = new Color(1, 1, 1, 0.25f);
GUILayout.Box("", "HorizontalSlider", GUILayout.Height(16));
GUI.color = Color.white;
}
// Label
void Label(string label)
{
EditorGUILayout.LabelField (label);
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cb850b86de9091d4db4595959c56f954
timeCreated: 1442269815
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,121 @@
/************************************************************************************
Filename : ONSPPropagationGeometryEditor.cs
Content : Geometry editor class
Attach to geometry to define material properties
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Licensed under the Oculus SDK Version 3.5 (the "License");
you may not use the Oculus SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
https://developer.oculus.com/licenses/sdk-3.5/
Unless required by applicable law or agreed to in writing, the Oculus SDK
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
************************************************************************************/
//#define ENABLE_DEBUG_EXPORT_OBJ
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(ONSPPropagationGeometry))]
public class ONSPPropagationGeometryEditor : Editor
{
public override void OnInspectorGUI()
{
ONSPPropagationGeometry mesh = (ONSPPropagationGeometry)target;
EditorGUI.BeginChangeCheck();
bool newIncludeChildMeshes = EditorGUILayout.Toggle( new GUIContent("Include Child Meshes","Include all child meshes into single geometry instance"), mesh.includeChildMeshes );
Separator();
#if UNITY_EDITOR
string newFilePath = mesh.filePath;
bool editedPath = false;
bool writeMesh = false;
EditorGUI.BeginDisabledGroup( Application.isPlaying );
bool newFileEnabled = EditorGUILayout.Toggle( new GUIContent("File Enabled","If set, the serialized mesh file is used as the mesh data source"), mesh.fileEnabled );
EditorGUILayout.LabelField( new GUIContent("File Path:","The path to the serialized mesh file, relative to the StreamingAssets directory" ),
new GUIContent(mesh.filePathRelative != null ? mesh.filePathRelative : ""));
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel( " " );
if ( GUILayout.Button("Set Path") )
{
if (!System.IO.Directory.Exists(Application.streamingAssetsPath))
{
System.IO.Directory.CreateDirectory(Application.streamingAssetsPath);
}
string directory = Application.streamingAssetsPath;
string fileName = mesh.gameObject.name + "." + ONSPPropagationGeometry.GEOMETRY_FILE_EXTENSION;
if (newFilePath != "")
{
directory = System.IO.Path.GetDirectoryName(newFilePath);
fileName = System.IO.Path.GetFileName(newFilePath);
}
newFilePath = EditorUtility.SaveFilePanel(
"Save baked mesh to file", directory, fileName,
ONSPPropagationGeometry.GEOMETRY_FILE_EXTENSION);
// If the user canceled, use the old path.
if ( newFilePath == null || newFilePath.Length == 0 )
newFilePath = mesh.filePath;
else
editedPath = true;
}
if ( GUILayout.Button("Bake Mesh to File") )
writeMesh = true;
EditorGUILayout.EndHorizontal();
#if ENABLE_DEBUG_EXPORT_OBJ
// this allows you to export the geometry to a .obj for viewing
// in an external model viewer for debugging/validation
if ( GUILayout.Button("Write to .obj (debug)") )
mesh.WriteToObj();
#endif
EditorGUI.EndDisabledGroup();
#endif
if ( EditorGUI.EndChangeCheck() )
{
Undo.RecordObject( mesh, "Edited OVRAudioMesh" );
mesh.includeChildMeshes = newIncludeChildMeshes;
mesh.fileEnabled = newFileEnabled;
newFilePath = newFilePath.Replace(Application.streamingAssetsPath + "/", "");
if ( editedPath )
mesh.filePathRelative = newFilePath;
if ( editedPath || writeMesh )
mesh.WriteFile();
}
if ( Application.isPlaying && GUILayout.Button("Upload Mesh") )
mesh.UploadGeometry();
}
void Separator()
{
GUI.color = new Color(1, 1, 1, 0.25f);
GUILayout.Box("", "HorizontalSlider", GUILayout.Height(16));
GUI.color = Color.white;
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 914f2bea7a48eba40885dfc3262f12e4
timeCreated: 1528234336
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,566 @@
/************************************************************************************
Filename : ONSPPropagationMaterialEditor.cs
Content : Propagation material editor class
Attach to geometry to define material properties
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Licensed under the Oculus SDK Version 3.5 (the "License");
you may not use the Oculus SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
https://developer.oculus.com/licenses/sdk-3.5/
Unless required by applicable law or agreed to in writing, the Oculus SDK
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
************************************************************************************/
using UnityEditor;
using UnityEngine;
using Spectrum = ONSPPropagationMaterial.Spectrum;
using Point = ONSPPropagationMaterial.Point;
[CustomEditor(typeof(ONSPPropagationMaterial))]
internal sealed class ONSPPropagationMaterialEditor : Editor{
private enum AxisScale{ Lin, Log, Sqr }
private sealed class SpectrumDrawer{
private const float cutoff = 20000f;
private static readonly Texture2D texture = EditorGUIUtility.whiteTexture;
private static readonly GUIStyle textStyle = new GUIStyle{
alignment = TextAnchor.MiddleLeft,
clipping = TextClipping.Overflow,
fontSize = 8,
fontStyle = FontStyle.Bold,
wordWrap = false,
normal = new GUIStyleState{ textColor = Color.grey },
focused = new GUIStyleState{ textColor = Color.grey }
};
private static int focus;
private readonly string label;
private readonly AxisScale scale;
private readonly Spectrum spectrum;
private bool dragInitiated;
private bool isDragging;
private bool displaySpectrum;
private bool displayPoints;
internal bool IsFocus{
get{
return focus == spectrum.GetHashCode();
}
}
internal SpectrumDrawer(string label, Spectrum spectrum, AxisScale scale){
this.label = label;
this.spectrum = spectrum;
this.scale = scale;
}
internal void Draw(Event e){
displaySpectrum = EditorGUILayout.Foldout(displaySpectrum, label);
if(displaySpectrum){
EditorGUI.indentLevel++;
DrawSpectrum(e);
displayPoints = EditorGUILayout.Foldout(displayPoints, "Points");
if(displayPoints){
EditorGUI.indentLevel++;
DrawPoints();
EditorGUI.indentLevel--;
}
EditorGUI.indentLevel--;
}
}
internal void LoadFoldoutState(){
displaySpectrum = EditorPrefs.GetBool(label + "Spectrum", true);
displayPoints = EditorPrefs.GetBool(label + "Points", false);
}
internal void SaveFoldoutState(){
EditorPrefs.SetBool(label + "Spectrum", displaySpectrum);
EditorPrefs.SetBool(label + "Points", displayPoints);
}
private void DrawSpectrum(Event e){
float height = 10 * EditorGUIUtility.singleLineHeight;
Rect r = EditorGUILayout.GetControlRect(true, height);
r.width -= rightMargin;
DrawDataTicks(r);
r = AudioCurveRendering.BeginCurveFrame(r);
AudioCurveRendering.DrawFilledCurve(r, EvaluateCurve, AudioCurveRendering.kAudioOrange);
DrawFrequencyTicks(r);
HandleEvent(r, e);
if(IsFocus) DrawSelected(r);
AudioCurveRendering.EndCurveFrame();
}
private void DrawPoints(){
var points = spectrum.points;
int lines = points.Count > 0 ? points.Count + 2 : 1;
float height = EditorGUIUtility.singleLineHeight * lines;
Rect r1 = EditorGUILayout.GetControlRect(true, height);
r1.width -= rightMargin;
r1.height = EditorGUIUtility.singleLineHeight;
{
int oldCount = points.Count;
int newCount = EditorGUI.DelayedIntField(r1, "Size", oldCount);
r1.y += r1.height;
if(newCount < points.Count){
points.RemoveRange(newCount, oldCount - newCount);
Undo.SetCurrentGroupName("Points Removed");
GUI.changed = true;
} else if(newCount > oldCount){
if(newCount > points.Capacity)
points.Capacity = newCount;
for(int i = oldCount; i < newCount; i++)
points.Add(new Point(125 * (1 << i)));
Undo.SetCurrentGroupName("Points Added");
GUI.changed = true;
}
}
if(points.Count > 0){
Rect r2 = new Rect(r1.xMax + 9, r1.y + r1.height * 1.125f, 24, r1.height * .75f);
r1.width /= 2;
EditorGUI.LabelField(r1, "Frequency");
r1.x += r1.width;
EditorGUI.LabelField(r1, "Data");
r1.x -= r1.width;
r1.y += r1.height;
for(int i = 0; i < points.Count; i++){
points[i].frequency = EditorGUI.FloatField(r1, points[i].frequency);
points[i].frequency = Mathf.Clamp(points[i].frequency, 0f, cutoff);
r1.x += r1.width;
points[i].data = EditorGUI.FloatField(r1, points[i].data);
points[i].data = Mathf.Clamp01(points[i].data);
r1.x -= r1.width;
r1.y += r1.height;
if(GUI.Button(r2, "")){
RemovePointAt(i);
break;
}
r2.y += r1.height;
}
}
}
private void DrawDataTicks(Rect r){
const int ticks = 10;
Rect label = new Rect(r.xMax + 9, r.y - r.height / (2 * ticks), 24, r.height / ticks);
Rect tick = new Rect(r.xMax + 2, r.y - 1, 4.5f, 2);
for(int i = 0; i <= ticks; i++){
float value = MapData(1 - (float)i / ticks, false);
EditorGUI.DrawRect(tick, textStyle.normal.textColor);
GUI.Label(label, value.ToString("0.000"), textStyle);
tick.y += label.height;
label.y += label.height;
}
}
private void DrawFrequencyTicks(Rect r){
Rect tick = new Rect(r.x, r.y, 1, r.height);
Rect label = new Rect(r.x, r.yMax - 1.5f * EditorGUIUtility.singleLineHeight, 32, EditorGUIUtility.singleLineHeight);
for(int i = 1; i < 30; i++){
float frequency;
if(MapFrequencyTick(i, out frequency)){
tick.x = MapFrequency(frequency) * r.width;
tick.height = label.y - r.y;
tick.width = 2;
EditorGUI.DrawRect(tick, textStyle.normal.textColor);
tick.y = label.yMax;
tick.height = r.yMax - label.yMax;
EditorGUI.DrawRect(tick, textStyle.normal.textColor);
label.x = tick.x - 2;
GUI.Label(label, FrequencyToString(frequency), textStyle);
tick.y = r.y;
tick.height = r.height;
tick.width = 1;
} else{
tick.x = MapFrequency(frequency) * r.width;
EditorGUI.DrawRect(tick, textStyle.normal.textColor);
}
}
}
private void DrawSelected(Rect r){
if(spectrum.points.Count > spectrum.selection){
const float radius = 12;
Vector2 position = MapPointPosition(r, spectrum.points[spectrum.selection]);
Vector2 size = new Vector2(radius, radius);
r = new Rect(position - size / 2, size);
#if UNITY_5
GUI.DrawTexture(r, texture, ScaleMode.StretchToFill, false, 0);
GUI.DrawTexture(r, texture, ScaleMode.StretchToFill, false, 0);
#else
GUI.DrawTexture(r, texture, ScaleMode.StretchToFill, false, 0, Color.white, 0, radius);
GUI.DrawTexture(r, texture, ScaleMode.StretchToFill, false, 0, Color.black, 2, radius);
#endif
}
}
private void HandleEvent(Rect r, Event e){
Vector2 position = e.mousePosition;
switch(e.type){
case EventType.MouseDown:
if(r.Contains(position)){
if(e.clickCount == 2){
spectrum.selection = spectrum.points.Count;
spectrum.points.Add(MapMouseEvent(r, position));
Undo.SetCurrentGroupName("Point Added");
GUI.changed = true;
} else{
int selection = spectrum.selection;
float minDistance = float.MaxValue;
for(int i = 0; i < spectrum.points.Count; i++){
float distance = Vector2.Distance(MapPointPosition(r, spectrum.points[i]), position);
if(distance < minDistance){
selection = i;
minDistance = distance;
}
}
if(selection != spectrum.selection){
spectrum.selection = selection;
Undo.SetCurrentGroupName("Point Selected");
GUI.changed = true;
}
}
focus = spectrum.GetHashCode();
dragInitiated = true;
} else{
isDragging = false;
focus = 0;
}
e.Use();
break;
case EventType.MouseDrag:
if(dragInitiated){
dragInitiated = false;
isDragging = true;
}
if(isDragging && spectrum.selection < spectrum.points.Count){
spectrum.points[spectrum.selection] = MapMouseEvent(r, position);
e.Use();
}
break;
case EventType.Ignore:
case EventType.MouseUp:
dragInitiated = false;
if(isDragging){
isDragging = false;
Undo.SetCurrentGroupName("Point Moved");
GUI.changed = true;
e.Use();
}
break;
case EventType.KeyDown:
switch(e.keyCode){
case KeyCode.Delete:
case KeyCode.Backspace:
if(spectrum.selection < spectrum.points.Count){
RemovePointAt(spectrum.selection);
e.Use();
}
break;
}
break;
}
}
private void RemovePointAt(int index){
spectrum.points.RemoveAt(index);
if(spectrum.selection == index)
spectrum.selection = spectrum.points.Count;
Undo.SetCurrentGroupName("Point Removed");
GUI.changed = true;
}
private float EvaluateCurve(float f){
return 2 * MapData(spectrum[MapFrequency(f, false)]) - 1;
}
private Vector2 MapPointPosition(Rect r, Point point){
return new Vector2{
x = r.x + r.width * MapFrequency(point.frequency),
y = r.y + r.height * (1 - MapData(point.data))
};
}
private Point MapMouseEvent(Rect r, Vector2 v){
return new Point{
frequency = v.x < r.xMin ? 0 : v.x > r.xMax ? cutoff : MapFrequency((v.x - r.x) / r.width, false),
data = v.y < r.yMin ? 1 : v.y > r.yMax ? 0 : MapData(1 - (v.y - r.y) / r.height, false)
};
}
private float MapData(float f, bool forward = true){
switch(scale){
case AxisScale.Log:
return forward ? f < 1e-3f ? 0 : 1 + Mathf.Log10(f) / 3 : Mathf.Pow(10, -3 * (1 - f));
case AxisScale.Sqr:
return forward ? Mathf.Sqrt(f) : f * f;
default:
case AxisScale.Lin:
return f;
}
}
public static bool MapFrequencyTick(int i, out float frequency){
int power = i / 9 + 1;
int multiplier = i % 9 + 1;
frequency = multiplier * Mathf.Pow(10, power);
return multiplier == 1;
}
public static float MapFrequency(float f, bool forward = true){
return forward ? f < 10 ? 0 : Mathf.Log(f / 10, cutoff / 10) : 10 * Mathf.Pow(cutoff / 10, f);
}
private static string FrequencyToString(float frequency){
if(frequency < 1000)
return string.Format("{0:F0} Hz", frequency);
else
return string.Format("{0:F0} kHz", frequency * .001f);
}
}
private const float rightMargin = 36;
private SpectrumDrawer absorption, scattering, transmission;
private void OnEnable(){
GetSpectra(out absorption, out scattering, out transmission);
absorption.LoadFoldoutState();
scattering.LoadFoldoutState();
transmission.LoadFoldoutState();
}
private void OnDisable(){
absorption.SaveFoldoutState();
scattering.SaveFoldoutState();
transmission.SaveFoldoutState();
}
public override void OnInspectorGUI(){
ONSPPropagationMaterial material = target as ONSPPropagationMaterial;
EditorGUI.BeginChangeCheck();
Rect r = EditorGUILayout.GetControlRect();
r.width -= rightMargin;
ONSPPropagationMaterial.Preset newPreset =
(ONSPPropagationMaterial.Preset)EditorGUI.EnumPopup(r, "Preset", material.preset);
Event e = Event.current;
EventType type = e.type;
absorption.Draw(e);
scattering.Draw(e);
transmission.Draw(e);
if(EditorGUI.EndChangeCheck()){
string groupName = Undo.GetCurrentGroupName();
Undo.RegisterCompleteObjectUndo(material, groupName);
if(groupName == "Point Added")
Undo.CollapseUndoOperations(Undo.GetCurrentGroup() - 1);
if(material.preset != newPreset)
material.preset = newPreset;
else
material.preset = ONSPPropagationMaterial.Preset.Custom;
if(Application.isPlaying)
material.UploadMaterial();
}
}
private void GetSpectra(out SpectrumDrawer absorption,
out SpectrumDrawer scattering,
out SpectrumDrawer transmission){
ONSPPropagationMaterial material = target as ONSPPropagationMaterial;
absorption = new SpectrumDrawer("Absorption", material.absorption, AxisScale.Sqr);
scattering = new SpectrumDrawer("Scattering", material.scattering, AxisScale.Lin);
transmission = new SpectrumDrawer("Transmission", material.transmission, AxisScale.Sqr);
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 232b6822c5f13ad449ffdb9cc4e6ba64
timeCreated: 1526949143
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,103 @@
/************************************************************************************
Filename : ONSPPropagationSerializationManager.cs
Content : Functionality for serializing Oculus Audio geometry
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Licensed under the Oculus SDK Version 3.5 (the "License");
you may not use the Oculus SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
https://developer.oculus.com/licenses/sdk-3.5/
Unless required by applicable law or agreed to in writing, the Oculus SDK
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
************************************************************************************/
using UnityEditor;
using UnityEditor.Build;
using UnityEngine;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
using System.Collections.Generic;
public enum PlayModeState
{
Stopped,
Playing,
Paused
}
class ONSPPropagationSerializationManager
{
static ONSPPropagationSerializationManager()
{
EditorSceneManager.sceneSaving += OnSceneSaving;
}
public int callbackOrder { get { return 0; } }
public void OnPreprocessBuild(BuildTarget target, string path)
{
Debug.Log("ONSPPropagationSerializationManager.OnPreprocessBuild for target " + target + " at path " + path);
}
[MenuItem("Oculus/Spatializer/Build audio geometry for current scene")]
public static void BuildAudioGeometryForCurrentScene()
{
BuildAudioGeometryForScene(EditorSceneManager.GetActiveScene());
}
[MenuItem("Oculus/Spatializer/Rebuild audio geometry all scenes")]
public static void RebuildAudioGeometryForAllScenes()
{
Debug.Log("Rebuilding geometry for all scenes");
System.IO.Directory.Delete(ONSPPropagationGeometry.GeometryAssetPath, true);
for (int i = 0; i < EditorSceneManager.sceneCount; ++i)
{
BuildAudioGeometryForScene(EditorSceneManager.GetSceneAt(i));
}
}
public static void OnSceneSaving(Scene scene, string path)
{
BuildAudioGeometryForScene(scene);
}
private static void BuildAudioGeometryForScene(Scene scene)
{
Debug.Log("Building audio geometry for scene " + scene.name);
List<GameObject> rootObjects = new List<GameObject>();
scene.GetRootGameObjects(rootObjects);
HashSet<string> fileNames = new HashSet<string>();
foreach (GameObject go in rootObjects)
{
var geometryComponents = go.GetComponentsInChildren<ONSPPropagationGeometry>();
foreach (ONSPPropagationGeometry geo in geometryComponents)
{
if (geo.fileEnabled)
{
if (!geo.WriteFile())
{
Debug.LogError("Failed writing geometry for " + geo.gameObject.name);
}
else
{
if (!fileNames.Add(geo.filePathRelative))
{
Debug.LogWarning("Duplicate file name detected: " + geo.filePathRelative);
}
}
}
}
}
Debug.Log("Successfully built " + fileNames.Count + " geometry objects");
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 3760abfc2459983428e22b8adf2e7198
timeCreated: 1543542380
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,144 @@
/************************************************************************************
Filename : ONSPReflectionCustomGUI.cs
Content : GUI for Oculus Spatializer mixer effect
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Licensed under the Oculus SDK Version 3.5 (the "License");
you may not use the Oculus SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
https://developer.oculus.com/licenses/sdk-3.5/
Unless required by applicable law or agreed to in writing, the Oculus SDK
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
************************************************************************************/
using UnityEditor;
using UnityEngine;
using System.Runtime.InteropServices;
public class OculusSpatializerReflectionCustomGUI : IAudioEffectPluginGUI
{
public override string Name
{
get { return "OculusSpatializerReflection"; }
}
public override string Description
{
get { return "Reflection parameters for Oculus Spatializer"; }
}
public override string Vendor
{
get { return "Oculus"; }
}
public override bool OnGUI(IAudioEffectPlugin plugin)
{
float fval = 0.0f;
bool bval = false;
Separator();
Label("Voice limit (1 - 1024)");
ONSPSettings.Instance.voiceLimit = EditorGUILayout.IntField(" ", ONSPSettings.Instance.voiceLimit);
if (GUI.changed)
{
GUI.changed = false;
EditorUtility.SetDirty(ONSPSettings.Instance);
}
Separator();
Label ("GLOBAL SCALE (0.00001 - 10000.0)");
plugin.GetFloatParameter("GScale", out fval);
plugin.SetFloatParameter("GScale", EditorGUILayout.FloatField(" ", Mathf.Clamp (fval, 0.00001f, 10000.0f)));
Separator();
Label ("REFLECTION ENGINE");
Label("");
// Treat these floats as bools in the inspector
plugin.GetFloatParameter("E.Rflt On", out fval);
bval = (fval == 0.0f) ? false : true;
bval = EditorGUILayout.Toggle("Enable Early Reflections", bval);
plugin.SetFloatParameter("E.Rflt On", (bval == false) ? 0.0f : 1.0f);
plugin.GetFloatParameter("E.Rflt Rev On", out fval);
bval = (fval == 0.0f) ? false : true;
bval = EditorGUILayout.Toggle("Enable Reverberation", bval);
plugin.SetFloatParameter("E.Rflt Rev On", (bval == false) ? 0.0f : 1.0f);
Separator();
Label("ROOM DIMENSIONS (meters)");
Label("");
plugin.GetFloatParameter("Room X", out fval);
plugin.SetFloatParameter("Room X", EditorGUILayout.Slider("Width", fval, 1.0f, 200.0f));
plugin.GetFloatParameter("Room Y", out fval);
plugin.SetFloatParameter("Room Y", EditorGUILayout.Slider("Height", fval, 1.0f, 200.0f));
plugin.GetFloatParameter("Room Z", out fval);
plugin.SetFloatParameter("Room Z", EditorGUILayout.Slider("Length", fval, 1.0f, 200.0f));
Separator();
Label("WALL REFLECTION COEFFICIENTS (0.0 - 0.97)");
Label("");
plugin.GetFloatParameter("Left", out fval);
plugin.SetFloatParameter("Left", EditorGUILayout.Slider("Left", fval, 0.0f, 0.97f));
plugin.GetFloatParameter("Right", out fval);
plugin.SetFloatParameter("Right", EditorGUILayout.Slider("Right", fval, 0.0f, 0.97f));
plugin.GetFloatParameter("Up", out fval);
plugin.SetFloatParameter("Up", EditorGUILayout.Slider("Up", fval, 0.0f, 0.97f));
plugin.GetFloatParameter("Down", out fval);
plugin.SetFloatParameter("Down", EditorGUILayout.Slider("Down", fval, 0.0f, 0.97f));
plugin.GetFloatParameter("Behind", out fval);
plugin.SetFloatParameter("Behind", EditorGUILayout.Slider("Back", fval, 0.0f, 0.97f));
plugin.GetFloatParameter("Front", out fval);
plugin.SetFloatParameter("Front", EditorGUILayout.Slider("Front", fval, 0.0f, 0.97f));
Separator();
Label("SHARED REVERB ATTENUATION RANGE (1.0 - 10000.0 meters)");
Label("");
plugin.GetFloatParameter("Shared Rev Min", out fval);
plugin.SetFloatParameter("Shared Rev Min", EditorGUILayout.Slider("Minimum", fval, 1.0f, 10000.0f));
plugin.GetFloatParameter("Shared Rev Max", out fval);
plugin.SetFloatParameter("Shared Rev Max", EditorGUILayout.Slider("Maximum", fval, 1.0f, 10000.0f));
Separator();
Label("SHARED REVERB WET MIX (-60.0 - 20.0 dB)");
Label("");
plugin.GetFloatParameter("Shared Rev Wet", out fval);
plugin.SetFloatParameter("Shared Rev Wet", EditorGUILayout.Slider(" ", fval, -60.0f, 20.0f));
Separator();
Label("PROPAGATION QUALITY LEVEL (0.0 - 200.0%)");
Label("");
plugin.GetFloatParameter("Prop Quality", out fval);
plugin.SetFloatParameter("Prop Quality", EditorGUILayout.Slider(" ", fval, 0.0f, 200.0f));
Separator();
// We will override the controls with our own, so return false
return false;
}
// Separator
void Separator()
{
GUI.color = new Color(1, 1, 1, 0.25f);
GUILayout.Box("", "HorizontalSlider", GUILayout.Height(16));
GUI.color = Color.white;
}
// Label
void Label(string label)
{
EditorGUILayout.LabelField (label);
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: db551baa938b4714490ee011b5541447
timeCreated: 1444752157
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
{
"name": "Oculus.Spatializer.Editor",
"references": [
"Oculus.Spatializer"
],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"versionDefines": [
{
"name": "com.unity.xr.management",
"expression": "",
"define": "USING_XR_MANAGEMENT"
},
{
"name": "com.unity.xr.oculus",
"expression": "",
"define": "USING_XR_SDK_OCULUS"
}
]
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 5c45576b5244bbf4ebf491eae8b06528
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: