Files
Fishing2/Assets/Scripts/Fishing2~/Common/CameraComponent.cs

98 lines
2.7 KiB
C#

using Fantasy.Async;
using NBC;
using Fantasy.Entitas;
using Fantasy.Entitas.Interface;
using Fantasy.Event;
using UnityEngine;
namespace NBF.Fishing2
{
public enum CameraShowMode
{
None = 0,
FPP,
TPP,
}
public class CameraComponent : Entity
{
public CameraShowMode Mode = CameraShowMode.None;
private CameraAsset _cameraAsset;
private CameraShowMode _lastMode = CameraShowMode.None;
public class CameraComponentAwakeSystem : AwakeSystem<CameraComponent>
{
protected override void Awake(CameraComponent self)
{
self._cameraAsset = Game.Instance.gameObject.GetComponentInChildren<CameraAsset>();
}
}
public class CameraComponentUpdateSystem : UpdateSystem<CameraComponent>
{
protected override void Update(CameraComponent self)
{
self.UpdateCamera();
}
}
public class CameraComponentDestroySystem : DestroySystem<CameraComponent>
{
protected override void Destroy(CameraComponent self)
{
self._cameraAsset = null;
self._lastMode = CameraShowMode.None;
self.Mode = CameraShowMode.None;
}
}
private void UpdateCamera()
{
if (_lastMode == Mode) return;
if (Mode == CameraShowMode.TPP)
{
//第三人称视角
SetTPPCam();
}
else if (Mode == CameraShowMode.FPP)
{
//第一人称视角
SetFPPCam();
}
}
private void SetTPPCam()
{
_cameraAsset.fppVCam.Priority = 0;
_cameraAsset.tppVCam.Priority = 10;
}
private void SetFPPCam()
{
var map = App.Main.GetComponent<Map>();
var unityComponent = map.SelfMapUnit.GetComponent<UnitUnityComponent>();
if (unityComponent != null)
{
_cameraAsset.fppVCam.LookAt = unityComponent.RootAsset.FppLook;
_cameraAsset.fppVCam.Follow = unityComponent.ModelAsset.NeckTransform;
unityComponent.ModelAsset.LookIk.solver.target = unityComponent.RootAsset.FppLook;
}
_cameraAsset.fppVCam.Priority = 10;
_cameraAsset.tppVCam.Priority = 0;
}
public void SetFppLook(Transform fppCamLook)
{
_cameraAsset.fppVCam.LookAt = fppCamLook;
}
public void SetFppFollow(Transform fppCamFollow)
{
_cameraAsset.fppVCam.Follow = fppCamFollow;
}
}
}