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-17 15:10:19 +08:00
|
|
|
|
|
|
|
|
|
namespace Gameplay.Player
|
|
|
|
|
{
|
|
|
|
|
public enum WatchMode
|
|
|
|
|
{
|
|
|
|
|
Normal,
|
|
|
|
|
Inside,
|
|
|
|
|
Outside
|
|
|
|
|
}
|
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-18 08:55:38 +08:00
|
|
|
|
public event Action OnEnterInsideWatchMode;
|
|
|
|
|
public event Action OnExitInsideWatchMode;
|
2025-10-17 15:10:19 +08:00
|
|
|
|
private InputManager inputManager;
|
|
|
|
|
private WatchMode currentMode = WatchMode.Normal;
|
2025-10-18 08:55:38 +08:00
|
|
|
|
public WatchMode CurrentWatchMode
|
|
|
|
|
{
|
|
|
|
|
get => currentMode;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != WatchMode.Inside)
|
|
|
|
|
{
|
|
|
|
|
OnExitInsideWatchMode?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
if (value == WatchMode.Inside)
|
|
|
|
|
{
|
|
|
|
|
OnEnterInsideWatchMode?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
currentMode = value;
|
|
|
|
|
SwitchWatchMode(currentMode);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-17 15:10:19 +08:00
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
inputManager = InputManager.Instance;
|
|
|
|
|
|
|
|
|
|
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-17 15:10:19 +08:00
|
|
|
|
};;
|
2025-10-18 08:55:38 +08:00
|
|
|
|
|
|
|
|
|
ControllerLocator.Instance.Register(this);
|
2025-10-17 15:10:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 实现按Tap键实现在WatchMode 3个模式切换,并通过SwitchWatchMode设置正确的相机模式
|
|
|
|
|
private void SwitchWatchMode(WatchMode watchMode)
|
|
|
|
|
{
|
|
|
|
|
switch (watchMode)
|
|
|
|
|
{
|
|
|
|
|
case WatchMode.Normal:
|
|
|
|
|
SetSeeLines(false);
|
|
|
|
|
break;
|
|
|
|
|
case WatchMode.Inside:
|
|
|
|
|
SetSeeLines(false);
|
|
|
|
|
break;
|
|
|
|
|
case WatchMode.Outside:
|
|
|
|
|
SetSeeLines(true);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|