forked from cgvr/DeltaVR
archery range glass display tank + wire
This commit is contained in:
@@ -162,7 +162,7 @@ public class ArcheryRange : NetworkBehaviour
|
|||||||
ArcheryTarget archeryTarget = targetObject.AddComponent<ArcheryTarget>();
|
ArcheryTarget archeryTarget = targetObject.AddComponent<ArcheryTarget>();
|
||||||
archeryTarget.pointsText = archeryTargetPointsText;
|
archeryTarget.pointsText = archeryTargetPointsText;
|
||||||
|
|
||||||
Rigidbody rigidbody = targetObject.GetComponent<Rigidbody>();
|
Rigidbody rigidbody = targetObject.AddComponent<Rigidbody>();
|
||||||
rigidbody.useGravity = false;
|
rigidbody.useGravity = false;
|
||||||
rigidbody.isKinematic = true;
|
rigidbody.isKinematic = true;
|
||||||
|
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ namespace _PROJECT.NewHandPresence
|
|||||||
{
|
{
|
||||||
if (leftHand == null || rightHand == null)
|
if (leftHand == null || rightHand == null)
|
||||||
{
|
{
|
||||||
Debug.Log("Left or right hand is null");
|
//Debug.Log("Left or right hand is null");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
139
Assets/_PROJECT/Materials/Glass_NonClear_Green.mat
Normal file
139
Assets/_PROJECT/Materials/Glass_NonClear_Green.mat
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!21 &2100000
|
||||||
|
Material:
|
||||||
|
serializedVersion: 8
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: Glass_NonClear_Green
|
||||||
|
m_Shader: {fileID: 4800000, guid: 0ca6dca7396eb48e5849247ffd444914, type: 3}
|
||||||
|
m_Parent: {fileID: 0}
|
||||||
|
m_ModifiedSerializedProperties: 0
|
||||||
|
m_ValidKeywords:
|
||||||
|
- _SURFACE_TYPE_TRANSPARENT
|
||||||
|
m_InvalidKeywords: []
|
||||||
|
m_LightmapFlags: 4
|
||||||
|
m_EnableInstancingVariants: 0
|
||||||
|
m_DoubleSidedGI: 0
|
||||||
|
m_CustomRenderQueue: 3000
|
||||||
|
stringTagMap:
|
||||||
|
RenderType: Transparent
|
||||||
|
disabledShaderPasses:
|
||||||
|
- DepthOnly
|
||||||
|
- SHADOWCASTER
|
||||||
|
m_LockedProperties:
|
||||||
|
m_SavedProperties:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TexEnvs:
|
||||||
|
- _BaseMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _BumpMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailAlbedoMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailMask:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailNormalMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _EmissionMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _MainTex:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _MetallicGlossMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _OcclusionMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _ParallaxMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _SpecGlossMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- unity_Lightmaps:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- unity_LightmapsInd:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- unity_ShadowMasks:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
m_Ints: []
|
||||||
|
m_Floats:
|
||||||
|
- _AlphaClip: 0
|
||||||
|
- _AlphaToMask: 0
|
||||||
|
- _Blend: 0
|
||||||
|
- _BlendModePreserveSpecular: 1
|
||||||
|
- _BlendOp: 0
|
||||||
|
- _BumpScale: 1
|
||||||
|
- _ClearCoatMask: 0
|
||||||
|
- _ClearCoatSmoothness: 0
|
||||||
|
- _Cull: 2
|
||||||
|
- _Cutoff: 0.5
|
||||||
|
- _DetailAlbedoMapScale: 1
|
||||||
|
- _DetailNormalMapScale: 1
|
||||||
|
- _DstBlend: 10
|
||||||
|
- _DstBlendAlpha: 10
|
||||||
|
- _EnvironmentReflections: 1
|
||||||
|
- _GlossMapScale: 1
|
||||||
|
- _Glossiness: 0
|
||||||
|
- _GlossyReflections: 1
|
||||||
|
- _Metallic: 0
|
||||||
|
- _Mode: 0
|
||||||
|
- _OcclusionStrength: 1
|
||||||
|
- _Parallax: 0.02
|
||||||
|
- _QueueOffset: 0
|
||||||
|
- _ReceiveShadows: 1
|
||||||
|
- _Smoothness: 0
|
||||||
|
- _SmoothnessTextureChannel: 0
|
||||||
|
- _SpecularHighlights: 1
|
||||||
|
- _SrcBlend: 5
|
||||||
|
- _SrcBlendAlpha: 1
|
||||||
|
- _Surface: 1
|
||||||
|
- _UVSec: 0
|
||||||
|
- _WorkflowMode: 1
|
||||||
|
- _ZWrite: 0
|
||||||
|
m_Colors:
|
||||||
|
- _BaseColor: {r: 0.36383638, g: 1, b: 0, a: 0.34509805}
|
||||||
|
- _Color: {r: 0.5294118, g: 0.5647059, b: 0.57254905, a: 0.29411766}
|
||||||
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
|
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||||
|
m_BuildTextureStacks: []
|
||||||
|
--- !u!114 &3140964517369894785
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 11
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
version: 7
|
||||||
8
Assets/_PROJECT/Materials/Glass_NonClear_Green.mat.meta
Normal file
8
Assets/_PROJECT/Materials/Glass_NonClear_Green.mat.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e2ac8c5522bae5a4794c3cbdb7bee948
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 2100000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
139
Assets/_PROJECT/Materials/Glass_NonClear_Red.mat
Normal file
139
Assets/_PROJECT/Materials/Glass_NonClear_Red.mat
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!21 &2100000
|
||||||
|
Material:
|
||||||
|
serializedVersion: 8
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: Glass_NonClear_Red
|
||||||
|
m_Shader: {fileID: 4800000, guid: 0ca6dca7396eb48e5849247ffd444914, type: 3}
|
||||||
|
m_Parent: {fileID: 0}
|
||||||
|
m_ModifiedSerializedProperties: 0
|
||||||
|
m_ValidKeywords:
|
||||||
|
- _SURFACE_TYPE_TRANSPARENT
|
||||||
|
m_InvalidKeywords: []
|
||||||
|
m_LightmapFlags: 4
|
||||||
|
m_EnableInstancingVariants: 0
|
||||||
|
m_DoubleSidedGI: 0
|
||||||
|
m_CustomRenderQueue: 3000
|
||||||
|
stringTagMap:
|
||||||
|
RenderType: Transparent
|
||||||
|
disabledShaderPasses:
|
||||||
|
- DepthOnly
|
||||||
|
- SHADOWCASTER
|
||||||
|
m_LockedProperties:
|
||||||
|
m_SavedProperties:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TexEnvs:
|
||||||
|
- _BaseMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _BumpMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailAlbedoMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailMask:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailNormalMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _EmissionMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _MainTex:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _MetallicGlossMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _OcclusionMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _ParallaxMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _SpecGlossMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- unity_Lightmaps:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- unity_LightmapsInd:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- unity_ShadowMasks:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
m_Ints: []
|
||||||
|
m_Floats:
|
||||||
|
- _AlphaClip: 0
|
||||||
|
- _AlphaToMask: 0
|
||||||
|
- _Blend: 0
|
||||||
|
- _BlendModePreserveSpecular: 1
|
||||||
|
- _BlendOp: 0
|
||||||
|
- _BumpScale: 1
|
||||||
|
- _ClearCoatMask: 0
|
||||||
|
- _ClearCoatSmoothness: 0
|
||||||
|
- _Cull: 2
|
||||||
|
- _Cutoff: 0.5
|
||||||
|
- _DetailAlbedoMapScale: 1
|
||||||
|
- _DetailNormalMapScale: 1
|
||||||
|
- _DstBlend: 10
|
||||||
|
- _DstBlendAlpha: 10
|
||||||
|
- _EnvironmentReflections: 1
|
||||||
|
- _GlossMapScale: 1
|
||||||
|
- _Glossiness: 0
|
||||||
|
- _GlossyReflections: 1
|
||||||
|
- _Metallic: 0
|
||||||
|
- _Mode: 0
|
||||||
|
- _OcclusionStrength: 1
|
||||||
|
- _Parallax: 0.02
|
||||||
|
- _QueueOffset: 0
|
||||||
|
- _ReceiveShadows: 1
|
||||||
|
- _Smoothness: 0
|
||||||
|
- _SmoothnessTextureChannel: 0
|
||||||
|
- _SpecularHighlights: 1
|
||||||
|
- _SrcBlend: 5
|
||||||
|
- _SrcBlendAlpha: 1
|
||||||
|
- _Surface: 1
|
||||||
|
- _UVSec: 0
|
||||||
|
- _WorkflowMode: 1
|
||||||
|
- _ZWrite: 0
|
||||||
|
m_Colors:
|
||||||
|
- _BaseColor: {r: 1, g: 0.53300416, b: 0, a: 0.4745098}
|
||||||
|
- _Color: {r: 0.5294118, g: 0.5647059, b: 0.57254905, a: 0.29411766}
|
||||||
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
|
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||||
|
m_BuildTextureStacks: []
|
||||||
|
--- !u!114 &3140964517369894785
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 11
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
version: 7
|
||||||
8
Assets/_PROJECT/Materials/Glass_NonClear_Red.mat.meta
Normal file
8
Assets/_PROJECT/Materials/Glass_NonClear_Red.mat.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1892de3c798cec947bcabf6cfc693b8c
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 2100000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
@@ -12,8 +12,13 @@ public class ArcheryRangeModelGenerationController : MonoBehaviour
|
|||||||
public Texture2D GeneratedTexture { get; private set; }
|
public Texture2D GeneratedTexture { get; private set; }
|
||||||
public Image imageDisplay;
|
public Image imageDisplay;
|
||||||
|
|
||||||
public Transform modelSpawnPoint;
|
|
||||||
public GameObject GeneratedModel { get; private set; }
|
public GameObject GeneratedModel { get; private set; }
|
||||||
|
public float generatedObjectRotationSpeed = 10f;
|
||||||
|
|
||||||
|
public Transform modelDisplay;
|
||||||
|
public Material modelDisplayActiveMaterial;
|
||||||
|
public Transform wire;
|
||||||
|
public Material wireActiveMaterial;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
@@ -25,7 +30,10 @@ public class ArcheryRangeModelGenerationController : MonoBehaviour
|
|||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
if (GeneratedModel != null)
|
||||||
|
{
|
||||||
|
GeneratedModel.transform.Rotate(Vector3.up, generatedObjectRotationSpeed * Time.deltaTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void InvokeImageGeneration()
|
private async void InvokeImageGeneration()
|
||||||
@@ -48,11 +56,13 @@ public class ArcheryRangeModelGenerationController : MonoBehaviour
|
|||||||
byte[] encodedModel = await TrellisClient.Instance.GenerateModel(encodedTexture);
|
byte[] encodedModel = await TrellisClient.Instance.GenerateModel(encodedTexture);
|
||||||
|
|
||||||
GameObject spawnedObject = await PipelineManager.Instance.SpawnModel(encodedModel);
|
GameObject spawnedObject = await PipelineManager.Instance.SpawnModel(encodedModel);
|
||||||
spawnedObject.AddComponent<Rigidbody>();
|
// Destroy previous generated object
|
||||||
spawnedObject.transform.parent = modelSpawnPoint;
|
Destroy(GeneratedModel);
|
||||||
spawnedObject.transform.position = modelSpawnPoint.position;
|
spawnedObject.transform.parent = modelDisplay;
|
||||||
|
spawnedObject.transform.position = modelDisplay.position;
|
||||||
GeneratedModel = spawnedObject;
|
GeneratedModel = spawnedObject;
|
||||||
|
|
||||||
|
OnModelReady();
|
||||||
modelGenerationButton.MoveButtonUp();
|
modelGenerationButton.MoveButtonUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,4 +93,14 @@ public class ArcheryRangeModelGenerationController : MonoBehaviour
|
|||||||
|
|
||||||
return sprite;
|
return sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnModelReady()
|
||||||
|
{
|
||||||
|
foreach (MeshRenderer meshRenderer in wire.GetComponentsInChildren<MeshRenderer>())
|
||||||
|
{
|
||||||
|
meshRenderer.material = wireActiveMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
|
modelDisplay.GetComponent<MeshRenderer>().material = modelDisplayActiveMaterial;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
97
Assets/_PROJECT/Scripts/ModeGeneration/MicrophoneTesting.cs
Normal file
97
Assets/_PROJECT/Scripts/ModeGeneration/MicrophoneTesting.cs
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[RequireComponent(typeof(AudioSource))]
|
||||||
|
public class MicrophoneTesting : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Header("Mic settings")]
|
||||||
|
[Tooltip("Leave empty for default device")]
|
||||||
|
public string deviceName = "";
|
||||||
|
[Range(1, 60)] public int bufferLengthSec = 10; // rolling buffer for mic clip
|
||||||
|
public int requestedSampleRate = 48000; // 48000 is best match for Quest & many headsets
|
||||||
|
public bool playOnStart = true;
|
||||||
|
|
||||||
|
[Header("Runtime")]
|
||||||
|
public bool isRecording;
|
||||||
|
public bool isPlaying;
|
||||||
|
|
||||||
|
private AudioSource _src;
|
||||||
|
private AudioClip _micClip;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
_src = GetComponent<AudioSource>();
|
||||||
|
_src.loop = true; // continuous playback
|
||||||
|
_src.playOnAwake = false; // we will start manually
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
if (playOnStart)
|
||||||
|
StartLoopback();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartLoopback()
|
||||||
|
{
|
||||||
|
if (isRecording) return;
|
||||||
|
|
||||||
|
// Pick default mic if none specified
|
||||||
|
string dev = deviceName;
|
||||||
|
if (string.IsNullOrEmpty(dev) && Microphone.devices.Length > 0)
|
||||||
|
dev = Microphone.devices[0];
|
||||||
|
|
||||||
|
// Optionally query supported sample range
|
||||||
|
Microphone.GetDeviceCaps(dev, out int minFreq, out int maxFreq);
|
||||||
|
int sampleRate = requestedSampleRate;
|
||||||
|
if (minFreq != 0 && maxFreq != 0)
|
||||||
|
{
|
||||||
|
// Clamp to supported range
|
||||||
|
sampleRate = Mathf.Clamp(requestedSampleRate, minFreq, maxFreq);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start recording into an AudioClip Unity manages
|
||||||
|
_micClip = Microphone.Start(dev, true, bufferLengthSec, sampleRate);
|
||||||
|
isRecording = true;
|
||||||
|
|
||||||
|
Debug.Log("Recording started. device name:");
|
||||||
|
Debug.Log(Microphone.GetPosition(deviceName));
|
||||||
|
|
||||||
|
// Wait until the mic has written at least one sample
|
||||||
|
StartCoroutine(PlayWhenReady());
|
||||||
|
}
|
||||||
|
|
||||||
|
System.Collections.IEnumerator PlayWhenReady()
|
||||||
|
{
|
||||||
|
// Ensure mic buffer has started writing
|
||||||
|
Debug.Log("device name: " + deviceName);
|
||||||
|
while (Microphone.GetPosition(deviceName) <= 0)
|
||||||
|
{
|
||||||
|
Debug.Log("Stuck in enumerator");
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_src.clip = _micClip;
|
||||||
|
Debug.Log("Playing clip " + _src.clip);
|
||||||
|
_src.Play();
|
||||||
|
isPlaying = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StopLoopback()
|
||||||
|
{
|
||||||
|
if (!isRecording) return;
|
||||||
|
|
||||||
|
_src.Stop();
|
||||||
|
if (_micClip != null)
|
||||||
|
{
|
||||||
|
Microphone.End(null); // stop default device
|
||||||
|
_micClip = null;
|
||||||
|
}
|
||||||
|
isPlaying = false;
|
||||||
|
isRecording = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnDisable()
|
||||||
|
{
|
||||||
|
StopLoopback();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f0e7aa48ae4094e45b6f427987c2fc93
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user