| 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 | |
| 8 | Licensed under the Oculus Audio SDK License Version 3.3 (the "License"); |
| 9 | you may not use the Oculus Audio SDK except in compliance with the License, |
| 10 | which is provided at the time of installation or download, or which |
| 11 | otherwise accompanies this software in either electronic or hard copy form. |
| 12 | |
| 13 | You may obtain a copy of the License at |
| 14 | |
| 15 | https://developer.oculus.com/licenses/audio-3.3/ |
| 16 | |
| 17 | Unless required by applicable law or agreed to in writing, the Oculus Audio SDK |
| 18 | distributed under the License is distributed on an "AS IS" BASIS, |
| 19 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 20 | See the License for the specific language governing permissions and |
| 21 | limitations under the License. |
| 22 | ************************************************************************************/ |
| 23 | using System.Collections; |
| 24 | using System.Collections.Generic; |
| 25 | using UnityEngine; |
| 26 | |
| 27 | public class LipSyncDemo_Control : MonoBehaviour { |
| 28 | |
| 29 | [Tooltip("Key used to rotate the demo object up to 45 degrees to the left.")] |
| 30 | public KeyCode rotateLeftKey = KeyCode.LeftArrow; |
| 31 | [Tooltip("Key used to rotate the demo object up to 45 degrees to the right.")] |
| 32 | public KeyCode rotateRightKey = KeyCode.RightArrow; |
| 33 | [Tooltip("Key used to reset demo object rotation.")] |
| 34 | public KeyCode resetRotationKey = KeyCode.DownArrow; |
| 35 | |
| 36 | private float resetRotation = 180.0f; |
| 37 | private float rotationAmount = 20.0f; |
| 38 | private float rotationMax = 45.0f; |
| 39 | |
| 40 | // Use this for initialization |
| 41 | void Start () { |
| 42 | } |
| 43 | |
| 44 | // Update is called once per frame |
| 45 | void Update () { |
| 46 | if (Input.GetKey(rotateLeftKey)) |
| 47 | { |
| 48 | RotateObject(rotationAmount); |
| 49 | } |
| 50 | else if (Input.GetKey(rotateRightKey)) |
| 51 | { |
| 52 | RotateObject(-rotationAmount); |
| 53 | } |
| 54 | else if (Input.GetKey(resetRotationKey)) |
| 55 | { |
| 56 | RotateObject(resetRotation, true); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void RotateObject(float amountDegrees, bool absolute = false) |
| 61 | { |
| 62 | GameObject target = GameObject.Find("LipSyncMorphTarget_Female"); |
| 63 | |
| 64 | if (target == null) |
| 65 | { |
| 66 | // Try for other scene object |
| 67 | target = GameObject.Find("RobotHead_TextureFlip"); |
| 68 | } |
| 69 | |
| 70 | if (target) |
| 71 | { |
| 72 | if (absolute) |
| 73 | { |
| 74 | float deltaRotate = amountDegrees - target.transform.eulerAngles.y; |
| 75 | target.transform.Rotate(Vector3.up * deltaRotate); |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | float deltaRotate = Time.deltaTime * amountDegrees; |
| 80 | if (deltaRotate + target.transform.eulerAngles.y >= resetRotation - rotationMax && |
| 81 | deltaRotate + target.transform.eulerAngles.y <= resetRotation + rotationMax) |
| 82 | { |
| 83 | target.transform.Rotate(Vector3.up * deltaRotate); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } |