2025-10-17 15:10:19 +08:00
|
|
|
|
using System;
|
|
|
|
|
using Script.Gameplay.Input;
|
|
|
|
|
using UnityEngine;
|
2025-10-18 08:55:38 +08:00
|
|
|
|
using Core;
|
2025-10-18 09:25:06 +08:00
|
|
|
|
using Script.Gameplay.Global;
|
2025-10-17 15:10:19 +08:00
|
|
|
|
|
2025-10-20 10:12:07 +08:00
|
|
|
|
namespace Script.Gameplay.Player
|
2025-10-17 15:10:19 +08:00
|
|
|
|
{
|
|
|
|
|
public enum WatchMode
|
|
|
|
|
{
|
|
|
|
|
Normal,
|
|
|
|
|
Inside,
|
|
|
|
|
Outside
|
|
|
|
|
}
|
2025-10-18 09:25:06 +08:00
|
|
|
|
|
2025-10-18 08:55:38 +08:00
|
|
|
|
public class PlayerWatchModeController : MonoBehaviour
|
2025-10-17 15:10:19 +08:00
|
|
|
|
{
|
|
|
|
|
[SerializeField] private Camera cam;
|
2025-10-19 19:38:52 +08:00
|
|
|
|
public event Action<WatchMode> OnEnterWatchMode;
|
|
|
|
|
public event Action<WatchMode> OnExitWatchMode;
|
2025-10-17 15:10:19 +08:00
|
|
|
|
private InputManager inputManager;
|
2025-10-18 09:25:06 +08:00
|
|
|
|
private TimePauseManager timePauseManager;
|
2025-10-18 11:00:06 +08:00
|
|
|
|
private PlayerInteractorController playerInteractorController;
|
2025-10-19 19:38:52 +08:00
|
|
|
|
private PlayerConnectController _playerConnectController;
|
|
|
|
|
private WatchMode previousMode = WatchMode.Normal;
|
|
|
|
|
private WatchMode currentMode = WatchMode.Normal;
|
2025-10-18 09:25:06 +08:00
|
|
|
|
|
2025-10-18 08:55:38 +08:00
|
|
|
|
public WatchMode CurrentWatchMode
|
|
|
|
|
{
|
|
|
|
|
get => currentMode;
|
|
|
|
|
set
|
|
|
|
|
{
|
2025-10-19 19:38:52 +08:00
|
|
|
|
previousMode = currentMode;
|
2025-10-18 08:55:38 +08:00
|
|
|
|
currentMode = value;
|
2025-10-19 19:38:52 +08:00
|
|
|
|
// 触发退出事件
|
|
|
|
|
OnExitWatchMode?.Invoke(previousMode);
|
|
|
|
|
OnEnterWatchMode?.Invoke(currentMode);
|
|
|
|
|
|
2025-10-18 08:55:38 +08:00
|
|
|
|
SwitchWatchMode(currentMode);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-17 15:10:19 +08:00
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
inputManager = InputManager.Instance;
|
2025-10-18 09:25:06 +08:00
|
|
|
|
timePauseManager = TimePauseManager.Instance;
|
2025-10-18 11:00:06 +08:00
|
|
|
|
playerInteractorController = GetComponent<PlayerInteractorController>();
|
2025-10-19 19:38:52 +08:00
|
|
|
|
_playerConnectController = GetComponent<PlayerConnectController>();
|
2025-10-18 09:25:06 +08:00
|
|
|
|
|
2025-10-17 15:10:19 +08:00
|
|
|
|
var input = inputManager.Input;
|
|
|
|
|
input.Player.SwitchWatchMode.performed += ctx =>
|
|
|
|
|
{
|
2025-10-18 08:55:38 +08:00
|
|
|
|
var modeTemp = (WatchMode)(((int)CurrentWatchMode + 1) % 3);
|
|
|
|
|
CurrentWatchMode = modeTemp;
|
2025-10-18 09:25:06 +08:00
|
|
|
|
};
|
|
|
|
|
;
|
|
|
|
|
|
2025-10-18 08:55:38 +08:00
|
|
|
|
ControllerLocator.Instance.Register(this);
|
2025-10-17 15:10:19 +08:00
|
|
|
|
}
|
2025-10-18 09:25:06 +08:00
|
|
|
|
|
2025-10-17 15:10:19 +08:00
|
|
|
|
// 实现按Tap键实现在WatchMode 3个模式切换,并通过SwitchWatchMode设置正确的相机模式
|
|
|
|
|
private void SwitchWatchMode(WatchMode watchMode)
|
|
|
|
|
{
|
|
|
|
|
switch (watchMode)
|
|
|
|
|
{
|
|
|
|
|
case WatchMode.Normal:
|
|
|
|
|
SetSeeLines(false);
|
2025-10-18 09:20:37 +08:00
|
|
|
|
inputManager.SetCursorState(false, CursorLockMode.Locked);
|
|
|
|
|
inputManager.SetInputForLook(true);
|
|
|
|
|
inputManager.SetInputForMove(true);
|
2025-10-18 09:25:06 +08:00
|
|
|
|
if (timePauseManager != null)
|
|
|
|
|
{
|
|
|
|
|
timePauseManager.SetPaused(false);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-18 11:00:06 +08:00
|
|
|
|
if (playerInteractorController != null)
|
|
|
|
|
{
|
|
|
|
|
playerInteractorController.SetPlayerInteractionEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-19 19:38:52 +08:00
|
|
|
|
if (_playerConnectController != null)
|
|
|
|
|
{
|
|
|
|
|
_playerConnectController.IsEnableConnecting = false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-17 15:10:19 +08:00
|
|
|
|
break;
|
|
|
|
|
case WatchMode.Inside:
|
|
|
|
|
SetSeeLines(false);
|
2025-10-18 09:20:37 +08:00
|
|
|
|
inputManager.SetCursorState(true, CursorLockMode.Confined);
|
|
|
|
|
inputManager.SetInputForLook(false);
|
|
|
|
|
inputManager.SetInputForMove(false);
|
2025-10-18 09:25:06 +08:00
|
|
|
|
if (timePauseManager != null)
|
|
|
|
|
{
|
|
|
|
|
timePauseManager.SetPaused(true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-18 11:00:06 +08:00
|
|
|
|
if (playerInteractorController != null)
|
|
|
|
|
{
|
|
|
|
|
playerInteractorController.SetPlayerInteractionEnabled(false);
|
|
|
|
|
}
|
2025-10-19 19:38:52 +08:00
|
|
|
|
|
|
|
|
|
if (_playerConnectController != null)
|
|
|
|
|
{
|
|
|
|
|
_playerConnectController.IsEnableConnecting = false;
|
|
|
|
|
}
|
2025-10-18 11:00:06 +08:00
|
|
|
|
|
2025-10-17 15:10:19 +08:00
|
|
|
|
break;
|
|
|
|
|
case WatchMode.Outside:
|
|
|
|
|
SetSeeLines(true);
|
2025-10-18 09:20:37 +08:00
|
|
|
|
inputManager.SetCursorState(false, CursorLockMode.Locked);
|
|
|
|
|
inputManager.SetInputForLook(true);
|
|
|
|
|
inputManager.SetInputForMove(true);
|
2025-10-18 09:25:06 +08:00
|
|
|
|
if (timePauseManager != null)
|
|
|
|
|
{
|
|
|
|
|
timePauseManager.SetPaused(false);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-18 11:00:06 +08:00
|
|
|
|
if (playerInteractorController != null)
|
|
|
|
|
{
|
|
|
|
|
playerInteractorController.SetPlayerInteractionEnabled(true);
|
|
|
|
|
}
|
2025-10-19 19:38:52 +08:00
|
|
|
|
|
|
|
|
|
if (_playerConnectController != null)
|
|
|
|
|
{
|
|
|
|
|
_playerConnectController.IsEnableConnecting = true;
|
|
|
|
|
}
|
2025-10-18 11:00:06 +08:00
|
|
|
|
|
2025-10-17 15:10:19 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetSeeLines(bool seeLine)
|
|
|
|
|
{
|
|
|
|
|
int linesLayer = LayerMask.NameToLayer("Lines");
|
|
|
|
|
int mask = cam.cullingMask;
|
|
|
|
|
|
|
|
|
|
if (seeLine)
|
|
|
|
|
mask |= 1 << linesLayer; // 打开
|
|
|
|
|
else
|
|
|
|
|
mask &= ~(1 << linesLayer); // 关闭
|
|
|
|
|
|
|
|
|
|
cam.cullingMask = mask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|