Build TravelRun intro and tutorial flow
This commit is contained in:
@@ -4,13 +4,32 @@ using UnityEngine;
|
||||
[ExecuteAlways]
|
||||
public class BackgroundLoop : MonoBehaviour {
|
||||
public Sprite[] backgroundSprites; // 순서대로 교체할 공항 배경 스프라이트
|
||||
public bool useResourceBackground = true; // Resources 폴더의 맵 배경을 자동으로 사용
|
||||
public string resourceBackgroundPath = ""; // 맵 데이터가 없을 때 사용할 Resources 배경
|
||||
public int startSpriteIndex = 0; // 이 배경 오브젝트가 시작할 스프라이트 번호
|
||||
public int spriteAdvanceOnLoop = 2; // 배경 오브젝트가 두 장이므로 재배치될 때 두 칸씩 진행
|
||||
|
||||
private static string activeResourceBackgroundPath = "";
|
||||
|
||||
private float width; // 배경의 가로 길이
|
||||
private int currentSpriteIndex; // 현재 표시 중인 스프라이트 번호
|
||||
private SpriteRenderer spriteRenderer; // 배경을 표시하는 스프라이트 렌더러
|
||||
private BoxCollider2D backgroundCollider; // 루프 폭 계산용 콜라이더
|
||||
private Sprite[] originalBackgroundSprites; // 맵 배경 리소스가 없을 때 되돌릴 기본 배경
|
||||
private bool originalBackgroundSpritesCached = false;
|
||||
|
||||
public static void ApplyResourceBackground(string resourcePath) {
|
||||
activeResourceBackgroundPath = resourcePath;
|
||||
|
||||
BackgroundLoop[] backgroundLoops = FindObjectsByType<BackgroundLoop>(FindObjectsSortMode.None);
|
||||
for(int i = 0; i < backgroundLoops.Length; i++)
|
||||
{
|
||||
if(backgroundLoops[i] != null)
|
||||
{
|
||||
backgroundLoops[i].InitializeBackground();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake() {
|
||||
InitializeBackground();
|
||||
@@ -39,6 +58,8 @@ public class BackgroundLoop : MonoBehaviour {
|
||||
|
||||
private void InitializeBackground() {
|
||||
CacheComponents();
|
||||
CacheOriginalBackgroundSprites();
|
||||
EnsureResourceBackground();
|
||||
|
||||
currentSpriteIndex = NormalizeSpriteIndex(startSpriteIndex);
|
||||
ApplyBackgroundSprite(currentSpriteIndex);
|
||||
@@ -58,6 +79,46 @@ public class BackgroundLoop : MonoBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureResourceBackground() {
|
||||
if(!useResourceBackground)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string finalResourcePath = !string.IsNullOrEmpty(activeResourceBackgroundPath)
|
||||
? activeResourceBackgroundPath
|
||||
: resourceBackgroundPath;
|
||||
|
||||
if(string.IsNullOrEmpty(finalResourcePath))
|
||||
{
|
||||
backgroundSprites = originalBackgroundSprites;
|
||||
return;
|
||||
}
|
||||
|
||||
Sprite resourceSprite = Resources.Load<Sprite>(finalResourcePath);
|
||||
if(resourceSprite == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(backgroundSprites != null && backgroundSprites.Length == 1 && backgroundSprites[0] == resourceSprite)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
backgroundSprites = new Sprite[] { resourceSprite };
|
||||
}
|
||||
|
||||
private void CacheOriginalBackgroundSprites() {
|
||||
if(originalBackgroundSpritesCached)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
originalBackgroundSprites = backgroundSprites;
|
||||
originalBackgroundSpritesCached = true;
|
||||
}
|
||||
|
||||
private void RefreshWidth() {
|
||||
if(spriteRenderer != null && spriteRenderer.sprite != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user