77 lines
1.9 KiB
C#
77 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class TestMicro : MonoBehaviour
|
|
{
|
|
private void Start()
|
|
{
|
|
CanvasGroup cv = GetComponent<CanvasGroup>();
|
|
|
|
cv.alpha = 0;
|
|
cv.blocksRaycasts = false;
|
|
}
|
|
|
|
public void StartTest()
|
|
{
|
|
StartCoroutine(TestMicroCor());
|
|
}
|
|
|
|
IEnumerator TestMicroCor()
|
|
{
|
|
Debug.Log(MicroOption.chosenMic + ", " + MicroPhoneChoose_Contorl.instance.chosenMic +
|
|
", " + System.IO.File.ReadAllText(Application.persistentDataPath + "/micro.txt"));
|
|
Text txt = transform.Find("txtTest").GetComponent<Text>();
|
|
|
|
GameObject objBtnTest = GameObject.Find("TestMicro");
|
|
objBtnTest.SetActive(false);
|
|
|
|
CanvasGroup cv = GetComponent<CanvasGroup>();
|
|
cv.alpha = 1;
|
|
cv.blocksRaycasts = true;
|
|
|
|
txt.text = "Say something near your microphone";
|
|
|
|
float time = 0;
|
|
Slider sliderTime = GetComponentInChildren<Slider>();
|
|
sliderTime.maxValue = 5;
|
|
sliderTime.value = 0;
|
|
|
|
AudioClip clip = Microphone.Start(Microphone.devices[MicroOption.chosenMic], false, 5, 20000);
|
|
|
|
while (time < 5.5f)
|
|
{
|
|
time += Time.deltaTime;
|
|
sliderTime.value = time;
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
time = 0;
|
|
|
|
Microphone.End(Microphone.devices[MicroOption.chosenMic]);
|
|
|
|
AudioSource audioSource = GetComponent<AudioSource>();
|
|
audioSource.clip = clip;
|
|
|
|
audioSource.Play();
|
|
|
|
txt.text = "If you're hearing what you said, your microphone is working";
|
|
|
|
while (time < 5)
|
|
{
|
|
time += Time.deltaTime;
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
cv.alpha = 0;
|
|
cv.blocksRaycasts = false;
|
|
|
|
objBtnTest.SetActive(true);
|
|
}
|
|
}
|