Animations added

This commit is contained in:
Savya Bikram Shah
2026-05-29 18:06:22 +05:45
parent 2d519a37b4
commit 931515193a
76 changed files with 5391 additions and 13 deletions

View File

@@ -31,7 +31,8 @@ public class ColoringController : IColoringController, IDisposable
private GameObject _colorInstance;
private GameObject _colorButtonPrefab;
private GameObject _completionAnimationPrefab;
private GameObject _completionAnimationInstance;
private CompletionAnimationView _completionAnimationView;
private readonly List<ColorRegionView> _regions = new();
private readonly List<ColorButton> _buttons = new();
private readonly Dictionary<string, Color> _authoredColors = new();
@@ -89,17 +90,17 @@ public class ColoringController : IColoringController, IDisposable
public async UniTask PlayCompletionAnimationAsync(CancellationToken ct)
{
if (_completionAnimationPrefab == null) return;
var instance = UnityEngine.Object.Instantiate(_completionAnimationPrefab, _refs.PaperRoot);
if (_completionAnimationInstance == null || _completionAnimationView == null) return;
if (_colorInstance != null) _colorInstance.SetActive(false);
_completionAnimationInstance.SetActive(true);
try
{
var view = instance.GetComponentInChildren<CompletionAnimationView>();
if (view == null) return;
await view.PlayAsync(ct);
await _completionAnimationView.PlayAsync(ct);
}
finally
{
if (instance != null) UnityEngine.Object.Destroy(instance);
if (_completionAnimationInstance != null)
_completionAnimationInstance.SetActive(false);
}
}
@@ -140,7 +141,13 @@ public class ColoringController : IColoringController, IDisposable
_regions.Clear();
_authoredColors.Clear();
_completionAnimationPrefab = null;
if (_completionAnimationInstance != null)
{
UnityEngine.Object.Destroy(_completionAnimationInstance);
_completionAnimationInstance = null;
_completionAnimationView = null;
}
if (_colorInstance != null)
{
@@ -154,7 +161,12 @@ public class ColoringController : IColoringController, IDisposable
private void InitializeColorRegions(IDrawingTemplate template, IReadOnlyDictionary<string, Color> savedColors)
{
_colorInstance = UnityEngine.Object.Instantiate(template.ColoringPrefab, _refs.PaperRoot);
_completionAnimationPrefab = template.CompletionAnimationPrefab;
if (template.CompletionAnimationPrefab != null)
{
_completionAnimationInstance = UnityEngine.Object.Instantiate(template.CompletionAnimationPrefab, _refs.PaperRoot);
_completionAnimationView = _completionAnimationInstance.GetComponentInChildren<CompletionAnimationView>(includeInactive: true);
_completionAnimationInstance.SetActive(false);
}
var views = _colorInstance.GetComponentsInChildren<ColorRegionView>(includeInactive: true);
foreach (var region in views)

View File

@@ -8,17 +8,28 @@ namespace Darkmatter.Features.Coloring.UI
public class CompletionAnimationView : MonoBehaviour
{
[SerializeField] private RectTransform target;
[SerializeField] private float duration = 0.6f;
[SerializeField] private float duration = 1f;
[SerializeField] private Vector3 startScale = Vector3.zero;
[SerializeField] private Vector3 endScale = Vector3.one;
[SerializeField] private Ease ease = Ease.OutBack;
[Header("Wiggle")]
[SerializeField] private float wiggleAngle = 10f;
[SerializeField] private float wiggleDuration = 0.25f;
[SerializeField, Min(1)] private int wiggleCycles = 3;
public async UniTask PlayAsync(CancellationToken ct)
{
var rt = target != null ? target : transform as RectTransform;
if (rt == null) return;
rt.localScale = startScale;
rt.localRotation = Quaternion.identity;
await Tween.Scale(rt, endScale, duration, ease).ToUniTask(cancellationToken: ct);
await Tween.LocalRotation(rt, new Vector3(0f, 0f, wiggleAngle), wiggleDuration, Ease.InOutSine,
cycles: wiggleCycles * 2, cycleMode: CycleMode.Yoyo)
.ToUniTask(cancellationToken: ct);
rt.localRotation = Quaternion.identity;
}
private void OnDestroy()