-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
WebGL Audio Support
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
using System; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Neocortex.Editor | ||
{ | ||
[InitializeOnLoad] | ||
public class WebGLTemplateImporter | ||
{ | ||
private const string SourceFolder = "Packages/link.neocortex.sdk/WebGLTemplates/Neocortex"; | ||
private const string DestinationFolder = "Assets/WebGLTemplates/Neocortex"; | ||
private const string ImportCompletedKey = "Neocortex.WebGLTemplateImported"; | ||
|
||
static WebGLTemplateImporter() | ||
{ | ||
EditorApplication.delayCall += OnEditorLoaded; | ||
} | ||
|
||
[MenuItem("Tools/Neocortex/Import WebGL Template", false, 0)] | ||
public static void ImportWebGLTemplate() | ||
{ | ||
if (EditorUtility.DisplayDialog("Import WebGL Template", "This will overwrite any changes you have made in the WebGL template. Are you sure you want to continue?", "Yes", "No")) | ||
{ | ||
if (Directory.Exists(DestinationFolder)) | ||
{ | ||
Directory.Delete(DestinationFolder, recursive: true); | ||
} | ||
|
||
OnEditorLoaded(); | ||
} | ||
} | ||
|
||
private static void OnEditorLoaded() | ||
{ | ||
if (EditorPrefs.HasKey(ImportCompletedKey) && Directory.Exists(DestinationFolder)) | ||
{ | ||
return; | ||
} | ||
|
||
EditorPrefs.DeleteKey(ImportCompletedKey); | ||
|
||
try{ | ||
CopyDirectory(SourceFolder, DestinationFolder); | ||
AssetDatabase.Refresh(); | ||
Debug.Log($"WebGL Template copied to {DestinationFolder} successfully."); | ||
} | ||
catch (System.Exception ex) | ||
{ | ||
Debug.LogError($"Failed to copy WebGL Template: {ex.Message}"); | ||
} | ||
} | ||
|
||
private static void CopyDirectory(string sourceDir, string destinationDir) | ||
{ | ||
if (!Directory.Exists(destinationDir)) | ||
{ | ||
Directory.CreateDirectory(destinationDir); | ||
} | ||
|
||
foreach (var file in Directory.GetFiles(sourceDir)) | ||
{ | ||
string destFile = Path.Combine(destinationDir, Path.GetFileName(file)); | ||
File.Copy(file, destFile, overwrite: true); | ||
} | ||
|
||
foreach (var directory in Directory.GetDirectories(sourceDir)) | ||
{ | ||
string destDir = Path.Combine(destinationDir, Path.GetFileName(directory)); | ||
CopyDirectory(directory, destDir); | ||
} | ||
|
||
EditorPrefs.SetBool(ImportCompletedKey, true); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using UnityEngine; | ||
using UnityEngine.Events; | ||
|
||
namespace Neocortex | ||
{ | ||
public abstract class AudioReceiver: MonoBehaviour | ||
{ | ||
[SerializeField] private bool usePushToTalk; | ||
public bool UsePushToTalk { get => usePushToTalk; protected set => usePushToTalk = value; } | ||
public float Amplitude { get; protected set; } | ||
public float ElapsedWaitTime { get; protected set; } | ||
|
||
public abstract void StartMicrophone(); | ||
public abstract void StopMicrophone(); | ||
|
||
[HideInInspector] public UnityEvent<AudioClip> OnAudioRecorded; | ||
[HideInInspector] public UnityEvent<string> OnRecordingFailed; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Neocortex.Data | ||
{ | ||
public enum MicrophoneState | ||
{ | ||
NotActive = 0, | ||
Booting = 1, | ||
Recording = 2, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Neocortex.Data | ||
{ | ||
public struct FloatArray | ||
{ | ||
public float [] Buffer; | ||
public int Written; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using UnityEngine; | ||
|
||
namespace Neocortex | ||
{ | ||
public sealed class NeocortexMicrophone | ||
{ | ||
public static AudioClip Start(string deviceName, bool loop, int lengthSec, int frequency) | ||
{ | ||
#if !UNITY_WEBGL || UNITY_EDITOR | ||
return Microphone.Start(deviceName, loop, lengthSec, frequency); | ||
#endif | ||
|
||
return null; | ||
} | ||
|
||
public static void End(string deviceName) | ||
{ | ||
#if !UNITY_WEBGL || UNITY_EDITOR | ||
Microphone.End(deviceName); | ||
#endif | ||
|
||
return; | ||
} | ||
|
||
public static int GetPosition(string deviceName) | ||
{ | ||
#if !UNITY_WEBGL || UNITY_EDITOR | ||
return Microphone.GetPosition(deviceName); | ||
#endif | ||
|
||
return 0; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.