CodingMode改善中
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic; // Listを使うために追加
|
||||
|
||||
/// <summary>
|
||||
/// プレイヤーの共通ゲージ、時間停止(Codingモード)、UI、および各種バフの制限時間を管理するクラス
|
||||
/// </summary>
|
||||
public class PlayerStatusManager : MonoBehaviour
|
||||
{
|
||||
public static PlayerStatusManager Instance { get; private set; }
|
||||
@@ -15,23 +19,35 @@ public class PlayerStatusManager : MonoBehaviour
|
||||
[SerializeField] private float currentGauge = 0f;
|
||||
|
||||
[Header("表示UI設定")]
|
||||
[Tooltip("ミニゲーム画面をまとめている親オブジェクトを指定してください")]
|
||||
[Tooltip("画面全体を追従させる親オブジェクト(World Space Canvasや3D台座)を指定してください")]
|
||||
[SerializeField] private GameObject codingModeUI;
|
||||
|
||||
[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;
|
||||
|
||||
// 【新設】一時停止させた敵のアニメーターを記憶しておくためのリスト
|
||||
private List<Animator> pausedAnimators = new List<Animator>();
|
||||
|
||||
#region プロパティ
|
||||
public bool IsAttackBuffActive => attackBuffTimer > 0f;
|
||||
public bool IsDefenseBuffActive => defenseBuffTimer > 0f;
|
||||
public float CurrentAttackMultiplier => IsAttackBuffActive ? attackBuffMultiplier : 1.0f;
|
||||
public float CurrentDefenseMultiplier => IsDefenseBuffActive ? defenseBuffMultiplier : 1.0f;
|
||||
#endregion
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -60,6 +76,7 @@ public class PlayerStatusManager : MonoBehaviour
|
||||
{
|
||||
CheckComboInput();
|
||||
|
||||
// ゲームプレイ中(時間停止中でないとき)のみ、バフのタイマーを減算する
|
||||
if (!isCodingMode)
|
||||
{
|
||||
UpdateBuffTimers();
|
||||
@@ -91,51 +108,59 @@ public class PlayerStatusManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Codingモード(時間停止)を開始する
|
||||
/// </summary>
|
||||
private void StartCodingMode()
|
||||
{
|
||||
isCodingMode = true;
|
||||
Time.timeScale = 0f; // 時間停止
|
||||
|
||||
if (codingModeUI != null)
|
||||
// 【変更】Time.timeScaleは弄らず、シーン内のAnimatorを検索して停止させる
|
||||
Animator[] allAnimators = FindObjectsByType<Animator>(FindObjectsSortMode.None);
|
||||
pausedAnimators.Clear();
|
||||
|
||||
foreach (var anim in allAnimators)
|
||||
{
|
||||
codingModeUI.SetActive(true);
|
||||
// ★新設:画面が開いた瞬間にミニゲームの盤面をランダム生成してリセットする
|
||||
CodingModeGridManager gridManager = codingModeUI.GetComponentInChildren<CodingModeGridManager>();
|
||||
if (gridManager != null) gridManager.ResetAndGenerateMinigame();
|
||||
if (anim == null) continue;
|
||||
|
||||
// ⚠️ プレイヤー自身のアニメーターまで止めないように除外する
|
||||
// (このマネージャーがプレイヤーオブジェクトについている、またはPlayerタグを想定)
|
||||
if (anim.gameObject == this.gameObject || anim.CompareTag("Player")) continue;
|
||||
|
||||
// 元のスピードに関わらず、0に上書きしてアニメーションを完全停止
|
||||
anim.speed = 0f;
|
||||
pausedAnimators.Add(anim); // 記憶リストに保存
|
||||
}
|
||||
|
||||
if (codingModeUI != null) codingModeUI.SetActive(true);
|
||||
Debug.Log("⏳ Codingモード:敵の時間(アニメーション)を停止しました。");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ★ミニゲームクリア時:獲得したバフリストをすべて適用して現実世界を再開する
|
||||
/// バフを適用してゲームを再開する
|
||||
/// </summary>
|
||||
public void CompleteCodingMode(List<string> earnedBuffs)
|
||||
public void ApplyBuffsAndResume(string buff1, string buff2)
|
||||
{
|
||||
Debug.Log("💻 【ハッキング成功】 ミニゲームクリア!現実世界に復帰します。");
|
||||
|
||||
foreach (string buff in earnedBuffs)
|
||||
// 1. 選択された2つのバフをそれぞれ発動
|
||||
ActivateBuffByName(buff1);
|
||||
ActivateBuffByName(buff2);
|
||||
|
||||
// 【変更】2. 停止させていた敵のアニメーターを元の速度(1.0f)に戻す
|
||||
foreach (var anim in pausedAnimators)
|
||||
{
|
||||
ActivateBuffByName(buff);
|
||||
if (anim != null)
|
||||
{
|
||||
anim.speed = 1f;
|
||||
}
|
||||
}
|
||||
pausedAnimators.Clear(); // リストを空にする
|
||||
|
||||
ResumeGameplay();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ★ミニゲーム失敗時:失敗ゾーン接触による強制終了処理(バフなしで復帰)
|
||||
/// </summary>
|
||||
public void FailCodingMode()
|
||||
{
|
||||
Debug.Log("🚨 【ハッキング強制失敗】 失敗ゾーンに接触しました。バフなしで復帰します。");
|
||||
ResumeGameplay();
|
||||
}
|
||||
|
||||
private void ResumeGameplay()
|
||||
{
|
||||
// 3. Codingモードの終了処理
|
||||
isCodingMode = false;
|
||||
Time.timeScale = 1f; // 時間再開
|
||||
|
||||
if (codingModeUI != null) codingModeUI.SetActive(false);
|
||||
currentGauge = 0f; // ゲージ消費
|
||||
currentGauge = 0f; // ゲージを消費
|
||||
Debug.Log("▶ Codingモード終了:敵の時間を再開しました。");
|
||||
}
|
||||
|
||||
private void ActivateBuffByName(string buffName)
|
||||
@@ -144,19 +169,29 @@ public class PlayerStatusManager : MonoBehaviour
|
||||
{
|
||||
case "AttackUp":
|
||||
attackBuffTimer = buffDuration;
|
||||
Debug.Log($"⚔️ 攻撃力UPが適用されました。効果時間: {buffDuration}秒");
|
||||
Debug.Log($"⚔️ 攻撃力UPバフ発動! 倍率: {attackBuffMultiplier} / 効果時間: {buffDuration}秒");
|
||||
break;
|
||||
|
||||
case "DefenseUp":
|
||||
defenseBuffTimer = buffDuration;
|
||||
Debug.Log($"🛡️ 防御力UPが適用されました。効果時間: {buffDuration}秒");
|
||||
Debug.Log($"🛡️ 防御力UPバフ発動! 被ダメージ倍率: {defenseBuffMultiplier} / 効果時間: {buffDuration}秒");
|
||||
break;
|
||||
|
||||
case "Heal":
|
||||
Debug.Log($"💚 HP回復が適用されました。回復量: {hpHealAmount}");
|
||||
// ※将来の拡張:PlayerHealth.Instance.Heal(hpHealAmount);
|
||||
ExecuteHeal();
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.LogWarning($"未定義のバフ名が検出されました: {buffName}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteHeal()
|
||||
{
|
||||
Debug.Log($"💚 HP回復バフ発動! 回復量: {hpHealAmount}");
|
||||
}
|
||||
|
||||
private void UpdateBuffTimers()
|
||||
{
|
||||
if (attackBuffTimer > 0f)
|
||||
|
||||
Reference in New Issue
Block a user