Skip to content

Commit 0514ddf

Browse files
committed
feat: Clean up transfer tweener
1 parent e59dbc3 commit 0514ddf

File tree

3 files changed

+43
-51
lines changed

3 files changed

+43
-51
lines changed

Assets/JCSUnity/Scripts/Effects/Particle/Type/JCS_TowardTarget.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class JCS_TowardTarget : JCS_Particle
2121
/* Variables */
2222

2323
// tweener effect to the object.
24-
private JCS_TransformTweener mJCSTweener = null;
24+
private JCS_TransformTweener mTweener = null;
2525

2626
// when reach the certain range disable it.
2727
private JCS_DisableWithCertainRangeEvent mDisableWidthCertainRangeEvent = null;
@@ -66,11 +66,11 @@ public void SetTarget(JCS_UnityObject trans)
6666

6767
private void Awake()
6868
{
69-
this.mJCSTweener = this.GetComponent<JCS_TransformTweener>();
69+
this.mTweener = this.GetComponent<JCS_TransformTweener>();
7070
this.mDisableWidthCertainRangeEvent = this.GetComponent<JCS_DisableWithCertainRangeEvent>();
7171

7272
// set destination callback.
73-
mJCSTweener.SetCallback(DestinationCallback);
73+
mTweener.onDone = DestinationCallback;
7474
}
7575

7676
private void OnEnable()
@@ -100,23 +100,23 @@ private void OnEnable()
100100
else
101101
{
102102
// set the target transform.
103-
this.mJCSTweener.SetTarget(this.mTarget);
103+
this.mTweener.SetTarget(this.mTarget);
104104
this.mDisableWidthCertainRangeEvent.SetTarget(this.mTarget);
105105

106106
// starting position.
107107
SetPosition(newPos);
108108
}
109109

110-
mJCSTweener.UpdateUnityData();
110+
mTweener.UpdateUnityData();
111111

112112
// reset alpha change.
113-
mJCSTweener.LocalAlpha = 1.0f;
113+
mTweener.LocalAlpha = 1.0f;
114114

115115
// enable the sprite renderer component.
116-
mJCSTweener.LocalEnabled = true;
116+
mTweener.LocalEnabled = true;
117117

118118
// reset tweener
119-
mJCSTweener.ResetTweener();
119+
mTweener.ResetTweener();
120120

121121
// update the unity data first.
122122
if (mReverseDirection)
@@ -125,10 +125,10 @@ private void OnEnable()
125125
* Reverse could only use DoTween, cannot
126126
* use DoTweenContinue.
127127
*/
128-
mJCSTweener.DoTween(newPos);
128+
mTweener.DoTween(newPos);
129129
}
130130
else
131-
mJCSTweener.DoTweenContinue(this.mTarget);
131+
mTweener.DoTweenContinue(this.mTarget);
132132
}
133133

134134
/// <summary>

Assets/JCSUnity/Scripts/Effects/Tweener/JCS_TransformTweener.cs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public class JCS_TransformTweener : JCS_UnityObject
2020
{
2121
/* Variables */
2222

23-
private Action mDestinationCallback = null;
23+
public Action onStart = null;
24+
public Action onDone = null;
2425

2526
#if UNITY_EDITOR
2627
[Separator("Helper Variables (JCS_TransformTweener)")]
@@ -216,9 +217,9 @@ protected override void Awake()
216217

217218
RandomizeDuration();
218219

219-
mTweenerX.SetCallback(DoneTweeningX);
220-
mTweenerY.SetCallback(DoneTweeningY);
221-
mTweenerZ.SetCallback(DoneTweeningZ);
220+
mTweenerX.onDone = DoneTweeningX;
221+
mTweenerY.onDone = DoneTweeningY;
222+
mTweenerZ.onDone = DoneTweeningZ;
222223
}
223224

224225
private void LateUpdate()
@@ -291,15 +292,6 @@ public void ResetTweener()
291292
mTweenerZ.ResetTweener();
292293
}
293294

294-
/// <summary>
295-
/// Callback when reach destination.
296-
/// </summary>
297-
/// <param name="func"> function pointer </param>
298-
public void SetCallback(Action func)
299-
{
300-
mDestinationCallback = func;
301-
}
302-
303295
/// <summary>
304296
/// Tween to this vector either position, scale, rotation.
305297
/// </summary>
@@ -622,21 +614,30 @@ private void DoCallback()
622614

623615
private void SafeDoCallback()
624616
{
625-
if (mDestinationCallback == null)
626-
return;
627-
628617
if (!this.mDoneTweenX || !this.mDoneTweenY || !this.mDoneTweenZ)
629618
return;
630619

631-
mDestinationCallback.Invoke();
620+
onDone?.Invoke();
632621
}
633622

634623
/// <summary>
635624
/// Callback for each tweener.
636625
/// </summary>
637-
private void DoneTweeningX() { this.mDoneTweenX = true; SafeDoCallback(); }
638-
private void DoneTweeningY() { this.mDoneTweenY = true; SafeDoCallback(); }
639-
private void DoneTweeningZ() { this.mDoneTweenZ = true; SafeDoCallback(); }
626+
private void DoneTweeningX()
627+
{
628+
this.mDoneTweenX = true;
629+
SafeDoCallback();
630+
}
631+
private void DoneTweeningY()
632+
{
633+
this.mDoneTweenY = true;
634+
SafeDoCallback();
635+
}
636+
private void DoneTweeningZ()
637+
{
638+
this.mDoneTweenZ = true;
639+
SafeDoCallback();
640+
}
640641

641642
/// <summary>
642643
/// Prepare for tweening.
@@ -662,7 +663,8 @@ private void StartTween(
662663
TweenDelegate easingZ = null,
663664
Action callback = null)
664665
{
665-
mDestinationCallback = callback;
666+
onStart?.Invoke();
667+
onDone = callback;
666668

667669
this.mIsDoneTweening = false;
668670
this.mDoneTweenX = false;

Assets/Tweener/Tweener.cs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class Tweener
1010
{
1111
/* Variables */
1212

13-
private Action _Callback = null;
13+
public Action onDone = null;
1414

1515
private TweenDelegate _Easing = null;
1616

@@ -35,15 +35,6 @@ public class Tweener
3535
public float progressPct { get { return _ProgressPct; } }
3636
public JCS_TimeType deltaTimeType { get { return this._DeltaTimeType; } }
3737

38-
/// <summary>
39-
/// Callback when reach destination.
40-
/// </summary>
41-
/// <param name="func"> function pointer </param>
42-
public void SetCallback(Action func)
43-
{
44-
this._Callback = func;
45-
}
46-
4738
/* Functions */
4839

4940
public Tweener() { }
@@ -55,17 +46,17 @@ public Tweener() { }
5546
/// <param name="to">To.</param>
5647
/// <param name="duration">Duration.</param>
5748
/// <param name="easing">Easing.</param>
58-
public void easeFromTo(float from, float to,
59-
bool resetElapsedTime = true,
60-
float duration = 1.0f,
49+
public void easeFromTo(float from, float to,
50+
bool resetElapsedTime = true,
51+
float duration = 1.0f,
6152
TweenDelegate easing = null, Action callback = null,
6253
JCS_TimeType deltaTimeType = JCS_TimeType.DELTA_TIME)
6354
{
6455
if (easing == null)
6556
easing = Easing.Linear;
6657

6758
_Easing = easing;
68-
SetCallback(callback);
59+
onDone = callback;
6960

7061
_From = from;
7162
_To = to;
@@ -104,8 +95,8 @@ public void update(bool callCallBack = true)
10495
_TimeElapsed = 0.0f;
10596
_ProgressPct = 1.0f;
10697

107-
if (callCallBack && _Callback != null)
108-
_Callback.Invoke();
98+
if (callCallBack)
99+
onDone?.Invoke();
109100
}
110101
}
111102

@@ -115,9 +106,9 @@ public void update(ref float whatToTween)
115106
update(false);
116107
whatToTween = _Progression;
117108

118-
if (wasAnimating && !_Animating && _Callback != null)
109+
if (wasAnimating && !_Animating)
119110
{
120-
_Callback.Invoke();
111+
onDone?.Invoke();
121112
}
122113
}
123114

@@ -137,8 +128,7 @@ public void ResetTweener()
137128
/// </summary>
138129
public void DoCallback()
139130
{
140-
if (_Callback != null)
141-
_Callback.Invoke();
131+
onDone?.Invoke();
142132
}
143133
}
144134
}

0 commit comments

Comments
 (0)