Codingモード研究中
This commit is contained in:
@@ -1,115 +1,195 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using System.Collections;
|
||||
|
||||
/// <summary>
|
||||
/// プレイヤーの共通ゲージ、時間停止(Codingモード)、UI、および各種バフの制限時間を管理するクラス
|
||||
/// </summary>
|
||||
public class PlayerStatusManager : MonoBehaviour
|
||||
{
|
||||
public static PlayerStatusManager Instance { get; private set;}
|
||||
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("画面全体を追従させる親オブジェクト(World Space Canvasや3D台座)を指定してください")]
|
||||
[SerializeField] private GameObject codingModeUI;
|
||||
|
||||
private bool isCodingMode = false;
|
||||
// ─── ★ここからバフ設定を新しく追加 ───
|
||||
[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;
|
||||
|
||||
void Awake()
|
||||
// 各バフの残り時間を管理するタイマー(0より大きければバフ有効)
|
||||
private float attackBuffTimer = 0f;
|
||||
private float defenseBuffTimer = 0f;
|
||||
|
||||
// 現在Codingモード(時間停止中)かどうかのフラグ
|
||||
private bool isCodingMode = false;
|
||||
// ─────────────────────────────────────
|
||||
|
||||
#region プロパティ(外部のスクリプトからバフ状態を参照するための窓口)
|
||||
/// <summary> 現在攻撃力UPバフが有効かどうか </summary>
|
||||
public bool IsAttackBuffActive => attackBuffTimer > 0f;
|
||||
|
||||
/// <summary> 現在防御力UPバフが有効かどうか </summary>
|
||||
public bool IsDefenseBuffActive => defenseBuffTimer > 0f;
|
||||
|
||||
/// <summary> 現在の攻撃力倍率を返す(バフなしなら1.0倍) </summary>
|
||||
public float CurrentAttackMultiplier => IsAttackBuffActive ? attackBuffMultiplier : 1.0f;
|
||||
|
||||
/// <summary> 現在の防御倍率を返す(バフなしなら1.0倍、バフありなら0.5倍など) </summary>
|
||||
public float CurrentDefenseMultiplier => IsDefenseBuffActive ? defenseBuffMultiplier : 1.0f;
|
||||
#endregion
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if(Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
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();
|
||||
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();
|
||||
if (zlButtonAction.action != null) zlButtonAction.action.Disable();
|
||||
if (zrButtonAction.action != null) zrButtonAction.action.Disable();
|
||||
}
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
if(codingModeUI != null)
|
||||
if (codingModeUI != null) codingModeUI.SetActive(false);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
CheckComboInput();
|
||||
|
||||
// ★新設:ゲームプレイ中(時間停止中でないとき)のみ、バフのタイマーを減算する
|
||||
if (!isCodingMode)
|
||||
{
|
||||
codingModeUI.SetActive(false);
|
||||
UpdateBuffTimers();
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
public void AddGauge(float amount)
|
||||
{
|
||||
CheckComboInput();
|
||||
}
|
||||
|
||||
public void AddGauge(float amout)
|
||||
{
|
||||
if(isCodingMode) return;
|
||||
|
||||
currentGauge += amout;
|
||||
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;
|
||||
if (zlButtonAction.action == null || zrButtonAction.action == null) return;
|
||||
|
||||
bool zlPressed = zlButtonAction.action.triggered && zlButtonAction.action.ReadValue<float>() > 0.5f;
|
||||
bool zrPressed = zlButtonAction.action.triggered && zrButtonAction.action.ReadValue<float>() > 0.5f;
|
||||
bool zrPressed = zrButtonAction.action.triggered && zrButtonAction.action.ReadValue<float>() > 0.5f;
|
||||
|
||||
if(!isCodingMode && currentGauge >= maxGauge)
|
||||
if (!isCodingMode && currentGauge >= maxGauge)
|
||||
{
|
||||
if((zlPressed && zrButtonAction.action.ReadValue<float>() > 0.5f) ||
|
||||
(zrPressed && zlButtonAction.action.ReadValue<float>() > 0.5f))
|
||||
if ((zlPressed && zrButtonAction.action.ReadValue<float>() > 0.5f) ||
|
||||
(zrPressed && zlButtonAction.action.ReadValue<float>() > 0.5f))
|
||||
{
|
||||
StartCodingMode();
|
||||
}
|
||||
}
|
||||
else if(isCodingMode)
|
||||
{
|
||||
if((zlPressed && zrButtonAction.action.ReadValue<float>() > 0.5f) ||
|
||||
(zrPressed && zlButtonAction.action.ReadValue<float>() > 0.5f))
|
||||
{
|
||||
EndCodingMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void StartCodingMode()
|
||||
{
|
||||
isCodingMode = true;
|
||||
Time.timeScale = 0f; // 時間を完全停止
|
||||
|
||||
Time.timeScale = 0f;
|
||||
|
||||
if(codingModeUI != null)
|
||||
{
|
||||
codingModeUI.SetActive(true);
|
||||
}
|
||||
if (codingModeUI != null) codingModeUI.SetActive(true);
|
||||
}
|
||||
|
||||
private void EndCodingMode()
|
||||
/// <summary>
|
||||
/// ★役割拡張:パズル完了時に呼び出され、指定された2つのバフを発動して時間を再開する
|
||||
/// </summary>
|
||||
public void ApplyBuffsAndResume(string buff1, string buff2)
|
||||
{
|
||||
// 1. 選択された2つのバフをそれぞれ発動(重複なしの仕様を適用)
|
||||
ActivateBuffByName(buff1);
|
||||
ActivateBuffByName(buff2);
|
||||
|
||||
// 2. Codingモードの終了処理
|
||||
isCodingMode = false;
|
||||
Time.timeScale = 1f; // 時間を再開
|
||||
|
||||
Time.timeScale = 1f;
|
||||
if (codingModeUI != null) codingModeUI.SetActive(false);
|
||||
currentGauge = 0f; // ゲージを消費
|
||||
}
|
||||
|
||||
if(codingModeUI != null)
|
||||
/// <summary>
|
||||
/// 文字列に応じて対象のバフを起動する内部メソッド
|
||||
/// </summary>
|
||||
private void ActivateBuffByName(string buffName)
|
||||
{
|
||||
switch (buffName)
|
||||
{
|
||||
codingModeUI.SetActive(false);
|
||||
case "AttackUp":
|
||||
attackBuffTimer = buffDuration; // タイマーをリセット(上書き補給)
|
||||
Debug.Log($"⚔️ 攻撃力UPバフ発動! 倍率: {attackBuffMultiplier} / 効果時間: {buffDuration}秒");
|
||||
break;
|
||||
|
||||
case "DefenseUp":
|
||||
defenseBuffTimer = buffDuration; // タイマーをリセット(上書き補給)
|
||||
Debug.Log($"🛡️ 防御力UPバフ発動! 被ダメージ倍率: {defenseBuffMultiplier} / 効果時間: {buffDuration}秒");
|
||||
break;
|
||||
|
||||
case "Heal":
|
||||
ExecuteHeal(); // HP回復は即時発動
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.LogWarning($"未定義のバフ名が検出されました: {buffName}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HP回復の即時実行処理
|
||||
/// </summary>
|
||||
private void ExecuteHeal()
|
||||
{
|
||||
Debug.Log($"💚 HP回復バフ発動! 回復量: {hpHealAmount}");
|
||||
// 【将来の拡張】プレイヤーのHealthスクリプトが完成したら、ここに回復処理を記述します
|
||||
// PlayerHealth.Instance.Heal(hpHealAmount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 毎フレーム、有効なバフタイマーをリアルタイムで減算する
|
||||
/// </summary>
|
||||
private void UpdateBuffTimers()
|
||||
{
|
||||
if (attackBuffTimer > 0f)
|
||||
{
|
||||
attackBuffTimer -= Time.deltaTime;
|
||||
if (attackBuffTimer <= 0f) Debug.Log("⚔️ 攻撃力UPバフの効果が終了しました。");
|
||||
}
|
||||
|
||||
currentGauge = 0f;
|
||||
if (defenseBuffTimer > 0f)
|
||||
{
|
||||
defenseBuffTimer -= Time.deltaTime;
|
||||
if (defenseBuffTimer <= 0f) Debug.Log("🛡️ 防御力UPバフの効果が終了しました。");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user