You've already forked taptap2024_GJ_chidouren
64 lines
2.1 KiB
C#
64 lines
2.1 KiB
C#
using Cinemachine;
|
|
using Framework.Timer;
|
|
using Sirenix.Utilities;
|
|
using UnityEngine;
|
|
|
|
namespace Game.Component
|
|
{
|
|
public class CameraManager : MonoBehaviour
|
|
{
|
|
public enum CameraState
|
|
{
|
|
Normal = 0, // 正常
|
|
Player_Near, // 在玩家附近
|
|
Player_Far, // 在玩家远处
|
|
CloseUp // 特写镜头
|
|
}
|
|
|
|
[SerializeField] private Camera mainCamera;
|
|
[SerializeField] private Animator cameraAnimator;
|
|
[SerializeField] private Transform closeUpTarget;
|
|
[SerializeField] private PolygonCollider2D boxBorder;
|
|
|
|
public CameraState cameraState = CameraState.Normal;
|
|
private static readonly int TriggerState = Animator.StringToHash ("TriggerState");
|
|
private TimeHandler _closeUpTimeHandler;
|
|
|
|
|
|
public void SetCameraState (CameraState state)
|
|
{
|
|
this.cameraState = state;
|
|
this.cameraAnimator.SetInteger (TriggerState , (int)state);
|
|
}
|
|
|
|
public void SetCloseUpTarget (Transform target , float duration = 3)
|
|
{
|
|
this._closeUpTimeHandler?.Kill ();
|
|
var lastState = this.cameraState;
|
|
this.closeUpTarget.position = target.position;
|
|
SetCameraState (CameraState.CloseUp);
|
|
MapContent.Instance.IsPause = true;
|
|
this._closeUpTimeHandler = GameUpdateMgr.Instance.CreateTimer (duration , () =>
|
|
{
|
|
SetCameraState (lastState);
|
|
this._closeUpTimeHandler = null;
|
|
MapContent.Instance.IsPause = false;
|
|
});
|
|
}
|
|
|
|
public void SetBoxCollider (PolygonCollider2D box)
|
|
{
|
|
this.boxBorder.offset = box.offset;
|
|
this.boxBorder.pathCount = box.pathCount;
|
|
this.boxBorder.points = box.points;
|
|
this.transform.GetComponentsInChildren<CinemachineConfiner2D> ().ForEach (d => d.InvalidateCache ());
|
|
}
|
|
|
|
public static CameraManager Instance { get; private set; }
|
|
|
|
private void Awake ()
|
|
{
|
|
Instance = this;
|
|
}
|
|
}
|
|
} |