Skip to content

Instantly share code, notes, and snippets.

@anchan828
Created February 6, 2012 06:44
Show Gist options
  • Save anchan828/1750276 to your computer and use it in GitHub Desktop.
Save anchan828/1750276 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class RecoderManager : MonoBehaviour
{
public Texture2D playButton, pauseButton, stopButton, recodeBotton, recodingButton;
public GameObject play, pause, stop, recode, recoding, meta;
private const string RECODE_START = "RecodeStart", RECODE_STOP = "RecodeStop", PLAY = "Play", PAUSE = "Pause", STOP = "Stop";
private Ray r;
private GameObject playobj, pauseObj;
#if UNITY_WEBPLAYER
IEnumerator Start ()
{
yield return Application.RequestUserAuthorization(UserAuthorization.Microphone);
}
#endif
void OnGUI ()
{
foreach (string s in Microphone.devices)
num = GUILayout.SelectionGrid (num, Microphone.devices, 3, GUILayout.Width (Screen.width));
Debug.Log (Microphone.devices [num]);
}
void Update ()
{
r = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Input.GetMouseButtonDown (0) && Physics.Raycast (r, out hit)) {
{
if (hit.transform.CompareTag (RECODE_START)) {
// Recode Start
Instantiate (recoding, hit.transform.position, Quaternion.Euler (Vector3.forward * 180));
Destroy (hit.transform.gameObject);
RecodeStart ();
}
if (hit.transform.CompareTag (RECODE_STOP)) {
// Recode Stop
Instantiate (recode, hit.transform.position, Quaternion.Euler (Vector3.forward * 180));
Destroy (hit.transform.gameObject);
RecodeStop ();
}
}
{
if (hit.transform.CompareTag (PLAY)) {
// Play
PlayClip ();
playobj = hit.transform.gameObject;
pauseObj = (GameObject)Instantiate (pause, hit.transform.position, Quaternion.Euler (Vector3.forward * 180));
Destroy (hit.transform.gameObject);
}
if (hit.transform.CompareTag (PAUSE)) {
// Pause
pauseObj = (GameObject)Instantiate (play, hit.transform.position, Quaternion.Euler (Vector3.forward * 180));
Destroy (hit.transform.gameObject);
PauseClip ();
}
}
if (hit.transform.CompareTag (STOP)) {
// Recode Start
StopClip ();
Destroy (pauseObj);
Instantiate (play, Vector3.right * -1.2f, Quaternion.Euler (Vector3.forward * 180));
}
}
}
void RecodeStart ()
{
audio.clip = Microphone.Start (Microphone.devices [num], false, 300, 44100);
}
private int num = 0;
void RecodeStop ()
{
Microphone.End (Microphone.devices [num]);
}
void PlayClip ()
{
audio.Play ();
}
void PauseClip ()
{
audio.Pause ();
}
void StopClip ()
{
audio.Stop ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment