10using System.Collections.Generic;
61 [Tooltip(
"Displays a representation of the interaction volume in the scene view")]
69 ReuseUpdateForPhysics,
70 ReusePhysicsForUpdate,
72 [Tooltip(
"When enabled, the provider will only calculate one leap frame instead of two.")]
81 [Tooltip(
"The mode to use when extrapolating physics.\n" +
82 " None - No extrapolation is used at all.\n" +
83 " Auto - Extrapolation is chosen based on the fixed timestep.\n" +
84 " Manual - Extrapolation time is chosen manually by the user.")]
88 [Tooltip(
"The amount of time (in seconds) to extrapolate the physics data by.")]
97 [Tooltip(
"[Service must be >= 4.9.2!] " +
98 "Which tracking mode to request that the service optimize for. " +
99 "(Use the LeapXRServiceProvider for HMD Mode instead of this option!)")]
104#if UNITY_2017_3_OR_NEWER
105 [Tooltip(
"When checked, profiling data from the LeapCSharp worker thread will be used to populate the UnityProfiler.")]
108 [Tooltip(
"Worker thread profiling requires a Unity version of 2017.3 or greater.")]
114 [Tooltip(
"Which Leap Service API Endpoint to connect to. This is configured on the service with the 'api_namespace' argument.")]
121 #region Internal Settings & Memory
126#if UNITY_ANDROID && !UNITY_EDITOR
148 #region Edit-time Frame Data
150 private Action<Device> _onDeviceSafe;
165 _onDeviceSafe += value;
168 _onDeviceSafe -= value;
173 private Frame _backingUntransformedEditTimeFrame =
null;
174 private Frame _untransformedEditTimeFrame {
176 if (_backingUntransformedEditTimeFrame ==
null) {
177 _backingUntransformedEditTimeFrame =
new Frame();
179 return _backingUntransformedEditTimeFrame;
182 private Frame _backingEditTimeFrame =
null;
183 private Frame _editTimeFrame {
185 if (_backingEditTimeFrame ==
null) {
186 _backingEditTimeFrame =
new Frame();
188 return _backingEditTimeFrame;
192 private Dictionary<TestHandFactory.TestHandPose,
Hand> _cachedLeftHands
193 =
new Dictionary<TestHandFactory.TestHandPose,
Hand>();
194 private Hand _editTimeLeftHand {
196 Hand cachedHand =
null;
197 if (_cachedLeftHands.TryGetValue(
editTimePose, out cachedHand)) {
201 cachedHand = TestHandFactory.MakeTestHand(isLeft:
true, pose:
editTimePose);
208 private Dictionary<TestHandFactory.TestHandPose,
Hand> _cachedRightHands
209 =
new Dictionary<TestHandFactory.TestHandPose,
Hand>();
210 private Hand _editTimeRightHand {
212 Hand cachedHand =
null;
213 if (_cachedRightHands.TryGetValue(
editTimePose, out cachedHand)) {
217 cachedHand = TestHandFactory.MakeTestHand(isLeft:
false, pose:
editTimePose);
228 #region LeapProvider Implementation
233 if (!Application.isPlaying) {
234 _editTimeFrame.
Hands.Clear();
235 _untransformedEditTimeFrame.Hands.Clear();
236 _untransformedEditTimeFrame.Hands.Add(_editTimeLeftHand);
237 _untransformedEditTimeFrame.Hands.Add(_editTimeRightHand);
239 return _editTimeFrame;
253 if (!Application.isPlaying) {
254 _editTimeFrame.
Hands.Clear();
255 _untransformedEditTimeFrame.Hands.Clear();
256 _untransformedEditTimeFrame.Hands.Add(_editTimeLeftHand);
257 _untransformedEditTimeFrame.Hands.Add(_editTimeRightHand);
259 return _editTimeFrame;
275 editTimePose = TestHandFactory.TestHandPose.DesktopModeA;
293 LeapProfiling.Update();
301 Debug.LogWarning(
"Unity hot reloading not currently supported. Stopping Editor Playback.");
314#if !UNITY_ANDROID || UNITY_EDITOR
358 throw new System.InvalidOperationException(
401 return Time.fixedDeltaTime;
405 throw new System.InvalidOperationException(
461 #region Internal Methods
464 #if UNITY_ANDROID && !UNITY_EDITOR
509 if (_onDeviceSafe !=
null) {
510 _onDeviceSafe(e.Device);
547 private int _framesSinceServiceConnectionChecked = 0;
548 private int _numberOfReconnectionAttempts = 0;
556 _framesSinceServiceConnectionChecked = 0;
557 _numberOfReconnectionAttempts = 0;
560 _framesSinceServiceConnectionChecked++;
563 _framesSinceServiceConnectionChecked = 0;
564 _numberOfReconnectionAttempts++;
566 Debug.LogWarning(
"Leap Service not connected; attempting to reconnect for try " +
587 dest.CopyFrom(source).Transform(transform.GetLeapMatrix());
The Controller class is your main interface to the Leap Motion Controller.
void StopConnection()
Stops the connection.
PolicyFlag
The supported controller policies.
Action< EndProfilingForThreadArgs > EndProfilingForThread
Dispatched whenever a thread is finished profiling. The event is always dispatched from the thread it...
long FrameTimestamp(int history=0)
Returns the timestamp of a recent tracking frame. Use the optional history parameter to specify how m...
void StartConnection()
Starts the connection.
Action< EndProfilingBlockArgs > EndProfilingBlock
Dispatched whenever a thread ends a profiling block. The event is always dispatched from the thread i...
Action< BeginProfilingForThreadArgs > BeginProfilingForThread
Dispatched whenever a thread wants to start profiling for a custom thread. The event is always dispat...
long Now()
Returns a timestamp value as close as possible to the current time. Values are in microseconds,...
Action< BeginProfilingBlockArgs > BeginProfilingBlock
Dispatched whenever a thread enters a profiling block. The event is always dispatched from the thread...
void ClearPolicy(PolicyFlag policy)
Requests clearing a policy.
void SetPolicy(PolicyFlag policy)
Requests setting a policy.
bool IsServiceConnected
Reports whether your application has a connection to the Leap Motion daemon/service....
DeviceList Devices
The list of currently attached and recognized Leap Motion controller devices.
Frame GetInterpolatedFrame(Int64 time)
Returns the Frame at the specified time, interpolating the data between existing frames,...
bool IsConnected
Reports whether this Controller is connected to the Leap Motion service and the Leap Motion hardware ...
Frame Frame(int history=0)
In most cases you should get Frame objects using the LeapProvider.CurrentFrame property....
EventHandler< DeviceEventArgs > Device
Dispatched when a Leap Motion device is connected.
void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceTime)
The Frame class represents a set of hand and finger tracking data detected in a single frame.
List< Hand > Hands
The list of Hand objects detected in this frame, given in arbitrary order. The list can be empty if n...
A generic object with no arguments beyond the event type.
Provides Frame object data to the Unity application by firing events as soon as Frame data is availab...
void DispatchUpdateFrameEvent(Frame frame)
TestHandPose editTimePose
void DispatchFixedFrameEvent(Frame frame)
The LeapServiceProvider provides tracked Leap Hand data and images from the device via the Leap servi...
virtual void transformFrame(Frame source, Frame dest)
SmoothedFloat _smoothedTrackingLatency
const double S_TO_NS
Converts seconds to nanoseconds.
InteractionVolumeVisualization _interactionVolumeVisualization
virtual void OnApplicationPause(bool isPaused)
Action< Device > OnDeviceSafe
A utility event to get a callback whenever a new device is connected to the service....
const int RECONNECTION_INTERVAL
The number of frames to wait between each reconnection attempt.
bool _workerThreadProfiling
float _physicsExtrapolationTime
virtual long CalculateInterpolationTime(bool endOfFrame=false)
FrameOptimizationMode _frameOptimization
Frame _transformedFixedFrame
override Frame CurrentFixedFrame
Frame _untransformedUpdateFrame
virtual void OnApplicationQuit()
Controller _leapController
void RetransformFrames()
Retransforms hand data from Leap space to the space of the Unity transform. This is only necessary if...
virtual void FixedUpdate()
Frame _untransformedFixedFrame
Controller GetLeapController()
Returns the Leap Controller instance.
const double NS_TO_S
Converts nanoseconds to seconds.
void onHandControllerConnect(object sender, LeapEventArgs args)
void destroyController()
Stops the connection for the existing instance of a Controller, clearing old policy flags and resetti...
Frame _transformedUpdateFrame
virtual void initializeFlags()
Initializes Leap Motion policy flags.
void createController()
Creates an instance of a Controller, initializing its policy flags and subscribing to its connection ...
SmoothedFloat _fixedOffset
InteractionVolumeVisualization
PhysicsExtrapolationMode _physicsExtrapolation
TrackingOptimizationMode _trackingOptimization
InteractionVolumeVisualization SelectedInteractionVolumeVisualization
override Frame CurrentFrame
const string HAND_ARRAY_GLOBAL_NAME
The transform array used for late-latching.
float CalculatePhysicsExtrapolation()
void CopySettingsToLeapXRServiceProvider(LeapXRServiceProvider leapXRServiceProvider)
Copies property settings from this LeapServiceProvider to the target LeapXRServiceProvider where appl...
bool IsConnected()
Returns true if the Leap Motion hardware is plugged in and this application is connected to the Leap ...
bool checkConnectionIntegrity()
Checks whether this provider is connected to a service; If it is not, attempt to reconnect at regular...
const int MAX_RECONNECTION_ATTEMPTS
The maximum number of times the provider will attempt to reconnect to the service before giving up.
The LeapXRServiceProvider expands on the standard LeapServiceProvider to account for the offset of th...
Time-step independent exponential smoothing.
void SetBlend(float blend, float deltaTime=1f)
float Update(float input, float deltaTime=1f)
A utility struct for ease of use when you want to wrap a piece of code in a Profiler....