Skip to content

Commit 9adb489

Browse files
committed
Improve tweening
1 parent e32c77d commit 9adb489

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

Assets/Scripts/Popup/PopupManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class PopupManager : MonoBehaviour
1818
[SerializeField]
1919
private TweenData closeAnimation;
2020

21-
private List<Popup> openedPopups = new();
21+
private readonly List<Popup> openedPopups = new();
2222

2323
public static PopupManager Instance { get; private set; }
2424

@@ -31,7 +31,7 @@ private void Start()
3131
{
3232
foreach (var popup in allPopups)
3333
{
34-
ClosePopup(popup);
34+
popup.CanvasGroup.transform.localScale = Vector2.zero;
3535
popup.OnClose += ClosePopup;
3636
}
3737
}
@@ -68,7 +68,7 @@ public void OpenPopup(Popup popup)
6868
openedPopups.Add(popup);
6969
popup.OpenTween = popup.transform.DOScale(Vector2.one, openAnimation.Duration)
7070
.SetEase(openAnimation.Ease)
71-
.SetTarget(this);
71+
.SetLink(popup.gameObject);
7272
}
7373

7474
public void ClosePopup(PopupType type)
@@ -81,7 +81,7 @@ public void ClosePopup(Popup popup)
8181
{
8282
popup.OpenTween?.Kill();
8383
int previousIndex = openedPopups.FindIndex(x => x == popup) - 1;
84-
if (previousIndex > -1 && openedPopups.Count > previousIndex)
84+
if (previousIndex >= 0 && openedPopups.Count > previousIndex)
8585
{
8686
openedPopups[previousIndex].CanvasGroup.blocksRaycasts = true;
8787
}
@@ -90,7 +90,7 @@ public void ClosePopup(Popup popup)
9090
popup.CloseTween = popup.transform.DOScale(Vector2.zero, closeAnimation.Duration * popup.transform.localScale.x)
9191
.SetEase(closeAnimation.Ease)
9292
.OnComplete(() => FinalizePopup(popup))
93-
.SetTarget(this);
93+
.SetLink(popup.gameObject);
9494
}
9595

9696
private void FinalizePopup(Popup popup)

Assets/Scripts/Utility/Extensions/TMPTweenExtension.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using DG.Tweening;
22
using DG.Tweening.Core;
33
using DG.Tweening.Plugins.Options;
4-
using System.Collections;
5-
using System.Collections.Generic;
64
using TMPro;
7-
using UnityEngine;
85

96
public static class TMPTweenExtension
107
{
@@ -17,7 +14,7 @@ public static TweenerCore<string, string, StringOptions> DOType(this TMP_Text ta
1714
}
1815

1916
var t = DOTween.To(() => target.text, x => target.text = x, endValue, endValue.Length / duration);
20-
t.SetTarget(target);
17+
t.SetLink(target.gameObject);
2118
return t;
2219
}
2320

@@ -30,7 +27,7 @@ public static TweenerCore<string, string, StringOptions> DOType(this TMP_InputFi
3027
}
3128

3229
var t = DOTween.To(() => target.text, x => target.text = x, endValue, endValue.Length / duration);
33-
t.SetTarget(target);
30+
t.SetLink(target.gameObject);
3431
return t;
3532
}
3633
}

0 commit comments

Comments
 (0)