comparison Orchestland/Assets/LeapMotion/Scripts/Utils/GrabbableObject.cs @ 3:0030a1b971fb default tip

merge
author Yuta ANSE <e135745@ie.u-ryukyu.ac.jp>
date Fri, 17 Jul 2015 23:23:43 +0900
parents f7675884f2a1
children
comparison
equal deleted inserted replaced
2:fdab88fc2cb9 3:0030a1b971fb
1 /******************************************************************************\
2 * Copyright (C) Leap Motion, Inc. 2011-2014. *
3 * Leap Motion proprietary. Licensed under Apache 2.0 *
4 * Available at http://www.apache.org/licenses/LICENSE-2.0.html *
5 \******************************************************************************/
6
7 using UnityEngine;
8 using System.Collections;
9
10 public class GrabbableObject : MonoBehaviour {
11
12 public bool useAxisAlignment = false;
13 public Vector3 rightHandAxis;
14 public Vector3 objectAxis;
15
16 public bool rotateQuickly = true;
17 public bool centerGrabbedObject = false;
18
19 public Rigidbody breakableJoint;
20 public float breakForce;
21 public float breakTorque;
22
23 protected bool grabbed_ = false;
24 protected bool hovered_ = false;
25
26 public bool IsHovered() {
27 return hovered_;
28 }
29
30 public bool IsGrabbed() {
31 return grabbed_;
32 }
33
34 public virtual void OnStartHover() {
35 hovered_ = true;
36 }
37
38 public virtual void OnStopHover() {
39 hovered_ = false;
40 }
41
42 public virtual void OnGrab() {
43 grabbed_ = true;
44 hovered_ = false;
45
46 if (breakableJoint != null) {
47 Joint breakJoint = breakableJoint.GetComponent<Joint>();
48 if (breakJoint != null) {
49 breakJoint.breakForce = breakForce;
50 breakJoint.breakTorque = breakTorque;
51 }
52 }
53 }
54
55 public virtual void OnRelease() {
56 grabbed_ = false;
57
58 if (breakableJoint != null) {
59 Joint breakJoint = breakableJoint.GetComponent<Joint>();
60 if (breakJoint != null) {
61 breakJoint.breakForce = Mathf.Infinity;
62 breakJoint.breakTorque = Mathf.Infinity;
63 }
64 }
65 }
66 }