151 lines
4.0 KiB
C#
151 lines
4.0 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.SceneManagement;
|
|
using System.Collections; // 必須引入 Coroutine
|
|
|
|
public class UIManager_Main : MonoBehaviour
|
|
{
|
|
public GridSpawner gridSpawner;
|
|
public HoldHintSpawner holdHintSpawner;
|
|
public GridDisplaySpawner gridDisplaySpawner;
|
|
|
|
public TouchManager_Main touchManager;
|
|
|
|
public Sprite imgAccount;
|
|
public Sprite imgSetting;
|
|
public Sprite imgWebsite;
|
|
public Sprite imgHoldStart;
|
|
public Sprite imgArrowRight;
|
|
public Sprite imgArrrowLeft;
|
|
public Sprite imgArrrowUp;
|
|
public Sprite imgArrrowDown;
|
|
|
|
public GameObject Start_1;
|
|
public GameObject Start_2;
|
|
public GameObject Start_3;
|
|
|
|
public string settingSceneName = "SettingScene";
|
|
public string accountSceneName = "AccountScene";
|
|
public string chooseSceneName = "ChooseScene";
|
|
|
|
// 開場動畫只在 app 啟動時播一次
|
|
private static bool introShown = false;
|
|
// 選單圖示出現前不接受操作(避免點到開場畫面下的格子)
|
|
private bool menuReady = false;
|
|
|
|
private bool isHolding = false;
|
|
private bool holdTriggered = false;
|
|
|
|
private float holdTimer = 0f;
|
|
private float holdTarget = 1f;
|
|
|
|
private int holdX, holdY;
|
|
|
|
void Start()
|
|
{
|
|
PlayerPrefs.SetInt("NowPlayingLevel", 1);
|
|
|
|
Start_1.SetActive(false);
|
|
Start_2.SetActive(false);
|
|
Start_3.SetActive(false);
|
|
|
|
if (introShown)
|
|
ShowMenu();
|
|
else
|
|
StartCoroutine(ShowStartPanelsSequence());
|
|
|
|
touchManager.OnTap += HandleTap;
|
|
touchManager.OnHoldStart += StartHold;
|
|
touchManager.OnHoldEnd += StopHold;
|
|
}
|
|
|
|
IEnumerator ShowStartPanelsSequence()
|
|
{
|
|
Start_1.SetActive(true);
|
|
yield return new WaitForSeconds(1.885f);
|
|
|
|
Start_1.SetActive(false);
|
|
Start_2.SetActive(true);
|
|
yield return new WaitForSeconds(1.846f);
|
|
|
|
Start_2.SetActive(false);
|
|
Start_3.SetActive(true);
|
|
yield return new WaitForSeconds(1.846f);
|
|
|
|
Start_3.SetActive(false);
|
|
introShown = true;
|
|
ShowMenu();
|
|
}
|
|
|
|
void ShowMenu()
|
|
{
|
|
menuReady = true;
|
|
gridDisplaySpawner.SetImage(1, 5, imgAccount);
|
|
gridDisplaySpawner.SetImage(2, 5, imgSetting);
|
|
gridDisplaySpawner.SetImage(3, 5, imgWebsite);
|
|
gridDisplaySpawner.SetImage(2, 2, imgHoldStart);
|
|
gridDisplaySpawner.SetImage(1, 2, imgArrowRight);
|
|
gridDisplaySpawner.SetImage(3, 2, imgArrrowLeft);
|
|
gridDisplaySpawner.SetImage(2, 1, imgArrrowUp);
|
|
gridDisplaySpawner.SetImage(2, 3, imgArrrowDown);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (isHolding)
|
|
{
|
|
holdTimer += Time.deltaTime;
|
|
|
|
if (!holdTriggered && holdTimer >= holdTarget)
|
|
{
|
|
holdTriggered = true;
|
|
|
|
// 清圖示
|
|
gridDisplaySpawner.Clear(1, 5);
|
|
gridDisplaySpawner.Clear(2, 5);
|
|
gridDisplaySpawner.Clear(3, 5);
|
|
gridDisplaySpawner.Clear(2, 2);
|
|
gridDisplaySpawner.Clear(1, 2);
|
|
gridDisplaySpawner.Clear(3, 2);
|
|
gridDisplaySpawner.Clear(2, 1);
|
|
gridDisplaySpawner.Clear(2, 3);
|
|
|
|
SceneManager.LoadScene(chooseSceneName);
|
|
}
|
|
}
|
|
}
|
|
|
|
void HandleTap(int x, int y)
|
|
{
|
|
if (!menuReady) return;
|
|
|
|
if (x == 1 && y == 5) SceneManager.LoadScene(accountSceneName);
|
|
if (x == 2 && y == 5) SceneManager.LoadScene(settingSceneName);
|
|
if (x == 3 && y == 5) Application.OpenURL("https://sthkm3.org");
|
|
}
|
|
|
|
void StartHold(int x, int y)
|
|
{
|
|
if (!menuReady) return;
|
|
|
|
isHolding = true;
|
|
holdTriggered = false;
|
|
holdTimer = 0f;
|
|
holdX = x;
|
|
holdY = y;
|
|
|
|
holdHintSpawner.StartProgressAt(x, y, holdTarget);
|
|
}
|
|
|
|
void StopHold()
|
|
{
|
|
if (!isHolding) return;
|
|
|
|
isHolding = false;
|
|
holdTriggered = false;
|
|
holdTimer = 0f;
|
|
|
|
holdHintSpawner.StopProgressAt(holdX, holdY);
|
|
}
|
|
}
|