TestVoice.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// 语音指令
  6. /// </summary>
  7. public enum Voice
  8. {
  9. /// <summary>
  10. /// 打开第一个景点
  11. /// </summary>
  12. OpenSpoitOne = 1,
  13. OpenSpoitTwo = 2,
  14. OpenSpoitThree = 3,
  15. OpenSpoitFour = 4,
  16. OpenSpoitFire = 5,
  17. /// <summary>
  18. /// 调高音量
  19. /// </summary>
  20. ADDAudio = 11,
  21. SubAudio = 12,
  22. /// <summary>
  23. /// 返回主菜单
  24. /// </summary>
  25. Menu = 13,
  26. NullVoice = -1
  27. }
  28. public class TestVoice : MonoBehaviour
  29. {
  30. public Transform voiceLocator;
  31. public Transform HeadPos;
  32. private Voice voice = Voice.NullVoice;
  33. /// <summary>
  34. /// 设置当前模式
  35. /// </summary>
  36. /// <param name="voice"> 语音指令</param>
  37. public void SettingVoice(int recognition)
  38. {
  39. voice = (Voice)recognition;
  40. // 首先要获取对应ImageTarget的cube位置
  41. // 判断当前是否为扫图模式
  42. // GameManager.Instance.text3.text = voice.ToString();
  43. switch (voice)
  44. {
  45. case Voice.OpenSpoitOne:
  46. case Voice.OpenSpoitTwo:
  47. case Voice.OpenSpoitThree:
  48. case Voice.OpenSpoitFour:
  49. case Voice.OpenSpoitFire:
  50. OpenSceneSpoit((int)voice);
  51. break;
  52. case Voice.ADDAudio:
  53. float addvolume = AudioListener.volume;
  54. addvolume += 0.1f;
  55. if (addvolume > 1)
  56. addvolume = 1;
  57. AudioListener.volume = addvolume;
  58. GameManager.Instance.text.text = AudioListener.volume.ToString();
  59. break;
  60. case Voice.SubAudio:
  61. float subvolume = AudioListener.volume;
  62. subvolume -= 0.1f;
  63. if (subvolume <0)
  64. subvolume = 0;
  65. AudioListener.volume = subvolume;
  66. GameManager.Instance.text.text = AudioListener.volume.ToString();
  67. break;
  68. case Voice.Menu:
  69. // 返回菜单
  70. break;
  71. case Voice.NullVoice:
  72. break;
  73. default:
  74. break;
  75. }
  76. }
  77. public void OpenSceneSpoit( int num)
  78. {
  79. if (VuforialControl.Instance.state)
  80. return;
  81. voiceLocator.position = new Vector3(HeadPos.position.x, HeadPos.position.y - 1f, HeadPos.position.z);
  82. voiceLocator.rotation = HeadPos.rotation;
  83. num--;
  84. VuforialControl.Instance.ReplaceSceneSpoit(voiceLocator, num, 0);
  85. }
  86. }