Add VRChat and GitHub packages to Unity project

This commit is contained in:
gunnbr committed 2021-01-18 09:14:18 -08:00
1 parent 0334a52b21
commit 85538aaccc
3297 files changed
+847877

No files matched your search

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 25fa1742a0cbd8141b952c76ad5431e6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bd6f01d423eff8a4a8f9de71e21f0b4a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,101 @@
/************************************************************************************
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");
{
EditorGUILayout.HelpBox("Please use a VRC_SpatialAudioSource in the future.", MessageType.Error);
#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);
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cb850b86de9091d4db4595959c56f954
timeCreated: 1442269815
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 344ab2b0b5177bc439a0e069b42277a7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,406 @@
/************************************************************************************
Filename : ONSPAudioSource.cs
Content : Interface into the Oculus Native Spatializer Plugin
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.
************************************************************************************/
// Uncomment below to test access of read-only spatializer parameters
//#define TEST_READONLY_PARAMETERS
using UnityEngine;
using System;
using System.Collections;
using System.Runtime.InteropServices;
public class ONSPAudioSource : MonoBehaviour
{
#if TEST_READONLY_PARAMETERS
// Spatializer read-only system parameters (global)
static int readOnly_GlobalRelectionOn = 8;
static int readOnly_NumberOfUsedSpatializedVoices = 9;
#endif
#if VRC_CLIENT
// don't include in SDK, not compatible with Unity's version of spatializer
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void OnBeforeSceneLoadRuntimeMethod()
{
OSP_SetGlobalVoiceLimit(ONSPSettings.Instance.voiceLimit);
}
#endif
// Import functions
public const string strONSPS = "AudioPluginOculusSpatializer";
[DllImport(strONSPS)]
private static extern void ONSP_GetGlobalRoomReflectionValues(ref bool reflOn, ref bool reverbOn,
ref float width, ref float height, ref float length);
// Public
[SerializeField]
private bool enableSpatialization = true;
public bool EnableSpatialization
{
get
{
return enableSpatialization;
}
set
{
enableSpatialization = value;
}
}
[SerializeField]
private float gain = 0.0f;
public float Gain
{
get
{
return gain;
}
set
{
gain = Mathf.Clamp(value, 0.0f, 24.0f);
}
}
[SerializeField]
private bool useInvSqr = false;
public bool UseInvSqr
{
get
{
return useInvSqr;
}
set
{
useInvSqr = value;
}
}
[SerializeField]
private float near = 0.25f;
public float Near
{
get
{
return near;
}
set
{
near = Mathf.Clamp(value, 0.0f, 1000000.0f);
}
}
[SerializeField]
private float far = 250.0f;
public float Far
{
get
{
return far;
}
set
{
far = Mathf.Clamp(value, 0.0f, 1000000.0f);
}
}
[SerializeField]
private float volumetricRadius = 0.0f;
public float VolumetricRadius
{
get
{
return volumetricRadius;
}
set
{
volumetricRadius = Mathf.Clamp(value, 0.0f, 1000.0f);
}
}
[SerializeField]
private float reverbSend = 0.0f;
public float ReverbSend
{
get
{
return reverbSend;
}
set
{
reverbSend = Mathf.Clamp(value, -60.0f, 20.0f);
}
}
[SerializeField]
private bool enableRfl = false;
public bool EnableRfl
{
get
{
return enableRfl;
}
set
{
enableRfl = value;
}
}
/// VRCHAT: We need to reset the params after avatar loading and viseme setup
public void Reset()
{
var source = GetComponent<AudioSource>();
if(source == null)
{
enabled = false;
return;
}
SetParameters(ref source);
}
/// <summary>
/// Awake this instance.
/// </summary>
void Awake()
{
Reset();
}
/// <summary>
/// Start this instance.
/// </summary>
void Start()
{
#if VRC_CLIENT
var source = GetComponent<AudioSource>();
if(source != null && source.outputAudioMixerGroup != VRCAudioManager.GetAvatarGroup())
VRCAudioManager.ApplyGameAudioMixerSettings(source);
#endif
}
/// <summary>
/// Update this instance.
/// </summary>
void LateUpdate()
{
// We might iterate through multiple sources / game object
var source = GetComponent<AudioSource>();
if(source == null)
{
enabled = false;
return;
}
// READ-ONLY PARAMETER TEST
#if TEST_READONLY_PARAMETERS
float rfl_enabled = 0.0f;
source.GetSpatializerFloat(readOnly_GlobalRelectionOn, out rfl_enabled);
float num_voices = 0.0f;
source.GetSpatializerFloat(readOnly_NumberOfUsedSpatializedVoices, out num_voices);
String readOnly = System.String.Format
("Read only values: refl enabled: {0:F0} num voices: {1:F0}", rfl_enabled, num_voices);
Debug.Log(readOnly);
#endif
// Check to see if we should disable spatializion
if ((Application.isPlaying == false) ||
(AudioListener.pause == true) ||
(source.isPlaying == false) ||
(source.isActiveAndEnabled == false)
)
{
source.spatialize = false;
return;
}
else
{
SetParameters(ref source);
}
}
enum Parameters : int
{
P_GAIN = 0,
P_USEINVSQR,
P_NEAR,
P_FAR,
P_RADIUS,
P_DISABLE_RFL,
P_VSPEAKERMODE,
P_AMBISTAT,
P_READONLY_GLOBAL_RFL_ENABLED, // READ-ONLY
P_READONLY_NUM_VOICES, // READ-ONLY
P_SENDLEVEL,
P_NUM
};
/// <summary>
/// Sets the parameters.
/// </summary>
/// <param name="source">Source.</param>
public void SetParameters(ref AudioSource source)
{
// VRCHAT: indentation is weird intentionally, for easier diff
// VRC jnuccio: added try here to catch unknown exception reported in analytics
try
{
if (source == null)
return;
// See if we should enable spatialization
source.spatialize = enableSpatialization;
source.SetSpatializerFloat((int)Parameters.P_GAIN, gain);
// All inputs are floats; convert bool to 0.0 and 1.0
if(useInvSqr == true)
source.SetSpatializerFloat((int)Parameters.P_USEINVSQR, 1.0f);
else
source.SetSpatializerFloat((int)Parameters.P_USEINVSQR, 0.0f);
source.SetSpatializerFloat((int)Parameters.P_NEAR, near);
source.SetSpatializerFloat((int)Parameters.P_FAR, far);
source.SetSpatializerFloat((int)Parameters.P_RADIUS, volumetricRadius);
if(enableRfl == true)
source.SetSpatializerFloat((int)Parameters.P_DISABLE_RFL, 0.0f);
else
source.SetSpatializerFloat((int)Parameters.P_DISABLE_RFL, 1.0f);
source.SetSpatializerFloat((int)Parameters.P_SENDLEVEL, reverbSend);
// VRCHAT: indentation is weird intentionally, for easier diff
}
catch (Exception)
{
// not sure why this throws sometimes
}
}
private static ONSPAudioSource RoomReflectionGizmoAS = null;
/// <summary>
///
/// </summary>
void OnDrawGizmos()
{
// Are we the first one created? make sure to set our static ONSPAudioSource
// for drawing out room parameters once
if(RoomReflectionGizmoAS == null)
{
RoomReflectionGizmoAS = this;
}
Color c;
const float colorSolidAlpha = 0.1f;
// Draw the near/far spheres
// Near (orange)
c.r = 1.0f;
c.g = 0.5f;
c.b = 0.0f;
c.a = 1.0f;
Gizmos.color = c;
Gizmos.DrawWireSphere(transform.position, Near);
c.a = colorSolidAlpha;
Gizmos.color = c;
Gizmos.DrawSphere(transform.position, Near);
// Far (red)
c.r = 1.0f;
c.g = 0.0f;
c.b = 0.0f;
c.a = 1.0f;
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, Far);
c.a = colorSolidAlpha;
Gizmos.color = c;
Gizmos.DrawSphere(transform.position, Far);
// VolumetricRadius (purple)
c.r = 1.0f;
c.g = 0.0f;
c.b = 1.0f;
c.a = 1.0f;
Gizmos.color = c;
Gizmos.DrawWireSphere(transform.position, VolumetricRadius);
c.a = colorSolidAlpha;
Gizmos.color = c;
Gizmos.DrawSphere(transform.position, VolumetricRadius);
// Draw room parameters ONCE only, provided reflection engine is on
if (RoomReflectionGizmoAS == this)
{
// Get global room parameters (write new C api to get reflection values)
bool reflOn = false;
bool reverbOn = false;
float width = 1.0f;
float height = 1.0f;
float length = 1.0f;
ONSP_GetGlobalRoomReflectionValues(ref reflOn, ref reverbOn, ref width, ref height, ref length);
// TO DO: Get the room reflection values and render those out as well (like we do in the VST)
if((Camera.main != null) && (reflOn == true))
{
// Set color of cube (cyan is early reflections only, white is with reverb on)
if(reverbOn == true)
c = Color.white;
else
c = Color.cyan;
Gizmos.color = c;
Gizmos.DrawWireCube(Camera.main.transform.position, new Vector3(width, height, length));
c.a = colorSolidAlpha;
Gizmos.color = c;
Gizmos.DrawCube(Camera.main.transform.position, new Vector3(width, height, length));
}
}
}
/// <summary>
///
/// </summary>
void OnDestroy()
{
// We will null out single pointer instance
// of the room reflection gizmo since we are being destroyed.
// Any ONSPAS that is alive or born will re-set this pointer
// so that we only draw it once
if(RoomReflectionGizmoAS == this)
{
RoomReflectionGizmoAS = null;
}
}
[System.Runtime.InteropServices.DllImport("AudioPluginOculusSpatializer")]
private static extern int OSP_SetGlobalVoiceLimit(int VoiceLimit);
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e503ea6418d27594caa33b93cac1b06a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 1
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
using UnityEngine;
using System.Collections;
#if UNITY_EDITOR
[UnityEditor.InitializeOnLoad]
#endif
public sealed class ONSPSettings : ScriptableObject
{
[SerializeField]
public int voiceLimit = 16; // very conservative fallback
private static ONSPSettings instance;
public static ONSPSettings Instance
{
get
{
if (instance == null)
{
#if UNITY_ANDROID
instance = Resources.Load<ONSPSettings>("ONSPSettings-Android");
#else
instance = Resources.Load<ONSPSettings>("ONSPSettings");
#endif
// This can happen if the developer never input their App Id into the Unity Editor
// and therefore never created the OculusPlatformSettings.asset file
// Use a dummy object with defaults for the getters so we don't have a null pointer exception
if (instance == null)
{
instance = ScriptableObject.CreateInstance<ONSPSettings>();
#if UNITY_EDITOR
// Only in the editor should we save it to disk
string properPath = System.IO.Path.Combine(UnityEngine.Application.dataPath, "Resources");
if (!System.IO.Directory.Exists(properPath))
{
UnityEditor.AssetDatabase.CreateFolder("Assets", "Resources");
}
string fullPath = System.IO.Path.Combine(
System.IO.Path.Combine("Assets", "Resources"),
#if UNITY_ANDROID
"ONSPSettings-Android.asset");
#else
"ONSPSettings.asset");
#endif
UnityEditor.AssetDatabase.CreateAsset(instance, fullPath);
#endif
}
}
return instance;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ad074644ff568a14187a3690cfbd7534
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: