You've already forked taptap2024_GJ_chidouren
updat core
This commit is contained in:
62
Assets/Scripts/Game/Component/CameraManager.cs
Normal file
62
Assets/Scripts/Game/Component/CameraManager.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
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);
|
||||
this._closeUpTimeHandler = GameUpdateMgr.Instance.CreateTimer (duration , () =>
|
||||
{
|
||||
SetCameraState (lastState);
|
||||
this._closeUpTimeHandler = null;
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user