Unity/UIUX프로그래밍

0422_ UI 팝업 창 애니메이션 하기

minquu 2021. 4. 22. 12:56
반응형

0. 먼저 구조대로 UI를 만들어줍니다.

 

 

 

 

 

1.  main를 잡고 애니메이션을 Create를 해주고, 키를 넣어줍니다.

키를 넣을려면 녹화버튼을 누르면 씬에서 작업하는 것들이 키로 들어갑니다 .

 

스타는 따로 스크립터에서 꺼주고, 팝업 애니가 끝났을때 켜줄 것 입니다.

 

 

 

테스트할 스크립터를 만들어서

 

버튼을 누르면 애니메이션이 작동하도록 한다.

 

 

 

 

 

----

 

2. 스타 애니메이션을 만들고, 코루틴을 활용해서 필요할때 애니를 불러오고 재생을 한다.

 

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class testComplte : MonoBehaviour
{
    public Button btnTest;
    public Animator anim;
    public Animator[] animStars;
    public GameObject starsGo;
    private void Start()
    {

        this.starsGo.SetActive(false);

        foreach (var animStar in this.animStars) {
            animStar.speed = 0;
            animStar.gameObject.SetActive(false);
        }
        this.anim.speed = 0;

        btnTest.onClick.AddListener(() =>
        {
            this.anim.speed = 1;
            this.anim.Play("uipopup_complete");

            StartCoroutine(this.WaitAnim(0.533f, () =>
            {
                this.starsGo.SetActive(true);
                this.animStars[0].gameObject.SetActive(true);
                this.animStars[0].speed = 0;
                //this.animStars[0].Play("uipopup_complete_star");

                StartCoroutine(this.WaitAnim(0.25f, () =>
                {
                    this.animStars[1].gameObject.SetActive(true);
                    this.animStars[1].speed = 0;

                    StartCoroutine(this.WaitAnim(0.25f, () =>
                    {
                        this.animStars[2].gameObject.SetActive(true);
                        this.animStars[2].speed = 0;
                    }));
                }));

            }));
        });
    }

    IEnumerator WaitAnim(float t, System.Action onComplete) {
        yield return new WaitForSeconds(t);
        onComplete();
    }
}

 

 

----

반응형