rabidus-test/Assets/Scripts/UIPopupController.cs

28 lines
936 B
C#

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>();
public void SpawnPopup(string message, UIMagnetType type, Action onComplete = null)
{
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);
}
}