Codingkaizenn
This commit is contained in:
@@ -10,6 +10,15 @@ public class CodingModeManager : MonoBehaviour
|
||||
[Tooltip("台座に配置した Slot_B の XRSocketInteractor を指定してください")]
|
||||
[SerializeField] private XRSocketInteractor socketB;
|
||||
|
||||
[Header("XR Interaction Toolkit 移動系コンポーネント")]
|
||||
[Tooltip("Continuous Move Provider などの移動スクリプトをアタッチ")]
|
||||
[SerializeField] private Behaviour moveProvider;
|
||||
|
||||
[Tooltip("Snap Turn Provider や Continuous Turn Provider などの旋回スクリプトをアタッチ")]
|
||||
[SerializeField] private Behaviour turnProvider;
|
||||
|
||||
public bool IsCodingModeActive { get; private set; } = false;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
// ソケットにオブジェクトが「ハメ込まれた瞬間」のイベントを登録
|
||||
@@ -85,4 +94,15 @@ public class CodingModeManager : MonoBehaviour
|
||||
socketB.firstInteractableSelected.transform.position = transform.position + (transform.forward * -0.2f) + (transform.right * 0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleCodingMode()
|
||||
{
|
||||
IsCodingModeActive = !IsCodingModeActive;
|
||||
|
||||
// CodingModeが有効(true)なら、enabled を false にして足止めする
|
||||
if (moveProvider != null) moveProvider.enabled = !IsCodingModeActive;
|
||||
if (turnProvider != null) turnProvider.enabled = !IsCodingModeActive;
|
||||
|
||||
Debug.Log($"💻 CodingMode: {(IsCodingModeActive ? "ON (移動・旋回を一時ロック)" : "OFF (移動解禁)")}");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.AI;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic; // Listを使うために追加
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// プレイヤーの共通ゲージ、時間停止(Codingモード)、UI、および各種バフの制限時間を管理するクラス
|
||||
@@ -14,6 +15,12 @@ public class PlayerStatusManager : MonoBehaviour
|
||||
[SerializeField] private InputActionProperty zlButtonAction;
|
||||
[SerializeField] private InputActionProperty zrButtonAction;
|
||||
|
||||
[Header("プレイヤー移動・操作制御用 入力設定")]
|
||||
[Tooltip("プレイヤーの移動入力(例: LeftHand Move)のアクションを指定してください")]
|
||||
[SerializeField] private InputActionProperty moveAction;
|
||||
[Tooltip("プレイヤーの視点回転入力(例: RightHand Turn)があれば指定してください(任意)")]
|
||||
[SerializeField] private InputActionProperty turnAction;
|
||||
|
||||
[Header("ゲージ設定")]
|
||||
[SerializeField] private float maxGauge = 100f;
|
||||
[SerializeField] private float currentGauge = 0f;
|
||||
@@ -39,8 +46,9 @@ public class PlayerStatusManager : MonoBehaviour
|
||||
// 現在Codingモード(時間停止中)かどうかのフラグ
|
||||
private bool isCodingMode = false;
|
||||
|
||||
// 【新設】一時停止させた敵のアニメーターを記憶しておくためのリスト
|
||||
// 【記憶リスト】一時停止させた敵のアニメーターとNavMeshAgentを記憶しておく
|
||||
private List<Animator> pausedAnimators = new List<Animator>();
|
||||
private List<NavMeshAgent> pausedAgents = new List<NavMeshAgent>();
|
||||
|
||||
#region プロパティ
|
||||
public bool IsAttackBuffActive => attackBuffTimer > 0f;
|
||||
@@ -59,12 +67,16 @@ public class PlayerStatusManager : MonoBehaviour
|
||||
{
|
||||
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()
|
||||
@@ -98,13 +110,22 @@ 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;
|
||||
|
||||
if (!isCodingMode && currentGauge >= maxGauge)
|
||||
// 同時押しの判定
|
||||
bool isComboTriggered = (zlPressed && zrButtonAction.action.ReadValue<float>() > 0.5f) ||
|
||||
(zrPressed && zlButtonAction.action.ReadValue<float>() > 0.5f);
|
||||
|
||||
if (isComboTriggered)
|
||||
{
|
||||
if ((zlPressed && zrButtonAction.action.ReadValue<float>() > 0.5f) ||
|
||||
(zrPressed && zlButtonAction.action.ReadValue<float>() > 0.5f))
|
||||
if (!isCodingMode && currentGauge >= maxGauge)
|
||||
{
|
||||
// 通常時 ➔ ゲージ満タンならCodingモード発動
|
||||
StartCodingMode();
|
||||
}
|
||||
else if (isCodingMode)
|
||||
{
|
||||
// ★Codingモード中に再度同時押し ➔ キャンセルして無消費で復帰
|
||||
CancelCodingMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,29 +136,45 @@ public class PlayerStatusManager : MonoBehaviour
|
||||
{
|
||||
isCodingMode = true;
|
||||
|
||||
// 【変更】Time.timeScaleは弄らず、シーン内のAnimatorを検索して停止させる
|
||||
// 1. プレイヤーの移動・視点回転の入力アクションを無効化(Disable)して足止めする
|
||||
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)
|
||||
{
|
||||
if (anim == null) continue;
|
||||
|
||||
// ⚠️ プレイヤー自身のアニメーターまで止めないように除外する
|
||||
// (このマネージャーがプレイヤーオブジェクトについている、またはPlayerタグを想定)
|
||||
if (anim.gameObject == this.gameObject || anim.CompareTag("Player")) continue;
|
||||
|
||||
// 元のスピードに関わらず、0に上書きしてアニメーションを完全停止
|
||||
anim.speed = 0f;
|
||||
pausedAnimators.Add(anim); // 記憶リストに保存
|
||||
pausedAnimators.Add(anim);
|
||||
}
|
||||
|
||||
// 3. ボスのNavMeshAgent(自動移動)も一時停止させる
|
||||
NavMeshAgent[] allAgents = FindObjectsByType<NavMeshAgent>(FindObjectsSortMode.None);
|
||||
pausedAgents.Clear();
|
||||
|
||||
foreach (var agent in allAgents)
|
||||
{
|
||||
if (agent == null || !agent.enabled || !agent.gameObject.activeInHierarchy) continue;
|
||||
if (agent.CompareTag("Player")) continue;
|
||||
|
||||
if (!agent.isStopped)
|
||||
{
|
||||
agent.isStopped = true;
|
||||
pausedAgents.Add(agent);
|
||||
}
|
||||
}
|
||||
|
||||
if (codingModeUI != null) codingModeUI.SetActive(true);
|
||||
Debug.Log("⏳ Codingモード:敵の時間(アニメーション)を停止しました。");
|
||||
Debug.Log("⏳ Codingモード:プレイヤー移動をロック&敵の時間(アニメ・NavMesh)を完全停止しました。");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// バフを適用してゲームを再開する
|
||||
/// バフを適用してゲームを再開する(ゲージ消費あり)
|
||||
/// </summary>
|
||||
public void ApplyBuffsAndResume(string buff1, string buff2)
|
||||
{
|
||||
@@ -145,7 +182,29 @@ public class PlayerStatusManager : MonoBehaviour
|
||||
ActivateBuffByName(buff1);
|
||||
ActivateBuffByName(buff2);
|
||||
|
||||
// 【変更】2. 停止させていた敵のアニメーターを元の速度(1.0f)に戻す
|
||||
// 2. ゲーム状態を復帰(ゲージを消費)
|
||||
ResumeWorldState(consumeGauge: true);
|
||||
|
||||
Debug.Log("▶ Codingモード完了:バフを適用してゲームを再開しました。");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ★新規実装:Codingモードをキャンセルしてゲームを再開する(ゲージ消費なし)
|
||||
/// </summary>
|
||||
public void CancelCodingMode()
|
||||
{
|
||||
// ゲーム状態を復帰(ゲージは維持)
|
||||
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)
|
||||
@@ -153,14 +212,31 @@ public class PlayerStatusManager : MonoBehaviour
|
||||
anim.speed = 1f;
|
||||
}
|
||||
}
|
||||
pausedAnimators.Clear(); // リストを空にする
|
||||
pausedAnimators.Clear();
|
||||
|
||||
// 3. Codingモードの終了処理
|
||||
// 2. 停止させていたNavMeshAgentの移動を再開する
|
||||
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);
|
||||
currentGauge = 0f; // ゲージを消費
|
||||
Debug.Log("▶ Codingモード終了:敵の時間を再開しました。");
|
||||
|
||||
// 5. ゲージの消費制御
|
||||
if (consumeGauge)
|
||||
{
|
||||
currentGauge = 0f; // バフ決定時のみゲージ消費
|
||||
}
|
||||
}
|
||||
|
||||
private void ActivateBuffByName(string buffName)
|
||||
|
||||
Reference in New Issue
Block a user