结构大修改,改成朴实无华的结构,不过度架构。能跑就行
This commit is contained in:
108
Assets/Scripts/Fishing2~/Unit/Move/CharacterLookComponent.cs
Normal file
108
Assets/Scripts/Fishing2~/Unit/Move/CharacterLookComponent.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using ECM2.Examples.FirstPerson;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
public class CharacterLookComponent : Entity
|
||||
{
|
||||
// private UnitUnityComponent _UnitUnityComponent;
|
||||
public FirstPersonCharacter FirstPerson { get; set; }
|
||||
private float lookXRot;
|
||||
private float lookYRot;
|
||||
private Vector2 _moveInput;
|
||||
|
||||
public float MouseSensitivity = 0.1f;
|
||||
[Space(15f)] public bool invertLook = true;
|
||||
|
||||
public float minPitch = -60f;
|
||||
|
||||
public float maxPitch = 60f;
|
||||
|
||||
|
||||
private InputComponent _inputComponent;
|
||||
private Quaternion lastRotation;
|
||||
public MapUnit MapUnit;
|
||||
|
||||
#region System
|
||||
|
||||
public class LookComponentDestroySystem : DestroySystem<CharacterLookComponent>
|
||||
{
|
||||
protected override void Destroy(CharacterLookComponent self)
|
||||
{
|
||||
self.FirstPerson = null;
|
||||
// var mapUnit = self.Parent as MapUnit;
|
||||
|
||||
self._inputComponent = null;
|
||||
}
|
||||
}
|
||||
|
||||
public class LookComponentAwakeSystem : AwakeSystem<CharacterLookComponent>
|
||||
{
|
||||
protected override void Awake(CharacterLookComponent self)
|
||||
{
|
||||
var mapUnit = self.Parent as MapUnit;
|
||||
self.MapUnit = mapUnit;
|
||||
var unitUnityComponent = self.Parent.GetComponent<UnitUnityComponent>();
|
||||
self.FirstPerson = unitUnityComponent.FirstPerson;
|
||||
self._inputComponent = self.Scene.GetComponent<InputComponent>();
|
||||
}
|
||||
}
|
||||
|
||||
public class LookComponentUpdateSystem : UpdateSystem<CharacterLookComponent>
|
||||
{
|
||||
protected override void Update(CharacterLookComponent self)
|
||||
{
|
||||
self.UpdateLookInput();
|
||||
}
|
||||
}
|
||||
|
||||
// public class LookComponentLateUpdateSystem : LateUpdateSystem<CharacterLookComponent>
|
||||
// {
|
||||
// protected override void LateUpdate(CharacterLookComponent self)
|
||||
// {
|
||||
// self.UpdateLookInput();
|
||||
// }
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private void UpdateLookInput()
|
||||
{
|
||||
|
||||
// TPPLookTarget.position = base.transform.position;
|
||||
// if (CameraView.Value == CameraViewType.TPP)
|
||||
// {
|
||||
// lookXRot -= MouseInput.Value.y;
|
||||
// lookXRot = Mathf.Clamp(lookXRot, -25f, 55f);
|
||||
// lookYRot += MouseInput.Value.x;
|
||||
// lookYRot = Mathf.Repeat(lookYRot, 360f);
|
||||
// TPPLookTarget.localEulerAngles = new Vector3(lookXRot, lookYRot, 0f);
|
||||
// }
|
||||
// else if (CameraView.Value == CameraViewType.FPP)
|
||||
{
|
||||
// if (_IsInVehicle && PlayerState.Value == State.vehicle)
|
||||
// {
|
||||
// lookXRot -= MouseInput.Value.y;
|
||||
// lookXRot = Mathf.Clamp(lookXRot, VehicleLookXMinMax.x, VehicleLookXMinMax.y);
|
||||
// lookYRot += MouseInput.Value.x;
|
||||
// lookYRot = Mathf.Clamp(lookYRot, VehicleLookYMinMax.x, VehicleLookYMinMax.y);
|
||||
// VehicleLookTargetParent.localEulerAngles = new Vector3(lookXRot, lookYRot, 0f);
|
||||
// _character.CameraPitch = 0f;
|
||||
// }
|
||||
// else
|
||||
{
|
||||
Vector2 value = _inputComponent.GetLookInput();
|
||||
FirstPerson.AddControlYawInput(value.x * (float)MouseSensitivity);
|
||||
FirstPerson.AddControlPitchInput((invertLook ? (0f - value.y) : value.y) * (float)MouseSensitivity,
|
||||
minPitch, maxPitch);
|
||||
// lookXRot = base.transform.eulerAngles.x;
|
||||
// lookYRot = base.transform.eulerAngles.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user