BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / LipSync / Scenes / Scripts / LipSyncDemo_Control.cs

LipSyncDemo_Control.cs

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
LipSyncDemo_Control.cs 3.1 KiB Download Raw
1/************************************************************************************
2Filename : LipSyncDemo_Control.cs
3Content : LipSync Demo controls
4Created : July 11, 2018
5Copyright : Copyright Facebook Technologies, LLC and its affiliates.
6 All rights reserved.
7
8Licensed under the Oculus Audio SDK License Version 3.3 (the "License");
9you may not use the Oculus Audio SDK except in compliance with the License,
10which is provided at the time of installation or download, or which
11otherwise accompanies this software in either electronic or hard copy form.
12
13You may obtain a copy of the License at
14
15https://developer.oculus.com/licenses/audio-3.3/
16
17Unless required by applicable law or agreed to in writing, the Oculus Audio SDK
18distributed under the License is distributed on an "AS IS" BASIS,
19WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20See the License for the specific language governing permissions and
21limitations under the License.
22************************************************************************************/
23using System.Collections;
24using System.Collections.Generic;
25using UnityEngine;
26
27public 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}