initial weapons

This commit is contained in:
MrTorex committed 2026-02-23 20:16:07 +03:00
1 parent b87010d2e5
commit afcd8761e6
66 files changed
+6388 -49

No files matched your search

@@ -1,6 +1,8 @@
using Code.DI;
using Code.Gameplay.Camera;
using Code.Gameplay.Character.Controller;
using Code.Gameplay.Character.Inventory;
using Code.Gameplay.Character.Stats;
using Code.Input;
using UnityEngine;
@@ -9,25 +11,64 @@ namespace Code.Gameplay.Character.Core
public class CharacterProvider : MonoBehaviour
{
[SerializeField] private CustomCharacterController customCharacterController;
public CustomCharacterController CustomCharacterController => customCharacterController;
[SerializeField] private Transform cameraFollowPoint;
public Transform GetFollowTransform() => cameraFollowPoint;
[SerializeField] private HealthSystem healthSystem;
[SerializeField] private WeaponInventory weaponInventory;
private IInputService _inputService;
private CameraController _cameraController;
public CustomCharacterController CustomCharacterController => customCharacterController;
public HealthSystem HealthSystem => healthSystem;
public WeaponInventory WeaponInventory => weaponInventory;
public Transform GetFollowTransform() => cameraFollowPoint;
private void Start()
{
_inputService = FindFirstObjectByType<DIContainer>().Resolve<IInputService>();
_inputService = FindFirstObjectByType<DIContainer>()?.Resolve<IInputService>();
_cameraController = FindFirstObjectByType<CameraController>();
if (_inputService == null)
{
Debug.LogError("IInputService not found!");
}
if (_cameraController == null)
{
Debug.LogError("CameraController not found!");
}
if (healthSystem != null)
{
healthSystem.OnDied += HandleDeath;
}
}
private void HandleDeath()
{
enabled = false;
if (customCharacterController != null)
{
customCharacterController.enabled = false;
}
Debug.Log("Character died!");
}
public void Teleport(Vector3 position, Quaternion rotation)
{
customCharacterController.SetPosition(position);
customCharacterController.SetRotation(rotation);
if (customCharacterController != null)
{
customCharacterController.SetPosition(position);
customCharacterController.SetRotation(rotation);
}
}
private void HandleCharacterInput()
{
if (_inputService == null || _cameraController == null || customCharacterController == null)
return;
var inputs = new CharacterInputs();
var moveInput = _inputService.MoveInput;
inputs.MoveAxisForward = moveInput.y;
@@ -35,15 +76,63 @@ namespace Code.Gameplay.Character.Core
inputs.SprintPressed = _inputService.SprintHeld;
inputs.JumpPressed = _inputService.JumpPressed;
inputs.CameraRotation = FindFirstObjectByType<CameraController>().GetCameraRotation();
inputs.CameraPlanarDirection = FindFirstObjectByType<CameraController>().GetPlanarDirection();
inputs.CameraRotation = _cameraController.GetCameraRotation();
inputs.CameraPlanarDirection = _cameraController.GetPlanarDirection();
customCharacterController.SetInputs(ref inputs);
HandleWeaponInput();
}
private void HandleWeaponInput()
{
if (weaponInventory == null) return;
if (_inputService.AttackPressed)
{
weaponInventory.ShootCurrentWeapon();
}
else
{
weaponInventory.StopShootingCurrentWeapon();
}
var scroll = UnityEngine.Input.GetAxis("Mouse ScrollWheel");
switch (scroll)
{
case > 0f:
weaponInventory.NextWeapon();
break;
case < 0f:
weaponInventory.PreviousWeapon();
break;
}
if (UnityEngine.Input.GetKeyDown(KeyCode.R))
{
weaponInventory.ReloadCurrentWeapon();
}
for (var i = 0; i < 9; i++)
{
if (UnityEngine.Input.GetKeyDown(KeyCode.Alpha1 + i))
{
weaponInventory.SwitchWeapon(i);
}
}
}
private void Update()
{
HandleCharacterInput();
}
private void OnDestroy()
{
if (healthSystem != null)
{
healthSystem.OnDied -= HandleDeath;
}
}
}
}