net.dreditor.chartweener 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/CharTween.asmdef CHANGED
@@ -1,17 +1,17 @@
1
- {
2
- "name": "CharTween",
3
- "rootNamespace": "",
4
- "references": [
5
- "DG.Tweening",
6
- "Unity.TextMeshPro"
7
- ],
8
- "includePlatforms": [],
9
- "excludePlatforms": [],
10
- "allowUnsafeCode": false,
11
- "overrideReferences": false,
12
- "precompiledReferences": [],
13
- "autoReferenced": true,
14
- "defineConstraints": [],
15
- "versionDefines": [],
16
- "noEngineReferences": false
1
+ {
2
+ "name": "CharTween",
3
+ "rootNamespace": "",
4
+ "references": [
5
+ "DG.Tweening",
6
+ "Unity.TextMeshPro"
7
+ ],
8
+ "includePlatforms": [],
9
+ "excludePlatforms": [],
10
+ "allowUnsafeCode": false,
11
+ "overrideReferences": false,
12
+ "precompiledReferences": [],
13
+ "autoReferenced": true,
14
+ "defineConstraints": [],
15
+ "versionDefines": [],
16
+ "noEngineReferences": false
17
17
  }
@@ -1,7 +1,7 @@
1
- fileFormatVersion: 2
2
- guid: b25d0b1823e671e48a2493fb15cb8f5b
3
- AssemblyDefinitionImporter:
4
- externalObjects: {}
5
- userData:
6
- assetBundleName:
7
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: b25d0b1823e671e48a2493fb15cb8f5b
3
+ AssemblyDefinitionImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
@@ -1,237 +1,237 @@
1
- //Author: Copyright (c) 2021 Matthew Dechatech under MIT License
2
- #if DOTWEEN
3
- using System;
4
- using DG.Tweening;
5
- using UnityEngine;
6
- using Random = UnityEngine.Random;
7
-
8
- namespace CharTween
9
- {
10
- // Contains tweens that don't exist in DOTween and are included as extra utilities
11
- public partial class CharTweener : MonoBehaviour
12
- {
13
- /// <summary></summary>
14
- /// <param name="charIndex"></param>
15
- /// <param name="endValue"></param>
16
- /// <param name="duration"></param>
17
- /// <param name="snapping"></param>
18
- public Tweener DOOffsetMove(int charIndex, Vector3 endValue, float duration, bool snapping = false)
19
- {
20
- NotifyActiveTransformTween();
21
- ProxyTransform proxy = GetProxyTransform(charIndex);
22
- return proxy.AddTween(proxy.Target.DOLocalMove(endValue, duration, snapping));
23
- }
24
-
25
- /// <summary></summary>
26
- /// <param name="charIndex"></param>
27
- /// <param name="endValue"></param>
28
- /// <param name="duration"></param>
29
- /// <param name="snapping"></param>
30
- public Tweener DOOffsetMoveX(int charIndex, float endValue, float duration, bool snapping = false)
31
- {
32
- NotifyActiveTransformTween();
33
- ProxyTransform proxy = GetProxyTransform(charIndex);
34
- return proxy.AddTween(proxy.Target.DOLocalMoveX(endValue, duration, snapping));
35
- }
36
-
37
- /// <summary></summary>
38
- /// <param name="charIndex"></param>
39
- /// <param name="endValue"></param>
40
- /// <param name="duration"></param>
41
- /// <param name="snapping"></param>
42
- public Tweener DOOffsetMoveY(int charIndex, float endValue, float duration, bool snapping = false)
43
- {
44
- NotifyActiveTransformTween();
45
- ProxyTransform proxy = GetProxyTransform(charIndex);
46
- return proxy.AddTween(proxy.Target.DOLocalMoveY(endValue, duration, snapping));
47
- }
48
-
49
- /// <summary></summary>
50
- /// <param name="charIndex"></param>
51
- /// <param name="endValue"></param>
52
- /// <param name="duration"></param>
53
- /// <param name="snapping"></param>
54
- public Tweener DOOffsetMoveZ(int charIndex, float endValue, float duration, bool snapping = false)
55
- {
56
- NotifyActiveTransformTween();
57
- ProxyTransform proxy = GetProxyTransform(charIndex);
58
- return proxy.AddTween(proxy.Target.DOLocalMoveZ(endValue, duration, snapping));
59
- }
60
-
61
- /// <summary>
62
- ///
63
- /// </summary>
64
- /// <param name="charIndex"></param>
65
- /// <param name="radius"></param>
66
- /// <param name="duration"></param>
67
- /// <returns></returns>
68
- public Tweener DOMoveCircle(int charIndex, float radius, float duration)
69
- {
70
- NotifyActiveTransformTween();
71
- ProxyTransform proxy = GetProxyTransform(charIndex);
72
- DOMoveCircleHandler handler = new DOMoveCircleHandler(proxy.Target, radius, duration);
73
- return proxy.AddTween(DOTween.To(handler.GetTime, handler.SetTime, duration, duration)
74
- .SetEase(Ease.Linear)
75
- .SetTarget(proxy.Target));
76
- }
77
-
78
- /// <summary>
79
- ///
80
- /// </summary>
81
- /// <param name="charIndex"></param>
82
- /// <param name="strength"></param>
83
- /// <param name="vibrato"></param>
84
- /// <param name="fadeInDuration"></param>
85
- /// <returns></returns>
86
- public Tweener DODriftPosition(int charIndex, Vector3 strength, Vector3 vibrato, float fadeInDuration = 1)
87
- {
88
- NotifyActiveTransformTween();
89
- ProxyTransform proxy = GetProxyTransform(charIndex);
90
- DODriftPositionHandler handler = new DODriftPositionHandler(proxy.Target, strength, vibrato);
91
- return proxy.AddTween(DOTween.To(handler.GetTime, handler.SetTime, DriftTime, DriftTime)
92
- .SetEase(Ease.Linear)
93
- .SetTarget(proxy.Target));
94
- }
95
-
96
- /// <summary>
97
- ///
98
- /// </summary>
99
- /// <param name="charIndex"></param>
100
- /// <param name="strength"></param>
101
- /// <param name="vibrato"></param>
102
- /// <param name="fadeInDuration"></param>
103
- /// <returns></returns>
104
- public Tweener DODriftRotation(int charIndex, Vector3 strength, Vector3 vibrato, float fadeInDuration = 1)
105
- {
106
- NotifyActiveTransformTween();
107
- ProxyTransform proxy = GetProxyTransform(charIndex);
108
- DODriftRotationHandler handler = new DODriftRotationHandler(proxy.Target, strength, vibrato);
109
- return proxy.AddTween(DOTween.To(handler.GetTime, handler.SetTime, DriftTime, DriftTime)
110
- .SetEase(Ease.Linear)
111
- .SetTarget(proxy.Target));
112
- }
113
-
114
- // Helper classes
115
- private class DOMoveCircleHandler
116
- {
117
- public Transform Target;
118
- public float Radius;
119
- public float Duration;
120
-
121
- public float Time;
122
-
123
- public DOMoveCircleHandler(Transform target, float radius, float duration)
124
- {
125
- Target = target;
126
- Radius = radius;
127
- Duration = duration;
128
- }
129
-
130
- public float GetTime()
131
- {
132
- return Time;
133
- }
134
-
135
- public void SetTime(float value)
136
- {
137
- Time = value;
138
- float angle = Mathf.Lerp(0, 2 * Mathf.PI, Time / Duration);
139
- Target.localPosition = new Vector3(Mathf.Cos(angle) * Radius, Mathf.Sin(angle) * Radius, 0);
140
- }
141
- }
142
-
143
- private const float DriftTime = 10000f;
144
- private class DODriftPositionHandler
145
- {
146
- public Transform Target;
147
- public Vector3 Strength;
148
- public Vector3 Vibrato;
149
- public float FadeInDuration;
150
-
151
- public float Time;
152
-
153
- private float seedX;
154
- private float seedY;
155
- private float seedZ;
156
-
157
- public DODriftPositionHandler(Transform target, Vector3 strength, Vector3 vibrato, float fadeInDuration = 1)
158
- {
159
- Target = target;
160
- Strength = strength;
161
- Vibrato = vibrato;
162
- FadeInDuration = fadeInDuration;
163
-
164
- seedX = Random.Range(0f, 1000f);
165
- seedY = Random.Range(0f, 1000f);
166
- seedZ = Random.Range(0f, 1000f);
167
- }
168
-
169
- public float GetTime()
170
- {
171
- return Time;
172
- }
173
-
174
- public void SetTime(float time)
175
- {
176
- Time = time;
177
- float fadeIn = Mathf.Clamp01(Time / Mathf.Max(0.0001f, FadeInDuration));
178
- Target.localPosition = new Vector3(
179
- (Mathf.PerlinNoise(Time * Vibrato.x, seedX) * 2 - 1) * Strength.x * fadeIn,
180
- (Mathf.PerlinNoise(Time * Vibrato.y, seedY) * 2 - 1) * Strength.y * fadeIn,
181
- (Mathf.PerlinNoise(Time * Vibrato.z, seedZ) * 2 - 1) * Strength.z * fadeIn
182
- );
183
-
184
- // If completing the tween, return character to start position
185
- if (time == DriftTime)
186
- Target.localPosition = Vector3.zero;
187
- }
188
- }
189
-
190
- private class DODriftRotationHandler
191
- {
192
- public Transform Target;
193
- public Vector3 Strength;
194
- public Vector3 Vibrato;
195
- public float FadeInDuration;
196
-
197
- public float Time;
198
-
199
- private float seedX;
200
- private float seedY;
201
- private float seedZ;
202
-
203
- public DODriftRotationHandler(Transform target, Vector3 strength, Vector3 vibrato, float fadeInDuration = 1)
204
- {
205
- Target = target;
206
- Strength = strength;
207
- Vibrato = vibrato;
208
- FadeInDuration = fadeInDuration;
209
-
210
- seedX = Random.Range(0f, 1000f);
211
- seedY = Random.Range(0f, 1000f);
212
- seedZ = Random.Range(0f, 1000f);
213
- }
214
-
215
- public float GetTime()
216
- {
217
- return Time;
218
- }
219
-
220
- public void SetTime(float time)
221
- {
222
- Time = time;
223
- float fadeIn = Mathf.Clamp01(Time / Mathf.Max(0.0001f, FadeInDuration));
224
- Target.localEulerAngles = new Vector3(
225
- (Mathf.PerlinNoise(Time * Vibrato.x, seedX) * 2 - 1) * Strength.x * fadeIn,
226
- (Mathf.PerlinNoise(Time * Vibrato.y, seedY) * 2 - 1) * Strength.y * fadeIn,
227
- (Mathf.PerlinNoise(Time * Vibrato.z, seedZ) * 2 - 1) * Strength.z * fadeIn
228
- );
229
-
230
- // If completing the tween, return character to original rotation
231
- if (time == DriftTime)
232
- Target.localEulerAngles = Vector3.zero;
233
- }
234
- }
235
- }
236
- }
1
+ //Author: Copyright (c) 2021 Matthew Dechatech under MIT License
2
+ #if DOTWEEN
3
+ using System;
4
+ using DG.Tweening;
5
+ using UnityEngine;
6
+ using Random = UnityEngine.Random;
7
+
8
+ namespace CharTween
9
+ {
10
+ // Contains tweens that don't exist in DOTween and are included as extra utilities
11
+ public partial class CharTweener : MonoBehaviour
12
+ {
13
+ /// <summary></summary>
14
+ /// <param name="charIndex"></param>
15
+ /// <param name="endValue"></param>
16
+ /// <param name="duration"></param>
17
+ /// <param name="snapping"></param>
18
+ public Tweener DOOffsetMove(int charIndex, Vector3 endValue, float duration, bool snapping = false)
19
+ {
20
+ NotifyActiveTransformTween();
21
+ ProxyTransform proxy = GetProxyTransform(charIndex);
22
+ return proxy.AddTween(proxy.Target.DOLocalMove(endValue, duration, snapping));
23
+ }
24
+
25
+ /// <summary></summary>
26
+ /// <param name="charIndex"></param>
27
+ /// <param name="endValue"></param>
28
+ /// <param name="duration"></param>
29
+ /// <param name="snapping"></param>
30
+ public Tweener DOOffsetMoveX(int charIndex, float endValue, float duration, bool snapping = false)
31
+ {
32
+ NotifyActiveTransformTween();
33
+ ProxyTransform proxy = GetProxyTransform(charIndex);
34
+ return proxy.AddTween(proxy.Target.DOLocalMoveX(endValue, duration, snapping));
35
+ }
36
+
37
+ /// <summary></summary>
38
+ /// <param name="charIndex"></param>
39
+ /// <param name="endValue"></param>
40
+ /// <param name="duration"></param>
41
+ /// <param name="snapping"></param>
42
+ public Tweener DOOffsetMoveY(int charIndex, float endValue, float duration, bool snapping = false)
43
+ {
44
+ NotifyActiveTransformTween();
45
+ ProxyTransform proxy = GetProxyTransform(charIndex);
46
+ return proxy.AddTween(proxy.Target.DOLocalMoveY(endValue, duration, snapping));
47
+ }
48
+
49
+ /// <summary></summary>
50
+ /// <param name="charIndex"></param>
51
+ /// <param name="endValue"></param>
52
+ /// <param name="duration"></param>
53
+ /// <param name="snapping"></param>
54
+ public Tweener DOOffsetMoveZ(int charIndex, float endValue, float duration, bool snapping = false)
55
+ {
56
+ NotifyActiveTransformTween();
57
+ ProxyTransform proxy = GetProxyTransform(charIndex);
58
+ return proxy.AddTween(proxy.Target.DOLocalMoveZ(endValue, duration, snapping));
59
+ }
60
+
61
+ /// <summary>
62
+ ///
63
+ /// </summary>
64
+ /// <param name="charIndex"></param>
65
+ /// <param name="radius"></param>
66
+ /// <param name="duration"></param>
67
+ /// <returns></returns>
68
+ public Tweener DOMoveCircle(int charIndex, float radius, float duration)
69
+ {
70
+ NotifyActiveTransformTween();
71
+ ProxyTransform proxy = GetProxyTransform(charIndex);
72
+ DOMoveCircleHandler handler = new DOMoveCircleHandler(proxy.Target, radius, duration);
73
+ return proxy.AddTween(DOTween.To(handler.GetTime, handler.SetTime, duration, duration)
74
+ .SetEase(Ease.Linear)
75
+ .SetTarget(proxy.Target));
76
+ }
77
+
78
+ /// <summary>
79
+ ///
80
+ /// </summary>
81
+ /// <param name="charIndex"></param>
82
+ /// <param name="strength"></param>
83
+ /// <param name="vibrato"></param>
84
+ /// <param name="fadeInDuration"></param>
85
+ /// <returns></returns>
86
+ public Tweener DODriftPosition(int charIndex, Vector3 strength, Vector3 vibrato, float fadeInDuration = 1)
87
+ {
88
+ NotifyActiveTransformTween();
89
+ ProxyTransform proxy = GetProxyTransform(charIndex);
90
+ DODriftPositionHandler handler = new DODriftPositionHandler(proxy.Target, strength, vibrato);
91
+ return proxy.AddTween(DOTween.To(handler.GetTime, handler.SetTime, DriftTime, DriftTime)
92
+ .SetEase(Ease.Linear)
93
+ .SetTarget(proxy.Target));
94
+ }
95
+
96
+ /// <summary>
97
+ ///
98
+ /// </summary>
99
+ /// <param name="charIndex"></param>
100
+ /// <param name="strength"></param>
101
+ /// <param name="vibrato"></param>
102
+ /// <param name="fadeInDuration"></param>
103
+ /// <returns></returns>
104
+ public Tweener DODriftRotation(int charIndex, Vector3 strength, Vector3 vibrato, float fadeInDuration = 1)
105
+ {
106
+ NotifyActiveTransformTween();
107
+ ProxyTransform proxy = GetProxyTransform(charIndex);
108
+ DODriftRotationHandler handler = new DODriftRotationHandler(proxy.Target, strength, vibrato);
109
+ return proxy.AddTween(DOTween.To(handler.GetTime, handler.SetTime, DriftTime, DriftTime)
110
+ .SetEase(Ease.Linear)
111
+ .SetTarget(proxy.Target));
112
+ }
113
+
114
+ // Helper classes
115
+ private class DOMoveCircleHandler
116
+ {
117
+ public Transform Target;
118
+ public float Radius;
119
+ public float Duration;
120
+
121
+ public float Time;
122
+
123
+ public DOMoveCircleHandler(Transform target, float radius, float duration)
124
+ {
125
+ Target = target;
126
+ Radius = radius;
127
+ Duration = duration;
128
+ }
129
+
130
+ public float GetTime()
131
+ {
132
+ return Time;
133
+ }
134
+
135
+ public void SetTime(float value)
136
+ {
137
+ Time = value;
138
+ float angle = Mathf.Lerp(0, 2 * Mathf.PI, Time / Duration);
139
+ Target.localPosition = new Vector3(Mathf.Cos(angle) * Radius, Mathf.Sin(angle) * Radius, 0);
140
+ }
141
+ }
142
+
143
+ private const float DriftTime = 10000f;
144
+ private class DODriftPositionHandler
145
+ {
146
+ public Transform Target;
147
+ public Vector3 Strength;
148
+ public Vector3 Vibrato;
149
+ public float FadeInDuration;
150
+
151
+ public float Time;
152
+
153
+ private float seedX;
154
+ private float seedY;
155
+ private float seedZ;
156
+
157
+ public DODriftPositionHandler(Transform target, Vector3 strength, Vector3 vibrato, float fadeInDuration = 1)
158
+ {
159
+ Target = target;
160
+ Strength = strength;
161
+ Vibrato = vibrato;
162
+ FadeInDuration = fadeInDuration;
163
+
164
+ seedX = Random.Range(0f, 1000f);
165
+ seedY = Random.Range(0f, 1000f);
166
+ seedZ = Random.Range(0f, 1000f);
167
+ }
168
+
169
+ public float GetTime()
170
+ {
171
+ return Time;
172
+ }
173
+
174
+ public void SetTime(float time)
175
+ {
176
+ Time = time;
177
+ float fadeIn = Mathf.Clamp01(Time / Mathf.Max(0.0001f, FadeInDuration));
178
+ Target.localPosition = new Vector3(
179
+ (Mathf.PerlinNoise(Time * Vibrato.x, seedX) * 2 - 1) * Strength.x * fadeIn,
180
+ (Mathf.PerlinNoise(Time * Vibrato.y, seedY) * 2 - 1) * Strength.y * fadeIn,
181
+ (Mathf.PerlinNoise(Time * Vibrato.z, seedZ) * 2 - 1) * Strength.z * fadeIn
182
+ );
183
+
184
+ // If completing the tween, return character to start position
185
+ if (time == DriftTime)
186
+ Target.localPosition = Vector3.zero;
187
+ }
188
+ }
189
+
190
+ private class DODriftRotationHandler
191
+ {
192
+ public Transform Target;
193
+ public Vector3 Strength;
194
+ public Vector3 Vibrato;
195
+ public float FadeInDuration;
196
+
197
+ public float Time;
198
+
199
+ private float seedX;
200
+ private float seedY;
201
+ private float seedZ;
202
+
203
+ public DODriftRotationHandler(Transform target, Vector3 strength, Vector3 vibrato, float fadeInDuration = 1)
204
+ {
205
+ Target = target;
206
+ Strength = strength;
207
+ Vibrato = vibrato;
208
+ FadeInDuration = fadeInDuration;
209
+
210
+ seedX = Random.Range(0f, 1000f);
211
+ seedY = Random.Range(0f, 1000f);
212
+ seedZ = Random.Range(0f, 1000f);
213
+ }
214
+
215
+ public float GetTime()
216
+ {
217
+ return Time;
218
+ }
219
+
220
+ public void SetTime(float time)
221
+ {
222
+ Time = time;
223
+ float fadeIn = Mathf.Clamp01(Time / Mathf.Max(0.0001f, FadeInDuration));
224
+ Target.localEulerAngles = new Vector3(
225
+ (Mathf.PerlinNoise(Time * Vibrato.x, seedX) * 2 - 1) * Strength.x * fadeIn,
226
+ (Mathf.PerlinNoise(Time * Vibrato.y, seedY) * 2 - 1) * Strength.y * fadeIn,
227
+ (Mathf.PerlinNoise(Time * Vibrato.z, seedZ) * 2 - 1) * Strength.z * fadeIn
228
+ );
229
+
230
+ // If completing the tween, return character to original rotation
231
+ if (time == DriftTime)
232
+ Target.localEulerAngles = Vector3.zero;
233
+ }
234
+ }
235
+ }
236
+ }
237
237
  #endif
@@ -1,2 +1,2 @@
1
- fileFormatVersion: 2
1
+ fileFormatVersion: 2
2
2
  guid: 47968b0c440a2b544ae55bdbaa05f42c