using UnityEngine; using UnityEngine.InputSystem; using System.Collections.Generic; public class PlayerStatusManager : MonoBehaviour { public static PlayerStatusManager Instance { get; private set; } // CodingModeスタート入力ボタン [SerializeField] private InputActionProperty zlButtonAction; [SerializeField] private InputActionProperty zrButtonAction; // ゲージ設定 [SerializeField] private float maxGauge = 100f; [SerializeField] private float currentGauge = 0f; // 表示UI設定 [SerializeField] private GameObject codingModeUI; // バフパラメータ設定 [SerializeField] private float buffDuration = 10f; [SerializeField] private float attackBuffMultiplier = 1.5f; [SerializeField] private float defenseBuffMultiplier = 0.5f; [SerializeField] private float hpHealAmount = 30f; private float attackBuffTimer = 0f; private float defenseBuffTimer = 0f; private bool isCodingMode = false; public bool IsAttackBuffActive => attackBuffTimer > 0f; public bool IsDefenseBuffActive => defenseBuffTimer > 0f; public float CurrentAttackMultiplier => IsAttackBuffActive ? attackBuffMultiplier : 1.0f; public float CurrentDefenseMultiplier => IsDefenseBuffActive ? defenseBuffMultiplier : 1.0f; private void Awake() { if (Instance == null) { Instance = this; } else { Destroy(gameObject); } } private void OnEnable() { if (zlButtonAction.action != null) zlButtonAction.action.Enable(); if (zrButtonAction.action != null) zrButtonAction.action.Enable(); } private void OnDisable() { if (zlButtonAction.action != null) zlButtonAction.action.Disable(); if (zrButtonAction.action != null) zrButtonAction.action.Disable(); } private void Start() { if (codingModeUI != null) codingModeUI.SetActive(false); } private void Update() { CheckComboInput(); if (!isCodingMode) { UpdateBuffTimers(); } } public void AddGauge(float amount) { if (isCodingMode) return; currentGauge += amount; currentGauge = Mathf.Clamp(currentGauge, 0f, maxGauge); Debug.Log($"共通ゲージ増加: {currentGauge} / {maxGauge}"); } private void CheckComboInput() { if (zlButtonAction.action == null || zrButtonAction.action == null) return; bool zlPressed = zlButtonAction.action.triggered && zlButtonAction.action.ReadValue() > 0.5f; bool zrPressed = zrButtonAction.action.triggered && zrButtonAction.action.ReadValue() > 0.5f; if (!isCodingMode && currentGauge >= maxGauge) { if ((zlPressed && zrButtonAction.action.ReadValue() > 0.5f) || (zrPressed && zlButtonAction.action.ReadValue() > 0.5f)) { StartCodingMode(); } } } private void StartCodingMode() { isCodingMode = true; Time.timeScale = 0f; // 時間停止 if (codingModeUI != null) { codingModeUI.SetActive(true); CodingModeGridManager gridManager = codingModeUI.GetComponentInChildren(); if (gridManager != null) gridManager.ResetAndGenerateMinigame(); } } // ミニゲームクリア時:獲得したバフリストをすべて適用して現実世界を再開する public void CompleteCodingMode(List earnedBuffs) { Debug.Log("ハッキング成功! ミニゲームクリア!現実世界に復帰します。"); foreach (string buff in earnedBuffs) { ActivateBuffByName(buff); } ResumeGameplay(); } // ミニゲーム失敗時:失敗ゾーン接触による強制終了処理(バフなしで復帰) public void FailCodingMode() { Debug.Log("ハッキング強制失敗 失敗ゾーンに接触しました。バフなしで復帰します。"); ResumeGameplay(); } private void ResumeGameplay() { isCodingMode = false; Time.timeScale = 1f; // 時間再開 if (codingModeUI != null) codingModeUI.SetActive(false); currentGauge = 0f; // ゲージ消費 } private void ActivateBuffByName(string buffName) { switch (buffName) { case "AttackUp": attackBuffTimer = buffDuration; Debug.Log($"攻撃力UPが適用されました。効果時間: {buffDuration}秒"); break; case "DefenseUp": defenseBuffTimer = buffDuration; Debug.Log($"防御力UPが適用されました。効果時間: {buffDuration}秒"); break; case "Heal": Debug.Log($"HP回復が適用されました。回復量: {hpHealAmount}"); break; } } 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バフの効果が終了しました。"); } } }