using System.Collections;
using UnityEngine;

namespace NBF
{
    public enum CameraShowMode
    {
        None = 0,
        FPP,
        TPP,
    }

    public class CameraManager : MonoService<CameraManager>
    {
        public CameraShowMode Mode = CameraShowMode.None;

        [SerializeField] private CameraAsset _cameraAsset;
        private CameraShowMode _lastMode = CameraShowMode.None;

        private void Update()
        {
            if (_lastMode == Mode) return;
            if (Mode == CameraShowMode.TPP)
            {
                //第三人称视角
                SetTPPCam();
            }
            else if (Mode == CameraShowMode.FPP)
            {
                //第一人称视角
                SetFPPCam();
            }

            _lastMode = Mode;
        }


        private void SetTPPCam()
        {
            _cameraAsset.fppVCam.Priority = 0;
            _cameraAsset.tppVCam.Priority = 10;
        }

        private void SetFPPCam()
        {
            var player = FPlayer.Instance;
            if (player != null)
            {
                _cameraAsset.fppVCam.LookAt = player.FppLook;
                _cameraAsset.fppVCam.Follow = player.ModelAsset.NeckTransform;
            }

            _cameraAsset.fppVCam.Priority = 10;
            _cameraAsset.tppVCam.Priority = 0;
            // StartCoroutine(SnapToTarget());
        }

        public void SetFppLook(Transform fppCamLook)
        {
            _cameraAsset.fppVCam.LookAt = fppCamLook;
        }

        public void SetFppFollow(Transform fppCamFollow)
        {
            _cameraAsset.fppVCam.Follow = fppCamFollow;
        }
        
    }
}