Tanoda
InterpolatorBases.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
14 public abstract class InterpolatorBase<ValueType, ObjType> : IInterpolator {
15 protected ValueType _a, _b;
16 protected ObjType _target;
17
18 public InterpolatorBase<ValueType, ObjType> Init(ValueType a, ValueType b, ObjType target) {
19 _a = a;
20 _b = b;
21 _target = target;
22 return this;
23 }
24
25 public abstract float length { get; }
26
27 public abstract void Interpolate(float percent);
28
29 public abstract bool isValid { get; }
30
31 public void OnSpawn() { }
32
33 public void OnRecycle() { }
34
35 public abstract void Dispose();
36 }
37
38 public abstract class FloatInterpolatorBase<ObjType> : InterpolatorBase<float, ObjType> {
39 public override float length {
40 get {
41 return Mathf.Abs(_b);
42 }
43 }
44
45 public new FloatInterpolatorBase<ObjType> Init(float a, float b, ObjType target) {
46 _a = a;
47 _b = b - a;
48 _target = target;
49 return this;
50 }
51 }
52
53 public abstract class Vector2InterpolatorBase<ObjType> : InterpolatorBase<Vector2, ObjType> {
54 public override float length {
55 get {
56 return _b.magnitude;
57 }
58 }
59
60 public new Vector2InterpolatorBase<ObjType> Init(Vector2 a, Vector2 b, ObjType target) {
61 _a = a;
62 _b = b - a;
63 _target = target;
64 return this;
65 }
66 }
67
68 public abstract class Vector3InterpolatorBase<ObjType> : InterpolatorBase<Vector3, ObjType> {
69 public override float length {
70 get {
71 return _b.magnitude;
72 }
73 }
74
75 public new Vector3InterpolatorBase<ObjType> Init(Vector3 a, Vector3 b, ObjType target) {
76 _a = a;
77 _b = b - a;
78 _target = target;
79 return this;
80 }
81 }
82
83 public abstract class Vector4InterpolatorBase<ObjType> : InterpolatorBase<Vector4, ObjType> {
84 public override float length {
85 get {
86 return _b.magnitude;
87 }
88 }
89
90 public new Vector4InterpolatorBase<ObjType> Init(Vector4 a, Vector4 b, ObjType target) {
91 _a = a;
92 _b = b - a;
93 _target = target;
94 return this;
95 }
96 }
97
98 public abstract class QuaternionInterpolatorBase<ObjType> : InterpolatorBase<Quaternion, ObjType> {
99 public override float length {
100 get {
101 return Quaternion.Angle(_a, _b);
102 }
103 }
104
105 public new QuaternionInterpolatorBase<ObjType> Init(Quaternion a, Quaternion b, ObjType target) {
106 _a = a;
107 _b = b;
108 _target = target;
109 return this;
110 }
111 }
112
113 public abstract class ColorInterpolatorBase<ObjType> : InterpolatorBase<Color, ObjType> {
114 public override float length {
115 get {
116 return ((Vector4)_b).magnitude;
117 }
118 }
119
120 public new ColorInterpolatorBase<ObjType> Init(Color a, Color b, ObjType target) {
121 _a = a;
122 _b = b - a;
123 _target = target;
124 return this;
125 }
126 }
127
128 public abstract class GradientInterpolatorBase : IInterpolator {
129
130 protected Gradient _gradient;
131
132 public GradientInterpolatorBase Init(Gradient gradient) {
133 _gradient = gradient;
134 return this;
135 }
136
137 public float length { get { return 1; } }
138
139 public abstract void Interpolate(float percent);
140 public abstract bool isValid { get; }
141
142 public void OnSpawn() { }
143
144 public void Dispose() { }
145
146 public void OnRecycle() { }
147 }
148
149}
UnityEngine.Color Color
Definition: TestScript.cs:32
new ColorInterpolatorBase< ObjType > Init(Color a, Color b, ObjType target)
new FloatInterpolatorBase< ObjType > Init(float a, float b, ObjType target)
abstract bool isValid
Returns whether or not this interpolator is currently considered valid. Any invalid interpolators wil...
abstract void Interpolate(float percent)
Called to trigger the interpolation of this interpolator. Use this callback to do whatever work your ...
GradientInterpolatorBase Init(Gradient gradient)
float length
Returns the 'length' of this interpolator, in whatever units make sense for this interpolator....
abstract bool isValid
Returns whether or not this interpolator is currently considered valid. Any invalid interpolators wil...
InterpolatorBase< ValueType, ObjType > Init(ValueType a, ValueType b, ObjType target)
abstract float length
Returns the 'length' of this interpolator, in whatever units make sense for this interpolator....
abstract void Interpolate(float percent)
Called to trigger the interpolation of this interpolator. Use this callback to do whatever work your ...
new QuaternionInterpolatorBase< ObjType > Init(Quaternion a, Quaternion b, ObjType target)
new Vector2InterpolatorBase< ObjType > Init(Vector2 a, Vector2 b, ObjType target)
new Vector3InterpolatorBase< ObjType > Init(Vector3 a, Vector3 b, ObjType target)
new Vector4InterpolatorBase< ObjType > Init(Vector4 a, Vector4 b, ObjType target)
Implement this interface to add your own interpolators to Tween!