Add new meta files and interfaces for project structure
This commit is contained in:
34
Assets/Scripts/Systems/Aiming.cs
Normal file
34
Assets/Scripts/Systems/Aiming.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using KBCore.Refs;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
public class Aiming : MonoBehaviour
|
||||
{
|
||||
[SerializeField, Scene] private Camera mainCamera;
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
if (!mainCamera)
|
||||
{
|
||||
mainCamera = Camera.main;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!mainCamera) return;
|
||||
var mousePosition = Mouse.current.position.ReadValue();
|
||||
|
||||
var worldPosition = mainCamera.ScreenToWorldPoint(mousePosition);
|
||||
worldPosition.z = transform.position.z;
|
||||
|
||||
var direction = (worldPosition - transform.position).normalized;
|
||||
var angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
|
||||
|
||||
transform.rotation = Quaternion.Euler(0,0, angle);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Systems/Aiming.cs.meta
Normal file
3
Assets/Scripts/Systems/Aiming.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8f62cd9ff7b4fcfa29d4c7fca486944
|
||||
timeCreated: 1752262081
|
36
Assets/Scripts/Systems/DeathHandler.cs
Normal file
36
Assets/Scripts/Systems/DeathHandler.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Data;
|
||||
using Interfaces;
|
||||
using KBCore.Refs;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
public class DeathHandler : MonoBehaviour
|
||||
{
|
||||
[Self, SerializeField] private Character character;
|
||||
[Self, SerializeField] private InterfaceRef<IDeathBehavior> deathBehavior;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
character.attributes.OnHealthChanged += OnHealthChanged;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
character.attributes.OnHealthChanged -= OnHealthChanged;
|
||||
}
|
||||
|
||||
private void OnHealthChanged(float newHealth)
|
||||
{
|
||||
if (newHealth <= 0f)
|
||||
{
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
private void Die()
|
||||
{
|
||||
deathBehavior.Value.Die();
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Systems/DeathHandler.cs.meta
Normal file
3
Assets/Scripts/Systems/DeathHandler.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fa2924c6ed8486bbfa95c439bf9e421
|
||||
timeCreated: 1752260559
|
24
Assets/Scripts/Systems/Health.cs
Normal file
24
Assets/Scripts/Systems/Health.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using Data;
|
||||
using KBCore.Refs;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
public class Health : MonoBehaviour
|
||||
{
|
||||
[Self, SerializeField] private Character character;
|
||||
[SerializeField] private float initialHealth = 100f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
character.attributes.SetHealth(initialHealth);
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
{
|
||||
var effectiveDamage = Math.Max(damage - character.attributes.Armor, 1);
|
||||
character.attributes.ModifyHealth(-effectiveDamage);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Systems/Health.cs.meta
Normal file
3
Assets/Scripts/Systems/Health.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9139aea24fd54a5eb0f5fc1556478cb6
|
||||
timeCreated: 1752257112
|
50
Assets/Scripts/Systems/Movement.cs
Normal file
50
Assets/Scripts/Systems/Movement.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using Data;
|
||||
using KBCore.Refs;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
public class Movement : MonoBehaviour
|
||||
{
|
||||
private InputSystem_Actions controls;
|
||||
private Vector2 movementInput;
|
||||
|
||||
[Self, SerializeField] private Character character;
|
||||
[Self, SerializeField] private Rigidbody2D rb;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
controls ??= new InputSystem_Actions();
|
||||
controls.Enable();
|
||||
controls.Player.Move.performed += OnMovePerformed;
|
||||
controls.Player.Move.canceled += ctx => movementInput = Vector2.zero;
|
||||
|
||||
}
|
||||
|
||||
private void OnMovePerformed(InputAction.CallbackContext obj)
|
||||
{
|
||||
movementInput = obj.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
controls.Disable();
|
||||
controls.Player.Move.performed -= OnMovePerformed;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
ApplyMovement();
|
||||
}
|
||||
|
||||
private void ApplyMovement()
|
||||
{
|
||||
if (!rb) return;
|
||||
|
||||
var velocity = new Vector2(movementInput.x, movementInput.y).normalized * character.attributes.MoveSpeed;
|
||||
rb.linearVelocity = velocity;
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Systems/Movement.cs.meta
Normal file
3
Assets/Scripts/Systems/Movement.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c35f16c2a9546a2b4911f4da933efa0
|
||||
timeCreated: 1752255167
|
14
Assets/Scripts/Systems/PlayerDeathBehavior.cs
Normal file
14
Assets/Scripts/Systems/PlayerDeathBehavior.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Interfaces;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
public class PlayerDeathBehavior : MonoBehaviour, IDeathBehavior
|
||||
{
|
||||
public void Die()
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Systems/PlayerDeathBehavior.cs.meta
Normal file
3
Assets/Scripts/Systems/PlayerDeathBehavior.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b46c8a98e30a405eb2d287515609ecda
|
||||
timeCreated: 1752258510
|
Reference in New Issue
Block a user