개발/졸업작품
2022-06-14 지금까지 해온 것
Smallghost
2022. 6. 14. 11:32
졸업 작품을 준비하면서 클릭형 스릴러 추리게임을 작업하고 있다.
아트와 UI, 프로그래밍까지 더불어서 하는 게 몸은 힘들지만 재밌어서 할 만 한 것 같다.
다른 건 얼추 찾아서 해보겠는데 로딩바 화면 작업이 조금 걸렸다. 여러모로 피드백을 받고 갖가지 시도를 해보다가 나온 결과는 마음에 든다.
게임 씬을 바꾸면서 반드시 로딩화면을 지나치도록 만들었다. AsyncOperation가 LoadScene 밖에 가져오지 못해 인덱스를 이용한 다음 장면 가져오기가 조금 힘들다. 조금만 더 하면 될 것 같긴한데... 일단 리팩토링은 나중에 하는 거로.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using TMPro;
using System;
public class Loading : MonoBehaviour
{
public static string nextScene;
[SerializeField] Image progressBar;
[SerializeField] TextMeshProUGUI loadpercentage;
private void Start()
{
StartCoroutine(LoadScene());
}
public static void LoadScene(string sceneName)
{
nextScene = sceneName;
SceneManager.LoadScene("Loading Scene");
}
IEnumerator LoadScene()
{
yield return null;
AsyncOperation op = SceneManager.LoadSceneAsync(nextScene);
op.allowSceneActivation = false;
float timer = 0.0f;
while (!op.isDone)
{
yield return null;
timer += Time.deltaTime;
if (op.progress < 0.9f)
{
progressBar.fillAmount = Mathf.Lerp(progressBar.fillAmount, op.progress, timer);
if (progressBar.fillAmount >= op.progress)
{
timer = 0f;
}
}
else
{
progressBar.fillAmount = Mathf.Lerp(progressBar.fillAmount, 1f, timer);
float temp = progressBar.fillAmount;
float percentage = (Mathf.Lerp(temp, 100, progressBar.fillAmount));
loadpercentage.text = (Mathf.RoundToInt(percentage)).ToString() + "%";
if (progressBar.fillAmount >= 1.0f)
{
op.allowSceneActivation = true;
yield break;
}
}
}
}
}
화면 페이드 효과와 텍스트 페이드 효과를 둘 다 적용한다. 이것도 클릭 했을 때랑 그냥 페이드 효과랑 따로 적용을 했어야했는데, 이 리팩토링도 아마 교수님께 여쭈어봐야할 것 같다...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class FadeAnimation : MonoBehaviour
{
[SerializeField] TextMeshProUGUI text;
[SerializeField] Image img;
void Awake()
{
TextMeshProUGUI text = GetComponent<TextMeshProUGUI>();
Image img = GetComponent<Image>();
StartCoroutine(FadeTextToFullAlpha());
}
public IEnumerator FadeTextToFullAlpha()
{
text.color = new Color(text.color.r, text.color.g, text.color.b, text.color.a);
while (text.color.a < 1.0f)
{
text.color = new Color(text.color.r, text.color.g, text.color.b, text.color.a + (Time.deltaTime / 2.0f));
yield return null;
}
//StartCoroutine(FadeTextToZero());
}
public IEnumerator FadeTextToZero()
{
text.color = new Color(text.color.r, text.color.g, text.color.b, text.color.a);
while (text.color.a > 0.0f)
{
text.color = new Color(text.color.r, text.color.g, text.color.b, text.color.a - (Time.deltaTime / 2.0f));
yield return null;
}
}
public IEnumerator FadeImgToZero() // 알파값 1에서 0으로 전환
{
Destroy(text);
img.color = new Color(img.color.r, img.color.g, img.color.b, img.color.a);
while (img.color.a > 0.0f)
{
img.color = new Color(img.color.r, img.color.g, img.color.b, img.color.a - (Time.deltaTime / 20.0f));
yield return null;
}
Destroy(img);
}
private void Update()
{
if (Input.GetMouseButton(0))
{
StartCoroutine(FadeImgToZero());
StartCoroutine(FadeTextToZero());
}
}
}