Tanoda
ValueInterpolators.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
12namespace Leap.Unity.Animation {
13 using Internal;
14
15 public partial struct Tween {
16
17 #region FLOAT
18 public Tween Value(float a, float b, Action<float> onValue) {
19 AddInterpolator(Pool<FloatInterpolator>.Spawn().Init(a, b, onValue));
20 return this;
21 }
22
23 private class FloatInterpolator : FloatInterpolatorBase<Action<float>> {
24 public override void Interpolate(float percent) {
25 _target(_a + _b * percent);
26 }
27
28 public override void Dispose() {
29 _target = null;
30 Pool<FloatInterpolator>.Recycle(this);
31 }
32
33 public override bool isValid { get { return true; } }
34 }
35 #endregion
36
37 #region VECTOR2
38 public Tween Value(Vector2 a, Vector2 b, Action<Vector2> onValue) {
39 AddInterpolator(Pool<Vector2Interpolator>.Spawn().Init(a, b, onValue));
40 return this;
41 }
42
43 private class Vector2Interpolator : Vector2InterpolatorBase<Action<Vector2>> {
44 public override void Interpolate(float percent) {
45 _target(_a + _b * percent);
46 }
47
48 public override void Dispose() {
49 _target = null;
50 Pool<Vector2Interpolator>.Recycle(this);
51 }
52
53 public override bool isValid { get { return true; } }
54 }
55 #endregion
56
57 #region VECTOR3
58 public Tween Value(Vector3 a, Vector3 b, Action<Vector3> onValue) {
59 AddInterpolator(Pool<Vector3Interpolator>.Spawn().Init(a, b, onValue));
60 return this;
61 }
62
63 private class Vector3Interpolator : Vector3InterpolatorBase<Action<Vector3>> {
64 public override void Interpolate(float percent) {
65 _target(_a + _b * percent);
66 }
67
68 public override void Dispose() {
69 _target = null;
70 Pool<Vector3Interpolator>.Recycle(this);
71 }
72
73 public override bool isValid { get { return true; } }
74 }
75 #endregion
76
77 #region QUATERNION
78 public Tween Value(Quaternion a, Quaternion b, Action<Quaternion> onValue) {
79 AddInterpolator(Pool<QuaternionInterpolator>.Spawn().Init(a, b, onValue));
80 return this;
81 }
82
83 private class QuaternionInterpolator : QuaternionInterpolatorBase<Action<Quaternion>> {
84 public override void Interpolate(float percent) {
85 _target(Quaternion.Slerp(_a, _b, percent));
86 }
87
88 public override void Dispose() {
89 _target = null;
90 Pool<QuaternionInterpolator>.Recycle(this);
91 }
92
93 public override bool isValid { get { return true; } }
94 }
95 #endregion
96
97 #region COLOR
98 public Tween Value(Color a, Color b, Action<Color> onValue) {
99 AddInterpolator(Pool<ColorInterpolator>.Spawn().Init(a, b, onValue));
100 return this;
101 }
102
103 private class ColorInterpolator : ColorInterpolatorBase<Action<Color>> {
104 public override void Interpolate(float percent) {
105 _target(_a + _b * percent);
106 }
107
108 public override void Dispose() {
109 _target = null;
110 Pool<ColorInterpolator>.Recycle(this);
111 }
112
113 public override bool isValid { get { return true; } }
114 }
115 #endregion
116 }
117}
UnityEngine.Color Color
Definition: TestScript.cs:32
Tween AddInterpolator(IInterpolator interpolator)
Adds a new Interpolator to this Tween. This Interpolator will have it's Interpolate method called eve...
Definition: Tween.cs:151
Tween Value(Quaternion a, Quaternion b, Action< Quaternion > onValue)
Tween Value(Vector2 a, Vector2 b, Action< Vector2 > onValue)
Tween Value(float a, float b, Action< float > onValue)
bool isValid
Returns whether or not this Tween is considered valid. A Tween can become invalid under the following...
Definition: Tween.cs:54
Tween Value(Color a, Color b, Action< Color > onValue)
Tween Value(Vector3 a, Vector3 b, Action< Vector3 > onValue)