Tanoda
PlaybackProvider.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
9using UnityEngine;
10using System;
11
13
15
16 public override Frame CurrentFrame {
17 get {
18 return _transformedFrame;
19 }
20 }
21
22 public override Frame CurrentFixedFrame {
23 get {
24 return CurrentFrame;
25 }
26 }
27
28 [SerializeField]
30
31 [SerializeField]
33
34 [SerializeField]
35 protected bool _autoPlay = true;
36
37 protected bool _isPlaying = false;
38 protected int _currentFrameIndex = 0;
39 protected float _startTime = 0;
40
41 protected Frame _transformedFrame = new Frame();
42
43 public virtual bool IsPlaying {
44 get {
45 return _isPlaying;
46 }
47 }
48
49 public virtual Recording recording {
50 get {
51 return _recording;
52 }
53 set {
54 Stop();
55 _recording = value;
56 }
57 }
58
59 public virtual void Play() {
61
62 switch (_playbackTimeline) {
63 case PlaybackTimeline.Graphics:
64 _startTime = Time.time - delta;
65 break;
66 case PlaybackTimeline.Physics:
67 _startTime = Time.fixedTime - delta;
68 break;
69 }
70
71 _isPlaying = true;
72 }
73
74 public virtual void Pause() {
75 _isPlaying = false;
76 }
77
78 public virtual void Stop() {
79 Pause();
80 if (_recording != null) {
81 Seek(0);
82 }
83 }
84
85 public virtual void Seek(int newFrameIndex) {
86 newFrameIndex = Mathf.Clamp(newFrameIndex, 0, _recording.frames.Count - 1);
87 if (newFrameIndex == _currentFrameIndex) {
88 return;
89 }
90
91 _currentFrameIndex = newFrameIndex;
92
93 _transformedFrame.CopyFrom(_recording.frames[_currentFrameIndex]).Transform(new LeapTransform(transform.position.ToVector(), transform.rotation.ToLeapQuaternion(), transform.lossyScale.ToVector()));
94 }
95
96 protected virtual void Start() {
97 if (_autoPlay) {
98 Play();
99 }
100 }
101
102 protected virtual void Update() {
103 if (_isPlaying) {
104 if (_playbackTimeline == PlaybackTimeline.Graphics) {
105 stepRecording(Time.time - _startTime);
106 }
108 }
109 }
110
111 protected virtual void FixedUpdate() {
112 if (_isPlaying) {
113 if (_playbackTimeline == PlaybackTimeline.Physics) {
114 stepRecording(Time.fixedTime - _startTime);
115 }
117 }
118 }
119
120 private void stepRecording(float time) {
121 while (true) {
122 if (_currentFrameIndex >= _recording.frames.Count - 1) {
123 Pause();
124 break;
125 }
126
128 if (time > crossover) {
130 } else {
131 break;
132 }
133 }
134 }
135
136 public enum PlaybackTimeline {
137 Graphics,
138 Physics
139 }
140 }
141}
The Frame class represents a set of hand and finger tracking data detected in a single frame.
Definition: Frame.cs:24
Provides Frame object data to the Unity application by firing events as soon as Frame data is availab...
Definition: LeapProvider.cs:21
void DispatchUpdateFrameEvent(Frame frame)
Definition: LeapProvider.cs:49
void DispatchFixedFrameEvent(Frame frame)
Definition: LeapProvider.cs:58
virtual void Seek(int newFrameIndex)
The LeapTransform class represents a transform in three dimensional space.