diff --git a/Assets/Code/OfficeGame/Location/LocationCameraTrigger.cs b/Assets/Code/OfficeGame/Location/LocationCameraTrigger.cs deleted file mode 100644 index f139b3e4..00000000 --- a/Assets/Code/OfficeGame/Location/LocationCameraTrigger.cs +++ /dev/null @@ -1,15 +0,0 @@ -using TinyGoose.Tremble; -using UnityEngine; - -namespace Code.Game.OfficeGame.Location -{ - [BrushEntity(type: BrushType.Trigger)] - public class LocationCameraTrigger : MonoBehaviour, IOnImportFromMapEntity - { - private int _id; - public void OnImportFromMapEntity(MapBsp mapBsp, BspEntity entity) - { - gameObject.layer = LayerMask.NameToLayer("CameraZone"); - } - } -} \ No newline at end of file diff --git a/Assets/Code/OfficeGame/Location/LocationCameraTrigger.cs.meta b/Assets/Code/OfficeGame/Location/LocationCameraTrigger.cs.meta deleted file mode 100644 index 4cd58013..00000000 --- a/Assets/Code/OfficeGame/Location/LocationCameraTrigger.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 8664bf69f30d4f558a6ab68b65c0ab8f -timeCreated: 1790280158 \ No newline at end of file diff --git a/Assets/Code/OfficeGame/Location/LocationSegmentTrigger.cs.meta b/Assets/Code/OfficeGame/Location/LocationSegmentTrigger.cs.meta deleted file mode 100644 index e5afc4bd..00000000 --- a/Assets/Code/OfficeGame/Location/LocationSegmentTrigger.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 630e34c01f57474894fcdb9490d516d9 -timeCreated: 1790332570 \ No newline at end of file diff --git a/Assets/Code/OfficeGame/Location/LocationTransitionPoint.cs b/Assets/Code/OfficeGame/Location/LocationTransitionPoint.cs deleted file mode 100644 index db87015c..00000000 --- a/Assets/Code/OfficeGame/Location/LocationTransitionPoint.cs +++ /dev/null @@ -1,14 +0,0 @@ -using TinyGoose.Tremble; -using Unity.VisualScripting; -using UnityEngine; - -namespace Code.Game.OfficeGame.Location -{ - [PointEntity(category: "Utility", trenchBroomName: "LocationTransitionPoint")] - public class LocationTransitionPoint : MonoBehaviour - { - public LocationIDs locationID; - [NoTremble] [DoNotSerialize] - public LocationIDs selfLocationID; - } -} \ No newline at end of file diff --git a/Assets/Code/OfficeGame/Location/LocationTransitionPoint.cs.meta b/Assets/Code/OfficeGame/Location/LocationTransitionPoint.cs.meta deleted file mode 100644 index 46e8ae79..00000000 --- a/Assets/Code/OfficeGame/Location/LocationTransitionPoint.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d3fe671e3d374beb9c03247bc7252cf3 -timeCreated: 1790332908 \ No newline at end of file diff --git a/Assets/Code/OfficeGame/Location/PlayerLocationChecker.cs.meta b/Assets/Code/OfficeGame/Location/PlayerLocationChecker.cs.meta deleted file mode 100644 index 60d100c3..00000000 --- a/Assets/Code/OfficeGame/Location/PlayerLocationChecker.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 91456def45ba47a7bb82f0b9f97a6101 -timeCreated: 1790335988 \ No newline at end of file diff --git a/Assets/Code/OfficeGame/Player/LocationTransitionState.cs b/Assets/Code/OfficeGame/Player/LocationTransitionState.cs deleted file mode 100644 index 17127837..00000000 --- a/Assets/Code/OfficeGame/Player/LocationTransitionState.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Code.Infrastructure.Camera; -using Code.Infrastructure.Camera.CameraStates; -using Cysharp.Threading.Tasks; -using LitMotion; -using LitMotion.Extensions; -using UnityEngine; - -namespace Code.OfficeGame.Player -{ - [Infrastructure.Generators.State(typeof(CameraMode), typeof(CameraStateMachineContext), ManualInherit = true)] - public partial class LocationTransitionState : BaseCameraState - { - public void SetTarget(Transform target) - { - _target = target; - Context.cameraLoadedData.Camera.transform.position = _target.position; - Context.cameraLoadedData.Camera.transform.rotation = _target.rotation; - } - - private Transform _target; - private float _smoothTime = 0.15f; - private Vector3 _velocity; - - public LocationTransitionState(CameraStateMachineContext context) : base(context) - { - } - - public override CameraMode MyState => CameraMode.LocationTransition; - - public override UniTask EnterState() - { - return UniTask.CompletedTask; - } - - public override async UniTask ExitState() - { - await UniTask.WaitUntil(() => _target); - - var taskPosition = LMotion - .Create(Context.cameraLoadedData.Camera.transform.position, _target.position, 0.5f) - .BindToPosition(Context.cameraLoadedData.Camera.transform) - .ToUniTask(); - - var taskRotation = LMotion - .Create(Context.cameraLoadedData.Camera.transform.rotation, _target.rotation, 0.5f) - .BindToRotation(Context.cameraLoadedData.Camera.transform) - .ToUniTask(); - - await UniTask.WhenAll(taskPosition, taskRotation); - - _target = null; - } - - public override void Update() - { - } - - public override void LateUpdate() - { - } - } -} \ No newline at end of file diff --git a/Assets/Code/OfficeGame/Player/LocationTransitionState.cs.meta b/Assets/Code/OfficeGame/Player/LocationTransitionState.cs.meta deleted file mode 100644 index 28875ff4..00000000 --- a/Assets/Code/OfficeGame/Player/LocationTransitionState.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: ed824cfd1fc54e00bc51298e87d21197 -timeCreated: 1790339775 \ No newline at end of file diff --git a/Assets/Code/OfficeGame/Player/OpenMovementCameraState.cs b/Assets/Code/OfficeGame/Player/OpenMovementCameraState.cs index 07fd2446..569560c5 100644 --- a/Assets/Code/OfficeGame/Player/OpenMovementCameraState.cs +++ b/Assets/Code/OfficeGame/Player/OpenMovementCameraState.cs @@ -1,38 +1,55 @@ +using System; using Code.Infrastructure.Camera; using Code.Infrastructure.Camera.CameraStates; +using Code.Infrastructure.Generators; +using Code.Infrastructure.Input; using Cysharp.Threading.Tasks; +using R3; using UnityEngine; +using UnityEngine.InputSystem; namespace Code.Game.Gameplay.Player { - [Infrastructure.Generators.State(typeof(CameraMode), typeof(CameraStateMachineContext), ManualInherit = true)] - public partial class OpenMovementCameraState : BaseCameraState + [State(typeof(CameraMode),typeof(CameraStateMachineContext), ManualInherit = true)] + public partial class CleanerCameraState : BaseCameraState { public void SetTarget(Transform target) { _target = target; - Context.cameraLoadedData.Camera.transform.position = _target.position + _offset; - Context.cameraLoadedData.Camera.transform.rotation = Quaternion.Euler(_rotationOffset); + Context.cameraLoadedData.Camera.transform.position = _target.position; + Context.cameraLoadedData.Camera.transform.rotation = _target.rotation; } - + + private Transform _target; - private Vector3 _offset = new(0f, 3.5f, -6f); - private Vector3 _rotationOffset = new(30f, 0, 0); - private int _cameraZoneMask = LayerMask.GetMask("CameraZone"); + private Vector2 _mouseDelta; + private Vector2 _rotation = Vector2.zero; + + private float _sensitivityX = 0.1f; + private float _sensitivityY = 0.1f; + private float _slideStupidity = 1f; + private bool _isSliding; - public OpenMovementCameraState(CameraStateMachineContext context) : base(context) + public CleanerCameraState(CameraStateMachineContext context) : base(context) { } + private void LookCancelled(InputAction.CallbackContext obj) => _mouseDelta = Vector2.zero; + private void LookPerformed(InputAction.CallbackContext obj) => _mouseDelta = obj.ReadValue(); + public override CameraMode MyState => CameraMode.OpenMovement; public override UniTask EnterState() { + Context.InputService.BindActionPerformed((int)ActionMappings.OpenMovement, (int)OpenMovementActions.Watchment, LookPerformed); + Context.InputService.BindActionCancelled((int)ActionMappings.OpenMovement, (int)OpenMovementActions.Watchment, LookCancelled); return UniTask.CompletedTask; } public override UniTask ExitState() - { + { + Context.InputService.UnbindActionPerformed((int)ActionMappings.OpenMovement, (int)OpenMovementActions.Watchment, LookPerformed); + Context.InputService.UnbindActionCancelled((int)ActionMappings.OpenMovement, (int)OpenMovementActions.Watchment, LookCancelled); return UniTask.CompletedTask; } @@ -40,53 +57,29 @@ namespace Code.Game.Gameplay.Player { } - private const float ZoneSearchRadius = 3f; - private static readonly Collider[] _zoneBuffer = new Collider[8]; - public override void LateUpdate() { if (_target is null) return; var camTransform = Context.cameraLoadedData.Camera.transform; - var desired = _target.position + _offset; - int count = Physics.OverlapSphereNonAlloc( - camTransform.position, - ZoneSearchRadius, - _zoneBuffer, - _cameraZoneMask, - QueryTriggerInteraction.Collide); + camTransform.position = _target.position; - if (count == 0) + var mouseDeltaX = _mouseDelta.x * _sensitivityX; + var mouseDeltaY = _mouseDelta.y * _sensitivityY; + + if (_isSliding) { - if (Physics.CheckSphere(desired, 0.01f, _cameraZoneMask, QueryTriggerInteraction.Collide)) - camTransform.position = desired; - return; + mouseDeltaX = Mathf.Clamp(mouseDeltaX, -_slideStupidity, _slideStupidity); + mouseDeltaY = Mathf.Clamp(mouseDeltaY, -_slideStupidity, _slideStupidity); } + + _rotation.x += mouseDeltaX; + _rotation.y -= mouseDeltaY; + + _rotation.y = Mathf.Clamp(_rotation.y, -90f, 90f); - var best = camTransform.position; - var bestSqr = float.MaxValue; - - for (int i = 0; i < count; i++) - { - var p = _zoneBuffer[i].ClosestPoint(desired); - var sqr = (p - desired).sqrMagnitude; - if (sqr < bestSqr) - { - bestSqr = sqr; - best = p; - } - } - - camTransform.position = best; + camTransform.localRotation = Quaternion.Euler(_rotation.y, _rotation.x, 0f); } - // if (_target is null) return; - // - // var camTransform = Context.cameraLoadedData.Camera.transform; - // - // var camTargetPosition = _target.position + _offset; - // - // if (Physics.CheckSphere(camTargetPosition, 0.01f, _cameraZoneMask)) - // camTransform.position = camTargetPosition; } } \ No newline at end of file diff --git a/Assets/Code/OfficeGame/Player/OpenMovementCameraState.cs.meta b/Assets/Code/OfficeGame/Player/OpenMovementCameraState.cs.meta index f81aba3e..89c54bb2 100644 --- a/Assets/Code/OfficeGame/Player/OpenMovementCameraState.cs.meta +++ b/Assets/Code/OfficeGame/Player/OpenMovementCameraState.cs.meta @@ -1,3 +1,3 @@ fileFormatVersion: 2 -guid: 9e592628c3fe45bf9659d1050680c296 -timeCreated: 1785846388 \ No newline at end of file +guid: ff3e1673b49d4a4ab9a7017656796b6e +timeCreated: 1792340121 \ No newline at end of file