@@ -5,10 +5,16 @@ using System.Collections.Generic;
|
||||
|
||||
public class CodingModeGridManager : MonoBehaviour
|
||||
{
|
||||
[Header("スティック入力設定")]
|
||||
[Tooltip("移動に使用するコントローラーのスティックのInputActionPropertyを指定してください")]
|
||||
[SerializeField] private InputActionProperty thumbstickAction;
|
||||
[SerializeField] private float inputThreshold = 0.5f; // スティックをどれくらい倒したら動くか
|
||||
[Range(0.1f, 0.9f)] [SerializeField] private float inputThreshold = 0.5f; // スティックをどれくらい倒したら動くか
|
||||
|
||||
[Header("5x5 マス目(UI Image)の登録")]
|
||||
[Tooltip("ヒエラルキー上の25個のマス目のImageコンポーネントを、左上(0)から右下(24)の順番で格納してください")]
|
||||
[SerializeField] private List<Image> gridCells = new List<Image>();
|
||||
|
||||
[Header("マスの配色設定")]
|
||||
[SerializeField] private Color colorNormal = Color.gray;
|
||||
[SerializeField] private Color colorPlayer = Color.green; // 自機(プレイヤー)
|
||||
[SerializeField] private Color colorGoal = Color.yellow; // ゴール
|
||||
@@ -46,6 +52,7 @@ public class CodingModeGridManager : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// ─── ★Time.timeScale = 0 でも動くスティック入力移動ロジック ───
|
||||
if (thumbstickAction.action == null) return;
|
||||
|
||||
Vector2 stickInput = thumbstickAction.action.ReadValue<Vector2>();
|
||||
@@ -62,36 +69,40 @@ public class CodingModeGridManager : MonoBehaviour
|
||||
{
|
||||
if (Mathf.Abs(stickInput.x) > Mathf.Abs(stickInput.y))
|
||||
{
|
||||
if (stickInput.x > inputThreshold) MovePlayer(1, 0);
|
||||
else if (stickInput.x < -inputThreshold) MovePlayer(-1, 0);
|
||||
// 横移動
|
||||
if (stickInput.x > inputThreshold) MovePlayer(1, 0); // 右
|
||||
else if (stickInput.x < -inputThreshold) MovePlayer(-1, 0); // 左
|
||||
}
|
||||
else
|
||||
{
|
||||
if (stickInput.y > inputThreshold) MovePlayer(0, -1);
|
||||
else if (stickInput.y < -inputThreshold) MovePlayer(0, 1);
|
||||
// 縦移動 (UIの配列構造上、上に行くとYマイナス、下に行くとYプラスとなるよう計算)
|
||||
if (stickInput.y > inputThreshold) MovePlayer(0, -1); // 上
|
||||
else if (stickInput.y < -inputThreshold) MovePlayer(0, 1); // 下
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 盤面を初期化し、ランダムに再配置する(PlayerStatusManagerから呼ばれる)
|
||||
/// <summary>
|
||||
/// 盤面を完全に初期化し、失敗ゾーンやチェックポイントをランダムに再配置する(PlayerStatusManagerから呼ばれる)
|
||||
/// </summary>
|
||||
public void ResetAndGenerateMinigame()
|
||||
{
|
||||
accumulatedBuffs.Clear();
|
||||
|
||||
// 全マスを通常マスとして初期化
|
||||
// 1. 全マスを通常マスとして初期化
|
||||
for (int i = 0; i < 25; i++)
|
||||
{
|
||||
cellLogicArray[i] = CellType.Normal;
|
||||
checkpointBuffTypeArray[i] = "";
|
||||
}
|
||||
|
||||
// スタートとゴールの固定配置、(余裕があればランダムに)
|
||||
// 2. スタートとゴールの固定配置 (左上スタート、右下ゴール)
|
||||
playerX = 0; playerY = 0;
|
||||
goalX = 4; goalY = 4;
|
||||
cellLogicArray[GetIndex(0, 0)] = CellType.Start;
|
||||
cellLogicArray[GetIndex(4, 4)] = CellType.Goal;
|
||||
|
||||
// 失敗ゾーンをランダムに5個配置
|
||||
// 3. 失敗ゾーン(赤マス)をランダムに5個配置 (スタート・ゴールには被らせない)
|
||||
int failZonesPlaced = 0;
|
||||
while (failZonesPlaced < 5)
|
||||
{
|
||||
@@ -103,7 +114,7 @@ public class CodingModeGridManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// チェックポイントを3つのバフに対応させてランダムに3個配置
|
||||
// 4. チェックポイント(青マス)を3つのバフに対応させてランダムに3個配置
|
||||
string[] buffPool = { "AttackUp", "DefenseUp", "Heal" };
|
||||
int checkpointsPlaced = 0;
|
||||
while (checkpointsPlaced < 3)
|
||||
@@ -117,10 +128,13 @@ public class CodingModeGridManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 視覚的(UIの色)に反映
|
||||
RedrawGridGraphic();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// プレイヤーの位置を指定された方向へ動かし、移動先のイベントを判定する
|
||||
/// </summary>
|
||||
private void MovePlayer(int xDirection, int yDirection)
|
||||
{
|
||||
int nextX = Mathf.Clamp(playerX + xDirection, 0, 4);
|
||||
@@ -136,7 +150,7 @@ public class CodingModeGridManager : MonoBehaviour
|
||||
int currentIndex = GetIndex(playerX, playerY);
|
||||
CellType landedCell = cellLogicArray[currentIndex];
|
||||
|
||||
Debug.Log("({playerX}, {playerY}) | マス属性: {landedCell}");
|
||||
Debug.Log($"👾 カーソル移動: ({playerX}, {playerY}) | マス属性: {landedCell}");
|
||||
|
||||
// 移動先のマスに応じた処理
|
||||
switch (landedCell)
|
||||
@@ -150,7 +164,7 @@ public class CodingModeGridManager : MonoBehaviour
|
||||
if (!accumulatedBuffs.Contains(buff))
|
||||
{
|
||||
accumulatedBuffs.Add(buff);
|
||||
Debug.Log("バフコード抽出成功: [{buff}] を一時キープ中!");
|
||||
Debug.Log($"💚 バフコード抽出成功: [{buff}] を一時キープ中!");
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -158,10 +172,14 @@ public class CodingModeGridManager : MonoBehaviour
|
||||
PlayerStatusManager.Instance.CompleteCodingMode(accumulatedBuffs); // クリア!バフ適用
|
||||
return;
|
||||
}
|
||||
|
||||
// 画面の色を最新状態に更新
|
||||
RedrawGridGraphic();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 現在のロジック配列に基づいて、25個のUI Imageの色をまとめて上書き変更する
|
||||
/// </summary>
|
||||
private void RedrawGridGraphic()
|
||||
{
|
||||
for (int y = 0; y < 5; y++)
|
||||
@@ -181,7 +199,7 @@ public class CodingModeGridManager : MonoBehaviour
|
||||
case CellType.Goal: gridCells[index].color = colorGoal; break;
|
||||
}
|
||||
|
||||
// チェックポイントをすでに踏み抜いている場合は、獲得済みとして通常色に戻す演出
|
||||
// チェックポイントをすでに踏み抜いている場合は、獲得済みとして通常色に戻す演出(任意)
|
||||
if (cellLogicArray[index] == CellType.Checkpoint && accumulatedBuffs.Contains(checkpointBuffTypeArray[index]))
|
||||
{
|
||||
gridCells[index].color = colorNormal * 0.7f; // 少し暗いグレーにして区別
|
||||
@@ -189,7 +207,7 @@ public class CodingModeGridManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// 最後にプレイヤーのいるマスを自機の色で最優先に塗り替える
|
||||
// 最後にプレイヤーのいるマスを「自機の色」で最優先に塗り替える
|
||||
int playerIndex = GetIndex(playerX, playerY);
|
||||
if (gridCells[playerIndex] != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user