修改提交
This commit is contained in:
3
Assets/Scripts/Fishing/New/View/Mono.meta
Normal file
3
Assets/Scripts/Fishing/New/View/Mono.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c38d17daa1164359ad9f9466be692b7c
|
||||
timeCreated: 1773038185
|
||||
185
Assets/Scripts/Fishing/New/View/Mono/PlayerAnimator.cs
Normal file
185
Assets/Scripts/Fishing/New/View/Mono/PlayerAnimator.cs
Normal file
@@ -0,0 +1,185 @@
|
||||
using System;
|
||||
using KINEMATION.MagicBlend.Runtime;
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerAnimator : PlayerMonoBehaviour
|
||||
{
|
||||
public Animator _Animator;
|
||||
|
||||
private bool _isRodLayerEnabled;
|
||||
private bool _isInit;
|
||||
private PlayerIK _IK;
|
||||
private MagicBlending _magicBlending;
|
||||
private bool _IsInVehicle;
|
||||
|
||||
#region 参数定义
|
||||
|
||||
// public static readonly int IsSwiming = Animator.StringToHash("Swim");
|
||||
//
|
||||
// public static readonly int ThrowFar = Animator.StringToHash("ThrowFar");
|
||||
//
|
||||
// public static readonly int BoatDriving = Animator.StringToHash("BoatDriving");
|
||||
//
|
||||
// public static readonly int BaitInWater = Animator.StringToHash("BaitInWater");
|
||||
//
|
||||
// public static readonly int HeldRod = Animator.StringToHash("HeldRod");
|
||||
//
|
||||
// public static readonly int RodArming = Animator.StringToHash("RodArming");
|
||||
|
||||
public static readonly int Forward = Animator.StringToHash("Forward");
|
||||
|
||||
public static readonly int Turn = Animator.StringToHash("Turn");
|
||||
|
||||
public static readonly int OnGroundHash = Animator.StringToHash("OnGround");
|
||||
public static readonly int PrepareThrowHash = Animator.StringToHash("PrepareThrow");
|
||||
public static readonly int StartThrowHash = Animator.StringToHash("StartThrow");
|
||||
public static readonly int BaitThrownHash = Animator.StringToHash("BaitThrown");
|
||||
private static readonly int FishingUpHash = Animator.StringToHash("FishingUp");
|
||||
|
||||
public static readonly string LureRodLayer = "LureRod";
|
||||
public static readonly string HandRodLayer = "HandRod";
|
||||
|
||||
|
||||
public float FishingUp
|
||||
{
|
||||
get => _Animator.GetFloat(FishingUpHash);
|
||||
set => _Animator.SetFloat(FishingUpHash, value);
|
||||
}
|
||||
|
||||
public bool OnGround
|
||||
{
|
||||
get => _Animator.GetBool(OnGroundHash);
|
||||
set => _Animator.SetBool(OnGroundHash, value);
|
||||
}
|
||||
|
||||
public bool StartThrow
|
||||
{
|
||||
get => _Animator.GetBool(StartThrowHash);
|
||||
set => _Animator.SetBool(StartThrowHash, value);
|
||||
}
|
||||
|
||||
public bool BaitThrown
|
||||
{
|
||||
get => _Animator.GetBool(BaitThrownHash);
|
||||
set => _Animator.SetBool(BaitThrownHash, value);
|
||||
}
|
||||
|
||||
public bool PrepareThrow
|
||||
{
|
||||
get => _Animator.GetBool(PrepareThrowHash);
|
||||
set => _Animator.SetBool(PrepareThrowHash, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
_magicBlending = GetComponent<MagicBlending>();
|
||||
_Animator = GetComponent<Animator>();
|
||||
_Animator.keepAnimatorStateOnDisable = true;
|
||||
_IK = GetComponent<PlayerIK>();
|
||||
_isInit = true;
|
||||
// Player.OnFishingSetEquiped += OnFishingSetEquiped_OnRaised;
|
||||
// Player.OnFishingSetUnequip += OnFishingSetUnequip;
|
||||
}
|
||||
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Player.OnFishingSetEquiped -= OnFishingSetEquiped_OnRaised;
|
||||
// Player.OnFishingSetUnequip -= OnFishingSetUnequip;
|
||||
}
|
||||
|
||||
|
||||
private void OnFishingSetUnequip()
|
||||
{
|
||||
_isRodLayerEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
private void OnFishingSetEquiped_OnRaised(FHandItem item)
|
||||
{
|
||||
if (item is FRod rod)
|
||||
{
|
||||
_isRodLayerEnabled = true;
|
||||
// var reel = Player.Rod.Reel;
|
||||
// _IK.SetBipedLeftHandIK(enabled: false, reel.FingersIKAnchor);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetLayerWeight(string layer, float weight)
|
||||
{
|
||||
_Animator.SetLayerWeight(_Animator.GetLayerIndex(layer), weight);
|
||||
}
|
||||
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
{
|
||||
float value3 = Mathf.Lerp(_Animator.GetFloat(Forward), Player.Speed / 5f,
|
||||
Time.deltaTime * 20f);
|
||||
float value4 = Mathf.Lerp(_Animator.GetFloat(Turn), Player.RotationSpeed,
|
||||
Time.deltaTime * 15f);
|
||||
_Animator.SetFloat(Forward, Mathf.Clamp01(value3));
|
||||
_Animator.SetFloat(Turn, Mathf.Clamp(value4, -1f, 1f));
|
||||
}
|
||||
|
||||
|
||||
_Animator.SetBool(OnGroundHash, _IsInVehicle || Player.IsGrounded);
|
||||
|
||||
|
||||
var isHandRodLayerEnabled = _isRodLayerEnabled && !Player.IsLureRod ? 1 : 0;
|
||||
|
||||
float handRodLayerWeight = _Animator.GetLayerWeight(_Animator.GetLayerIndex(HandRodLayer));
|
||||
SetLayerWeight(HandRodLayer,
|
||||
Mathf.MoveTowards(handRodLayerWeight, isHandRodLayerEnabled, Time.deltaTime * 3f));
|
||||
|
||||
|
||||
var isLureRodLayerEnabled = _isRodLayerEnabled && Player.IsLureRod ? 1 : 0;
|
||||
float lureRodLayerWeight = _Animator.GetLayerWeight(_Animator.GetLayerIndex(LureRodLayer));
|
||||
SetLayerWeight(LureRodLayer,
|
||||
Mathf.MoveTowards(lureRodLayerWeight, isLureRodLayerEnabled, Time.deltaTime * 3f));
|
||||
}
|
||||
|
||||
#region 动画事件
|
||||
|
||||
/// <summary>
|
||||
/// 抬杆到底动画事件
|
||||
/// </summary>
|
||||
public void OnRodPowerUp()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始抛出动画事件
|
||||
/// </summary>
|
||||
public void OnRodThrowStart()
|
||||
{
|
||||
// if (Player.State is PlayerStateThrow playerStateThrow)
|
||||
// {
|
||||
// playerStateThrow.OnRodThrowStart();
|
||||
// }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抛竿结束动画事件
|
||||
/// </summary>
|
||||
public void OnRodThrownEnd()
|
||||
{
|
||||
// if (Player.Fsm.CurrentState is PlayerStateThrow playerStateThrow)
|
||||
// {
|
||||
// playerStateThrow.OnRodThrownEnd();
|
||||
// }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fc336a939c4416db623f3b4ae855265
|
||||
timeCreated: 1766470716
|
||||
29
Assets/Scripts/Fishing/New/View/Mono/PlayerArm.cs
Normal file
29
Assets/Scripts/Fishing/New/View/Mono/PlayerArm.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerArm : PlayerMonoBehaviour
|
||||
{
|
||||
public bool FixLowerArm;
|
||||
public bool IsLeft;
|
||||
public LimbIK IK;
|
||||
public Transform LowerArm;
|
||||
public Transform RodContainer;
|
||||
public FingerRig FingerRig;
|
||||
|
||||
|
||||
[HideInInspector] public float interactionTargetWeight;
|
||||
|
||||
private const int MaxFixEyeAngle = 15;
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/New/View/Mono/PlayerArm.cs.meta
Normal file
3
Assets/Scripts/Fishing/New/View/Mono/PlayerArm.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01ef40348d8b4d4da250acf0a921fc2a
|
||||
timeCreated: 1768660096
|
||||
24
Assets/Scripts/Fishing/New/View/Mono/PlayerChest.cs
Normal file
24
Assets/Scripts/Fishing/New/View/Mono/PlayerChest.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerChest : PlayerMonoBehaviour
|
||||
{
|
||||
private const int MaxFixEyeAngle = 15;
|
||||
private const int MinFixEyeAngle = -10;
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
FixArmAngle();
|
||||
}
|
||||
|
||||
private void FixArmAngle()
|
||||
{
|
||||
var angle = Player.EyeAngle;
|
||||
if (angle > MaxFixEyeAngle) angle = MaxFixEyeAngle;
|
||||
else if (angle < MinFixEyeAngle) angle = MinFixEyeAngle;
|
||||
var val = transform.localEulerAngles;
|
||||
transform.localEulerAngles = new Vector3(val.x, val.y, val.z - angle);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/New/View/Mono/PlayerChest.cs.meta
Normal file
3
Assets/Scripts/Fishing/New/View/Mono/PlayerChest.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e152a74e74b54d17ace5403a1570e12a
|
||||
timeCreated: 1768668096
|
||||
58
Assets/Scripts/Fishing/New/View/Mono/PlayerIK.cs
Normal file
58
Assets/Scripts/Fishing/New/View/Mono/PlayerIK.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerIK : PlayerMonoBehaviour
|
||||
{
|
||||
public enum UpdateType
|
||||
{
|
||||
Update = 0,
|
||||
FixedUpdate = 1,
|
||||
LateUpdate = 2,
|
||||
Default = 3
|
||||
}
|
||||
|
||||
public UpdateType UpdateSelected;
|
||||
|
||||
private LookAtIK _LookAtIK;
|
||||
|
||||
[SerializeField] private float transitionWeightTimeScale = 1f;
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
_LookAtIK = GetComponent<LookAtIK>();
|
||||
}
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (UpdateSelected == UpdateType.Update)
|
||||
{
|
||||
IKUpdateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (UpdateSelected == UpdateType.FixedUpdate)
|
||||
{
|
||||
IKUpdateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (UpdateSelected == UpdateType.LateUpdate)
|
||||
{
|
||||
IKUpdateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private void IKUpdateHandler()
|
||||
{
|
||||
_LookAtIK.UpdateSolverExternal();
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/New/View/Mono/PlayerIK.cs.meta
Normal file
3
Assets/Scripts/Fishing/New/View/Mono/PlayerIK.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb36ecc5b1784d948837600cf18808cd
|
||||
timeCreated: 1765121426
|
||||
22
Assets/Scripts/Fishing/New/View/Mono/PlayerMonoBehaviour.cs
Normal file
22
Assets/Scripts/Fishing/New/View/Mono/PlayerMonoBehaviour.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public abstract class PlayerMonoBehaviour : MonoBehaviour
|
||||
{
|
||||
public Player Player { get; private set; }
|
||||
|
||||
public PlayerUnityComponent UnityComponent { get; private set; }
|
||||
|
||||
protected void Awake()
|
||||
{
|
||||
UnityComponent = GetComponentInParent<PlayerUnityComponent>();
|
||||
Player = UnityComponent.Player;
|
||||
OnAwake();
|
||||
}
|
||||
|
||||
protected virtual void OnAwake()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fbde40efe5345cd8c05ea6c1f1914cf
|
||||
timeCreated: 1773040970
|
||||
25
Assets/Scripts/Fishing/New/View/Mono/PlayerUnityComponent.cs
Normal file
25
Assets/Scripts/Fishing/New/View/Mono/PlayerUnityComponent.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using ECM2;
|
||||
using ECM2.Examples.FirstPerson;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerUnityComponent : MonoBehaviour
|
||||
{
|
||||
public Player Player { get; set; }
|
||||
public Transform Root;
|
||||
public Transform Eye;
|
||||
public Transform FppLook;
|
||||
public Transform IK;
|
||||
public PlayerModelAsset ModelAsset;
|
||||
public CharacterMovement Character;
|
||||
public FirstPersonCharacter FirstPerson;
|
||||
|
||||
[Header("视角相关")] public float MouseSensitivity = 0.1f;
|
||||
[Space(15f)] public bool invertLook = true;
|
||||
|
||||
public float minPitch = -60f;
|
||||
|
||||
public float maxPitch = 60f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a25908f34e4e4464a922b88337a5b733
|
||||
timeCreated: 1773038189
|
||||
200
Assets/Scripts/Fishing/New/View/PlayerInputComponent.cs
Normal file
200
Assets/Scripts/Fishing/New/View/PlayerInputComponent.cs
Normal file
@@ -0,0 +1,200 @@
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerInputComponent : Entity
|
||||
{
|
||||
public Player Player { get; private set; }
|
||||
public PlayerViewComponent View { get; private set; }
|
||||
|
||||
#region 生命周期
|
||||
|
||||
public class PlayerViewAwakeSystem : AwakeSystem<PlayerInputComponent>
|
||||
{
|
||||
protected override void Awake(PlayerInputComponent self)
|
||||
{
|
||||
self.Player = self.GetParent<Player>();
|
||||
self.View = self.Player.GetComponent<PlayerViewComponent>();
|
||||
self.AddInputEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayerViewUpdateSystem : UpdateSystem<PlayerInputComponent>
|
||||
{
|
||||
protected override void Update(PlayerInputComponent self)
|
||||
{
|
||||
self.UpdateMove();
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayerViewDestroySystem : DestroySystem<PlayerInputComponent>
|
||||
{
|
||||
protected override void Destroy(PlayerInputComponent self)
|
||||
{
|
||||
self.RemoveInputEvent();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Input
|
||||
|
||||
private void AddInputEvent()
|
||||
{
|
||||
InputManager.OnPlayerPerformed += OnPlayerCanceled;
|
||||
InputManager.OnPlayerPerformed += OnPlayerPerformed;
|
||||
|
||||
InputManager.OnPlayerValueCanceled += OnPlayerValueCanceled;
|
||||
InputManager.OnPlayerValuePerformed += OnPlayerValuePerformed;
|
||||
}
|
||||
|
||||
private void RemoveInputEvent()
|
||||
{
|
||||
InputManager.OnPlayerPerformed += OnPlayerCanceled;
|
||||
InputManager.OnPlayerPerformed += OnPlayerPerformed;
|
||||
|
||||
InputManager.OnPlayerValueCanceled += OnPlayerValueCanceled;
|
||||
InputManager.OnPlayerValuePerformed += OnPlayerValuePerformed;
|
||||
}
|
||||
|
||||
private void OnPlayerPerformed(string action)
|
||||
{
|
||||
if (action == InputDef.Player.Run)
|
||||
{
|
||||
Player.Run = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerCanceled(string action)
|
||||
{
|
||||
if (action == InputDef.Player.Run)
|
||||
{
|
||||
Player.Run = false;
|
||||
}
|
||||
else if (action == InputDef.Player.ToBag)
|
||||
{
|
||||
//取消手持物品
|
||||
Log.Info($"取消手持物品");
|
||||
Player.UnUseItem();
|
||||
// Game.Instance.StartCoroutine(UnUseItem());
|
||||
}
|
||||
else if (action.StartsWith(InputDef.Player.QuickStarts))
|
||||
{
|
||||
var index = int.Parse(action.Replace(InputDef.Player.QuickStarts, string.Empty));
|
||||
Log.Info($"快速使用===={index}");
|
||||
var item = RoleModel.Instance.GetSlotItem(index - 1);
|
||||
if (item != null)
|
||||
{
|
||||
Player.UseItem(item);
|
||||
// Game.Instance.StartCoroutine(UseItem(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerValueCanceled(InputAction.CallbackContext context)
|
||||
{
|
||||
var actionName = context.action.name;
|
||||
if (actionName == InputDef.Player.Move)
|
||||
{
|
||||
Player.MoveInput = Vector2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerValuePerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
var actionName = context.action.name;
|
||||
if (actionName == InputDef.Player.Move)
|
||||
{
|
||||
var v2 = context.ReadValue<Vector2>();
|
||||
Player.MoveInput = v2;
|
||||
}
|
||||
else if (actionName == InputDef.Player.Look)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Move
|
||||
|
||||
private Quaternion lastRotation;
|
||||
|
||||
private void UpdateMove()
|
||||
{
|
||||
UpdateGrounded();
|
||||
ProcessMoveStates();
|
||||
UpdateLookInput();
|
||||
}
|
||||
|
||||
private void ProcessMoveStates()
|
||||
{
|
||||
{
|
||||
var num2 = Player.Run ? 7 : 5;
|
||||
Vector3 vector2 = View.Unity.FirstPerson.GetRightVector() * Player.MoveInput.x * num2;
|
||||
vector2 += View.Unity.FirstPerson.GetForwardVector() * Player.MoveInput.y * num2;
|
||||
// if (checkWaterBound)
|
||||
// {
|
||||
// SetMovementDirectionWithRaycastCheck(vector2);
|
||||
// }
|
||||
// else
|
||||
{
|
||||
View.Unity.FirstPerson.SetMovementDirection(vector2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateGrounded()
|
||||
{
|
||||
Player.IsGrounded = View.Unity.FirstPerson.IsGrounded();
|
||||
Player.Speed = View.Unity.FirstPerson.velocity.magnitude;
|
||||
|
||||
Quaternion rotation = View.Unity.FirstPerson.transform.rotation;
|
||||
|
||||
// 计算当前帧与上一帧的旋转差异
|
||||
Quaternion rotationDelta = rotation * Quaternion.Inverse(lastRotation);
|
||||
|
||||
// 将四元数转换为角度轴表示
|
||||
rotationDelta.ToAngleAxis(out float angle, out Vector3 axis);
|
||||
|
||||
// 确保角度在0-360范围内
|
||||
if (angle > 180f) angle -= 360f;
|
||||
|
||||
// 获取Y轴旋转分量(归一化处理)
|
||||
float yRotation = 0f;
|
||||
if (Mathf.Abs(angle) > 0.001f && Mathf.Abs(axis.y) > 0.1f)
|
||||
{
|
||||
// 计算Y轴方向的旋转角度(考虑旋转轴方向)
|
||||
yRotation = angle * Mathf.Sign(axis.y);
|
||||
}
|
||||
|
||||
float maxTurnSpeed = 180f; // 度/秒
|
||||
// 转换为角速度并归一化到[-1, 1]
|
||||
float angularSpeed = yRotation / Time.deltaTime;
|
||||
float turnValue = Mathf.Clamp(angularSpeed / maxTurnSpeed, -1f, 1f);
|
||||
|
||||
|
||||
Player.RotationSpeed = turnValue;
|
||||
|
||||
lastRotation = rotation;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Look
|
||||
|
||||
private void UpdateLookInput()
|
||||
{
|
||||
Vector2 value = InputManager.GetLookInput();
|
||||
var u3d = View.Unity;
|
||||
u3d.FirstPerson.AddControlYawInput(value.x * u3d.MouseSensitivity);
|
||||
u3d.FirstPerson.AddControlPitchInput((u3d.invertLook ? 0f - value.y : value.y) * u3d.MouseSensitivity,
|
||||
u3d.minPitch, u3d.maxPitch);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d74cb6e741243478aeb0a3053211fcd
|
||||
timeCreated: 1773039193
|
||||
89
Assets/Scripts/Fishing/New/View/PlayerViewComponent.cs
Normal file
89
Assets/Scripts/Fishing/New/View/PlayerViewComponent.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using NBF.Fishing2;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerViewComponent : Entity
|
||||
{
|
||||
public Player Player { get; private set; }
|
||||
|
||||
public PlayerUnityComponent Unity { get; private set; }
|
||||
|
||||
#region 生命周期
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
Player = GetParent<Player>();
|
||||
var gameObject = PrefabsHelper.CreatePlayer(SceneSettings.Instance.Node);
|
||||
Unity = gameObject.GetComponent<PlayerUnityComponent>();
|
||||
Unity.Player = Player;
|
||||
CreatePlayerModel();
|
||||
if (Player.IsSelf)
|
||||
{
|
||||
CameraManager.Instance.SetFppLook(Unity);
|
||||
}
|
||||
Unity.transform.localPosition = new Vector3(484, 1, 422);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
}
|
||||
|
||||
public void LateUpdate()
|
||||
{
|
||||
Player.EyeAngle = GameUtils.GetVerticalAngle(Unity.transform, Unity.FppLook);
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 模型创建
|
||||
|
||||
private void CreatePlayerModel()
|
||||
{
|
||||
var modelObject = PrefabsHelper.CreatePlayer(Unity.Root, "Human_Male");
|
||||
modelObject.transform.localPosition = Vector3.zero;
|
||||
Unity.ModelAsset = modelObject.GetComponent<PlayerModelAsset>();
|
||||
Unity.ModelAsset.SetPlayer(Unity.FppLook);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class PlayerViewAwakeSystem : AwakeSystem<PlayerViewComponent>
|
||||
{
|
||||
protected override void Awake(PlayerViewComponent self)
|
||||
{
|
||||
self.Awake();
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayerViewDestroySystem : DestroySystem<PlayerViewComponent>
|
||||
{
|
||||
protected override void Destroy(PlayerViewComponent self)
|
||||
{
|
||||
self.Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayerViewUpdateSystem : UpdateSystem<PlayerViewComponent>
|
||||
{
|
||||
protected override void Update(PlayerViewComponent self)
|
||||
{
|
||||
self.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayerViewLateUpdateSystem : LateUpdateSystem<PlayerViewComponent>
|
||||
{
|
||||
protected override void LateUpdate(PlayerViewComponent self)
|
||||
{
|
||||
self.LateUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 418da378516646cdb672fa05c2066432
|
||||
timeCreated: 1773037811
|
||||
Reference in New Issue
Block a user