| 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 | |
| 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 UnityEngine; |
| 24 | using System.Collections; |
| 25 | |
| 26 | public class LipSyncDemo_SetCurrentTarget : MonoBehaviour |
| 27 | { |
| 28 | public EnableSwitch[] SwitchTargets; |
| 29 | |
| 30 | private int targetSet = 0; |
| 31 | private int maxTarget = 6; |
| 32 | |
| 33 | // Use this for initialization |
| 34 | void Start () |
| 35 | { |
| 36 | // Add a listener to the OVRTouchpad for touch events |
| 37 | OVRTouchpad.AddListener(LocalTouchEventCallback); |
| 38 | |
| 39 | // Initialize the proper target set |
| 40 | targetSet = 0; |
| 41 | SwitchTargets[0].SetActive<OVRLipSyncContextMorphTarget>(0); |
| 42 | SwitchTargets[1].SetActive<OVRLipSyncContextMorphTarget>(0); |
| 43 | } |
| 44 | |
| 45 | // Update is called once per frame |
| 46 | // Logic for LipSync_Demo |
| 47 | void Update () |
| 48 | { |
| 49 | if (Input.GetKeyDown(KeyCode.Alpha1)) |
| 50 | { |
| 51 | targetSet = 0; |
| 52 | SetCurrentTarget(); |
| 53 | } |
| 54 | else if (Input.GetKeyDown(KeyCode.Alpha2)) |
| 55 | { |
| 56 | targetSet = 1; |
| 57 | SetCurrentTarget(); |
| 58 | } |
| 59 | else if (Input.GetKeyDown(KeyCode.Alpha3)) |
| 60 | { |
| 61 | targetSet = 2; |
| 62 | SetCurrentTarget(); |
| 63 | } |
| 64 | else if (Input.GetKeyDown(KeyCode.Alpha4)) |
| 65 | { |
| 66 | targetSet = 3; |
| 67 | SetCurrentTarget(); |
| 68 | } |
| 69 | else if (Input.GetKeyDown(KeyCode.Alpha5)) |
| 70 | { |
| 71 | targetSet = 4; |
| 72 | SetCurrentTarget(); |
| 73 | } |
| 74 | else if (Input.GetKeyDown(KeyCode.Alpha6)) |
| 75 | { |
| 76 | targetSet = 5; |
| 77 | SetCurrentTarget(); |
| 78 | } |
| 79 | |
| 80 | // Close app |
| 81 | if(Input.GetKeyDown (KeyCode.Escape)) |
| 82 | Application.Quit(); |
| 83 | } |
| 84 | |
| 85 | /// <summary> |
| 86 | /// Sets the current target. |
| 87 | /// </summary> |
| 88 | void SetCurrentTarget() |
| 89 | { |
| 90 | switch(targetSet) |
| 91 | { |
| 92 | case(0): |
| 93 | SwitchTargets[0].SetActive<OVRLipSyncContextMorphTarget>(0); |
| 94 | SwitchTargets[1].SetActive<OVRLipSyncContextMorphTarget>(0); |
| 95 | break; |
| 96 | case(1): |
| 97 | SwitchTargets[0].SetActive<OVRLipSyncContextTextureFlip>(0); |
| 98 | SwitchTargets[1].SetActive<OVRLipSyncContextTextureFlip>(1); |
| 99 | break; |
| 100 | case(2): |
| 101 | SwitchTargets[0].SetActive<OVRLipSyncContextMorphTarget>(1); |
| 102 | SwitchTargets[1].SetActive<OVRLipSyncContextMorphTarget>(2); |
| 103 | break; |
| 104 | case(3): |
| 105 | SwitchTargets[0].SetActive<OVRLipSyncContextTextureFlip>(1); |
| 106 | SwitchTargets[1].SetActive<OVRLipSyncContextTextureFlip>(3); |
| 107 | break; |
| 108 | case(4): |
| 109 | SwitchTargets[0].SetActive<OVRLipSyncContextMorphTarget>(2); |
| 110 | SwitchTargets[1].SetActive<OVRLipSyncContextMorphTarget>(4); |
| 111 | break; |
| 112 | case(5): |
| 113 | SwitchTargets[0].SetActive<OVRLipSyncContextTextureFlip>(2); |
| 114 | SwitchTargets[1].SetActive<OVRLipSyncContextTextureFlip>(5); |
| 115 | break; |
| 116 | } |
| 117 | OVRLipSyncDebugConsole.Clear(); |
| 118 | } |
| 119 | |
| 120 | /// <summary> |
| 121 | /// Local touch event callback. |
| 122 | /// </summary> |
| 123 | /// <param name="touchEvent">Touch event.</param> |
| 124 | void LocalTouchEventCallback(OVRTouchpad.TouchEvent touchEvent) |
| 125 | { |
| 126 | switch(touchEvent) |
| 127 | { |
| 128 | case(OVRTouchpad.TouchEvent.Left): |
| 129 | |
| 130 | targetSet--; |
| 131 | if(targetSet < 0) |
| 132 | targetSet = maxTarget - 1; |
| 133 | |
| 134 | SetCurrentTarget(); |
| 135 | |
| 136 | break; |
| 137 | |
| 138 | case(OVRTouchpad.TouchEvent.Right): |
| 139 | |
| 140 | targetSet++; |
| 141 | if(targetSet >= maxTarget) |
| 142 | targetSet = 0; |
| 143 | |
| 144 | SetCurrentTarget(); |
| 145 | |
| 146 | break; |
| 147 | } |
| 148 | } |
| 149 | } |