AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
GrabbableSimple.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 
6 namespace HoloToolkit.Unity.InputModule.Examples.Grabbables
7 {
12  {
13  private Rigidbody _rigidbody;
14 
15  [SerializeField]
16  private bool matchPosition = true;
17  [SerializeField]
18  private bool matchRotation = false;
19 
20  protected override void Start()
21  {
22  base.Start();
23  _rigidbody = GetComponent<Rigidbody>();
24  }
25 
29  protected override void StartGrab(BaseGrabber grabber)
30  {
31  base.StartGrab(grabber);
32  if (_rigidbody)
33  {
34  _rigidbody.useGravity = false;
35  }
36  }
37 
41  protected override void EndGrab()
42  {
43  if (_rigidbody)
44  {
45  _rigidbody.useGravity = true;
46  }
47 
48  base.EndGrab();
49  }
50 
51  protected override void OnGrabStay()
52  {
53  if (matchPosition)
54  {
55  transform.position = GrabberPrimary.GrabHandle.position;
56  }
57 
58  if (matchRotation)
59  {
60  transform.rotation = GrabberPrimary.GrabHandle.rotation;
61  }
62  }
63 
64  // The next two functions provide basic behaviour. Extend from this base script in order to provide more specific functionality.
65 
66  protected override void AttachToGrabber(BaseGrabber grabber)
67  {
68  if (_rigidbody == null)
69  {
70  _rigidbody = GetComponent<Rigidbody>();
71  }
72 
73  _rigidbody.isKinematic = true;
74  if (!activeGrabbers.Contains(grabber))
75  {
76  activeGrabbers.Add(grabber);
77  }
78  }
79 
80  protected override void DetachFromGrabber(BaseGrabber grabber)
81  {
82  if (_rigidbody == null)
83  {
84  _rigidbody = GetComponent<Rigidbody>();
85  }
86 
87  _rigidbody.isKinematic = false;
88  _rigidbody.useGravity = true;
89  }
90  }
91 }
override void StartGrab(BaseGrabber grabber)
Specify the target and turn off gravity. Otherwise gravity will interfere with desired grab effect ...
override void EndGrab()
On release turn gravity back on the so the object falls and set the target back to null ...
Intended usage: scripts that inherit from this can be attached to the controller, or any object with ...
Definition: BaseGrabber.cs:18
//Intended Usage// Attach a "grabbable_x" script (a script that inherits from this) to any object tha...
This type of grab makes the grabbed object follow the position and rotation of the grabber...
override void OnGrabStay()
Called every frame while StayGrab is active