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 { protected override void Destroy(CharacterLookComponent self) { self.FirstPerson = null; // var mapUnit = self.Parent as MapUnit; self._inputComponent = null; } } public class LookComponentAwakeSystem : AwakeSystem { protected override void Awake(CharacterLookComponent self) { var mapUnit = self.Parent as MapUnit; self.MapUnit = mapUnit; var unitUnityComponent = self.Parent.GetComponent(); self.FirstPerson = unitUnityComponent.FirstPerson; self._inputComponent = self.Scene.GetComponent(); } } public class LookComponentUpdateSystem : UpdateSystem { protected override void Update(CharacterLookComponent self) { self.UpdateLookInput(); } } // public class LookComponentLateUpdateSystem : LateUpdateSystem // { // 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; } } } } }