rabidus-test/Assets/Scripts/UIPopupController.cs

28 lines
936 B
C#
Raw Normal View History

2023-08-22 15:41:12 +03:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIPopupController : MonoBehaviour
{
[SerializeField]
private RectTransform _root;
[SerializeField]
private RectTransform _spawnPoint;
[SerializeField]
private List<UIPopupPair> _UIPairs = new List<UIPopupPair>();
2023-08-22 17:17:54 +03:00
public void SpawnPopup(string message, UIMagnetType type, Action onComplete = null)
2023-08-22 15:41:12 +03:00
{
var selectedPair = _UIPairs.Find(x => x.UIMagnetType == type);
var scorePoint = Instantiate(selectedPair.Popup, _root);
scorePoint.Init(message);
scorePoint.GetComponent<RectTransform>().anchoredPosition = _spawnPoint.anchoredPosition;
RectTransform target = selectedPair.MovePositon;
scorePoint.GetComponent<RectTransform>().LeanMoveLocal(target.anchoredPosition, 1).setOnComplete(onComplete).setEaseInExpo().setDestroyOnComplete(true);
}
}