Updated oculus stuff
This commit is contained in:
223
Assets/Oculus/VoiceMod/Scripts/Helpers/OVRDebugConsole.cs
Normal file
223
Assets/Oculus/VoiceMod/Scripts/Helpers/OVRDebugConsole.cs
Normal file
@@ -0,0 +1,223 @@
|
||||
/************************************************************************************
|
||||
Filename : OVRDebugConsole.cs
|
||||
Content : Write to a text string, used by UI.Text
|
||||
Created : May 22, 2015
|
||||
Copyright : Copyright 2015 Oculus VR, Inc. All Rights reserved.
|
||||
|
||||
Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
|
||||
you may not use the Oculus VR Rift 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
|
||||
|
||||
http://www.oculusvr.com/licenses/LICENSE-3.1
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Oculus VR 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 UnityEngine.UI;
|
||||
using System.Collections;
|
||||
|
||||
public class OVRDebugConsole : MonoBehaviour
|
||||
{
|
||||
public ArrayList messages = new ArrayList();
|
||||
public int maxMessages = 15; // The max number of messages displayed
|
||||
public Text textMsg; // text string to display
|
||||
|
||||
// Our instance to allow this script to be called without a direct connection.
|
||||
private static OVRDebugConsole s_Instance = null;
|
||||
|
||||
// Clear timeout
|
||||
private bool clearTimeoutOn = false;
|
||||
private float clearTimeout = 0.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance.
|
||||
/// </summary>
|
||||
/// <value>The instance.</value>
|
||||
public static OVRDebugConsole instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_Instance == null)
|
||||
{
|
||||
s_Instance = FindObjectOfType(typeof(OVRDebugConsole)) as OVRDebugConsole;
|
||||
|
||||
if (s_Instance == null)
|
||||
{
|
||||
GameObject console = new GameObject();
|
||||
console.AddComponent<OVRDebugConsole>();
|
||||
console.name = "OVRDebugConsole";
|
||||
s_Instance = FindObjectOfType(typeof(OVRDebugConsole)) as OVRDebugConsole;
|
||||
}
|
||||
}
|
||||
|
||||
return s_Instance;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Awake this instance.
|
||||
/// </summary>
|
||||
void Awake()
|
||||
{
|
||||
s_Instance = this;
|
||||
Init();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update this instance.
|
||||
/// </summary>
|
||||
void Update()
|
||||
{
|
||||
if(clearTimeoutOn == true)
|
||||
{
|
||||
clearTimeout -= Time.deltaTime;
|
||||
if(clearTimeout < 0.0f)
|
||||
{
|
||||
Clear();
|
||||
clearTimeout = 0.0f;
|
||||
clearTimeoutOn = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init this instance.
|
||||
/// </summary>
|
||||
public void Init()
|
||||
{
|
||||
if(textMsg == null)
|
||||
{
|
||||
Debug.LogWarning("DebugConsole Init WARNING::UI text not set. Will not be able to display anything.");
|
||||
}
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
//+++++++++ INTERFACE FUNCTIONS ++++++++++++++++++++++++++++++++
|
||||
|
||||
/// <summary>
|
||||
/// Log the specified message.
|
||||
/// </summary>
|
||||
/// <param name="message">Message.</param>
|
||||
public static void Log(string message)
|
||||
{
|
||||
OVRDebugConsole.instance.AddMessage(message, Color.white);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log the specified message and color.
|
||||
/// </summary>
|
||||
/// <param name="message">Message.</param>
|
||||
/// <param name="color">Color.</param>
|
||||
public static void Log(string message, Color color)
|
||||
{
|
||||
OVRDebugConsole.instance.AddMessage(message, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear this instance.
|
||||
/// </summary>
|
||||
public static void Clear()
|
||||
{
|
||||
OVRDebugConsole.instance.ClearMessages();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls clear after a certain time.
|
||||
/// </summary>
|
||||
/// <param name="timeToClear">Time to clear.</param>
|
||||
public static void ClearTimeout(float timeToClear)
|
||||
{
|
||||
OVRDebugConsole.instance.SetClearTimeout(timeToClear);
|
||||
}
|
||||
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds the message.
|
||||
/// </summary>
|
||||
/// <param name="message">Message.</param>
|
||||
/// <param name="color">Color.</param>
|
||||
public void AddMessage(string message, Color color)
|
||||
{
|
||||
messages.Add(message);
|
||||
|
||||
if(textMsg != null)
|
||||
textMsg.color = color;
|
||||
|
||||
Display();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the messages.
|
||||
/// </summary>
|
||||
public void ClearMessages()
|
||||
{
|
||||
messages.Clear();
|
||||
Display();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the clear timeout.
|
||||
/// </summary>
|
||||
/// <param name="timeout">Timeout.</param>
|
||||
public void SetClearTimeout(float timeout)
|
||||
{
|
||||
clearTimeout = timeout;
|
||||
clearTimeoutOn = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
// Prunes the array to fit within the maxMessages limit
|
||||
/// </summary>
|
||||
void Prune()
|
||||
{
|
||||
int diff;
|
||||
if (messages.Count > maxMessages)
|
||||
{
|
||||
if (messages.Count <= 0)
|
||||
{
|
||||
diff = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
diff = messages.Count - maxMessages;
|
||||
}
|
||||
messages.RemoveRange(0, (int)diff);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display this instance.
|
||||
/// </summary>
|
||||
void Display()
|
||||
{
|
||||
if (messages.Count > maxMessages)
|
||||
{
|
||||
Prune();
|
||||
}
|
||||
|
||||
if(textMsg != null)
|
||||
{
|
||||
textMsg.text = ""; // Clear text out
|
||||
int x = 0;
|
||||
|
||||
while (x < messages.Count)
|
||||
{
|
||||
textMsg.text += (string)messages[x];
|
||||
textMsg.text +='\n';
|
||||
x += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 032142ba4fe4a53458d86dc9a8610f36
|
||||
timeCreated: 1450118836
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
470
Assets/Oculus/VoiceMod/Scripts/Helpers/OVRMessenger.cs
Normal file
470
Assets/Oculus/VoiceMod/Scripts/Helpers/OVRMessenger.cs
Normal file
@@ -0,0 +1,470 @@
|
||||
/************************************************************************************
|
||||
Filename : OVRMessenger.cs
|
||||
Content : Base component OVR class
|
||||
Created : January 8, 2013
|
||||
Authors : Peter Giokaris
|
||||
Copyright : Copyright 2014 Oculus VR, LLC. All Rights reserved.
|
||||
|
||||
Use of this software is subject to the terms of the Oculus LLC license
|
||||
agreement provided at the time of installation or download, or which
|
||||
otherwise accompanies this software in either electronic or hard copy form.
|
||||
|
||||
Messenger.cs from Unity3d: http://wiki.unity3d.com/index.php/Advanced_CSharp_Messenger
|
||||
|
||||
Renamed to OVRMessenger
|
||||
|
||||
* Advanced C# messenger by Ilya Suzdalnitski. V1.0
|
||||
*
|
||||
* Based on Rod Hyde's "CSharpMessenger" and Magnus Wolffelt's "CSharpMessenger Extended".
|
||||
*
|
||||
* Features:
|
||||
* Prevents a MissingReferenceException because of a reference to a destroyed message handler.
|
||||
* Option to log all messages
|
||||
* Extensive error detection, preventing silent bugs
|
||||
*
|
||||
* Usage examples:
|
||||
1. Messenger.AddListener<GameObject>("prop collected", PropCollected);
|
||||
Messenger.Broadcast<GameObject>("prop collected", prop);
|
||||
2. Messenger.AddListener<float>("speed changed", SpeedChanged);
|
||||
Messenger.Broadcast<float>("speed changed", 0.5f);
|
||||
*
|
||||
* Messenger cleans up its evenTable automatically upon loading of a new level.
|
||||
*
|
||||
* Don't forget that the messages that should survive the cleanup, should be marked with Messenger.MarkAsPermanent(string)
|
||||
*
|
||||
|
||||
************************************************************************************/
|
||||
//#define LOG_ALL_MESSAGES
|
||||
//#define LOG_ADD_LISTENER
|
||||
//#define LOG_BROADCAST_MESSAGE
|
||||
//#define REQUIRE_LISTENER
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
// Add more delegate types here and implement them the same way below..
|
||||
public delegate void OVRCallback();
|
||||
public delegate void OVRCallback<T>(T arg1);
|
||||
public delegate void OVRCallback<T, U>(T arg1, U arg2);
|
||||
public delegate void OVRCallback<T, U, V>(T arg1, U arg2, V arg3);
|
||||
|
||||
static internal class OVRMessenger {
|
||||
|
||||
#region Internal variables
|
||||
//Disable the unused variable warning
|
||||
#pragma warning disable 0414
|
||||
//Ensures that the MessengerHelper will be created automatically upon start of the game.
|
||||
static private MessengerHelper messengerHelper = ( new GameObject("MessengerHelper") ).AddComponent< MessengerHelper >();
|
||||
#pragma warning restore 0414
|
||||
|
||||
static public Dictionary<string, Delegate> eventTable = new Dictionary<string, Delegate>();
|
||||
|
||||
//Message handlers that should never be removed, regardless of calling Cleanup
|
||||
static public List< string > permanentMessages = new List< string > ();
|
||||
#endregion
|
||||
|
||||
#region Helper methods
|
||||
|
||||
/// <summary>
|
||||
/// Marks a certain message as permanent.
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
static public void MarkAsPermanent(string eventType)
|
||||
{
|
||||
#if LOG_ALL_MESSAGES
|
||||
Debug.Log("Messenger MarkAsPermanent \t\"" + eventType + "\"");
|
||||
#endif
|
||||
permanentMessages.Add( eventType );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleanup this instance.
|
||||
/// </summary>
|
||||
static public void Cleanup()
|
||||
{
|
||||
#if LOG_ALL_MESSAGES
|
||||
Debug.Log("MESSENGER Cleanup. Make sure that none of necessary listeners are removed.");
|
||||
#endif
|
||||
List< string > messagesToRemove = new List<string>();
|
||||
|
||||
foreach (KeyValuePair<string, Delegate> pair in eventTable) {
|
||||
bool wasFound = false;
|
||||
|
||||
foreach (string message in permanentMessages) {
|
||||
|
||||
if (pair.Key == message) {
|
||||
wasFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!wasFound)
|
||||
messagesToRemove.Add( pair.Key );
|
||||
}
|
||||
|
||||
|
||||
foreach (string message in messagesToRemove) {
|
||||
eventTable.Remove( message );
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints the event table.
|
||||
/// </summary>
|
||||
static public void PrintEventTable()
|
||||
{
|
||||
Debug.Log("\t\t\t=== MESSENGER PrintEventTable ===");
|
||||
|
||||
foreach (KeyValuePair<string, Delegate> pair in eventTable) {
|
||||
Debug.Log("\t\t\t" + pair.Key + "\t\t" + pair.Value);
|
||||
}
|
||||
|
||||
Debug.Log("\n");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Message logging and exception throwing
|
||||
/// <summary>
|
||||
/// Raises the listener adding event.
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
/// <param name="listenerBeingAdded">Listener being added.</param>
|
||||
static public void OnListenerAdding(string eventType, Delegate listenerBeingAdded)
|
||||
{
|
||||
#if LOG_ALL_MESSAGES || LOG_ADD_LISTENER
|
||||
Debug.Log("MESSENGER OnListenerAdding \t\"" + eventType + "\"\t{" + listenerBeingAdded.Target + " -> " + listenerBeingAdded.Method + "}");
|
||||
#endif
|
||||
|
||||
if (!eventTable.ContainsKey(eventType)) {
|
||||
eventTable.Add(eventType, null );
|
||||
}
|
||||
|
||||
Delegate d = eventTable[eventType];
|
||||
|
||||
if (d != null && d.GetType() != listenerBeingAdded.GetType()) {
|
||||
throw new ListenerException(string.Format("Attempting to add listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being added has type {2}", eventType, d.GetType().Name, listenerBeingAdded.GetType().Name));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the listener removing event.
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
/// <param name="listenerBeingRemoved">Listener being removed.</param>
|
||||
static public void OnListenerRemoving(string eventType, Delegate listenerBeingRemoved)
|
||||
{
|
||||
|
||||
#if LOG_ALL_MESSAGES
|
||||
Debug.Log("MESSENGER OnListenerRemoving \t\"" + eventType + "\"\t{" + listenerBeingRemoved.Target + " -> " + listenerBeingRemoved.Method + "}");
|
||||
#endif
|
||||
|
||||
if (eventTable.ContainsKey(eventType))
|
||||
{
|
||||
Delegate d = eventTable[eventType];
|
||||
|
||||
if (d == null)
|
||||
{
|
||||
throw new ListenerException(string.Format("Attempting to remove listener with for event type \"{0}\" but current listener is null.", eventType));
|
||||
} else if (d.GetType() != listenerBeingRemoved.GetType())
|
||||
{
|
||||
throw new ListenerException(string.Format("Attempting to remove listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being removed has type {2}", eventType, d.GetType().Name, listenerBeingRemoved.GetType().Name));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ListenerException(string.Format("Attempting to remove listener for type \"{0}\" but Messenger doesn't know about this event type.", eventType));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the listener removed event.
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
static public void OnListenerRemoved(string eventType) {
|
||||
|
||||
if (eventTable[eventType] == null) {
|
||||
eventTable.Remove(eventType);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the broadcasting event.
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
static public void OnBroadcasting(string eventType)
|
||||
{
|
||||
|
||||
#if REQUIRE_LISTENER
|
||||
if (!eventTable.ContainsKey(eventType)) {
|
||||
throw new BroadcastException(string.Format("Broadcasting message \"{0}\" but no listener found. Try marking the message with Messenger.MarkAsPermanent.", eventType));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the broadcast signature exception.
|
||||
/// </summary>
|
||||
/// <returns>The broadcast signature exception.</returns>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
static public BroadcastException CreateBroadcastSignatureException(string eventType)
|
||||
{
|
||||
return new BroadcastException(string.Format("Broadcasting message \"{0}\" but listeners have a different signature than the broadcaster.", eventType));
|
||||
}
|
||||
|
||||
public class BroadcastException : Exception
|
||||
{
|
||||
public BroadcastException(string msg)
|
||||
: base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class ListenerException : Exception
|
||||
{
|
||||
public ListenerException(string msg)
|
||||
: base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AddListener
|
||||
/// <summary>
|
||||
/// No parameters.
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
/// <param name="handler">Handler.</param>
|
||||
static public void AddListener(string eventType, OVRCallback handler)
|
||||
{
|
||||
OnListenerAdding(eventType, handler);
|
||||
eventTable[eventType] = (OVRCallback)eventTable[eventType] + handler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Single parameter.
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
/// <param name="handler">Handler.</param>
|
||||
/// <typeparam name="T">The 1st type parameter.</typeparam>
|
||||
static public void AddListener<T>(string eventType, OVRCallback<T> handler)
|
||||
{
|
||||
OnListenerAdding(eventType, handler);
|
||||
eventTable[eventType] = (OVRCallback<T>)eventTable[eventType] + handler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Two parameters.
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
/// <param name="handler">Handler.</param>
|
||||
/// <typeparam name="T">The 1st type parameter.</typeparam>
|
||||
/// <typeparam name="U">The 2nd type parameter.</typeparam>
|
||||
static public void AddListener<T, U>(string eventType, OVRCallback<T, U> handler)
|
||||
{
|
||||
OnListenerAdding(eventType, handler);
|
||||
eventTable[eventType] = (OVRCallback<T, U>)eventTable[eventType] + handler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Three parameters
|
||||
/// </summary
|
||||
/// <param name="eventType">Event type.</param>
|
||||
/// <param name="handler">Handler.</param>
|
||||
/// <typeparam name="T">The 1st type parameter.</typeparam>
|
||||
/// <typeparam name="U">The 2nd type parameter.</typeparam>
|
||||
/// <typeparam name="V">The 3rd type parameter.</typeparam>
|
||||
static public void AddListener<T, U, V>(string eventType, OVRCallback<T, U, V> handler)
|
||||
{
|
||||
OnListenerAdding(eventType, handler);
|
||||
eventTable[eventType] = (OVRCallback<T, U, V>)eventTable[eventType] + handler;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region RemoveListener
|
||||
/// <summary>
|
||||
/// No parameters
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
/// <param name="handler">Handler.</param>
|
||||
static public void RemoveListener(string eventType, OVRCallback handler)
|
||||
{
|
||||
OnListenerRemoving(eventType, handler);
|
||||
eventTable[eventType] = (OVRCallback)eventTable[eventType] - handler;
|
||||
OnListenerRemoved(eventType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Single parameter
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
/// <param name="handler">Handler.</param>
|
||||
/// <typeparam name="T">The 1st type parameter.</typeparam>
|
||||
static public void RemoveListener<T>(string eventType, OVRCallback<T> handler)
|
||||
{
|
||||
OnListenerRemoving(eventType, handler);
|
||||
eventTable[eventType] = (OVRCallback<T>)eventTable[eventType] - handler;
|
||||
OnListenerRemoved(eventType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Two parameters
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
/// <param name="handler">Handler.</param>
|
||||
/// <typeparam name="T">The 1st type parameter.</typeparam>
|
||||
/// <typeparam name="U">The 2nd type parameter.</typeparam>
|
||||
static public void RemoveListener<T, U>(string eventType, OVRCallback<T, U> handler)
|
||||
{
|
||||
OnListenerRemoving(eventType, handler);
|
||||
eventTable[eventType] = (OVRCallback<T, U>)eventTable[eventType] - handler;
|
||||
OnListenerRemoved(eventType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
//Three parameters.
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
/// <param name="handler">Handler.</param>
|
||||
/// <typeparam name="T">The 1st type parameter.</typeparam>
|
||||
/// <typeparam name="U">The 2nd type parameter.</typeparam>
|
||||
/// <typeparam name="V">The 3rd type parameter.</typeparam>
|
||||
static public void RemoveListener<T, U, V>(string eventType, OVRCallback<T, U, V> handler)
|
||||
{
|
||||
OnListenerRemoving(eventType, handler);
|
||||
eventTable[eventType] = (OVRCallback<T, U, V>)eventTable[eventType] - handler;
|
||||
OnListenerRemoved(eventType);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Broadcast
|
||||
/// <summary>
|
||||
/// Broadcast the specified eventType.
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
static public void Broadcast(string eventType)
|
||||
{
|
||||
#if LOG_ALL_MESSAGES || LOG_BROADCAST_MESSAGE
|
||||
Debug.Log("MESSENGER\t" + System.DateTime.Now.ToString("hh:mm:ss.fff") + "\t\t\tInvoking \t\"" + eventType + "\"");
|
||||
#endif
|
||||
OnBroadcasting(eventType);
|
||||
|
||||
Delegate d;
|
||||
if (eventTable.TryGetValue(eventType, out d)) {
|
||||
OVRCallback callback = d as OVRCallback;
|
||||
|
||||
if (callback != null) {
|
||||
callback();
|
||||
} else {
|
||||
throw CreateBroadcastSignatureException(eventType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast the specified eventType and arg1.
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
/// <param name="arg1">Arg1.</param>
|
||||
/// <typeparam name="T">The 1st type parameter.</typeparam>
|
||||
static public void Broadcast<T>(string eventType, T arg1) {
|
||||
#if LOG_ALL_MESSAGES || LOG_BROADCAST_MESSAGE
|
||||
Debug.Log("MESSENGER\t" + System.DateTime.Now.ToString("hh:mm:ss.fff") + "\t\t\tInvoking \t\"" + eventType + "\"");
|
||||
#endif
|
||||
OnBroadcasting(eventType);
|
||||
|
||||
Delegate d;
|
||||
|
||||
if (eventTable.TryGetValue(eventType, out d)) {
|
||||
OVRCallback<T> callback = d as OVRCallback<T>;
|
||||
|
||||
if (callback != null) {
|
||||
callback(arg1);
|
||||
} else {
|
||||
throw CreateBroadcastSignatureException(eventType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast the specified eventType, arg1 and arg2.
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
/// <param name="arg1">Arg1.</param>
|
||||
/// <param name="arg2">Arg2.</param>
|
||||
/// <typeparam name="T">The 1st type parameter.</typeparam>
|
||||
/// <typeparam name="U">The 2nd type parameter.</typeparam>
|
||||
static public void Broadcast<T, U>(string eventType, T arg1, U arg2)
|
||||
{
|
||||
#if LOG_ALL_MESSAGES || LOG_BROADCAST_MESSAGE
|
||||
Debug.Log("MESSENGER\t" + System.DateTime.Now.ToString("hh:mm:ss.fff") + "\t\t\tInvoking \t\"" + eventType + "\"");
|
||||
#endif
|
||||
OnBroadcasting(eventType);
|
||||
|
||||
Delegate d;
|
||||
|
||||
if (eventTable.TryGetValue(eventType, out d)) {
|
||||
OVRCallback<T, U> callback = d as OVRCallback<T, U>;
|
||||
|
||||
if (callback != null) {
|
||||
callback(arg1, arg2);
|
||||
} else {
|
||||
throw CreateBroadcastSignatureException(eventType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast the specified eventType, arg1, arg2 and arg3.
|
||||
/// </summary>
|
||||
/// <param name="eventType">Event type.</param>
|
||||
/// <param name="arg1">Arg1.</param>
|
||||
/// <param name="arg2">Arg2.</param>
|
||||
/// <param name="arg3">Arg3.</param>
|
||||
/// <typeparam name="T">The 1st type parameter.</typeparam>
|
||||
/// <typeparam name="U">The 2nd type parameter.</typeparam>
|
||||
/// <typeparam name="V">The 3rd type parameter.</typeparam>
|
||||
static public void Broadcast<T, U, V>(string eventType, T arg1, U arg2, V arg3)
|
||||
{
|
||||
#if LOG_ALL_MESSAGES || LOG_BROADCAST_MESSAGE
|
||||
Debug.Log("MESSENGER\t" + System.DateTime.Now.ToString("hh:mm:ss.fff") + "\t\t\tInvoking \t\"" + eventType + "\"");
|
||||
#endif
|
||||
OnBroadcasting(eventType);
|
||||
|
||||
Delegate d;
|
||||
if (eventTable.TryGetValue(eventType, out d)) {
|
||||
OVRCallback<T, U, V> callback = d as OVRCallback<T, U, V>;
|
||||
|
||||
if (callback != null) {
|
||||
callback(arg1, arg2, arg3);
|
||||
} else {
|
||||
throw CreateBroadcastSignatureException(eventType);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Messenger helper.
|
||||
/// This manager will ensure that the messenger's eventTable will be cleaned up upon loading of a new level.
|
||||
/// </summary>
|
||||
public sealed class MessengerHelper : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Awake this instance.
|
||||
/// </summary>
|
||||
void Awake ()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the disable event.
|
||||
/// </summary>
|
||||
public void OnDisable()
|
||||
{
|
||||
OVRMessenger.Cleanup();
|
||||
}
|
||||
}
|
||||
12
Assets/Oculus/VoiceMod/Scripts/Helpers/OVRMessenger.cs.meta
Normal file
12
Assets/Oculus/VoiceMod/Scripts/Helpers/OVRMessenger.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7841d42721591642aa796e18d66d248
|
||||
timeCreated: 1447374135
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
297
Assets/Oculus/VoiceMod/Scripts/Helpers/OVRMicInput.cs
Normal file
297
Assets/Oculus/VoiceMod/Scripts/Helpers/OVRMicInput.cs
Normal file
@@ -0,0 +1,297 @@
|
||||
/************************************************************************************
|
||||
Filename : OVRMicInput.cs
|
||||
Content : Interface to microphone input
|
||||
Created : May 12, 2015
|
||||
Copyright : Copyright 2015 Oculus VR, Inc. All Rights reserved.
|
||||
|
||||
Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
|
||||
you may not use the Oculus VR Rift 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
|
||||
|
||||
http://www.oculusvr.com/licenses/LICENSE-3.1
|
||||
|
||||
Unless required by applicable law or agreed to in writing, the Oculus VR 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;
|
||||
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
|
||||
public class OVRMicInput : MonoBehaviour
|
||||
{
|
||||
public enum micActivation
|
||||
{
|
||||
HoldToSpeak,
|
||||
PushToSpeak,
|
||||
ConstantSpeak
|
||||
}
|
||||
|
||||
// PUBLIC MEMBERS
|
||||
public AudioSource audioSource = null;
|
||||
public bool GuiSelectDevice = true;
|
||||
|
||||
[SerializeField]
|
||||
private float sensitivity = 100;
|
||||
public float Sensitivity
|
||||
{
|
||||
get{return sensitivity;}
|
||||
set{sensitivity = Mathf.Clamp (value, 0, 100);}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private float sourceVolume = 100;
|
||||
public float SourceVolume
|
||||
{
|
||||
get{return sourceVolume;}
|
||||
set{sourceVolume = Mathf.Clamp (value, 0, 100);}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private int micFrequency = 16000;
|
||||
public float MicFrequency
|
||||
{
|
||||
get{return micFrequency;}
|
||||
set{micFrequency = (int)Mathf.Clamp ((float)value, 0, 96000);}
|
||||
}
|
||||
|
||||
|
||||
public micActivation micControl;
|
||||
|
||||
public string selectedDevice;
|
||||
|
||||
public float loudness; // Use this to chenge visual values. Range is 0 - 100
|
||||
|
||||
// PRIVATE MEMBERS
|
||||
private bool micSelected = false;
|
||||
private int minFreq, maxFreq;
|
||||
private bool focused = true;
|
||||
|
||||
//----------------------------------------------------
|
||||
// MONOBEHAVIOUR OVERRIDE FUNCTIONS
|
||||
//----------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Awake this instance.
|
||||
/// </summary>
|
||||
void Awake()
|
||||
{
|
||||
// First thing to do, cache the unity audio source (can be managed by the
|
||||
// user if audio source can change)
|
||||
if (!audioSource) audioSource = GetComponent<AudioSource>();
|
||||
if (!audioSource) return; // this should never happen
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start this instance.
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
audioSource.loop = true; // Set the AudioClip to loop
|
||||
audioSource.mute = false;
|
||||
|
||||
if(Microphone.devices.Length!= 0)
|
||||
{
|
||||
selectedDevice = Microphone.devices[0].ToString();
|
||||
micSelected = true;
|
||||
GetMicCaps();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update this instance.
|
||||
/// </summary>
|
||||
void Update()
|
||||
{
|
||||
if (!focused)
|
||||
StopMicrophone();
|
||||
|
||||
if (!Application.isPlaying)
|
||||
StopMicrophone();
|
||||
|
||||
audioSource.volume = (sourceVolume / 100);
|
||||
loudness = Mathf.Clamp(GetAveragedVolume() * sensitivity * (sourceVolume / 10), 0, 100);
|
||||
|
||||
//Hold To Speak
|
||||
if (micControl == micActivation.HoldToSpeak)
|
||||
{
|
||||
if (Microphone.IsRecording(selectedDevice) && Input.GetKey(KeyCode.Space) == false)
|
||||
StopMicrophone();
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space)) //Push to talk
|
||||
StartMicrophone();
|
||||
|
||||
if (Input.GetKeyUp(KeyCode.Space))
|
||||
StopMicrophone();
|
||||
}
|
||||
|
||||
//Push To Talk
|
||||
if (micControl == micActivation.PushToSpeak)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
if (Microphone.IsRecording(selectedDevice))
|
||||
StopMicrophone();
|
||||
else if (!Microphone.IsRecording(selectedDevice))
|
||||
StartMicrophone();
|
||||
}
|
||||
}
|
||||
|
||||
//Constant Speak
|
||||
if (micControl == micActivation.ConstantSpeak)
|
||||
if (!Microphone.IsRecording(selectedDevice))
|
||||
StartMicrophone();
|
||||
|
||||
|
||||
//Mic Slected = False
|
||||
if (Input.GetKeyDown(KeyCode.M))
|
||||
micSelected = false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Raises the application focus event.
|
||||
/// </summary>
|
||||
/// <param name="focus">If set to <c>true</c> focus.</param>
|
||||
void OnApplicationFocus(bool focus)
|
||||
{
|
||||
focused = focus;
|
||||
|
||||
// fixes app with a delayed buffer if going out of focus
|
||||
if (!focused)
|
||||
StopMicrophone();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the application pause event.
|
||||
/// </summary>
|
||||
/// <param name="focus">If set to <c>true</c> focus.</param>
|
||||
void OnApplicationPause(bool focus)
|
||||
{
|
||||
focused = focus;
|
||||
|
||||
// fixes app with a delayed buffer if going out of focus
|
||||
if (!focused)
|
||||
StopMicrophone();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
StopMicrophone();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the GU event.
|
||||
/// </summary>
|
||||
void OnGUI()
|
||||
{
|
||||
MicDeviceGUI((Screen.width/2)-150, (Screen.height/2)-75, 300, 50, 10, -300);
|
||||
}
|
||||
|
||||
//----------------------------------------------------
|
||||
// PUBLIC FUNCTIONS
|
||||
//----------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Mics the device GU.
|
||||
/// </summary>
|
||||
/// <param name="left">Left.</param>
|
||||
/// <param name="top">Top.</param>
|
||||
/// <param name="width">Width.</param>
|
||||
/// <param name="height">Height.</param>
|
||||
/// <param name="buttonSpaceTop">Button space top.</param>
|
||||
/// <param name="buttonSpaceLeft">Button space left.</param>
|
||||
public void MicDeviceGUI (float left, float top, float width, float height, float buttonSpaceTop, float buttonSpaceLeft)
|
||||
{
|
||||
//If there is more than one device, choose one.
|
||||
if (Microphone.devices.Length >= 1 && GuiSelectDevice == true && micSelected == false)
|
||||
{
|
||||
for (int i = 0; i < Microphone.devices.Length; ++i)
|
||||
{
|
||||
if (GUI.Button(new Rect(left + ((width + buttonSpaceLeft) * i), top + ((height + buttonSpaceTop) * i), width, height),
|
||||
Microphone.devices[i].ToString()))
|
||||
{
|
||||
StopMicrophone();
|
||||
selectedDevice = Microphone.devices[i].ToString();
|
||||
micSelected = true;
|
||||
GetMicCaps();
|
||||
StartMicrophone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mic caps.
|
||||
/// </summary>
|
||||
public void GetMicCaps ()
|
||||
{
|
||||
if(micSelected == false) return;
|
||||
|
||||
//Gets the frequency of the device
|
||||
Microphone.GetDeviceCaps(selectedDevice, out minFreq, out maxFreq);
|
||||
|
||||
if ( minFreq == 0 && maxFreq == 0 )
|
||||
{
|
||||
Debug.LogWarning ("GetMicCaps warning:: min and max frequencies are 0");
|
||||
minFreq = 44100;
|
||||
maxFreq = 44100;
|
||||
}
|
||||
|
||||
if (micFrequency > maxFreq)
|
||||
micFrequency = maxFreq;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the microphone.
|
||||
/// </summary>
|
||||
public void StartMicrophone ()
|
||||
{
|
||||
if(micSelected == false) return;
|
||||
|
||||
//Starts recording
|
||||
audioSource.clip = Microphone.Start(selectedDevice, true, 1, micFrequency);
|
||||
|
||||
// Wait until the recording has started
|
||||
while (!(Microphone.GetPosition(selectedDevice) > 0)){}
|
||||
|
||||
// Play the audio source
|
||||
audioSource.Play();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the microphone.
|
||||
/// </summary>
|
||||
public void StopMicrophone ()
|
||||
{
|
||||
if(micSelected == false) return;
|
||||
|
||||
// Overriden with a clip to play? Don't stop the audio source
|
||||
if((audioSource != null) && (audioSource.clip != null) &&(audioSource.clip.name == "Microphone"))
|
||||
audioSource.Stop();
|
||||
|
||||
Microphone.End(selectedDevice);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------
|
||||
// PRIVATE FUNCTIONS
|
||||
//----------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Gets the averaged volume.
|
||||
/// </summary>
|
||||
/// <returns>The averaged volume.</returns>
|
||||
float GetAveragedVolume()
|
||||
{
|
||||
// We will use the SR to get average volume
|
||||
// return OVRSpeechRec.GetAverageVolume();
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
12
Assets/Oculus/VoiceMod/Scripts/Helpers/OVRMicInput.cs.meta
Normal file
12
Assets/Oculus/VoiceMod/Scripts/Helpers/OVRMicInput.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19e8290db1b2e0748a6126d146686a6d
|
||||
timeCreated: 1450118836
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user