パーツ準備

This commit is contained in:
oogushiyuuga
2026-07-21 16:45:01 +09:00
parent 029b50400b
commit 8506e8d155
23 changed files with 7051 additions and 158 deletions

View File

@@ -1,52 +1,35 @@
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.AI;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// プレイヤーの共通ゲージ、時間停止Codingモード、UI、および各種バフの制限時間を管理するクラス
/// </summary>
public class PlayerStatusManager : MonoBehaviour
{
public static PlayerStatusManager Instance { get; private set; }
[Header("Codingモード用 入力設定")]
[SerializeField] private InputActionProperty zlButtonAction;
[SerializeField] private InputActionProperty zrButtonAction;
[Header("プレイヤー移動・操作制御用 入力設定")]
[Tooltip("プレイヤーの移動入力(例: LeftHand Moveのアクションを指定してください")]
[SerializeField] private InputActionProperty moveAction;
[Tooltip("プレイヤーの視点回転入力(例: RightHand Turnがあれば指定してください任意")]
[SerializeField] private InputActionProperty turnAction;
[SerializeField] private float codingLimitDuration = 15f;
private float codingTimer = 0f;
[Header("ゲージ設定")]
[SerializeField] private float maxGauge = 100f;
[SerializeField] private float currentGauge = 0f;
[Header("表示UI設定")]
[Tooltip("画面全体を追従させる親オブジェクトWorld Space Canvasや3D台座を指定してください")]
[SerializeField] private GameObject codingModeUI;
[SerializeField] private PuzzleGridBoard puzzleBoard; // 盤面参照
[Header("バフパラメータ設定")]
[Tooltip("攻撃力UP・防御力UPの持続時間 (秒)")]
[SerializeField] private float buffDuration = 10f;
[Tooltip("攻撃力UP時のダメージ倍率 (例: 1.5倍)")]
[SerializeField] private float attackBuffMultiplier = 1.5f;
[Tooltip("防御力UP時の被ダメージ軽減率 (例: 0.5ならダメージ50%カット)")]
[SerializeField] private float defenseBuffMultiplier = 0.5f;
[Tooltip("HP回復バフ発動時の回復量")]
[SerializeField] private float hpHealAmount = 30f;
// 各バフの残り時間を管理するタイマー0より大きければバフ有効
private float attackBuffTimer = 0f;
private float defenseBuffTimer = 0f;
// 現在Codingモード時間停止中かどうかのフラグ
private bool isCodingMode = false;
// 【記憶リスト】一時停止させた敵のアニメーターとNavMeshAgentを記憶しておく
private List<Animator> pausedAnimators = new List<Animator>();
private List<NavMeshAgent> pausedAgents = new List<NavMeshAgent>();
@@ -63,36 +46,22 @@ public class PlayerStatusManager : MonoBehaviour
else { Destroy(gameObject); }
}
private void OnEnable()
{
if (zlButtonAction.action != null) zlButtonAction.action.Enable();
if (zrButtonAction.action != null) zrButtonAction.action.Enable();
if (moveAction.action != null) moveAction.action.Enable();
if (turnAction.action != null) turnAction.action.Enable();
}
private void OnDisable()
{
if (zlButtonAction.action != null) zlButtonAction.action.Disable();
if (zrButtonAction.action != null) zrButtonAction.action.Disable();
if (moveAction.action != null) moveAction.action.Disable();
if (turnAction.action != null) turnAction.action.Disable();
}
private void Start()
{
if (codingModeUI != null) codingModeUI.SetActive(false);
}
private void Update()
{
CheckComboInput();
// ゲームプレイ中(時間停止中でないとき)のみ、バフのタイマーを減算する
if (!isCodingMode)
{
UpdateBuffTimers();
}
else
{
codingTimer -= Time.deltaTime;
if (codingTimer <= 0f)
{
FailCodingModeByTimeout();
}
}
}
public void AddGauge(float amount)
@@ -100,7 +69,6 @@ public class PlayerStatusManager : MonoBehaviour
if (isCodingMode) return;
currentGauge += amount;
currentGauge = Mathf.Clamp(currentGauge, 0f, maxGauge);
Debug.Log($"🔋 共通ゲージ増加: {currentGauge} / {maxGauge}");
}
private void CheckComboInput()
@@ -110,7 +78,6 @@ public class PlayerStatusManager : MonoBehaviour
bool zlPressed = zlButtonAction.action.triggered && zlButtonAction.action.ReadValue<float>() > 0.5f;
bool zrPressed = zrButtonAction.action.triggered && zrButtonAction.action.ReadValue<float>() > 0.5f;
// 同時押しの判定
bool isComboTriggered = (zlPressed && zrButtonAction.action.ReadValue<float>() > 0.5f) ||
(zrPressed && zlButtonAction.action.ReadValue<float>() > 0.5f);
@@ -118,148 +85,85 @@ public class PlayerStatusManager : MonoBehaviour
{
if (!isCodingMode && currentGauge >= maxGauge)
{
// 通常時 ➔ ゲージ満タンならCodingモード発動
StartCodingMode();
}
else if (isCodingMode)
{
// ★Codingモード中に再度同時押し ➔ キャンセルして無消費で復帰
CancelCodingMode();
CancelCodingMode(); // 手動キャンセルはゲージ維持
}
}
}
/// <summary>
/// Codingモード時間停止を開始する
/// </summary>
private void StartCodingMode()
{
isCodingMode = true;
codingTimer = codingLimitDuration; // タイマーリセット
// 1. プレイヤーの移動・視点回転の入力アクションを無効化Disableして足止めする
if (puzzleBoard != null) puzzleBoard.ClearBoard();
if (moveAction.action != null) moveAction.action.Disable();
if (turnAction.action != null) turnAction.action.Disable();
// 2. シーン内の敵のアニメーターを検索して完全停止
Animator[] allAnimators = FindObjectsByType<Animator>(FindObjectsSortMode.None);
pausedAnimators.Clear();
foreach (var anim in allAnimators)
foreach (var anim in FindObjectsByType<Animator>(FindObjectsSortMode.None))
{
if (anim == null) continue;
if (anim.gameObject == this.gameObject || anim.CompareTag("Player")) continue;
anim.speed = 0f;
if (anim == null || anim.gameObject == this.gameObject || anim.CompareTag("Player")) continue;
anim.speed = 0f;
pausedAnimators.Add(anim);
}
// 3. ボスのNavMeshAgent自動移動も一時停止させる
NavMeshAgent[] allAgents = FindObjectsByType<NavMeshAgent>(FindObjectsSortMode.None);
pausedAgents.Clear();
foreach (var agent in allAgents)
foreach (var agent in FindObjectsByType<NavMeshAgent>(FindObjectsSortMode.None))
{
if (agent == null || !agent.enabled || !agent.gameObject.activeInHierarchy) continue;
if (agent.CompareTag("Player")) continue;
if (!agent.isStopped)
{
agent.isStopped = true;
pausedAgents.Add(agent);
}
if (agent == null || !agent.enabled || !agent.gameObject.activeInHierarchy || agent.CompareTag("Player")) continue;
if (!agent.isStopped) { agent.isStopped = true; pausedAgents.Add(agent); }
}
if (codingModeUI != null) codingModeUI.SetActive(true);
Debug.Log("⏳ Codingモードプレイヤー移動をロック敵の時間アニメ・NavMeshを完全停止しました。");
Debug.Log($"⏳ Codingモード開始(パズル制限時間: {codingLimitDuration}秒)");
}
/// <summary>
/// バフを適用してゲームを再開する(ゲージ消費あり)
/// </summary>
public void ApplyBuffsAndResume(string buff1, string buff2)
{
// 1. 選択された2つのバフをそれぞれ発動
ActivateBuffByName(buff1);
ActivateBuffByName(buff2);
// 2. ゲーム状態を復帰(ゲージを消費)
ResumeWorldState(consumeGauge: true);
Debug.Log("▶ Codingモード完了バフを適用してゲームを再開しました。");
Debug.Log("🎉 パズル成功!バフを適用して再開。");
}
private void FailCodingModeByTimeout()
{
ResumeWorldState(consumeGauge: true); // 失敗したのでゲージは消費される
Debug.Log("💀 時間切れ! Codingモード失敗バフなし・ゲージ消費。");
}
/// <summary>
/// ★新規実装Codingモードをキャンセルしてゲームを再開するゲージ消費なし
/// </summary>
public void CancelCodingMode()
{
// ゲーム状態を復帰(ゲージは維持)
ResumeWorldState(consumeGauge: false);
Debug.Log("↩️ Codingモードキャンセルゲージを維持したまま通常状態に復帰しました。");
ResumeWorldState(consumeGauge: false); // 手動キャンセルはゲージ消費なし
Debug.Log("↩️ Codingモード手動キャンセル。");
}
/// <summary>
/// 世界の状態アニメーション・NavMesh・プレイヤー移動・UIを復帰させる共通メソッド
/// </summary>
private void ResumeWorldState(bool consumeGauge)
{
// 1. 停止させていた敵のアニメーターを元の速度1.0f)に戻す
foreach (var anim in pausedAnimators)
{
if (anim != null)
{
anim.speed = 1f;
}
}
foreach (var anim in pausedAnimators) { if (anim != null) anim.speed = 1f; }
pausedAnimators.Clear();
// 2. 停止させていたNavMeshAgentの移動を再開する
foreach (var agent in pausedAgents)
{
if (agent != null && agent.enabled)
{
agent.isStopped = false;
}
}
foreach (var agent in pausedAgents) { if (agent != null && agent.enabled) agent.isStopped = false; }
pausedAgents.Clear();
// 3. プレイヤーの移動・視点回転の入力アクションを再有効化Enableして操作ロックを解除
if (moveAction.action != null) moveAction.action.Enable();
if (turnAction.action != null) turnAction.action.Enable();
// 4. フラグとUIをリセット
isCodingMode = false;
if (codingModeUI != null) codingModeUI.SetActive(false);
// 5. ゲージの消費制御
if (consumeGauge)
{
currentGauge = 0f; // バフ決定時のみゲージ消費
}
if (consumeGauge) currentGauge = 0f;
}
private void ActivateBuffByName(string buffName)
{
switch (buffName)
{
case "AttackUp":
attackBuffTimer = buffDuration;
Debug.Log($"⚔️ 攻撃力UPバフ発動 倍率: {attackBuffMultiplier} / 効果時間: {buffDuration}秒");
break;
case "DefenseUp":
defenseBuffTimer = buffDuration;
Debug.Log($"🛡️ 防御力UPバフ発動 被ダメージ倍率: {defenseBuffMultiplier} / 効果時間: {buffDuration}秒");
break;
case "Heal":
ExecuteHeal();
break;
default:
Debug.LogWarning($"未定義のバフ名が検出されました: {buffName}");
break;
case "AttackUp": attackBuffTimer = buffDuration; break;
case "DefenseUp": defenseBuffTimer = buffDuration; break;
case "Heal": ExecuteHeal(); break;
}
}
@@ -270,16 +174,7 @@ public class PlayerStatusManager : MonoBehaviour
private void UpdateBuffTimers()
{
if (attackBuffTimer > 0f)
{
attackBuffTimer -= Time.deltaTime;
if (attackBuffTimer <= 0f) Debug.Log("⚔️ 攻撃力UPバフの効果が終了しました。");
}
if (defenseBuffTimer > 0f)
{
defenseBuffTimer -= Time.deltaTime;
if (defenseBuffTimer <= 0f) Debug.Log("🛡️ 防御力UPバフの効果が終了しました。");
}
if (attackBuffTimer > 0f) attackBuffTimer -= Time.deltaTime;
if (defenseBuffTimer > 0f) defenseBuffTimer -= Time.deltaTime;
}
}

