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.

88 lines
3.1 KiB

  1. /************************************************************************************
  2. Filename : LipSyncDemo_Control.cs
  3. Content : LipSync Demo controls
  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 System.Collections;
  20. using System.Collections.Generic;
  21. using UnityEngine;
  22. public class LipSyncDemo_Control : MonoBehaviour {
  23. [Tooltip("Key used to rotate the demo object up to 45 degrees to the left.")]
  24. public KeyCode rotateLeftKey = KeyCode.LeftArrow;
  25. [Tooltip("Key used to rotate the demo object up to 45 degrees to the right.")]
  26. public KeyCode rotateRightKey = KeyCode.RightArrow;
  27. [Tooltip("Key used to reset demo object rotation.")]
  28. public KeyCode resetRotationKey = KeyCode.DownArrow;
  29. private float resetRotation = 180.0f;
  30. private float rotationAmount = 20.0f;
  31. private float rotationMax = 45.0f;
  32. // Use this for initialization
  33. void Start () {
  34. }
  35. // Update is called once per frame
  36. void Update () {
  37. if (Input.GetKey(rotateLeftKey))
  38. {
  39. RotateObject(rotationAmount);
  40. }
  41. else if (Input.GetKey(rotateRightKey))
  42. {
  43. RotateObject(-rotationAmount);
  44. }
  45. else if (Input.GetKey(resetRotationKey))
  46. {
  47. RotateObject(resetRotation, true);
  48. }
  49. }
  50. void RotateObject(float amountDegrees, bool absolute = false)
  51. {
  52. GameObject target = GameObject.Find("LipSyncMorphTarget_Female");
  53. if (target == null)
  54. {
  55. // Try for other scene object
  56. target = GameObject.Find("RobotHead_TextureFlip");
  57. }
  58. if (target)
  59. {
  60. if (absolute)
  61. {
  62. float deltaRotate = amountDegrees - target.transform.eulerAngles.y;
  63. target.transform.Rotate(Vector3.up * deltaRotate);
  64. }
  65. else
  66. {
  67. float deltaRotate = Time.deltaTime * amountDegrees;
  68. if (deltaRotate + target.transform.eulerAngles.y >= resetRotation - rotationMax &&
  69. deltaRotate + target.transform.eulerAngles.y <= resetRotation + rotationMax)
  70. {
  71. target.transform.Rotate(Vector3.up * deltaRotate);
  72. }
  73. }
  74. }
  75. }
  76. }