Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.5 KiB

  1. /************************************************************************************
  2. Filename : LipSyncDemo_SetCurrentTarget.cs
  3. Content : Update LipSync Demo current target
  4. Created : July 11, 2018
  5. Copyright : Copyright Facebook Technologies, LLC and its affiliates.
  6. All rights reserved.
  7. Licensed under the Oculus Audio SDK License Version 3.3 (the "License");
  8. you may not use the Oculus Audio SDK except in compliance with the License,
  9. which is provided at the time of installation or download, or which
  10. otherwise accompanies this software in either electronic or hard copy form.
  11. You may obtain a copy of the License at
  12. https://developer.oculus.com/licenses/audio-3.3/
  13. Unless required by applicable law or agreed to in writing, the Oculus Audio SDK
  14. distributed under the License is distributed on an "AS IS" BASIS,
  15. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. See the License for the specific language governing permissions and
  17. limitations under the License.
  18. ************************************************************************************/
  19. using UnityEngine;
  20. using System.Collections;
  21. public class LipSyncDemo_SetCurrentTarget : MonoBehaviour
  22. {
  23. public EnableSwitch[] SwitchTargets;
  24. private int targetSet = 0;
  25. private int maxTarget = 6;
  26. // Use this for initialization
  27. void Start ()
  28. {
  29. // Add a listener to the OVRTouchpad for touch events
  30. OVRTouchpad.AddListener(LocalTouchEventCallback);
  31. // Initialize the proper target set
  32. targetSet = 0;
  33. SwitchTargets[0].SetActive<OVRLipSyncContextMorphTarget>(0);
  34. SwitchTargets[1].SetActive<OVRLipSyncContextMorphTarget>(0);
  35. }
  36. // Update is called once per frame
  37. // Logic for LipSync_Demo
  38. void Update ()
  39. {
  40. if (Input.GetKeyDown(KeyCode.Alpha1))
  41. {
  42. targetSet = 0;
  43. SetCurrentTarget();
  44. }
  45. else if (Input.GetKeyDown(KeyCode.Alpha2))
  46. {
  47. targetSet = 1;
  48. SetCurrentTarget();
  49. }
  50. else if (Input.GetKeyDown(KeyCode.Alpha3))
  51. {
  52. targetSet = 2;
  53. SetCurrentTarget();
  54. }
  55. else if (Input.GetKeyDown(KeyCode.Alpha4))
  56. {
  57. targetSet = 3;
  58. SetCurrentTarget();
  59. }
  60. else if (Input.GetKeyDown(KeyCode.Alpha5))
  61. {
  62. targetSet = 4;
  63. SetCurrentTarget();
  64. }
  65. else if (Input.GetKeyDown(KeyCode.Alpha6))
  66. {
  67. targetSet = 5;
  68. SetCurrentTarget();
  69. }
  70. // Close app
  71. if(Input.GetKeyDown (KeyCode.Escape))
  72. Application.Quit();
  73. }
  74. /// <summary>
  75. /// Sets the current target.
  76. /// </summary>
  77. void SetCurrentTarget()
  78. {
  79. switch(targetSet)
  80. {
  81. case(0):
  82. SwitchTargets[0].SetActive<OVRLipSyncContextMorphTarget>(0);
  83. SwitchTargets[1].SetActive<OVRLipSyncContextMorphTarget>(0);
  84. break;
  85. case(1):
  86. SwitchTargets[0].SetActive<OVRLipSyncContextTextureFlip>(0);
  87. SwitchTargets[1].SetActive<OVRLipSyncContextTextureFlip>(1);
  88. break;
  89. case(2):
  90. SwitchTargets[0].SetActive<OVRLipSyncContextMorphTarget>(1);
  91. SwitchTargets[1].SetActive<OVRLipSyncContextMorphTarget>(2);
  92. break;
  93. case(3):
  94. SwitchTargets[0].SetActive<OVRLipSyncContextTextureFlip>(1);
  95. SwitchTargets[1].SetActive<OVRLipSyncContextTextureFlip>(3);
  96. break;
  97. case(4):
  98. SwitchTargets[0].SetActive<OVRLipSyncContextMorphTarget>(2);
  99. SwitchTargets[1].SetActive<OVRLipSyncContextMorphTarget>(4);
  100. break;
  101. case(5):
  102. SwitchTargets[0].SetActive<OVRLipSyncContextTextureFlip>(2);
  103. SwitchTargets[1].SetActive<OVRLipSyncContextTextureFlip>(5);
  104. break;
  105. }
  106. OVRLipSyncDebugConsole.Clear();
  107. }
  108. /// <summary>
  109. /// Local touch event callback.
  110. /// </summary>
  111. /// <param name="touchEvent">Touch event.</param>
  112. void LocalTouchEventCallback(OVRTouchpad.TouchEvent touchEvent)
  113. {
  114. switch(touchEvent)
  115. {
  116. case(OVRTouchpad.TouchEvent.Left):
  117. targetSet--;
  118. if(targetSet < 0)
  119. targetSet = maxTarget - 1;
  120. SetCurrentTarget();
  121. break;
  122. case(OVRTouchpad.TouchEvent.Right):
  123. targetSet++;
  124. if(targetSet >= maxTarget)
  125. targetSet = 0;
  126. SetCurrentTarget();
  127. break;
  128. }
  129. }
  130. }