일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- Oculus
- HAPTIC
- 모작
- CGV
- 유니티 Json 데이터 연동
- 앱 배포
- 길건너 친구들
- 유니티 UI
- 유니티
- 팀 프로젝트
- 멀티플레이
- Photon Fusion
- 오큘러스
- 포트폴리오
- 팀프로젝트
- meta
- 연습
- 드래곤 플라이트
- ChatGPT
- OVR
- 개발일지
- VR
- 유니티 GUI
- 오브젝트 풀링
- 가상현실
- 드래곤 플라이트 모작
- meta xr
- XR
- input system
- 개발
Archives
- Today
- Total
EasyCastleUNITY
유니티 GUI 애니메이션 본문
유니티 RequireComponent
https://artiper.tistory.com/105
애니메이션 이벤트
마지막 프레임에 이벤트 추가
애니메이션 이벤트 활용
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class Test07Main : MonoBehaviour
{
[SerializeField] private Button btnStarsPlay;
[SerializeField] private Button btnRibbonAndStarsPlay;
[SerializeField] private Animator animRibbon;
[SerializeField] private Animator animLeftStar;
[SerializeField] private Animator animMiddleStar;
[SerializeField] private Animator animRightStar;
[SerializeField] TMP_Dropdown dropdown;
[SerializeField] private ParticleSystem[] fxStars;
[SerializeField] private ParticleSystem fxBurstStars;
private int starCount=1;
// Start is called before the first frame update
void Start()
{
this.dropdown.onValueChanged.AddListener((index) => {
this.starCount = index + 1;
});
this.btnRibbonAndStarsPlay.onClick.AddListener(() => {
this.animRibbon.GetComponent<AnimationReceiver>().onFinished = () => {
switch (this.starCount)
{
case 1:
this.PlayStar1();
break;
case 2:
this.PlayStar2();
break;
case 3:
this.PlayStar3();
break;
}
};
this.animRibbon.SetTrigger("Play");
});
this.btnStarsPlay.onClick.AddListener(() => {
Debug.LogFormat("{0} 별 애니메이션 실행", this.starCount);
switch (this.starCount)
{
case 1:
this.PlayStar1();
break;
case 2:
this.PlayStar2();
break;
case 3:
this.PlayStar3();
break;
}
});
}
private void PlayStar1()
{
this.animLeftStar.GetComponent<AnimationReceiver>().onFinished = () =>
{
var fx = this.fxStars[0];
fx.gameObject.SetActive(true);
fx.Play();
};
this.animLeftStar.SetTrigger("Play");
}
private void PlayStar2()
{
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");
}
private void PlayStar3()
{
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();
var burstFx = this.fxBurstStars;
burstFx.gameObject.SetActive(true);
burstFx.Play();
};
this.animRightStar.SetTrigger("Play");
};
this.animMiddleStar.SetTrigger("Play");
};
this.animLeftStar.SetTrigger("Play");
}
}
보상 아이템 리스트 애니메이션과 슬라이더 애니메이션 버튼 등장 애니메이션 추가
AnimationReceiver
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Animator))] //이게 붙어있으면, 해당 요소는 제거하지 못함
public class AnimationReceiver : MonoBehaviour
{
public System.Action onFinished;
public void OnFinished()
{
Debug.Log("Animation Finished");
if(this.onFinished != null)
{
this.onFinished();
}
}
}
SetSliderText
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class SetSliderText : MonoBehaviour
{
[SerializeField] Slider slider;
[SerializeField] TMP_Text sliderText;
// Update is called once per frame
void Update()
{
this.sliderText.text = string.Format("{0} / 400", (int)(slider.value*400));
}
}
Main
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.U2D;
using UnityEngine.UI;
public class Test07Main : MonoBehaviour
{
[SerializeField] private Button btnWholeStart;
[SerializeField] private Animator animRibbon;
[SerializeField] private Animator animLeftStar;
[SerializeField] private Animator animMiddleStar;
[SerializeField] private Animator animRightStar;
[SerializeField] private Animator animBtnClaim;
[SerializeField] private Animator animBtnDoubleClaim;
[SerializeField] private Animator animRewardItemTitle;
[SerializeField] private Animator[] animRewardItems;
[SerializeField] private Animator animSlider;
[SerializeField] TMP_Dropdown starDropdown;
[SerializeField] TMP_Dropdown itemDropdown;
[SerializeField] private ParticleSystem[] fxStars;
[SerializeField] private ParticleSystem fxBurstStars;
private int starCount = 1;
private int itemCount = 1;
// Start is called before the first frame update
void Start()
{
this.starDropdown.onValueChanged.AddListener((index) =>
{
this.starCount = index + 1;
});
this.itemDropdown.onValueChanged.AddListener((index) =>
{
this.itemCount = index + 1;
});
this.btnWholeStart.onClick.AddListener(() =>
{
this.animRibbon.GetComponent<AnimationReceiver>().onFinished = () =>
{
switch (this.starCount)
{
case 1:
this.PlayStar1();
break;
case 2:
this.PlayStar2();
break;
case 3:
this.PlayStar3();
break;
}
};
this.animRibbon.SetTrigger("Play");
});
}
private void PlayStar1()
{
this.animLeftStar.GetComponent<AnimationReceiver>().onFinished = () =>
{
var fx = this.fxStars[0];
fx.gameObject.SetActive(true);
fx.Play();
PlayRewardItemListAnim();
};
this.animLeftStar.SetTrigger("Play");
}
private void PlayStar2()
{
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();
PlayRewardItemListAnim();
};
this.animMiddleStar.SetTrigger("Play");
};
this.animLeftStar.SetTrigger("Play");
}
private void PlayStar3()
{
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();
var burstFx = this.fxBurstStars;
burstFx.gameObject.SetActive(true);
burstFx.Play();
PlayRewardItemListAnim();
//this.PlayButtonAnim();
};
this.animRightStar.SetTrigger("Play");
};
this.animMiddleStar.SetTrigger("Play");
};
this.animLeftStar.SetTrigger("Play");
}
private void PlayRewardItemListAnim()
{
this.StartCoroutine(this.CoPlayRewardItemList());
}
private IEnumerator CoPlayRewardItemList()
{
for (int i = 0; i < this.itemCount; i++)
{
this.animRewardItems[i].SetTrigger("Play");
yield return new WaitForSeconds(0.3f);
}
this.PlaySlider();
}
private void PlaySlider()
{
this.animSlider.GetComponent<AnimationReceiver>().onFinished = () =>
{
this.PlayButtonAnim();
};
this.animSlider.SetTrigger("Play");
}
private void PlayButtonAnim()
{
this.animBtnClaim.SetTrigger("Play");
this.animBtnDoubleClaim.SetTrigger("Play");
}
}
시연 결과
지금은 프로젝트에 박은 상태로 Item을 구현하였지만, 아틀라스와 프리팹을 응용하여 만들어보는 방법도 있다
'유니티 심화' 카테고리의 다른 글
유니티 GUI 미션 (데이터 연동 및 저장, 저장한 데이터 불러오기) (0) | 2023.09.10 |
---|---|
보석 상점 GUI (0) | 2023.09.09 |
골드 상점 GUI (0) | 2023.09.09 |
유니티 GUI (스크롤 뷰 및 셀) 및 데이터 연동 (0) | 2023.09.07 |
유니티 GUI 3 (Stage UI) (0) | 2023.09.06 |