1445 lines
51 KiB
C#
1445 lines
51 KiB
C#
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
|
|
public class GameFlowManager : MonoBehaviour {
|
|
public enum FlowScreen {
|
|
Intro,
|
|
OpeningStory,
|
|
Game,
|
|
Result,
|
|
DutyFreeShop,
|
|
MapPreview
|
|
}
|
|
|
|
public static GameFlowManager Instance { get; private set; }
|
|
|
|
public static bool IsGameplayActive {
|
|
get {
|
|
return Instance == null || Instance.gameplayActive;
|
|
}
|
|
}
|
|
|
|
public GameSaveData SaveData {
|
|
get { return saveData; }
|
|
}
|
|
|
|
public MapDefinition CurrentMap {
|
|
get { return currentMap; }
|
|
}
|
|
|
|
private const string IntroSceneName = "Intro";
|
|
private const string GameSceneName = "Main";
|
|
private const string ResultSceneName = "Result";
|
|
private const string DutyFreeShopSceneName = "DutyFreeShop";
|
|
private const string MapPreviewSceneName = "MapPreview";
|
|
private const int ShieldCost = 120;
|
|
private const int LunchboxCost = 80;
|
|
private const int SpeedShoesCost = 140;
|
|
private const int MileageCardCost = 160;
|
|
private static readonly string[] OpeningStoryPageAssetPaths = {
|
|
"Assets/ConceptArt/Opening/opening_cutscene_comic_jj_03_no_bubbles.png",
|
|
"Assets/ConceptArt/Opening/opening_cutscene_comic_jj_04_prepare_no_bubbles.png",
|
|
"Assets/ConceptArt/Opening/opening_cutscene_final_departure_jj_06_street_strict_stylematch.png"
|
|
};
|
|
|
|
private GameSaveData saveData;
|
|
private MapDefinition currentMap;
|
|
private MapDefinition completedMap;
|
|
private FlowScreen currentScreen = FlowScreen.Intro;
|
|
private bool gameplayActive = false;
|
|
private bool pendingStartGameplay = false;
|
|
private bool lastResultCleared = false;
|
|
private int lastResultScore = 0;
|
|
private int lastResultMileage = 0;
|
|
private float lastResultTime = 0f;
|
|
private float lastResultDistance = 0f;
|
|
private int openingStoryPageIndex = 0;
|
|
|
|
private Canvas overlayCanvas;
|
|
private RectTransform overlayRoot;
|
|
private Image overlayBackground;
|
|
private Camera flowCamera;
|
|
private TMP_FontAsset runtimeFont;
|
|
|
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
|
private static void Bootstrap() {
|
|
if(Instance != null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GameObject flowObject = new GameObject("Game Flow Manager");
|
|
flowObject.AddComponent<GameFlowManager>();
|
|
DontDestroyOnLoad(flowObject);
|
|
}
|
|
|
|
private void Awake() {
|
|
if(Instance != null && Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
saveData = GameSaveManager.Load();
|
|
currentMap = MapDatabase.GetMapByIndex(saveData.currentMapIndex);
|
|
SceneManager.sceneLoaded += OnSceneLoaded;
|
|
}
|
|
|
|
private void Start() {
|
|
ShowIntro();
|
|
}
|
|
|
|
private void OnDestroy() {
|
|
if(Instance == this)
|
|
{
|
|
SceneManager.sceneLoaded -= OnSceneLoaded;
|
|
Instance = null;
|
|
}
|
|
}
|
|
|
|
private void OnSceneLoaded(Scene scene, LoadSceneMode mode) {
|
|
EnsureOverlay();
|
|
|
|
if(pendingStartGameplay)
|
|
{
|
|
StartCoroutine(StartGameplayAfterSceneLoad());
|
|
return;
|
|
}
|
|
|
|
if(currentScreen != FlowScreen.Game)
|
|
{
|
|
RefreshCurrentScreen();
|
|
}
|
|
}
|
|
|
|
public void SetTotalMileage(int totalMileage) {
|
|
if(saveData == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
saveData.totalMileage = Mathf.Max(0, totalMileage);
|
|
GameSaveManager.Save(saveData);
|
|
}
|
|
|
|
public void AddMileage(int amount) {
|
|
if(saveData == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GameSaveManager.AddMileage(saveData, amount);
|
|
}
|
|
|
|
public void CompleteMap(bool cleared, int score, int stageMileage, float elapsedTime, float distance) {
|
|
if(!gameplayActive && currentScreen == FlowScreen.Result)
|
|
{
|
|
return;
|
|
}
|
|
|
|
gameplayActive = false;
|
|
currentScreen = FlowScreen.Result;
|
|
completedMap = currentMap;
|
|
lastResultCleared = cleared;
|
|
lastResultScore = score;
|
|
lastResultMileage = stageMileage;
|
|
lastResultTime = elapsedTime;
|
|
lastResultDistance = distance;
|
|
|
|
if(cleared)
|
|
{
|
|
saveData.bestScore = Mathf.Max(saveData.bestScore, score);
|
|
GameSaveManager.AddMileage(saveData, completedMap.clearMileageReward);
|
|
|
|
if(completedMap.hasNextMap)
|
|
{
|
|
GameSaveManager.UnlockMap(saveData, completedMap.nextMapId);
|
|
}
|
|
else
|
|
{
|
|
GameSaveManager.Save(saveData);
|
|
}
|
|
}
|
|
|
|
ShowResult();
|
|
}
|
|
|
|
private void StartNewJourney() {
|
|
saveData = GameSaveManager.ResetSave();
|
|
currentMap = MapDatabase.GetMapByIndex(saveData.currentMapIndex);
|
|
completedMap = null;
|
|
openingStoryPageIndex = 0;
|
|
ShowOpeningStory();
|
|
}
|
|
|
|
private void ContinueJourney() {
|
|
saveData = GameSaveManager.Load();
|
|
currentMap = MapDatabase.GetMapByIndex(saveData.currentMapIndex);
|
|
completedMap = null;
|
|
ShowMapPreview();
|
|
}
|
|
|
|
private void RetryCurrentMap() {
|
|
currentMap = MapDatabase.GetMapByIndex(saveData.currentMapIndex);
|
|
LoadGameSceneForCurrentMap();
|
|
}
|
|
|
|
private void LoadGameSceneForCurrentMap() {
|
|
currentScreen = FlowScreen.Game;
|
|
gameplayActive = false;
|
|
pendingStartGameplay = true;
|
|
ShowLoading("탑승 준비 중", currentMap.displayName + " 코스를 불러오는 중입니다.");
|
|
|
|
if(Application.CanStreamedLevelBeLoaded(GameSceneName))
|
|
{
|
|
SceneManager.LoadScene(GameSceneName);
|
|
return;
|
|
}
|
|
|
|
Scene activeScene = SceneManager.GetActiveScene();
|
|
if(!string.IsNullOrEmpty(activeScene.name))
|
|
{
|
|
SceneManager.LoadScene(activeScene.name);
|
|
}
|
|
}
|
|
|
|
private IEnumerator StartGameplayAfterSceneLoad() {
|
|
yield return null;
|
|
|
|
pendingStartGameplay = false;
|
|
currentScreen = FlowScreen.Game;
|
|
gameplayActive = true;
|
|
|
|
SetOverlayVisible(false);
|
|
|
|
if(GameManager.instance != null)
|
|
{
|
|
GameManager.instance.BeginMap(currentMap);
|
|
}
|
|
}
|
|
|
|
private void ShowOpeningStory() {
|
|
currentScreen = FlowScreen.OpeningStory;
|
|
gameplayActive = false;
|
|
pendingStartGameplay = false;
|
|
|
|
if(TryLoadFlowScene(IntroSceneName))
|
|
{
|
|
return;
|
|
}
|
|
|
|
EnsureOverlay();
|
|
ClearOverlay();
|
|
SetOverlayVisible(true);
|
|
|
|
BuildOpeningStoryScreen();
|
|
}
|
|
|
|
private void ShowIntro() {
|
|
currentScreen = FlowScreen.Intro;
|
|
gameplayActive = false;
|
|
pendingStartGameplay = false;
|
|
completedMap = null;
|
|
|
|
if(TryLoadFlowScene(IntroSceneName))
|
|
{
|
|
return;
|
|
}
|
|
|
|
EnsureOverlay();
|
|
ClearOverlay();
|
|
SetOverlayVisible(true);
|
|
|
|
BuildIntroScreen();
|
|
}
|
|
|
|
private void ShowResult() {
|
|
if(TryLoadFlowScene(ResultSceneName))
|
|
{
|
|
return;
|
|
}
|
|
|
|
EnsureOverlay();
|
|
ClearOverlay();
|
|
SetOverlayVisible(true);
|
|
SetDefaultOverlayBackground();
|
|
|
|
string title = lastResultCleared ? "맵 클리어" : "일정 실패";
|
|
string body = completedMap.displayName
|
|
+ "\n점수: " + lastResultScore
|
|
+ "\n획득 마일리지: " + lastResultMileage
|
|
+ "\n거리: " + Mathf.FloorToInt(lastResultDistance) + "m / " + Mathf.FloorToInt(completedMap.targetDistance) + "m"
|
|
+ "\n시간: " + lastResultTime.ToString("0.0") + "s";
|
|
|
|
if(lastResultCleared)
|
|
{
|
|
body += "\n클리어 보상: " + completedMap.clearMileageReward + " 마일리지";
|
|
}
|
|
|
|
AddTitle(title);
|
|
AddBody(body);
|
|
|
|
if(lastResultCleared)
|
|
{
|
|
AddButton("면세점으로", ShowDutyFreeShop);
|
|
}
|
|
else
|
|
{
|
|
AddButton("다시 도전", RetryCurrentMap);
|
|
}
|
|
|
|
AddButton("인트로", ShowIntro);
|
|
}
|
|
|
|
private void ShowDutyFreeShop() {
|
|
currentScreen = FlowScreen.DutyFreeShop;
|
|
gameplayActive = false;
|
|
pendingStartGameplay = false;
|
|
|
|
if(TryLoadFlowScene(DutyFreeShopSceneName))
|
|
{
|
|
return;
|
|
}
|
|
|
|
EnsureOverlay();
|
|
ClearOverlay();
|
|
SetOverlayVisible(true);
|
|
SetDefaultOverlayBackground();
|
|
|
|
AddTitle("면세점");
|
|
AddBody("보유 마일리지: " + saveData.totalMileage
|
|
+ "\n도시락: " + saveData.lunchboxStock
|
|
+ " / 방어막: " + saveData.shieldStock
|
|
+ "\n운동화: " + saveData.speedShoesStock
|
|
+ " / 마일리지 카드: " + saveData.mileageCardStock);
|
|
|
|
AddButton("도시락 구매 " + LunchboxCost, BuyLunchbox);
|
|
AddButton("방어막 구매 " + ShieldCost, BuyShield);
|
|
AddButton("운동화 구매 " + SpeedShoesCost, BuySpeedShoes);
|
|
AddButton("마일리지 카드 구매 " + MileageCardCost, BuyMileageCard);
|
|
AddButton("다음 맵 보기", ShowMapPreview);
|
|
}
|
|
|
|
private void ShowMapPreview() {
|
|
currentScreen = FlowScreen.MapPreview;
|
|
gameplayActive = false;
|
|
pendingStartGameplay = false;
|
|
|
|
if(completedMap != null && lastResultCleared && completedMap.hasNextMap)
|
|
{
|
|
currentMap = MapDatabase.GetMap(completedMap.nextMapId);
|
|
}
|
|
else
|
|
{
|
|
currentMap = MapDatabase.GetMapByIndex(saveData.currentMapIndex);
|
|
}
|
|
|
|
if(TryLoadFlowScene(MapPreviewSceneName))
|
|
{
|
|
return;
|
|
}
|
|
|
|
EnsureOverlay();
|
|
ClearOverlay();
|
|
SetOverlayVisible(true);
|
|
SetDefaultOverlayBackground();
|
|
|
|
AddTitle("다음 경로");
|
|
AddBody(currentMap.displayName
|
|
+ "\n" + currentMap.routeName
|
|
+ "\n목표 거리: " + Mathf.FloorToInt(currentMap.targetDistance) + "m"
|
|
+ "\n제한 시간: " + currentMap.timeLimit.ToString("0") + "s");
|
|
AddButton("출발", ConfirmMapAndStart);
|
|
AddButton("인트로", ShowIntro);
|
|
}
|
|
|
|
private void ConfirmMapAndStart() {
|
|
saveData.currentMapIndex = MapDatabase.GetIndex(currentMap.mapId);
|
|
saveData.unlockedMapIndex = Mathf.Max(saveData.unlockedMapIndex, saveData.currentMapIndex);
|
|
GameSaveManager.Save(saveData);
|
|
LoadGameSceneForCurrentMap();
|
|
}
|
|
|
|
private void RefreshCurrentScreen() {
|
|
switch(currentScreen)
|
|
{
|
|
case FlowScreen.Result:
|
|
ShowResult();
|
|
break;
|
|
case FlowScreen.DutyFreeShop:
|
|
ShowDutyFreeShop();
|
|
break;
|
|
case FlowScreen.MapPreview:
|
|
ShowMapPreview();
|
|
break;
|
|
case FlowScreen.OpeningStory:
|
|
ShowOpeningStory();
|
|
break;
|
|
case FlowScreen.Intro:
|
|
default:
|
|
ShowIntro();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void ResetAndStayIntro() {
|
|
saveData = GameSaveManager.ResetSave();
|
|
currentMap = MapDatabase.GetMapByIndex(saveData.currentMapIndex);
|
|
ShowIntro();
|
|
}
|
|
|
|
private void BuyLunchbox() {
|
|
if(TrySpendMileage(LunchboxCost))
|
|
{
|
|
saveData.lunchboxStock++;
|
|
GameSaveManager.Save(saveData);
|
|
}
|
|
|
|
ShowDutyFreeShop();
|
|
}
|
|
|
|
private void BuyShield() {
|
|
if(TrySpendMileage(ShieldCost))
|
|
{
|
|
saveData.shieldStock++;
|
|
GameSaveManager.Save(saveData);
|
|
}
|
|
|
|
ShowDutyFreeShop();
|
|
}
|
|
|
|
private void BuySpeedShoes() {
|
|
if(TrySpendMileage(SpeedShoesCost))
|
|
{
|
|
saveData.speedShoesStock++;
|
|
GameSaveManager.Save(saveData);
|
|
}
|
|
|
|
ShowDutyFreeShop();
|
|
}
|
|
|
|
private void BuyMileageCard() {
|
|
if(TrySpendMileage(MileageCardCost))
|
|
{
|
|
saveData.mileageCardStock++;
|
|
GameSaveManager.Save(saveData);
|
|
}
|
|
|
|
ShowDutyFreeShop();
|
|
}
|
|
|
|
private bool TrySpendMileage(int cost) {
|
|
if(saveData.totalMileage < cost)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
saveData.totalMileage -= cost;
|
|
return true;
|
|
}
|
|
|
|
private void ShowLoading(string title, string body) {
|
|
EnsureOverlay();
|
|
ClearOverlay();
|
|
SetOverlayVisible(true);
|
|
SetDefaultOverlayBackground();
|
|
AddTitle(title);
|
|
AddBody(body);
|
|
}
|
|
|
|
private bool TryLoadFlowScene(string sceneName) {
|
|
Scene activeScene = SceneManager.GetActiveScene();
|
|
if(activeScene.name == sceneName)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(!Application.CanStreamedLevelBeLoaded(sceneName))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
SceneManager.LoadScene(sceneName);
|
|
return true;
|
|
}
|
|
|
|
private void EnsureOverlay() {
|
|
EnsureEventSystem();
|
|
|
|
if(overlayCanvas != null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GameObject canvasObject = new GameObject("Flow Overlay", typeof(RectTransform), typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster));
|
|
DontDestroyOnLoad(canvasObject);
|
|
|
|
overlayCanvas = canvasObject.GetComponent<Canvas>();
|
|
overlayCanvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
|
overlayCanvas.worldCamera = null;
|
|
overlayCanvas.sortingOrder = 100;
|
|
SetUiLayer(canvasObject);
|
|
|
|
CanvasScaler scaler = canvasObject.GetComponent<CanvasScaler>();
|
|
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
|
scaler.referenceResolution = new Vector2(1280f, 720f);
|
|
scaler.matchWidthOrHeight = 0.5f;
|
|
|
|
GameObject rootObject = new GameObject("Flow Overlay Root", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image));
|
|
rootObject.transform.SetParent(canvasObject.transform, false);
|
|
SetUiLayer(rootObject);
|
|
|
|
overlayRoot = rootObject.GetComponent<RectTransform>();
|
|
overlayRoot.anchorMin = Vector2.zero;
|
|
overlayRoot.anchorMax = Vector2.one;
|
|
overlayRoot.offsetMin = Vector2.zero;
|
|
overlayRoot.offsetMax = Vector2.zero;
|
|
|
|
Image background = rootObject.GetComponent<Image>();
|
|
overlayBackground = background;
|
|
background.color = new Color(0.02f, 0.035f, 0.045f, 0.92f);
|
|
background.raycastTarget = true;
|
|
|
|
runtimeFont = CreateKoreanFontAsset();
|
|
}
|
|
|
|
private void SetDefaultOverlayBackground() {
|
|
if(overlayBackground != null)
|
|
{
|
|
overlayBackground.color = new Color(0.02f, 0.035f, 0.045f, 0.92f);
|
|
}
|
|
|
|
if(flowCamera != null)
|
|
{
|
|
flowCamera.backgroundColor = new Color(0.02f, 0.035f, 0.045f, 1f);
|
|
}
|
|
}
|
|
|
|
private void BuildIntroScreen() {
|
|
if(overlayBackground != null)
|
|
{
|
|
overlayBackground.color = Color.clear;
|
|
}
|
|
|
|
if(flowCamera != null)
|
|
{
|
|
flowCamera.backgroundColor = new Color(0.006f, 0.022f, 0.035f, 1f);
|
|
}
|
|
|
|
RectTransform mapRect = AddIntroWorldMap();
|
|
Vector2[] routePoints = GetIntroRoutePoints();
|
|
AddIntroRoute(mapRect, routePoints);
|
|
AddIntroPlane(mapRect, routePoints);
|
|
AddIntroPassportAndPhone();
|
|
AddIntroTitlePanel();
|
|
AddIntroButtonDock();
|
|
}
|
|
|
|
private void BuildOpeningStoryScreen() {
|
|
if(overlayBackground != null)
|
|
{
|
|
overlayBackground.color = new Color(0.012f, 0.018f, 0.024f, 0.96f);
|
|
}
|
|
|
|
if(flowCamera != null)
|
|
{
|
|
flowCamera.backgroundColor = new Color(0.012f, 0.018f, 0.024f, 1f);
|
|
}
|
|
|
|
openingStoryPageIndex = Mathf.Clamp(openingStoryPageIndex, 0, OpeningStoryPageAssetPaths.Length - 1);
|
|
AddOpeningStoryPage();
|
|
AddOpeningStoryProgressDots();
|
|
AddOpeningStoryControls();
|
|
}
|
|
|
|
private void AddOpeningStoryPage() {
|
|
GameObject shadowObject = CreateUiObject("Opening Story Shadow", overlayRoot, typeof(Image));
|
|
RectTransform shadowRect = shadowObject.GetComponent<RectTransform>();
|
|
shadowRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
shadowRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
shadowRect.pivot = new Vector2(0.5f, 0.5f);
|
|
shadowRect.anchoredPosition = new Vector2(7f, 18f);
|
|
shadowRect.sizeDelta = new Vector2(1132f, 637f);
|
|
|
|
Image shadowImage = shadowObject.GetComponent<Image>();
|
|
shadowImage.color = new Color(0f, 0f, 0f, 0.34f);
|
|
shadowImage.raycastTarget = false;
|
|
|
|
GameObject pageObject = CreateUiObject("Opening Story Page", overlayRoot, typeof(Image), typeof(Button));
|
|
RectTransform pageRect = pageObject.GetComponent<RectTransform>();
|
|
pageRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
pageRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
pageRect.pivot = new Vector2(0.5f, 0.5f);
|
|
pageRect.anchoredPosition = new Vector2(0f, 24f);
|
|
pageRect.sizeDelta = new Vector2(1120f, 630f);
|
|
|
|
Image pageImage = pageObject.GetComponent<Image>();
|
|
pageImage.sprite = LoadUiTextureSprite(OpeningStoryPageAssetPaths[openingStoryPageIndex]);
|
|
pageImage.color = pageImage.sprite != null
|
|
? Color.white
|
|
: new Color(0.91f, 0.87f, 0.78f, 1f);
|
|
pageImage.preserveAspect = true;
|
|
|
|
Button pageButton = pageObject.GetComponent<Button>();
|
|
pageButton.transition = Selectable.Transition.None;
|
|
pageButton.onClick.AddListener(AdvanceOpeningStory);
|
|
}
|
|
|
|
private void AddOpeningStoryProgressDots() {
|
|
float startX = -((OpeningStoryPageAssetPaths.Length - 1) * 18f) * 0.5f;
|
|
|
|
for(int i = 0; i < OpeningStoryPageAssetPaths.Length; i++)
|
|
{
|
|
GameObject dotObject = CreateUiObject("Opening Story Dot " + (i + 1), overlayRoot, typeof(Image));
|
|
RectTransform dotRect = dotObject.GetComponent<RectTransform>();
|
|
dotRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
dotRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
dotRect.pivot = new Vector2(0.5f, 0.5f);
|
|
dotRect.anchoredPosition = new Vector2(startX + (i * 18f), -324f);
|
|
dotRect.sizeDelta = i == openingStoryPageIndex ? new Vector2(12f, 12f) : new Vector2(8f, 8f);
|
|
|
|
Image dotImage = dotObject.GetComponent<Image>();
|
|
dotImage.color = i == openingStoryPageIndex
|
|
? new Color(1f, 0.86f, 0.28f, 0.95f)
|
|
: new Color(0.72f, 0.84f, 0.88f, 0.5f);
|
|
dotImage.raycastTarget = false;
|
|
}
|
|
}
|
|
|
|
private void AddOpeningStoryControls() {
|
|
if(openingStoryPageIndex > 0)
|
|
{
|
|
AddOpeningStoryButton("이전", new Vector2(-450f, -324f), PreviousOpeningStoryPage);
|
|
}
|
|
|
|
string nextLabel = openingStoryPageIndex >= OpeningStoryPageAssetPaths.Length - 1 ? "게임 시작" : "다음";
|
|
AddOpeningStoryButton(nextLabel, new Vector2(450f, -324f), AdvanceOpeningStory);
|
|
}
|
|
|
|
private void AddOpeningStoryButton(string label, Vector2 position, UnityEngine.Events.UnityAction action) {
|
|
GameObject buttonObject = CreateUiObject("Opening Story Button " + label, overlayRoot, typeof(Image), typeof(Button));
|
|
RectTransform buttonRect = buttonObject.GetComponent<RectTransform>();
|
|
buttonRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
buttonRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
buttonRect.pivot = new Vector2(0.5f, 0.5f);
|
|
buttonRect.anchoredPosition = position;
|
|
buttonRect.sizeDelta = label == "게임 시작" ? new Vector2(178f, 44f) : new Vector2(126f, 42f);
|
|
|
|
Image buttonImage = buttonObject.GetComponent<Image>();
|
|
buttonImage.color = label == "게임 시작"
|
|
? new Color(1f, 0.86f, 0.34f, 0.96f)
|
|
: new Color(0.88f, 0.96f, 1f, 0.88f);
|
|
|
|
Button button = buttonObject.GetComponent<Button>();
|
|
button.onClick.AddListener(action);
|
|
|
|
TextMeshProUGUI buttonText = AddTextTo(buttonObject.transform, "Label", label, label == "게임 시작" ? 17f : 15f, FontStyles.Bold);
|
|
RectTransform textRect = buttonText.rectTransform;
|
|
textRect.anchorMin = Vector2.zero;
|
|
textRect.anchorMax = Vector2.one;
|
|
textRect.offsetMin = Vector2.zero;
|
|
textRect.offsetMax = Vector2.zero;
|
|
buttonText.color = new Color(0.035f, 0.065f, 0.08f, 1f);
|
|
}
|
|
|
|
private void AdvanceOpeningStory() {
|
|
if(openingStoryPageIndex >= OpeningStoryPageAssetPaths.Length - 1)
|
|
{
|
|
LoadGameSceneForCurrentMap();
|
|
return;
|
|
}
|
|
|
|
openingStoryPageIndex++;
|
|
ShowOpeningStory();
|
|
}
|
|
|
|
private void PreviousOpeningStoryPage() {
|
|
if(openingStoryPageIndex <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
openingStoryPageIndex--;
|
|
ShowOpeningStory();
|
|
}
|
|
|
|
private RectTransform AddIntroWorldMap() {
|
|
GameObject mapObject = CreateUiObject("Intro World Map", overlayRoot, typeof(Image));
|
|
RectTransform mapRect = mapObject.GetComponent<RectTransform>();
|
|
mapRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
mapRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
mapRect.pivot = new Vector2(0.5f, 0.5f);
|
|
mapRect.anchoredPosition = Vector2.zero;
|
|
mapRect.sizeDelta = new Vector2(1280f, 720f);
|
|
|
|
Image mapImage = mapObject.GetComponent<Image>();
|
|
mapImage.sprite = LoadUiSprite("", "Assets/ConceptArt/Intro/intro_world_map_clean_01.png");
|
|
mapImage.color = mapImage.sprite != null
|
|
? Color.white
|
|
: new Color(0.015f, 0.078f, 0.112f, 0.76f);
|
|
mapImage.preserveAspect = true;
|
|
mapImage.raycastTarget = false;
|
|
|
|
GameObject vignetteObject = CreateUiObject("Intro Map Vignette", overlayRoot, typeof(Image));
|
|
RectTransform vignetteRect = vignetteObject.GetComponent<RectTransform>();
|
|
vignetteRect.anchorMin = Vector2.zero;
|
|
vignetteRect.anchorMax = Vector2.one;
|
|
vignetteRect.offsetMin = Vector2.zero;
|
|
vignetteRect.offsetMax = Vector2.zero;
|
|
|
|
Image vignetteImage = vignetteObject.GetComponent<Image>();
|
|
vignetteImage.color = new Color(0f, 0.006f, 0.012f, 0.08f);
|
|
vignetteImage.raycastTarget = false;
|
|
|
|
return mapRect;
|
|
}
|
|
|
|
private void AddIntroMapGrid(RectTransform mapRect) {
|
|
Color gridColor = new Color(0.46f, 0.86f, 1f, 0.12f);
|
|
|
|
for(int i = -5; i <= 5; i++)
|
|
{
|
|
GameObject lineObject = CreateUiObject("Intro Map Longitude " + i, mapRect, typeof(Image));
|
|
RectTransform lineRect = lineObject.GetComponent<RectTransform>();
|
|
lineRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
lineRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
lineRect.pivot = new Vector2(0.5f, 0.5f);
|
|
lineRect.anchoredPosition = new Vector2(i * 92f, 0f);
|
|
lineRect.sizeDelta = new Vector2(2f, 610f);
|
|
|
|
Image lineImage = lineObject.GetComponent<Image>();
|
|
lineImage.color = gridColor;
|
|
lineImage.raycastTarget = false;
|
|
}
|
|
|
|
for(int i = -3; i <= 3; i++)
|
|
{
|
|
GameObject lineObject = CreateUiObject("Intro Map Latitude " + i, mapRect, typeof(Image));
|
|
RectTransform lineRect = lineObject.GetComponent<RectTransform>();
|
|
lineRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
lineRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
lineRect.pivot = new Vector2(0.5f, 0.5f);
|
|
lineRect.anchoredPosition = new Vector2(0f, i * 74f);
|
|
lineRect.sizeDelta = new Vector2(1110f, 2f);
|
|
|
|
Image lineImage = lineObject.GetComponent<Image>();
|
|
lineImage.color = gridColor;
|
|
lineImage.raycastTarget = false;
|
|
}
|
|
}
|
|
|
|
private void AddIntroLandMass(RectTransform mapRect, string objectName, Vector2 position, Vector2 size, float rotation) {
|
|
GameObject landObject = CreateUiObject(objectName, mapRect, typeof(Image));
|
|
RectTransform landRect = landObject.GetComponent<RectTransform>();
|
|
landRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
landRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
landRect.pivot = new Vector2(0.5f, 0.5f);
|
|
landRect.anchoredPosition = position;
|
|
landRect.sizeDelta = size;
|
|
landRect.localRotation = Quaternion.Euler(0f, 0f, rotation);
|
|
|
|
Image landImage = landObject.GetComponent<Image>();
|
|
landImage.color = new Color(0.24f, 0.72f, 0.59f, 0.22f);
|
|
landImage.raycastTarget = false;
|
|
}
|
|
|
|
private Vector2[] GetIntroRoutePoints() {
|
|
return new Vector2[] {
|
|
new Vector2(356f, 50f),
|
|
new Vector2(405f, 58f),
|
|
new Vector2(316f, 42f),
|
|
new Vector2(-450f, 94f)
|
|
};
|
|
}
|
|
|
|
private void AddIntroRoute(RectTransform mapRect, Vector2[] routePoints) {
|
|
Color routeColor = new Color(1f, 0.86f, 0.28f, 0.82f);
|
|
|
|
for(int i = 0; i < routePoints.Length - 1; i++)
|
|
{
|
|
AddIntroRouteSegment(mapRect, routePoints[i], routePoints[i + 1], routeColor, 4f);
|
|
}
|
|
|
|
AddIntroRouteMarker(mapRect, routePoints[0], "INCHEON", true, 0f, new Vector2(-4f, -25f));
|
|
AddIntroRouteMarker(mapRect, routePoints[1], "JAPAN", false, 0.4f, new Vector2(28f, -20f));
|
|
AddIntroRouteMarker(mapRect, routePoints[2], "CHINA", false, 0.8f, new Vector2(-18f, -24f));
|
|
AddIntroRouteMarker(mapRect, routePoints[3], "AMERICA", false, 1.2f, new Vector2(0f, -25f));
|
|
}
|
|
|
|
private void AddIntroRouteSegment(RectTransform mapRect, Vector2 from, Vector2 to, Color color, float thickness) {
|
|
GameObject segmentObject = CreateUiObject("Intro Route Segment", mapRect, typeof(Image));
|
|
RectTransform segmentRect = segmentObject.GetComponent<RectTransform>();
|
|
Vector2 delta = to - from;
|
|
segmentRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
segmentRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
segmentRect.pivot = new Vector2(0.5f, 0.5f);
|
|
segmentRect.anchoredPosition = from + (delta * 0.5f);
|
|
segmentRect.sizeDelta = new Vector2(delta.magnitude, thickness);
|
|
segmentRect.localRotation = Quaternion.Euler(0f, 0f, Mathf.Atan2(delta.y, delta.x) * Mathf.Rad2Deg);
|
|
|
|
Image segmentImage = segmentObject.GetComponent<Image>();
|
|
segmentImage.color = color;
|
|
segmentImage.raycastTarget = false;
|
|
}
|
|
|
|
private void AddIntroRouteMarker(RectTransform mapRect, Vector2 position, string label, bool current, float phase, Vector2 labelOffset) {
|
|
GameObject markerObject = CreateUiObject("Intro Route Marker " + label, mapRect, typeof(Image));
|
|
RectTransform markerRect = markerObject.GetComponent<RectTransform>();
|
|
markerRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
markerRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
markerRect.pivot = new Vector2(0.5f, 0.5f);
|
|
markerRect.anchoredPosition = position;
|
|
markerRect.sizeDelta = current ? new Vector2(23f, 23f) : new Vector2(17f, 17f);
|
|
|
|
Image markerImage = markerObject.GetComponent<Image>();
|
|
markerImage.color = current
|
|
? new Color(1f, 0.92f, 0.22f, 0.95f)
|
|
: new Color(0.78f, 0.96f, 1f, 0.86f);
|
|
markerImage.raycastTarget = false;
|
|
|
|
FlowIntroFloatMotion markerMotion = markerObject.AddComponent<FlowIntroFloatMotion>();
|
|
markerMotion.scalePulse = current ? 0.18f : 0.09f;
|
|
markerMotion.frequency = new Vector2(0f, 0.72f);
|
|
markerMotion.phase = phase;
|
|
|
|
TextMeshProUGUI labelText = AddIntroMapLabel(mapRect, "Intro Marker Label " + label, label, position + labelOffset, new Vector2(84f, 20f), 9.5f);
|
|
labelText.color = current
|
|
? new Color(1f, 0.94f, 0.44f, 0.92f)
|
|
: new Color(0.78f, 0.94f, 1f, 0.72f);
|
|
}
|
|
|
|
private TextMeshProUGUI AddIntroMapLabel(RectTransform parent, string objectName, string text, Vector2 position, Vector2 size, float fontSize) {
|
|
GameObject textObject = CreateUiObject(objectName, parent);
|
|
RectTransform textRect = textObject.GetComponent<RectTransform>();
|
|
textRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
textRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
textRect.pivot = new Vector2(0.5f, 0.5f);
|
|
textRect.anchoredPosition = position;
|
|
textRect.sizeDelta = size;
|
|
|
|
TextMeshProUGUI textComponent = textObject.AddComponent<TextMeshProUGUI>();
|
|
textComponent.text = text;
|
|
textComponent.font = runtimeFont != null ? runtimeFont : textComponent.font;
|
|
textComponent.fontSize = fontSize;
|
|
textComponent.fontStyle = FontStyles.Bold;
|
|
textComponent.alignment = TextAlignmentOptions.Center;
|
|
textComponent.raycastTarget = false;
|
|
textComponent.textWrappingMode = TextWrappingModes.NoWrap;
|
|
return textComponent;
|
|
}
|
|
|
|
private void AddIntroPlane(RectTransform mapRect, Vector2[] routePoints) {
|
|
Sprite planeSprite = LoadUiSprite("", "Assets/Sprites/UIIcons/UI_AirplaneTravel.png");
|
|
GameObject planeObject = CreateUiObject("Intro Airplane", overlayRoot, typeof(Image));
|
|
RectTransform rectTransform = planeObject.GetComponent<RectTransform>();
|
|
rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
|
|
rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
|
|
rectTransform.pivot = new Vector2(0.5f, 0.5f);
|
|
rectTransform.anchoredPosition = routePoints[0] + mapRect.anchoredPosition;
|
|
rectTransform.sizeDelta = new Vector2(58f, 58f);
|
|
|
|
Image image = planeObject.GetComponent<Image>();
|
|
image.sprite = planeSprite;
|
|
image.color = planeSprite != null
|
|
? new Color(1f, 1f, 1f, 0.95f)
|
|
: new Color(0.9f, 0.97f, 1f, 0.88f);
|
|
image.preserveAspect = true;
|
|
image.raycastTarget = false;
|
|
|
|
FlowIntroRouteMotion motion = planeObject.AddComponent<FlowIntroRouteMotion>();
|
|
motion.points = routePoints;
|
|
motion.offset = mapRect.anchoredPosition;
|
|
motion.duration = 7.5f;
|
|
}
|
|
|
|
private void AddIntroPassportAndPhone() {
|
|
AddIntroPassportCover();
|
|
AddIntroSmartPhone();
|
|
}
|
|
|
|
private void AddIntroPassportCover() {
|
|
GameObject passportObject = CreateUiObject("Intro Passport Cover", overlayRoot, typeof(Image));
|
|
RectTransform passportRect = passportObject.GetComponent<RectTransform>();
|
|
passportRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
passportRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
passportRect.pivot = new Vector2(0.5f, 0.5f);
|
|
passportRect.anchoredPosition = new Vector2(424f, -242f);
|
|
passportRect.sizeDelta = new Vector2(270f, 300f);
|
|
passportRect.localRotation = Quaternion.Euler(0f, 0f, -24f);
|
|
|
|
Image passportImage = passportObject.GetComponent<Image>();
|
|
passportImage.sprite = LoadUiTextureSprite("Assets/ConceptArt/Intro/UI/intro_passport_clean.png");
|
|
passportImage.color = passportImage.sprite != null
|
|
? new Color(1f, 1f, 1f, 0.98f)
|
|
: new Color(0.034f, 0.18f, 0.22f, 0.96f);
|
|
passportImage.preserveAspect = true;
|
|
passportImage.raycastTarget = false;
|
|
}
|
|
|
|
private void AddIntroSmartPhone() {
|
|
GameObject phoneObject = CreateUiObject("Intro Smart Phone", overlayRoot, typeof(Image));
|
|
RectTransform phoneRect = phoneObject.GetComponent<RectTransform>();
|
|
phoneRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
phoneRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
phoneRect.pivot = new Vector2(0.5f, 0.5f);
|
|
phoneRect.anchoredPosition = new Vector2(558f, -218f);
|
|
phoneRect.sizeDelta = new Vector2(132f, 252f);
|
|
phoneRect.localRotation = Quaternion.Euler(0f, 0f, 10f);
|
|
|
|
Image phoneImage = phoneObject.GetComponent<Image>();
|
|
phoneImage.sprite = LoadUiTextureSprite("Assets/ConceptArt/Intro/UI/intro_phone_clean.png");
|
|
phoneImage.color = phoneImage.sprite != null
|
|
? new Color(1f, 1f, 1f, 0.98f)
|
|
: new Color(0.015f, 0.018f, 0.022f, 0.98f);
|
|
phoneImage.preserveAspect = true;
|
|
phoneImage.raycastTarget = false;
|
|
|
|
FlowIntroFloatMotion phoneMotion = phoneObject.AddComponent<FlowIntroFloatMotion>();
|
|
phoneMotion.amplitude = new Vector2(0f, 5f);
|
|
phoneMotion.frequency = new Vector2(0f, 0.45f);
|
|
phoneMotion.phase = 0.6f;
|
|
}
|
|
|
|
private void AddIntroTitlePanel() {
|
|
GameObject titleObject = CreateUiObject("Intro Title Lockup", overlayRoot, typeof(Image));
|
|
RectTransform titleRect = titleObject.GetComponent<RectTransform>();
|
|
titleRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
titleRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
titleRect.pivot = new Vector2(0.5f, 0.5f);
|
|
titleRect.anchoredPosition = new Vector2(-364f, 196f);
|
|
titleRect.sizeDelta = new Vector2(448f, 166f);
|
|
|
|
Image titleImage = titleObject.GetComponent<Image>();
|
|
titleImage.sprite = LoadUiTextureSprite("Assets/ConceptArt/Intro/UI/intro_title_lockup.png");
|
|
titleImage.color = titleImage.sprite != null
|
|
? Color.white
|
|
: new Color(0.86f, 0.98f, 1f, 0.94f);
|
|
titleImage.preserveAspect = true;
|
|
titleImage.raycastTarget = false;
|
|
}
|
|
|
|
private void AddIntroButtonDock() {
|
|
GameObject dockObject = CreateUiObject("Intro Button Dock", overlayRoot);
|
|
RectTransform dockRect = dockObject.GetComponent<RectTransform>();
|
|
dockRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
dockRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
dockRect.pivot = new Vector2(0.5f, 0.5f);
|
|
dockRect.anchoredPosition = new Vector2(0f, -224f);
|
|
dockRect.sizeDelta = new Vector2(424f, 136f);
|
|
|
|
AddIntroButton(dockRect, "게임 시작", new Vector2(45f, 0f), StartNewJourney, true, 0);
|
|
AddIntroButton(dockRect, "이어하기", new Vector2(0f, -76f), ContinueJourney, false, 1);
|
|
AddIntroButton(dockRect, "설정", new Vector2(220f, -76f), ShowIntroSettingsPlaceholder, false, 2);
|
|
}
|
|
|
|
private void AddIntroButton(RectTransform parent, string label, Vector2 position, UnityEngine.Events.UnityAction action, bool primary, int buttonStyle) {
|
|
GameObject buttonObject = CreateUiObject("Button " + label, parent, typeof(Image), typeof(Button));
|
|
RectTransform buttonRect = buttonObject.GetComponent<RectTransform>();
|
|
buttonRect.anchorMin = new Vector2(0f, 1f);
|
|
buttonRect.anchorMax = new Vector2(0f, 1f);
|
|
buttonRect.pivot = new Vector2(0f, 1f);
|
|
buttonRect.anchoredPosition = position;
|
|
buttonRect.sizeDelta = primary ? new Vector2(334f, 74f) : new Vector2(204f, 58f);
|
|
|
|
Image buttonImage = buttonObject.GetComponent<Image>();
|
|
buttonImage.sprite = GetIntroButtonSprite(primary, buttonStyle);
|
|
buttonImage.color = buttonImage.sprite != null
|
|
? Color.white
|
|
: primary
|
|
? new Color(0.98f, 0.88f, 0.38f, 0.96f)
|
|
: new Color(0.88f, 0.96f, 1f, 0.9f);
|
|
buttonImage.preserveAspect = true;
|
|
buttonImage.raycastTarget = true;
|
|
|
|
Button button = buttonObject.GetComponent<Button>();
|
|
button.targetGraphic = buttonImage;
|
|
button.navigation = new Navigation {
|
|
mode = Navigation.Mode.None
|
|
};
|
|
|
|
GameObject stampObject = CreateUiObject("Departure Stamp", buttonObject.transform, typeof(Image));
|
|
RectTransform stampRect = stampObject.GetComponent<RectTransform>();
|
|
stampRect.anchorMin = new Vector2(1f, 0.5f);
|
|
stampRect.anchorMax = new Vector2(1f, 0.5f);
|
|
stampRect.pivot = new Vector2(0.5f, 0.5f);
|
|
stampRect.anchoredPosition = new Vector2(primary ? -47f : -28f, primary ? 1f : 0f);
|
|
stampRect.sizeDelta = primary ? new Vector2(58f, 58f) : new Vector2(44f, 44f);
|
|
stampRect.localRotation = Quaternion.Euler(0f, 0f, -12f);
|
|
|
|
Image stampImage = stampObject.GetComponent<Image>();
|
|
stampImage.sprite = LoadUiSpriteRegion("Assets/ConceptArt/Intro/intro_stamps_01.png", new Rect(54f, 48f, 790f, 790f));
|
|
stampImage.color = stampImage.sprite != null
|
|
? new Color(1f, 1f, 1f, 0.94f)
|
|
: new Color(0.76f, 0.08f, 0.06f, 0.96f);
|
|
stampImage.preserveAspect = true;
|
|
stampImage.raycastTarget = false;
|
|
|
|
TextMeshProUGUI stampText = AddTextTo(stampObject.transform, "Stamp Label", "출국", primary ? 13f : 11f, FontStyles.Bold);
|
|
RectTransform stampTextRect = stampText.rectTransform;
|
|
stampTextRect.anchorMin = Vector2.zero;
|
|
stampTextRect.anchorMax = Vector2.one;
|
|
stampTextRect.offsetMin = Vector2.zero;
|
|
stampTextRect.offsetMax = Vector2.zero;
|
|
stampText.color = new Color(0.74f, 0.04f, 0.03f, 0.98f);
|
|
stampObject.SetActive(false);
|
|
|
|
button.onClick.AddListener(delegate {
|
|
button.interactable = false;
|
|
stampObject.SetActive(true);
|
|
FlowIntroStampMotion stampMotion = stampObject.GetComponent<FlowIntroStampMotion>();
|
|
if(stampMotion == null)
|
|
{
|
|
stampMotion = stampObject.AddComponent<FlowIntroStampMotion>();
|
|
}
|
|
|
|
stampMotion.Play();
|
|
StartCoroutine(InvokeIntroActionAfterStamp(action));
|
|
});
|
|
|
|
if(primary)
|
|
{
|
|
FlowIntroFloatMotion motion = buttonObject.AddComponent<FlowIntroFloatMotion>();
|
|
motion.scalePulse = 0.018f;
|
|
motion.frequency = new Vector2(0f, 0.55f);
|
|
}
|
|
}
|
|
|
|
private void AddIntroButtonIcon(Transform parent, int buttonStyle) {
|
|
GameObject iconObject = CreateUiObject("Button Icon", parent, typeof(Image));
|
|
RectTransform iconRect = iconObject.GetComponent<RectTransform>();
|
|
iconRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
iconRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
iconRect.pivot = new Vector2(0.5f, 0.5f);
|
|
iconRect.anchoredPosition = new Vector2(-38f, 0f);
|
|
iconRect.sizeDelta = new Vector2(30f, 30f);
|
|
|
|
Image iconImage = iconObject.GetComponent<Image>();
|
|
iconImage.sprite = GetIntroButtonIconSprite(buttonStyle);
|
|
iconImage.color = iconImage.sprite != null
|
|
? new Color(1f, 1f, 1f, 0.96f)
|
|
: new Color(0.94f, 0.98f, 1f, 0.92f);
|
|
iconImage.preserveAspect = true;
|
|
iconImage.raycastTarget = false;
|
|
}
|
|
|
|
private Sprite GetIntroButtonSprite(bool primary, int buttonStyle) {
|
|
if(primary)
|
|
{
|
|
return LoadUiTextureSprite("Assets/ConceptArt/Intro/UI/intro_button_start.png");
|
|
}
|
|
|
|
if(buttonStyle == 2)
|
|
{
|
|
return LoadUiTextureSprite("Assets/ConceptArt/Intro/UI/intro_button_settings.png");
|
|
}
|
|
|
|
return LoadUiTextureSprite("Assets/ConceptArt/Intro/UI/intro_button_continue.png");
|
|
}
|
|
|
|
private Sprite GetIntroButtonIconSprite(int buttonStyle) {
|
|
if(buttonStyle == 2)
|
|
{
|
|
return LoadUiTextureSprite("Assets/ConceptArt/Intro/Cutouts/intro_icon_settings.png");
|
|
}
|
|
|
|
return LoadUiTextureSprite("Assets/ConceptArt/Intro/Cutouts/intro_icon_continue.png");
|
|
}
|
|
|
|
private void ShowIntroSettingsPlaceholder() {
|
|
ShowIntro();
|
|
}
|
|
|
|
private IEnumerator InvokeIntroActionAfterStamp(UnityEngine.Events.UnityAction action) {
|
|
yield return new WaitForSecondsRealtime(0.32f);
|
|
|
|
if(action != null)
|
|
{
|
|
action.Invoke();
|
|
}
|
|
}
|
|
|
|
private TextMeshProUGUI AddTextToPanel(RectTransform parent, string objectName, string text, Vector2 position, Vector2 size, float fontSize, FontStyles fontStyle, TextAlignmentOptions alignment) {
|
|
GameObject textObject = CreateUiObject(objectName, parent);
|
|
RectTransform textRect = textObject.GetComponent<RectTransform>();
|
|
textRect.anchorMin = new Vector2(0f, 1f);
|
|
textRect.anchorMax = new Vector2(0f, 1f);
|
|
textRect.pivot = new Vector2(0f, 1f);
|
|
textRect.anchoredPosition = position;
|
|
textRect.sizeDelta = size;
|
|
|
|
TextMeshProUGUI textComponent = textObject.AddComponent<TextMeshProUGUI>();
|
|
textComponent.text = text;
|
|
textComponent.font = runtimeFont != null ? runtimeFont : textComponent.font;
|
|
textComponent.fontSize = fontSize;
|
|
textComponent.fontStyle = fontStyle;
|
|
textComponent.alignment = alignment;
|
|
textComponent.color = new Color(0.95f, 0.98f, 1f, 0.96f);
|
|
textComponent.raycastTarget = false;
|
|
textComponent.textWrappingMode = TextWrappingModes.Normal;
|
|
return textComponent;
|
|
}
|
|
|
|
private GameObject CreateUiObject(string objectName, Transform parent, params System.Type[] components) {
|
|
System.Type[] finalComponents;
|
|
if(components == null || components.Length == 0)
|
|
{
|
|
finalComponents = new System.Type[] {
|
|
typeof(RectTransform),
|
|
typeof(CanvasRenderer)
|
|
};
|
|
}
|
|
else
|
|
{
|
|
finalComponents = new System.Type[components.Length + 2];
|
|
finalComponents[0] = typeof(RectTransform);
|
|
finalComponents[1] = typeof(CanvasRenderer);
|
|
for(int i = 0; i < components.Length; i++)
|
|
{
|
|
finalComponents[i + 2] = components[i];
|
|
}
|
|
}
|
|
|
|
GameObject gameObject = new GameObject(objectName, finalComponents);
|
|
gameObject.transform.SetParent(parent, false);
|
|
SetUiLayer(gameObject);
|
|
return gameObject;
|
|
}
|
|
|
|
private void SetUiLayer(GameObject gameObject) {
|
|
if(gameObject != null)
|
|
{
|
|
gameObject.layer = GetUiLayer();
|
|
}
|
|
}
|
|
|
|
private int GetUiLayer() {
|
|
int uiLayer = LayerMask.NameToLayer("UI");
|
|
return uiLayer >= 0 ? uiLayer : 0;
|
|
}
|
|
|
|
private Sprite LoadUiSprite(string resourcePath, string assetPath) {
|
|
if(!string.IsNullOrEmpty(resourcePath))
|
|
{
|
|
Sprite resourceSprite = Resources.Load<Sprite>(resourcePath);
|
|
if(resourceSprite != null)
|
|
{
|
|
return resourceSprite;
|
|
}
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
if(!string.IsNullOrEmpty(assetPath))
|
|
{
|
|
Object[] assets = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath);
|
|
if(assets != null)
|
|
{
|
|
for(int i = 0; i < assets.Length; i++)
|
|
{
|
|
Sprite sprite = assets[i] as Sprite;
|
|
if(sprite != null)
|
|
{
|
|
return sprite;
|
|
}
|
|
}
|
|
}
|
|
|
|
Sprite directSprite = AssetDatabase.LoadAssetAtPath<Sprite>(assetPath);
|
|
if(directSprite != null)
|
|
{
|
|
return directSprite;
|
|
}
|
|
|
|
Texture2D texture = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
|
|
if(texture == null)
|
|
{
|
|
AssetDatabase.Refresh();
|
|
texture = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
|
|
}
|
|
|
|
if(texture != null)
|
|
{
|
|
return Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100f);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
return null;
|
|
}
|
|
|
|
private Sprite LoadUiTextureSprite(string assetPath) {
|
|
#if UNITY_EDITOR
|
|
if(string.IsNullOrEmpty(assetPath))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
Texture2D texture = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
|
|
if(texture == null)
|
|
{
|
|
AssetDatabase.Refresh();
|
|
texture = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
|
|
}
|
|
|
|
if(texture == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100f);
|
|
#else
|
|
return null;
|
|
#endif
|
|
}
|
|
|
|
private Sprite LoadUiSpriteRegion(string assetPath, Rect pixelRect) {
|
|
#if UNITY_EDITOR
|
|
if(string.IsNullOrEmpty(assetPath))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
Texture2D texture = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
|
|
if(texture == null)
|
|
{
|
|
AssetDatabase.Refresh();
|
|
texture = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
|
|
}
|
|
|
|
if(texture == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
Rect safeRect = ClampSpriteRect(pixelRect, texture.width, texture.height);
|
|
if(safeRect.width <= 0f || safeRect.height <= 0f)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return Sprite.Create(texture, safeRect, new Vector2(0.5f, 0.5f), 100f);
|
|
#else
|
|
return null;
|
|
#endif
|
|
}
|
|
|
|
private Rect ClampSpriteRect(Rect pixelRect, int textureWidth, int textureHeight) {
|
|
float xMin = Mathf.Clamp(pixelRect.xMin, 0f, textureWidth);
|
|
float yMin = Mathf.Clamp(pixelRect.yMin, 0f, textureHeight);
|
|
float xMax = Mathf.Clamp(pixelRect.xMax, 0f, textureWidth);
|
|
float yMax = Mathf.Clamp(pixelRect.yMax, 0f, textureHeight);
|
|
|
|
if(xMax < xMin)
|
|
{
|
|
xMax = xMin;
|
|
}
|
|
|
|
if(yMax < yMin)
|
|
{
|
|
yMax = yMin;
|
|
}
|
|
|
|
return Rect.MinMaxRect(xMin, yMin, xMax, yMax);
|
|
}
|
|
|
|
private void EnsureEventSystem() {
|
|
if(EventSystem.current != null)
|
|
{
|
|
EventSystem.current.enabled = true;
|
|
EventSystem.current.gameObject.SetActive(true);
|
|
|
|
StandaloneInputModule inputModule = EventSystem.current.GetComponent<StandaloneInputModule>();
|
|
if(inputModule == null)
|
|
{
|
|
inputModule = EventSystem.current.gameObject.AddComponent<StandaloneInputModule>();
|
|
}
|
|
|
|
inputModule.enabled = true;
|
|
DontDestroyOnLoad(EventSystem.current.gameObject);
|
|
return;
|
|
}
|
|
|
|
GameObject eventSystemObject = new GameObject("EventSystem", typeof(EventSystem), typeof(StandaloneInputModule));
|
|
DontDestroyOnLoad(eventSystemObject);
|
|
}
|
|
|
|
private void EnsureFlowCamera() {
|
|
if(flowCamera != null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GameObject cameraObject = new GameObject("Flow UI Camera", typeof(Camera));
|
|
DontDestroyOnLoad(cameraObject);
|
|
|
|
flowCamera = cameraObject.GetComponent<Camera>();
|
|
flowCamera.transform.position = new Vector3(640f, 360f, -10f);
|
|
flowCamera.clearFlags = CameraClearFlags.SolidColor;
|
|
flowCamera.backgroundColor = new Color(0.006f, 0.022f, 0.035f, 1f);
|
|
flowCamera.cullingMask = 1 << GetUiLayer();
|
|
flowCamera.depth = 100f;
|
|
flowCamera.orthographic = true;
|
|
flowCamera.orthographicSize = 360f;
|
|
}
|
|
|
|
private void ClearOverlay() {
|
|
if(overlayRoot == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for(int i = overlayRoot.childCount - 1; i >= 0; i--)
|
|
{
|
|
Destroy(overlayRoot.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
|
|
private void SetOverlayVisible(bool visible) {
|
|
if(overlayCanvas != null)
|
|
{
|
|
overlayCanvas.gameObject.SetActive(visible);
|
|
}
|
|
|
|
if(flowCamera != null)
|
|
{
|
|
flowCamera.gameObject.SetActive(visible);
|
|
}
|
|
}
|
|
|
|
private void AddTitle(string text) {
|
|
TextMeshProUGUI title = AddText("Title", text, 34f, FontStyles.Bold);
|
|
RectTransform rectTransform = title.rectTransform;
|
|
rectTransform.anchoredPosition = new Vector2(0f, 160f);
|
|
rectTransform.sizeDelta = new Vector2(760f, 62f);
|
|
}
|
|
|
|
private void AddBody(string text) {
|
|
TextMeshProUGUI body = AddText("Body", text, 17f, FontStyles.Normal);
|
|
RectTransform rectTransform = body.rectTransform;
|
|
rectTransform.anchoredPosition = new Vector2(0f, 52f - (GetBodyCount() * 82f));
|
|
rectTransform.sizeDelta = new Vector2(760f, 96f);
|
|
}
|
|
|
|
private void AddButton(string label, UnityEngine.Events.UnityAction action) {
|
|
int buttonIndex = GetButtonCount();
|
|
|
|
GameObject buttonObject = new GameObject("Button " + label, typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button));
|
|
buttonObject.transform.SetParent(overlayRoot, false);
|
|
SetUiLayer(buttonObject);
|
|
|
|
RectTransform buttonRect = buttonObject.GetComponent<RectTransform>();
|
|
buttonRect.anchorMin = new Vector2(0.5f, 0.5f);
|
|
buttonRect.anchorMax = new Vector2(0.5f, 0.5f);
|
|
buttonRect.pivot = new Vector2(0.5f, 0.5f);
|
|
buttonRect.anchoredPosition = new Vector2(0f, -82f - (buttonIndex * 46f));
|
|
buttonRect.sizeDelta = new Vector2(260f, 34f);
|
|
|
|
Image buttonImage = buttonObject.GetComponent<Image>();
|
|
buttonImage.color = new Color(0.92f, 0.96f, 1f, 0.95f);
|
|
|
|
Button button = buttonObject.GetComponent<Button>();
|
|
button.onClick.AddListener(action);
|
|
|
|
TextMeshProUGUI buttonText = AddTextTo(buttonObject.transform, "Label", label, 15f, FontStyles.Bold);
|
|
RectTransform textRect = buttonText.rectTransform;
|
|
textRect.anchorMin = Vector2.zero;
|
|
textRect.anchorMax = Vector2.one;
|
|
textRect.offsetMin = Vector2.zero;
|
|
textRect.offsetMax = Vector2.zero;
|
|
buttonText.color = new Color(0.04f, 0.07f, 0.09f, 1f);
|
|
}
|
|
|
|
private int GetBodyCount() {
|
|
int count = 0;
|
|
|
|
for(int i = 0; i < overlayRoot.childCount; i++)
|
|
{
|
|
if(overlayRoot.GetChild(i).name.StartsWith("Body"))
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
private int GetButtonCount() {
|
|
int count = 0;
|
|
|
|
for(int i = 0; i < overlayRoot.childCount; i++)
|
|
{
|
|
if(overlayRoot.GetChild(i).name.StartsWith("Button"))
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
private TextMeshProUGUI AddText(string objectName, string text, float fontSize, FontStyles fontStyle) {
|
|
GameObject textObject = new GameObject(objectName + " " + GetBodyCount(), typeof(RectTransform), typeof(CanvasRenderer));
|
|
textObject.transform.SetParent(overlayRoot, false);
|
|
SetUiLayer(textObject);
|
|
|
|
RectTransform rectTransform = textObject.GetComponent<RectTransform>();
|
|
rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
|
|
rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
|
|
rectTransform.pivot = new Vector2(0.5f, 0.5f);
|
|
|
|
TextMeshProUGUI label = textObject.AddComponent<TextMeshProUGUI>();
|
|
label.text = text;
|
|
label.font = runtimeFont != null ? runtimeFont : label.font;
|
|
label.fontSize = fontSize;
|
|
label.fontStyle = fontStyle;
|
|
label.alignment = TextAlignmentOptions.Center;
|
|
label.color = new Color(0.95f, 0.98f, 1f, 1f);
|
|
label.raycastTarget = false;
|
|
label.textWrappingMode = TextWrappingModes.Normal;
|
|
return label;
|
|
}
|
|
|
|
private TextMeshProUGUI AddTextTo(Transform parent, string objectName, string text, float fontSize, FontStyles fontStyle) {
|
|
GameObject textObject = new GameObject(objectName, typeof(RectTransform), typeof(CanvasRenderer));
|
|
textObject.transform.SetParent(parent, false);
|
|
SetUiLayer(textObject);
|
|
TextMeshProUGUI label = textObject.AddComponent<TextMeshProUGUI>();
|
|
label.text = text;
|
|
label.font = runtimeFont != null ? runtimeFont : label.font;
|
|
label.fontSize = fontSize;
|
|
label.fontStyle = fontStyle;
|
|
label.alignment = TextAlignmentOptions.Center;
|
|
label.raycastTarget = false;
|
|
label.textWrappingMode = TextWrappingModes.NoWrap;
|
|
return label;
|
|
}
|
|
|
|
private TMP_FontAsset CreateKoreanFontAsset() {
|
|
string[] familyNames = {
|
|
"Malgun Gothic",
|
|
"맑은 고딕",
|
|
"Arial Unicode MS"
|
|
};
|
|
|
|
for(int i = 0; i < familyNames.Length; i++)
|
|
{
|
|
TMP_FontAsset fontAsset = TMP_FontAsset.CreateFontAsset(familyNames[i], "Regular", 80);
|
|
if(fontAsset != null)
|
|
{
|
|
fontAsset.name = "Runtime Flow Korean Font";
|
|
return fontAsset;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|