[UGUI연습] UI 연출
UI 애니메이션
-애니메이션으 루프는 꺼준다.
Animation receiver 사용해보기
- New State를 생성하고 기본 state로 만든 후, trigger로 transition을 추가해준다.
-리본의 자식의 text 두개를 비활성화 시킨다.(애니메이션으로 켜줄 것이다.)
-RequireComponent 속성은 요구되는 컴포넌트를 종속성으로 자동으로 추가한다.
비슷한 방법으로 별 애니메이션도 추가해보았다.
-다만 onfinished를 수정하였다. 원하는 지점에서 이벤트를 받아 파티클 시스템이 실행되도록 메인에서 호출할것이다.
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class Test07Main : MonoBehaviour
{
[SerializeField] private Button btnPlay;
[SerializeField] private Animator animRibbon;
[SerializeField] private Button btnStarsPlay;
[SerializeField] private TMP_Dropdown dropdown;
[SerializeField] private Animator animLeftStar;
[SerializeField] private Animator animMiddleStar;
[SerializeField] private Animator animRightStar;
[SerializeField] private ParticleSystem[] fxStars;
private int starCount = 1;
void Start()
{
this.btnPlay.onClick.AddListener(() => {
this.animRibbon.SetTrigger("Play");
});
this.dropdown.onValueChanged.AddListener((index) =>
{
Debug.LogFormat("onValueChanged: {0}", index);
this.starCount = index + 1;
});
this.btnStarsPlay.onClick.AddListener(() =>
{
Debug.LogFormat("{0} 별 애니메이션 실행", this.starCount);
switch (this.starCount)
{
case 1:
this.animLeftStar.GetComponent<AnimationReceiver>().onFinished = () =>
{
var fx = this.fxStars[0];
fx.gameObject.SetActive(true);
fx.Play();
};
this.animLeftStar.SetTrigger("Play");
break;
case 2:
this.animLeftStar.GetComponent<AnimationReceiver>().onFinished = () =>
{
var fx = this.fxStars[0];
fx.gameObject.SetActive(true);
fx.Play();
this.animMiddleStar.GetComponent<AnimationReceiver>().onFinished = () =>
{
var fx1 = this.fxStars[1];
fx1.gameObject.SetActive(true);
fx1.Play();
};
this.animMiddleStar.SetTrigger("Play");
};
this.animLeftStar.SetTrigger("Play");
break;
case 3:
this.animLeftStar.GetComponent<AnimationReceiver>().onFinished = () =>
{
var fx = this.fxStars[0];
fx.gameObject.SetActive(true);
fx.Play();
this.animMiddleStar.GetComponent<AnimationReceiver>().onFinished = () =>
{
var fx1 = this.fxStars[1];
fx1.gameObject.SetActive(true);
fx1.Play();
this.animRightStar.GetComponent<AnimationReceiver>().onFinished = () =>
{
var fx2 = this.fxStars[2];
fx2.gameObject.SetActive(true);
fx2.Play();
};
this.animRightStar.SetTrigger("Play");
};
this.animMiddleStar.SetTrigger("Play");
};
this.animLeftStar.SetTrigger("Play");
break;
}
});
}
}
'유니티 심화' 카테고리의 다른 글
[음원파일 추출] FSB파일 wav로 변환하기 (0) | 2023.09.15 |
---|---|
[UGUI 연습] UI 연출2 (0) | 2023.09.12 |
[UGUI 연습] 데이터 저장, 불러오기 연습 (0) | 2023.09.09 |
[UGUI연습] 미션(동적 스크롤뷰 활용) (0) | 2023.09.08 |
[UGUI연습]-동적 스크롤 뷰, json연결 (0) | 2023.09.07 |