UUUUUUUUUUUUUUUUH
This commit is contained in:
1 parent
e8393a28ad
commit
f0bb83c869
110 files changed
+55065
-21232
No files matched your search
@@ -12,6 +12,7 @@ using ObservableCollections;
|
||||
using R3;
|
||||
using Reflex.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Code.Game.TestingLevel
|
||||
@@ -29,12 +30,21 @@ namespace Code.Game.TestingLevel
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
Context.InputService.EnableMap(ActionMappings.Debug);
|
||||
|
||||
Context.InputService.BindActionPerformed((int)ActionMappings.Debug, (int)DebugActions.ToggleBattleMode, ToggleBattleMode);
|
||||
#endif
|
||||
|
||||
Context.InputService.EnableMap(ActionMappings.OpenMovement);
|
||||
|
||||
Context.AudioService.SetAudioListener(Context.Camera.Camera.GetComponent<AudioListener>());
|
||||
|
||||
|
||||
await Context.Camera.SwitchState(CameraMode.OpenMovement);
|
||||
|
||||
if (Context.StateMachine.CurrentState == AppStates.BattleState) return;
|
||||
|
||||
Context.AudioService.SetAudioListener(Context.Camera.Camera.GetComponent<AudioListener>());
|
||||
|
||||
var waitForContainer =
|
||||
Context.SceneContainerManager.ScenesContainers
|
||||
.ObserveDictionaryAdd()
|
||||
@@ -94,8 +104,17 @@ namespace Code.Game.TestingLevel
|
||||
playerMovementController.Freeze = false;
|
||||
}
|
||||
|
||||
private void ToggleBattleMode(InputAction.CallbackContext obj)
|
||||
{
|
||||
Context.StateMachine.SwitchState(AppStates.BattleState).Forget();
|
||||
}
|
||||
|
||||
public override async UniTask ExitState()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
Context.InputService.DisableMap(ActionMappings.Debug);
|
||||
Context.InputService.UnbindActionPerformed((int)ActionMappings.Debug, (int)DebugActions.ToggleBattleMode, ToggleBattleMode);
|
||||
#endif
|
||||
Context.InputService.DisableMap(ActionMappings.OpenMovement);
|
||||
|
||||
if (Context.StateMachine.NextState == AppStates.BattleState) return;
|
||||
|
||||
@@ -8,7 +8,8 @@ namespace Code.Infrastructure.Camera
|
||||
{
|
||||
None,
|
||||
OpenMovement,
|
||||
LocationTransition
|
||||
LocationTransition,
|
||||
BattleMode
|
||||
}
|
||||
|
||||
public class CameraStateMachineContext
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Infrastructure.StateMachine
|
||||
{
|
||||
@@ -37,6 +38,8 @@ namespace Code.Infrastructure.StateMachine
|
||||
var newState = States[nextState];
|
||||
await newState.EnterState();
|
||||
|
||||
Debug.Log($"Switched from {CurrentState} to {nextState}");
|
||||
|
||||
CurrentBaseState = newState;
|
||||
CurrentState = nextState;
|
||||
NextState = default;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76cd78321bad4dda82b99b79508d68a5
|
||||
timeCreated: 1791907691
|
||||
@@ -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
|
||||
@@ -1,5 +1,11 @@
|
||||
using Code.Infrastructure.App;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Generators;
|
||||
using Code.Infrastructure.Input;
|
||||
using Code.Infrastructure.SceneLoader;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Code.Game.OfficeGame.GameStates
|
||||
{
|
||||
@@ -11,5 +17,39 @@ namespace Code.Game.OfficeGame.GameStates
|
||||
}
|
||||
|
||||
public override AppStates MyState => AppStates.BattleState;
|
||||
|
||||
public override async UniTask EnterState()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Confined;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
Context.InputService.EnableMap(ActionMappings.Debug);
|
||||
|
||||
Context.InputService.BindActionPerformed((int)ActionMappings.Debug, (int)DebugActions.ToggleBattleMode, ToggleBattleMode);
|
||||
#endif
|
||||
|
||||
Context.InputService.EnableMap(ActionMappings.BattleMode);
|
||||
|
||||
await Context.Camera.SwitchState(CameraMode.BattleMode);
|
||||
|
||||
var container = Context.SceneContainerManager.ScenesContainers[SceneId.Testing];
|
||||
|
||||
(Context.Camera.CurrentBaseState).EnterState();
|
||||
}
|
||||
|
||||
private void ToggleBattleMode(InputAction.CallbackContext obj)
|
||||
{
|
||||
Context.StateMachine.SwitchState(AppStates.Testing).Forget();
|
||||
}
|
||||
|
||||
public override async UniTask ExitState()
|
||||
{
|
||||
|
||||
#if UNITY_EDITOR
|
||||
Context.InputService.DisableMap(ActionMappings.Debug);
|
||||
Context.InputService.UnbindActionPerformed((int)ActionMappings.Debug, (int)DebugActions.ToggleBattleMode, ToggleBattleMode);
|
||||
#endif
|
||||
Context.InputService.DisableMap(ActionMappings.BattleMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using KinematicCharacterController;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.OfficeGame.Player
|
||||
{
|
||||
public class PlayerAnimator : MonoBehaviour
|
||||
{
|
||||
private static readonly int VelocityForward = Animator.StringToHash("VelocityForward");
|
||||
private static readonly int VelocityRight = Animator.StringToHash("VelocityRight");
|
||||
|
||||
private KinematicCharacterMotor _motor;
|
||||
private Animator _animator;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_motor = GetComponent<KinematicCharacterMotor>();
|
||||
_animator = GetComponentInChildren<Animator>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var forwardVelocity =
|
||||
Vector3.Project(_motor.Velocity, transform.right).magnitude;
|
||||
_animator.SetFloat(VelocityForward, forwardVelocity);
|
||||
|
||||
var rightVelocity =
|
||||
Vector3.Project(_motor.Velocity, transform.forward).magnitude;
|
||||
_animator.SetFloat(VelocityRight, rightVelocity);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05290340b907438c8fcb9d5f0e75624f
|
||||
timeCreated: 1791910777
|
||||
@@ -55,8 +55,6 @@ namespace Code.Game.Gameplay.Player
|
||||
[TabGroup("Jumping")] public Vector3 Gravity = new Vector3(0, -30f, 0);
|
||||
|
||||
[TabGroup("Misc")] public List<Collider> IgnoredColliders = new List<Collider>();
|
||||
public Vector3 CurrentVelocity => Motor.Velocity;
|
||||
public Quaternion CurrentRotation => Motor.TransientRotation;
|
||||
|
||||
private Vector3 _moveInputVector;
|
||||
private Vector3 _lookInputVector;
|
||||
|
||||
@@ -2,8 +2,9 @@ namespace Code.Infrastructure.Input
|
||||
{
|
||||
public enum ActionMappings
|
||||
{
|
||||
UI,
|
||||
OpenMovement
|
||||
Debug,
|
||||
OpenMovement,
|
||||
BattleMode
|
||||
}
|
||||
|
||||
// Написать, чтобы розлин сама писала этот енам
|
||||
@@ -12,4 +13,14 @@ namespace Code.Infrastructure.Input
|
||||
Movement,
|
||||
Interact
|
||||
}
|
||||
// Написать, чтобы розлин сама писала этот енам
|
||||
public enum BattleModeActions
|
||||
{
|
||||
Movement
|
||||
}
|
||||
// Написать, чтобы розлин сама писала этот енам
|
||||
public enum DebugActions
|
||||
{
|
||||
ToggleBattleMode
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user