Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/unity-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ jobs:
- name: Validate Unity repository
run: python scripts/validate_unity_repo.py

- name: Check legacy integration usage
run: python scripts/check_legacy_usage.py

- name: Upload repository reports
if: always()
uses: actions/upload-artifact@v4
with:
name: repository-validation-reports
path: Logs/*.json
if-no-files-found: warn

unity-editmode-tests:
name: Unity EditMode tests
if: ${{ vars.RUN_UNITY_TESTS == 'true' }}
Expand Down
8 changes: 7 additions & 1 deletion Assets/Script/ArrowController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.InputSystem;

public sealed class ArrowController : MonoBehaviour
{
Expand Down Expand Up @@ -31,7 +32,12 @@ private void Update()
return;
}

Vector3 mousePosition = mainCamera.ScreenToWorldPoint(Input.mousePosition);
if (Mouse.current == null)
{
return;
}

Vector3 mousePosition = mainCamera.ScreenToWorldPoint(Mouse.current.position.ReadValue());
mousePosition.z = transform.position.z;
transform.position = mousePosition;
}
Expand Down
5 changes: 3 additions & 2 deletions Assets/Script/CameraFollow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.InputSystem;

public sealed class CameraFollow : MonoBehaviour
{
Expand Down Expand Up @@ -32,12 +33,12 @@ private void LateUpdate()
desiredPosition.z = staticZPosition;
transform.position = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);

if (!Input.GetMouseButton(1) || controlledCamera == null)
if (Mouse.current == null || !Mouse.current.rightButton.isPressed || controlledCamera == null)
{
return;
}

Vector3 mouseWorldPosition = controlledCamera.ScreenToWorldPoint(Input.mousePosition);
Vector3 mouseWorldPosition = controlledCamera.ScreenToWorldPoint(Mouse.current.position.ReadValue());
mouseWorldPosition.z = staticZPosition;

Vector3 moveDirection = mouseWorldPosition - transform.position;
Expand Down
54 changes: 21 additions & 33 deletions Assets/Script/GlobalSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;

Expand Down Expand Up @@ -35,8 +36,13 @@ public sealed class GlobalSystem : MonoBehaviour
public float BloodImpulseDuration => bloodImpulseDuration;
public ParticleSystem BloodParticleSystem => bloodParticleSystem;
public Transform RuntimeContainer => runtimeContainer;

[Obsolete("Gameplay code must use WeaponAmmoPresenter events instead of accessing UI through GlobalSystem.")]
public UIAmmoSystem AmmoUI => ammoUI;

public RuntimeObjectPool ObjectPool => objectPool;
public int TrackedInstanceCount => objectPool != null ? objectPool.TrackedInstanceCount : 0;
public int ScheduledReleaseCount => objectPool != null ? objectPool.ScheduledReleaseCount : 0;

private void Awake()
{
Expand All @@ -53,41 +59,27 @@ private void Awake()

private void OnDestroy()
{
if (Instance == this)
{
Instance = null;
}
if (Instance == this) Instance = null;
}

public GameObject Spawn(GameObject prefab, Vector3 position, Quaternion rotation, Transform parent = null)
{
if (prefab == null)
{
return null;
}

if (prefab == null) return null;
EnsureRuntimeInfrastructure();
return objectPool.Spawn(prefab, position, rotation, parent);
}

public T Spawn<T>(T prefab, Vector3 position, Quaternion rotation, Transform parent = null)
where T : Component
{
if (prefab == null)
{
return null;
}

if (prefab == null) return null;
EnsureRuntimeInfrastructure();
return objectPool.Spawn(prefab, position, rotation, parent);
}

public void Release(GameObject instance)
{
if (instance == null)
{
return;
}
if (instance == null) return;

EnsureRuntimeInfrastructure();
if (objectPool.Owns(instance))
Expand All @@ -101,10 +93,7 @@ public void Release(GameObject instance)

public void ReleaseAfter(GameObject instance, float delay)
{
if (instance == null)
{
return;
}
if (instance == null) return;

EnsureRuntimeInfrastructure();
if (objectPool.Owns(instance))
Expand All @@ -118,28 +107,27 @@ public void ReleaseAfter(GameObject instance, float delay)

public void Prewarm(GameObject prefab, int count)
{
if (prefab == null || count <= 0)
{
return;
}

if (prefab == null || count <= 0) return;
EnsureRuntimeInfrastructure();
objectPool.Prewarm(prefab, count);
}

public bool Owns(GameObject instance)
{
EnsureRuntimeInfrastructure();
return objectPool.Owns(instance);
}

public bool TryGetRandomBlood(out GameObject prefab)
{
prefab = null;
if (bloodPrefabs == null || bloodPrefabs.Length == 0) return false;

if (bloodPrefabs == null || bloodPrefabs.Length == 0)
{
return false;
}

prefab = bloodPrefabs[Random.Range(0, bloodPrefabs.Length)];
prefab = bloodPrefabs[UnityEngine.Random.Range(0, bloodPrefabs.Length)];
return prefab != null;
}

[Obsolete("Use TryGetRandomBlood(out GameObject) and handle an empty configuration explicitly.")]
public GameObject getRandomBlood()
{
TryGetRandomBlood(out GameObject prefab);
Expand Down
80 changes: 27 additions & 53 deletions Assets/Script/Health.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,66 +62,45 @@ private void Start()

public void SetHealth(int health)
{
if (deathRaised)
{
return;
}
if (deathRaised) return;

int previous = state.CurrentHealth;
state.SetHealth(health);
SyncSerializedState();
RaiseHealthChanged(previous);

if (!state.IsAlive)
{
DieOnce();
}
if (!state.IsAlive) DieOnce();
}

public void SetMaximumHealth(int maximumHealth, bool preserveRatio = false)
{
if (deathRaised)
{
return;
}
if (deathRaised) return;

int previous = state.CurrentHealth;
state.SetMaximumHealth(maximumHealth, preserveRatio);
defaultHeals = state.MaximumHealth;
SyncSerializedState();
RaiseHealthChanged(previous, force: true);

if (!state.IsAlive)
{
DieOnce();
}
if (!state.IsAlive) DieOnce();
}

public void RestoreHealth(int amount)
{
int restored = state.Heal(amount);
if (restored <= 0)
{
return;
}
if (restored <= 0) return;

int previous = state.CurrentHealth - restored;
SyncSerializedState();
Healed?.Invoke(restored);
RaiseHealthChanged(previous);
}

public void RestoreFullHealth()
{
RestoreHealth(state.MaximumHealth - state.CurrentHealth);
}
public void RestoreFullHealth() => RestoreHealth(state.MaximumHealth - state.CurrentHealth);

public void ReceiveDamage(in DamageInfo damageInfo)
{
if (!state.IsAlive || isImunable || damageInfo.Amount <= 0f)
{
return;
}
if (!state.IsAlive || isImunable || damageInfo.Amount <= 0f) return;

float resistance = resistanceProfile != null
? resistanceProfile.GetResistance(damageInfo.DamageType)
Expand All @@ -132,29 +111,21 @@ public void ReceiveDamage(in DamageInfo damageInfo)
incomingDamageMultiplier);

DamageResolved?.Invoke(damageInfo, resolution);
if (resolution.AppliedAmount <= 0)
{
return;
}
if (resolution.AppliedAmount <= 0) return;

int previous = state.CurrentHealth;
int applied = state.ApplyDamage(resolution.AppliedAmount);
if (applied <= 0)
{
return;
}
if (applied <= 0) return;

SyncSerializedState();
Damaged?.Invoke(damageInfo);
RaiseHealthChanged(previous);
damageEffectsPresenter?.Present(in damageInfo, applied);

if (!state.IsAlive)
{
DieOnce();
}
if (!state.IsAlive) DieOnce();
}

[Obsolete("Use ReceiveDamage(in DamageInfo) so source, type, position and impulse are preserved.")]
public void ReceiveDamage(int damageAmount)
{
DamageInfo damageInfo = new DamageInfo(
Expand All @@ -169,10 +140,7 @@ public void ReceiveDamage(int damageAmount)

private void DieOnce()
{
if (deathRaised)
{
return;
}
if (deathRaised) return;

deathRaised = true;
state.SetHealth(0);
Expand All @@ -189,25 +157,31 @@ private void RaiseHealthChanged(int previousHealth, bool force = false)
}
}

private void SyncSerializedState()
{
currentHeals = state.CurrentHealth;
}
private void SyncSerializedState() => currentHeals = state.CurrentHealth;

[Obsolete("Health state is evaluated immediately. Subscribe to Died or use IsAlive instead.")]
public void HealthLogic()
{
if (!state.IsAlive)
{
DieOnce();
}
if (!state.IsAlive) DieOnce();
}

// Compatibility API retained until scenes, prefabs and UnityEvents are audited.
// Compatibility API retained only for serialized UnityEvents during prefab migration.
[Obsolete("Use SetHealth(int).")]
public void setHeals(int heals) => SetHealth(heals);

[Obsolete("Use RestoreHealth(int).")]
public void restoreSomeHeals(int amount) => RestoreHealth(amount);

[Obsolete("Use RestoreFullHealth().")]
public void restoreDefaultHeals() => RestoreFullHealth();

[Obsolete("Use CurrentHealth.")]
public int getHeals() => CurrentHealth;

[Obsolete("Use ReceiveDamage(in DamageInfo).")]
public void receiveDamage(int damageAmount) => ReceiveDamage(damageAmount);

[Obsolete("Use IsAlive.")]
public bool getIsAlive() => IsAlive;

private void OnValidate()
Expand Down
23 changes: 18 additions & 5 deletions Assets/Script/WeaponController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Assets.Script;
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using ZoneUA.Combat;

[RequireComponent(typeof(Weapon))]
Expand Down Expand Up @@ -178,10 +179,17 @@ private void Update()

private void HandleLegacyPlayerInput()
{
if (Input.GetButtonDown("Fire1")) StartFire();
if (Input.GetButtonUp("Fire1")) StopFire();
if (Input.GetKeyDown(KeyCode.B)) SwitchFireMode();
if (Input.GetKeyDown(KeyCode.R)) Reload();
if (Mouse.current != null)
{
if (Mouse.current.leftButton.wasPressedThisFrame) StartFire();
if (Mouse.current.leftButton.wasReleasedThisFrame) StopFire();
}

if (Keyboard.current != null)
{
if (Keyboard.current.bKey.wasPressedThisFrame) SwitchFireMode();
if (Keyboard.current.rKey.wasPressedThisFrame) Reload();
}
}

public void SetExternalInputEnabled(bool enabled)
Expand Down Expand Up @@ -556,7 +564,12 @@ public Vector3 CalculateDirectionForPlayerMouse()
return Vector3.zero;
}

Vector3 mousePosition = mainCamera.ScreenToWorldPoint(Input.mousePosition);
if (Mouse.current == null)
{
return Vector3.zero;
}

Vector3 mousePosition = mainCamera.ScreenToWorldPoint(Mouse.current.position.ReadValue());
mousePosition.z = transform.position.z;
return mousePosition - transform.position;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Script/World/GrassSorting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void OnTriggerStay2D(Collider2D other)

private void CachePlayer(Collider2D other)
{
if (!other.CompareTag("Player"))
if (other.GetComponentInParent<PlayerInputRouter>() == null)
{
return;
}
Expand Down
Loading
Loading