Detector.cs
2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/******************************************************************************
* Copyright (C) Leap Motion, Inc. 2011-2017. *
* Leap Motion proprietary and confidential. *
* *
* Use subject to the terms of the Leap Motion SDK Agreement available at *
* https://developer.leapmotion.com/sdk_agreement, or another agreement *
* between Leap Motion and you, your company or other organization. *
******************************************************************************/
using UnityEngine;
using UnityEngine.Events;
using System.Collections;
using Leap;
namespace Leap.Unity {
/**
* Base class for detectors.
*
* A Detector is an object that observes some aspect of a scene and reports true
* when the specified conditions are met. Typically these conditions involve hand
* information, but this is not required.
*
* Detector implementations must call Activate() when their conditions are met and
* Deactivate() when those conditions are no longer met. Implementations should
* also call Deactivate() when they, or the object they are a component of become disabled.
* Implementations can call Activate() and Deactivate() more often than is strictly necessary.
* This Detector base class keeps track of the IsActive status and only dispatches events
* when the status changes.
*
* @since 4.1.2
*/
public class Detector : MonoBehaviour {
/** The current detector state.
* @since 4.1.2
*/
public bool IsActive{ get{ return _isActive;}}
private bool _isActive = false;
/** Dispatched when the detector activates (becomes true).
* @since 4.1.2
*/
[Tooltip("Dispatched when condition is detected.")]
public UnityEvent OnActivate;
/** Dispatched when the detector deactivates (becomes false).
* @since 4.1.2
*/
[Tooltip("Dispatched when condition is no longer detected.")]
public UnityEvent OnDeactivate;
/**
* Invoked when this detector activates.
* Subclasses must call this function when the detector's conditions become true.
* @since 4.1.2
*/
public virtual void Activate(){
if (!IsActive) {
_isActive = true;
OnActivate.Invoke();
}
}
/**
* Invoked when this detector deactivates.
* Subclasses must call this function when the detector's conditions change from true to false.
* @since 4.1.2
*/
public virtual void Deactivate(){
if (IsActive) {
_isActive = false;
OnDeactivate.Invoke();
}
}
//Gizmo colors
protected Color OnColor = Color.green;
protected Color OffColor = Color.red;
protected Color LimitColor = Color.blue;
protected Color DirectionColor = Color.white;
protected Color NormalColor = Color.gray;
}
}