I have been testing some things with the Leap Motion and Unity, using the provided UnitySandbox project and I am confused about some aspects of the LeapInput class.
I want to use C# delegates and events to pass information on gestures to another script whenever they occur. In the LeapInput class, comments say that event handling can be placed directly in the class. However, when I try to enable events on the static m_controller class, they don't seem to register.
Yet, when I have a separate script that inherits from MonoBehaviour that declares an instance of the Leap Controller class like so:
using UnityEngine;
using System.Collections;
using Leap;
public class LeapToUnityInterface : MonoBehaviour {
Leap.Controller controller;
#region delegates
#endregion
#region events
#endregion
// Use this for initialization
void Start ()
{
controller = new Controller();
controller.EnableGesture(Gesture.GestureType.TYPECIRCLE);
controller.EnableGesture(Gesture.GestureType.TYPEINVALID);
controller.EnableGesture(Gesture.GestureType.TYPEKEYTAP);
controller.EnableGesture(Gesture.GestureType.TYPESCREENTAP);
controller.EnableGesture(Gesture.GestureType.TYPESWIPE);
}
Then, when I check for events in Update they seem to register fine:
// Update is called once per frame
void Update ()
{
Frame frame = controller.Frame();
foreach (Gesture gesture in frame.Gestures())
{
switch(gesture.Type)
{
case(Gesture.GestureType.TYPECIRCLE):
{
Debug.Log("Circle gesture recognized.");
break;
}
case(Gesture.GestureType.TYPEINVALID):
{
Debug.Log("Invalid gesture recognized.");
break;
}
case(Gesture.GestureType.TYPEKEYTAP):
{
Debug.Log("Key Tap gesture recognized.");
break;
}
case(Gesture.GestureType.TYPESCREENTAP):
{
Debug.Log("Screen tap gesture recognized.");
break;
}
case(Gesture.GestureType.TYPESWIPE):
{
Debug.Log("Swipe gesture recognized.");
break;
}
default:
{
break;
}
}
}
}
My question is two part: Why, when I try to enable events for the static m_controller in either a static start or static awake, does it not succeed? And why, when I enable events on an just an instance of the Leap.Controller event class does that succed(i.e. how does that change register with the controller that is interfacing with the Leap?)?