Tanoda
TransformHandle.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
10using System.Collections;
11using System.Collections.Generic;
12using UnityEngine;
14
15namespace Leap.Unity.Examples {
16
17 [AddComponentMenu("")]
18 [RequireComponent(typeof(InteractionBehaviour))]
19 public class TransformHandle : MonoBehaviour {
20
23
24 public UnityEvent OnShouldShowHandle = new UnityEvent();
25 public UnityEvent OnShouldHideHandle = new UnityEvent();
26 public UnityEvent OnHandleActivated = new UnityEvent();
27 public UnityEvent OnHandleDeactivated = new UnityEvent();
28
29 protected virtual void Start() {
30 _intObj = GetComponent<InteractionBehaviour>();
31 _intObj.OnGraspBegin += onGraspBegin;
32 _intObj.OnGraspEnd += onGraspEnd;
33
34 _tool = GetComponentInParent<TransformTool>();
35 if (_tool == null) Debug.LogError("No TransformTool found in a parent GameObject.");
36 }
37
39 _intObj.rigidbody.position = this.transform.position;
40 _intObj.rigidbody.rotation = this.transform.rotation;
41 }
42
43 private void onGraspBegin() {
45
46 OnHandleActivated.Invoke();
47 }
48
49 private void onGraspEnd() {
51
52 OnHandleDeactivated.Invoke();
53 }
54
55 #region Handle Visibility
56
60 public void EnsureVisible() {
61 OnShouldShowHandle.Invoke();
62
63 _intObj.ignoreGrasping = false;
64 }
65
69 public void EnsureHidden() {
70 OnShouldHideHandle.Invoke();
71
73 }
74
75 #endregion
76
77 }
78
79}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
void EnsureHidden()
Called by the Transform Tool when this handle should not be visible.
void EnsureVisible()
Called by the Transform Tool when this handle should be visible.
void NotifyHandleDeactivated(TransformHandle handle)
Called by Handles when they are released.
void NotifyHandleActivated(TransformHandle handle)
Called by handles when they are grasped.
InteractionBehaviours are components that enable GameObjects to interact with interaction controllers...
Action OnGraspBegin
Called when the object becomes grasped, if it was not already held by any interaction controllers on ...
Rigidbody rigidbody
The Rigidbody associated with this interaction object.
Action OnGraspEnd
Called when the object is no longer grasped by any interaction controllers.