Files
VRProject/Assets/_Scripts/PlayerStatusManager.cs
oogushiyuuga 4d3fee6ca5 いろいろやってみた
Playerが蜘蛛にめり込まないようにしたい
2026-07-01 16:23:04 +09:00

174 lines
5.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using UnityEngine.InputSystem;
using System.Collections.Generic;
public class PlayerStatusManager : MonoBehaviour
{
public static PlayerStatusManager Instance { get; private set; }
[Header("Codingモード用 入力設定")]
[SerializeField] private InputActionProperty zlButtonAction;
[SerializeField] private InputActionProperty zrButtonAction;
[Header("ゲージ設定")]
[SerializeField] private float maxGauge = 100f;
[SerializeField] private float currentGauge = 0f;
[Header("表示UI設定")]
[Tooltip("ミニゲーム画面をまとめている親オブジェクトを指定してください")]
[SerializeField] private GameObject codingModeUI;
[Header("バフパラメータ設定")]
[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<float>() > 0.5f;
bool zrPressed = zrButtonAction.action.triggered && zrButtonAction.action.ReadValue<float>() > 0.5f;
if (!isCodingMode && currentGauge >= maxGauge)
{
if ((zlPressed && zrButtonAction.action.ReadValue<float>() > 0.5f) ||
(zrPressed && zlButtonAction.action.ReadValue<float>() > 0.5f))
{
StartCodingMode();
}
}
}
private void StartCodingMode()
{
isCodingMode = true;
Time.timeScale = 0f; // 時間停止
if (codingModeUI != null)
{
codingModeUI.SetActive(true);
// ★新設:画面が開いた瞬間にミニゲームの盤面をランダム生成してリセットする
CodingModeGridManager gridManager = codingModeUI.GetComponentInChildren<CodingModeGridManager>();
if (gridManager != null) gridManager.ResetAndGenerateMinigame();
}
}
/// <summary>
/// ★ミニゲームクリア時:獲得したバフリストをすべて適用して現実世界を再開する
/// </summary>
public void CompleteCodingMode(List<string> earnedBuffs)
{
Debug.Log("💻 【ハッキング成功】 ミニゲームクリア!現実世界に復帰します。");
foreach (string buff in earnedBuffs)
{
ActivateBuffByName(buff);
}
ResumeGameplay();
}
/// <summary>
/// ★ミニゲーム失敗時:失敗ゾーン接触による強制終了処理(バフなしで復帰)
/// </summary>
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}");
// ※将来の拡張PlayerHealth.Instance.Heal(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バフの効果が終了しました。");
}
}
}