| 1 | /************************************************************************************ |
| 2 | |
| 3 | Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. |
| 4 | |
| 5 | See SampleFramework license.txt for license terms. Unless required by applicable law |
| 6 | or agreed to in writing, the sample code is provided “AS IS” WITHOUT WARRANTIES OR |
| 7 | CONDITIONS OF ANY KIND, either express or implied. See the license for specific |
| 8 | language governing permissions and limitations under the license. |
| 9 | |
| 10 | ************************************************************************************/ |
| 11 | using System.Collections; |
| 12 | using System.Collections.Generic; |
| 13 | using UnityEngine; |
| 14 | using UnityEngine.UI; |
| 15 | |
| 16 | namespace OculusSampleFramework |
| 17 | { |
| 18 | public class DistanceGrabberSample : MonoBehaviour |
| 19 | { |
| 20 | |
| 21 | bool museSpherecast = false; |
| 22 | bool allowGrabThroughWalls = false; |
| 23 | |
| 24 | public bool UseSpherecast |
| 25 | { |
| 26 | get { return museSpherecast; } |
| 27 | set |
| 28 | { |
| 29 | museSpherecast = value; |
| 30 | for (int i = 0; i < m_grabbers.Length; ++i) |
| 31 | { |
| 32 | m_grabbers[i].UseSpherecast = museSpherecast; |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | public bool AllowGrabThroughWalls |
| 38 | { |
| 39 | get { return allowGrabThroughWalls; } |
| 40 | set |
| 41 | { |
| 42 | allowGrabThroughWalls = value; |
| 43 | for (int i = 0; i < m_grabbers.Length; ++i) |
| 44 | { |
| 45 | m_grabbers[i].m_preventGrabThroughWalls = !allowGrabThroughWalls; |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | [SerializeField] |
| 51 | DistanceGrabber[] m_grabbers; |
| 52 | |
| 53 | // Use this for initialization |
| 54 | void Start() |
| 55 | { |
| 56 | DebugUIBuilder.instance.AddLabel("Distance Grab Sample"); |
| 57 | DebugUIBuilder.instance.AddToggle("Use Spherecasting", ToggleSphereCasting, museSpherecast); |
| 58 | DebugUIBuilder.instance.AddToggle("Grab Through Walls", ToggleGrabThroughWalls, allowGrabThroughWalls); |
| 59 | DebugUIBuilder.instance.Show(); |
| 60 | } |
| 61 | |
| 62 | public void ToggleSphereCasting(Toggle t) |
| 63 | { |
| 64 | UseSpherecast = !UseSpherecast; |
| 65 | } |
| 66 | |
| 67 | public void ToggleGrabThroughWalls(Toggle t) |
| 68 | { |
| 69 | AllowGrabThroughWalls = !AllowGrabThroughWalls; |
| 70 | } |
| 71 | } |
| 72 | } |