Initial import of Rhyculator
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
commit
728bb0c657
315 files changed
+96030
No files matched your search
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GridDisplay_MainScene : MonoBehaviour
|
||||
{
|
||||
public GridManager_MainScene gridManager;
|
||||
|
||||
public Sprite imgAccount;
|
||||
public Sprite imgSetting;
|
||||
public Sprite imgWebsite;
|
||||
|
||||
private bool initialized = false;
|
||||
|
||||
void Update()
|
||||
{
|
||||
// 等待 GridManager
|
||||
if (!initialized && gridManager != null && gridManager.gridCells != null)
|
||||
{
|
||||
if (gridManager.gridCells[0,0] != null)
|
||||
{
|
||||
InitDisplay();
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InitDisplay()
|
||||
{
|
||||
PlaceImage(1, 5, imgAccount);
|
||||
PlaceImage(2, 5, imgSetting);
|
||||
PlaceImage(3, 5, imgWebsite);
|
||||
}
|
||||
|
||||
void PlaceImage(int cellX, int cellY, Sprite sprite)
|
||||
{
|
||||
var cell = gridManager.gridCells[cellX, cellY];
|
||||
if (cell == null) return;
|
||||
|
||||
GameObject obj = new GameObject("DisplayIcon", typeof(RectTransform), typeof(Image));
|
||||
obj.transform.SetParent(cell.transform, false);
|
||||
|
||||
Image img = obj.GetComponent<Image>();
|
||||
img.sprite = sprite;
|
||||
img.preserveAspect = true;
|
||||
|
||||
RectTransform rt = obj.GetComponent<RectTransform>();
|
||||
rt.anchorMin = Vector2.zero;
|
||||
rt.anchorMax = Vector2.one;
|
||||
rt.offsetMin = Vector2.zero;
|
||||
rt.offsetMax = Vector2.zero;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8c7d3a3af0b5554089fa9c8ef5b0ac1
|
||||
@@ -0,0 +1,125 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class GridManager : MonoBehaviour
|
||||
{
|
||||
public GameObject cellPrefab; // Grid_cell 預製件
|
||||
public int rows = 6;
|
||||
public int columns = 5;
|
||||
public GridColor[,] gridCells;
|
||||
public string settingSceneName = "SettingScene";
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
// === 這裡設定比例 ===
|
||||
float baseWidth = 1080f; // 你的基準寬度
|
||||
float cellBase = 180f; // 格子原始比例
|
||||
float spaceBase = 20f; // 間距原始比例
|
||||
float heightBase = 90f; // 上推高度 邊60*1.5
|
||||
|
||||
// 以螢幕寬度計算等比例縮放
|
||||
float scale = Screen.width / baseWidth;
|
||||
|
||||
float cellSize = cellBase * scale;
|
||||
float spacing = spaceBase * scale;
|
||||
float heightOffset = heightBase * scale;
|
||||
|
||||
// 建立二維陣列
|
||||
gridCells = new GridColor[columns, rows];
|
||||
|
||||
// 計算最底部開始的起點 (Bottom Center)
|
||||
RectTransform rt = GetComponent<RectTransform>();
|
||||
if (rt == null) rt = gameObject.AddComponent<RectTransform>();
|
||||
|
||||
// 保證錨點是 bottom center
|
||||
rt.anchorMin = new Vector2(0.5f, 0f);
|
||||
rt.anchorMax = new Vector2(0.5f, 0f);
|
||||
rt.pivot = new Vector2(0.5f, 0f);
|
||||
|
||||
// 整個 grid 的寬度
|
||||
float totalWidth = columns * cellSize + (columns - 1) * spacing;
|
||||
|
||||
// 左邊起點(因為錨點是中心)
|
||||
float startX = -totalWidth / 2f;
|
||||
|
||||
// Y 起點永遠是 0(底部)
|
||||
float startY = heightOffset;
|
||||
|
||||
for (int i = 0; i < rows * columns; i++)
|
||||
{
|
||||
// 生成格子
|
||||
GameObject cellObj = Instantiate(cellPrefab, transform);
|
||||
|
||||
int x = i % columns;
|
||||
int y = i / columns;
|
||||
|
||||
RectTransform cellRT = cellObj.GetComponent<RectTransform>();
|
||||
|
||||
// 設定錨點跟 pivot(全用左下)
|
||||
cellRT.anchorMin = new Vector2(0f, 0f);
|
||||
cellRT.anchorMax = new Vector2(0f, 0f);
|
||||
cellRT.pivot = new Vector2(0f, 0f);
|
||||
|
||||
// 設定大小
|
||||
cellRT.sizeDelta = new Vector2(cellSize, cellSize);
|
||||
|
||||
// 計算位置(由下往上排列)
|
||||
float posX = startX + x * (cellSize + spacing);
|
||||
float posY = startY + y * (cellSize + spacing);
|
||||
|
||||
cellRT.anchoredPosition = new Vector2(posX, posY);
|
||||
|
||||
// 設定 GridColor
|
||||
GridColor cellColor = cellObj.GetComponent<GridColor>();
|
||||
cellColor.cellX = x;
|
||||
cellColor.cellY = y;
|
||||
|
||||
gridCells[x, y] = cellColor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
DetectTouch();
|
||||
}
|
||||
|
||||
void DetectTouch()
|
||||
{
|
||||
if (Touchscreen.current == null) return;
|
||||
|
||||
foreach (var touch in Touchscreen.current.touches)
|
||||
{
|
||||
if (!touch.isInProgress) continue;
|
||||
|
||||
Vector2 touchPos = touch.position.ReadValue();
|
||||
var phase = touch.phase.ReadValue();
|
||||
|
||||
// 判定落在哪個格子
|
||||
for (int y = 0; y < rows; y++)
|
||||
{
|
||||
for (int x = 0; x < columns; x++)
|
||||
{
|
||||
var cell = gridCells[x, y];
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(
|
||||
cell.GetComponent<RectTransform>(), touchPos))
|
||||
{
|
||||
if (phase == UnityEngine.InputSystem.TouchPhase.Began)
|
||||
{
|
||||
// 按下瞬間
|
||||
cell.FlashBlue();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 持續觸摸
|
||||
cell.FlashWhite();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16721c86445ac454e93e37ff47b7945b
|
||||
@@ -0,0 +1,166 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class GridManager_MainScene : MonoBehaviour
|
||||
{
|
||||
public GameObject cellPrefab;
|
||||
public int rows = 6;
|
||||
public int columns = 5;
|
||||
|
||||
public GridColor[,] gridCells;
|
||||
|
||||
// Hold 參數
|
||||
private bool isHolding = false;
|
||||
private float holdTimer = 0f;
|
||||
private float holdTarget = 1f;
|
||||
|
||||
private bool holdingCell = false;
|
||||
private bool holdTriggered = false;
|
||||
private int holdX, holdY;
|
||||
|
||||
public HoldHintSpawner holdProgressManager;
|
||||
|
||||
public string settingSceneName = "SettingScene";
|
||||
public string accountSceneName = "AccountScene";
|
||||
|
||||
void Start()
|
||||
{
|
||||
float baseWidth = 1080f;
|
||||
float cellBase = 180f;
|
||||
float spaceBase = 20f;
|
||||
float heightBase = 90f;
|
||||
|
||||
float scale = Screen.width / baseWidth;
|
||||
|
||||
float cellSize = cellBase * scale;
|
||||
float spacing = spaceBase * scale;
|
||||
float heightOffset = heightBase * scale;
|
||||
|
||||
gridCells = new GridColor[columns, rows];
|
||||
|
||||
RectTransform rt = GetComponent<RectTransform>();
|
||||
if (rt == null) rt = gameObject.AddComponent<RectTransform>();
|
||||
|
||||
rt.anchorMin = new Vector2(0.5f, 0f);
|
||||
rt.anchorMax = new Vector2(0.5f, 0f);
|
||||
rt.pivot = new Vector2(0.5f, 0f);
|
||||
|
||||
float totalWidth = columns * cellSize + (columns - 1) * spacing;
|
||||
float startX = -totalWidth / 2f;
|
||||
float startY = heightOffset;
|
||||
|
||||
for (int i = 0; i < rows * columns; i++)
|
||||
{
|
||||
GameObject cellObj = Instantiate(cellPrefab, transform);
|
||||
|
||||
int x = i % columns;
|
||||
int y = i / columns;
|
||||
|
||||
RectTransform cellRT = cellObj.GetComponent<RectTransform>();
|
||||
cellRT.anchorMin = new Vector2(0f, 0f);
|
||||
cellRT.anchorMax = new Vector2(0f, 0f);
|
||||
cellRT.pivot = new Vector2(0f, 0f);
|
||||
|
||||
cellRT.sizeDelta = new Vector2(cellSize, cellSize);
|
||||
|
||||
float posX = startX + x * (cellSize + spacing);
|
||||
float posY = startY + y * (cellSize + spacing);
|
||||
cellRT.anchoredPosition = new Vector2(posX, posY);
|
||||
|
||||
GridColor cellColor = cellObj.GetComponent<GridColor>();
|
||||
cellColor.cellX = x;
|
||||
cellColor.cellY = y;
|
||||
|
||||
gridCells[x, y] = cellColor;
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
DetectTouch();
|
||||
|
||||
// 按住 → 開始倒數
|
||||
if (isHolding)
|
||||
{
|
||||
holdTimer += Time.deltaTime;
|
||||
|
||||
if (!holdTriggered && holdTimer >= holdTarget)
|
||||
{
|
||||
holdTriggered = true;
|
||||
Debug.Log("成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DetectTouch()
|
||||
{
|
||||
if (Touchscreen.current == null) return;
|
||||
|
||||
foreach (var touch in Touchscreen.current.touches)
|
||||
{
|
||||
UnityEngine.InputSystem.TouchPhase phase = touch.phase.ReadValue();
|
||||
Vector2 touchPos = touch.position.ReadValue();
|
||||
|
||||
// ------------------------------------
|
||||
// 若正在長按,不再判斷是否還在格子內
|
||||
// ------------------------------------
|
||||
if (holdingCell)
|
||||
{
|
||||
if (phase == UnityEngine.InputSystem.TouchPhase.Ended || phase == UnityEngine.InputSystem.TouchPhase.Canceled)
|
||||
{
|
||||
// 放開 → 結束
|
||||
isHolding = false;
|
||||
holdingCell = false;
|
||||
holdTimer = 0f;
|
||||
holdTriggered = false;
|
||||
|
||||
holdProgressManager.StopProgressAt(holdX, holdY);
|
||||
}
|
||||
|
||||
return; // 已經在長按 → 不再找其他格子
|
||||
}
|
||||
|
||||
// -------------------------------------------------------
|
||||
// 如果沒有在 holding,這裡才會尋找目前手指所在格子
|
||||
// -------------------------------------------------------
|
||||
for (int y = 0; y < rows; y++)
|
||||
{
|
||||
for (int x = 0; x < columns; x++)
|
||||
{
|
||||
var cell = gridCells[x, y];
|
||||
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(
|
||||
cell.GetComponent<RectTransform>(), touchPos))
|
||||
{
|
||||
cell.FlashWhite();
|
||||
|
||||
// =============== 原本功能 ===============
|
||||
if (phase == UnityEngine.InputSystem.TouchPhase.Began)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
// =============== Hold 觸發格子 (2,2) ===============
|
||||
if (x == 2 && y == 2 && phase == UnityEngine.InputSystem.TouchPhase.Began)
|
||||
{
|
||||
// 開始長按序列
|
||||
isHolding = true;
|
||||
holdingCell = true;
|
||||
holdTriggered = false;
|
||||
holdTimer = 0f;
|
||||
|
||||
holdX = x;
|
||||
holdY = y;
|
||||
|
||||
holdProgressManager.StartProgressAt(x, y, holdTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8865d87391b016443b60048183c38076
|
||||
Whitespace-only changes.
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72f889392d8c1e348bee3747b3c41b22
|
||||
Reference in new issue
Block a user