Files
2025TapTapGameJam/Assets/Script/Gameplay/Player/PlayerWatchModeController.cs

85 lines
2.4 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 System;
using Script.Gameplay.Input;
using UnityEngine;
using Core;
namespace Gameplay.Player
{
public enum WatchMode
{
Normal,
Inside,
Outside
}
public class PlayerWatchModeController : MonoBehaviour
{
[SerializeField] private Camera cam;
public event Action OnEnterInsideWatchMode;
public event Action OnExitInsideWatchMode;
private InputManager inputManager;
private WatchMode currentMode = WatchMode.Normal;
public WatchMode CurrentWatchMode
{
get => currentMode;
set
{
if (value != WatchMode.Inside)
{
OnExitInsideWatchMode?.Invoke();
}
if (value == WatchMode.Inside)
{
OnEnterInsideWatchMode?.Invoke();
}
currentMode = value;
SwitchWatchMode(currentMode);
}
}
private void Start()
{
inputManager = InputManager.Instance;
var input = inputManager.Input;
input.Player.SwitchWatchMode.performed += ctx =>
{
var modeTemp = (WatchMode)(((int)CurrentWatchMode + 1) % 3);
CurrentWatchMode = modeTemp;
};;
ControllerLocator.Instance.Register(this);
}
// 实现按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;
}
}
}