View File

@@ -0,0 +1,105 @@
using UnityEngine;
using System.Collections.Generic;
public enum BlockColor { Red, Blue, Green }
public enum BlockShapeType { TShape, CShape }
public class PuzzleBlock : MonoBehaviour
{
[field: SerializeField] public BlockColor Color { get; private set; }
[field: SerializeField] public BlockShapeType ShapeType { get; private set; }
// 原点(0,0)を基準としたブロックのマス配置データ
public List<Vector2Int> LocalCells { get; private set; } = new List<Vector2Int>();
private PuzzleGridBoard currentBoard;
private bool isGrabbed = false;
private void Awake()
{
InitializeShapeCells();
}
private void InitializeShapeCells()
{
LocalCells.Clear();
if (ShapeType == BlockShapeType.TShape)
{
LocalCells.Add(new Vector2Int(0, 0));
LocalCells.Add(new Vector2Int(0, 1));
LocalCells.Add(new Vector2Int(0, 2));
LocalCells.Add(new Vector2Int(1, 1));
}
else if (ShapeType == BlockShapeType.CShape)
{
LocalCells.Add(new Vector2Int(0, 0));
LocalCells.Add(new Vector2Int(1, 0));
LocalCells.Add(new Vector2Int(0, 1));
LocalCells.Add(new Vector2Int(0, 2));
LocalCells.Add(new Vector2Int(1, 2));
}
}
public List<Vector2Int> GetRotatedCells()
{
List<Vector2Int> rotated = new List<Vector2Int>();
// 現在のY回転を90度単位に丸める (0, 1, 2, 3)
int steps = Mathf.RoundToInt(transform.eulerAngles.y / 90f) % 4;
if (steps < 0) steps += 4;
foreach (var cell in LocalCells)
{
Vector2Int c = cell;
for (int i = 0; i < steps; i++)
{
// 時計回りに90度回転: (x, y) -> (y, -x)
c = new Vector2Int(c.y, -c.x);
}
rotated.Add(c);
}
return rotated;
}
public void OnGrabbed()
{
isGrabbed = true;
if (currentBoard != null)
{
currentBoard.RemoveBlock(this);
currentBoard = null;
}
}
// PuzzleBlock.cs 内に以下を追加・修正
private PuzzleGridBoard overlappingBoard;
private void OnTriggerEnter(Collider other)
{
var board = other.GetComponentInParent<PuzzleGridBoard>();
if (board != null) overlappingBoard = board;
}
private void OnTriggerExit(Collider other)
{
var board = other.GetComponentInParent<PuzzleGridBoard>();
if (board == overlappingBoard) overlappingBoard = null;
}
// 引数なしで呼べるように変更
public void OnReleased()
{
isGrabbed = false;
// 1. 手の傾きを最も近い90度単位にスナップ補正
Vector3 currentEuler = transform.eulerAngles;
float snappedY = Mathf.Round(currentEuler.y / 90f) * 90f;
transform.rotation = Quaternion.Euler(0f, snappedY, 0f);
// 2. 近くにある盤面へのセットを試みる
if (overlappingBoard != null && overlappingBoard.TryPlaceBlock(this))
{
currentBoard = overlappingBoard;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f5140afa8506840059b73ebefeda1e8c

View File

@@ -0,0 +1,106 @@
using UnityEngine;
using System.Collections.Generic;
public class PuzzleGridBoard : MonoBehaviour
{
[Header("盤面設定")]
[SerializeField] private float cellSize = 0.1f; // 1マスのサイズメートル
[SerializeField] private Transform originAnchor; // 3x3の左下(0,0)の基準Transform
// 3x3 のマス目データ(設置されているブロックを管理)
private PuzzleBlock[,] grid = new PuzzleBlock[3, 3];
private List<PuzzleBlock> placedBlocks = new List<PuzzleBlock>();
public bool TryPlaceBlock(PuzzleBlock block)
{
// ブロックの原点位置から盤面のグリッド座標(0~2, 0~2)を算出
Vector3 localPos = originAnchor.InverseTransformPoint(block.transform.position);
int originX = Mathf.RoundToInt(localPos.x / cellSize);
int originY = Mathf.RoundToInt(localPos.z / cellSize);
List<Vector2Int> shapeCells = block.GetRotatedCells();
// 設置可能かチェック(はみ出し・重ね被りがないか)
foreach (var cell in shapeCells)
{
int targetX = originX + cell.x;
int targetY = originY + cell.y;
if (targetX < 0 || targetX >= 3 || targetY < 0 || targetY >= 3) return false; // 盤面外
if (grid[targetX, targetY] != null) return false; // すでに埋まっている
}
// 設置確定処理
foreach (var cell in shapeCells)
{
grid[originX + cell.x, originY + cell.y] = block;
}
placedBlocks.Add(block);
// 吸い付き(スナップ)位置の固定
Vector3 snapLocalPos = new Vector3(originX * cellSize, 0f, originY * cellSize);
block.transform.position = originAnchor.TransformPoint(snapLocalPos);
// 成功チェック全9マスが単一色で埋まったか
EvaluateBoardComplete();
return true;
}
public void RemoveBlock(PuzzleBlock block)
{
for (int x = 0; x < 3; x++)
{
for (int y = 0; y < 3; y++)
{
if (grid[x, y] == block) grid[x, y] = null;
}
}
placedBlocks.Remove(block);
}
private void EvaluateBoardComplete()
{
// 全9マスが埋まっているかチェック
for (int x = 0; x < 3; x++)
{
for (int y = 0; y < 3; y++)
{
if (grid[x, y] == null) return; // 空きマスがあるので未完成
}
}
// 全ブロックの色が統一されているかチェック
BlockColor firstColor = placedBlocks[0].Color;
foreach (var b in placedBlocks)
{
if (b.Color != firstColor)
{
Debug.Log("❌ 3x3は埋まりましたが、色が混ざっているため失敗です。");
return;
}
}
// ★パズル成功! 色に対応したバフを発動してCodingModeを終了する
Debug.Log($"🎉 パズル成功! 単一色 ({firstColor}) で完成しました!");
string buffName = ConvertColorToBuffName(firstColor);
PlayerStatusManager.Instance.ApplyBuffsAndResume(buffName, buffName);
}
private string ConvertColorToBuffName(BlockColor color)
{
return color switch
{
BlockColor.Red => "AttackUp",
BlockColor.Blue => "DefenseUp",
BlockColor.Green => "Heal",
_ => "AttackUp"
};
}
public void ClearBoard()
{
grid = new PuzzleBlock[3, 3];
placedBlocks.Clear();
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3c49da017d0074aa4b9f4c23133fbb5d