UUUUUUUUUUUUUUUUH
This commit is contained in:
1 parent
e8393a28ad
commit
f0bb83c869
110 files changed
+55065
-21232
No files matched your search
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9215926b015340c6a09a965a071a2134
|
||||
timeCreated: 1791915045
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Camera.CameraStates;
|
||||
using Code.Infrastructure.Input;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Code.Game.OfficeGame.BattleMode
|
||||
{
|
||||
[Infrastructure.Generators.State(typeof(CameraMode), typeof(CameraStateMachineContext), ManualInherit = true)]
|
||||
public partial class CameraBattleModeState : BaseCameraState
|
||||
{
|
||||
private Vector3 _rotationOffset = new(30f, 0, 0);
|
||||
private int _cameraZoneMask = LayerMask.GetMask("CameraZone");
|
||||
|
||||
public CameraBattleModeState(CameraStateMachineContext context) : base(context)
|
||||
{
|
||||
}
|
||||
public override CameraMode MyState => CameraMode.BattleMode;
|
||||
public override UniTask EnterState()
|
||||
{
|
||||
Context.InputService.BindActionPerformed(
|
||||
(int)ActionMappings.BattleMode,
|
||||
(int)BattleModeActions.Movement,
|
||||
SetMovement);
|
||||
Context.InputService.BindActionCancelled(
|
||||
(int)ActionMappings.BattleMode,
|
||||
(int)BattleModeActions.Movement,
|
||||
ResetMovement);
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
public override UniTask ExitState()
|
||||
{
|
||||
Context.InputService.UnbindActionPerformed(
|
||||
(int)ActionMappings.BattleMode,
|
||||
(int)BattleModeActions.Movement,
|
||||
SetMovement);
|
||||
Context.InputService.UnbindActionCancelled(
|
||||
(int)ActionMappings.BattleMode,
|
||||
(int)BattleModeActions.Movement,
|
||||
ResetMovement);
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
private Vector2 _movement;
|
||||
private float _speed = 5f; // ToConf
|
||||
private void SetMovement(InputAction.CallbackContext obj)
|
||||
{
|
||||
_movement = obj.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
private void ResetMovement(InputAction.CallbackContext obj)
|
||||
{
|
||||
_movement = Vector2.zero;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private const float ZoneSearchRadius = 3f;
|
||||
private static readonly Collider[] _zoneBuffer = new Collider[8];
|
||||
|
||||
public override void LateUpdate()
|
||||
{
|
||||
var camTransform = Context.cameraLoadedData.Camera.transform;
|
||||
var desired = camTransform.position
|
||||
+ new Vector3(_movement.x, 0 , _movement.y) * (Time.deltaTime * _speed);
|
||||
|
||||
int count = Physics.OverlapSphereNonAlloc(
|
||||
camTransform.position,
|
||||
ZoneSearchRadius,
|
||||
_zoneBuffer,
|
||||
_cameraZoneMask,
|
||||
QueryTriggerInteraction.Collide);
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
if (Physics.CheckSphere(desired, 0.01f, _cameraZoneMask, QueryTriggerInteraction.Collide))
|
||||
camTransform.position = desired;
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9699d867118a45658bbd8cd5743cbf02
|
||||
timeCreated: 1791907718
|
||||
Reference in new issue
Block a user