From 4ecafef8ee1dff0217d91aa2d3d58d9eb6f6c990 Mon Sep 17 00:00:00 2001 From: ThomasCharester Date: Tue, 17 Mar 2026 18:09:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B4=D0=BE=D1=80=D0=BE=D0=B2=D1=8C?= =?UTF-8?q?=D0=B5=20=D1=87=D1=83=D1=82=D0=BA=D0=B0=20=D0=B8=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.idea.Infratest/.idea/workspace.xml | 35 ++++--------------- .../Code/Example/Platformer/Entity/Entity.cs | 4 --- .../Example/Platformer/Entity/EntityHealth.cs | 13 ++++--- .../Entity/PlatformerEnemyFactory.cs | 17 +++++---- .../Example/Platformer/Entity/PlayerEntity.cs | 2 +- .../Example/Platformer/PlatformerState.cs | 6 ++-- 6 files changed, 27 insertions(+), 50 deletions(-) diff --git a/.idea/.idea.Infratest/.idea/workspace.xml b/.idea/.idea.Infratest/.idea/workspace.xml index 9ab36de..c932928 100644 --- a/.idea/.idea.Infratest/.idea/workspace.xml +++ b/.idea/.idea.Infratest/.idea/workspace.xml @@ -5,32 +5,12 @@ - - - - - - - + + - + - - - - - - - - - - - - - - - - + diff --git a/Assets/Code/Example/Platformer/Entity/Entity.cs b/Assets/Code/Example/Platformer/Entity/Entity.cs index b95a580..20f97c4 100644 --- a/Assets/Code/Example/Platformer/Entity/Entity.cs +++ b/Assets/Code/Example/Platformer/Entity/Entity.cs @@ -15,13 +15,11 @@ namespace Code.Example.Platformer.Entity [SerializeField] protected SpriteRenderer spriteRenderer; [SerializeField] private Vector2 groundPoint; - private EntityHealth _health; private PlatformerEntityData _data; public void SetData(PlatformerEntityData data) { _data = data; - _health = new(data.maxHealth); } protected bool onGround; @@ -51,7 +49,5 @@ namespace Code.Example.Platformer.Entity } protected abstract void Move(); - - public virtual void GetDamage(int damage) => _health.GiveDamage(damage); } } \ No newline at end of file diff --git a/Assets/Code/Example/Platformer/Entity/EntityHealth.cs b/Assets/Code/Example/Platformer/Entity/EntityHealth.cs index 5f85861..7329874 100644 --- a/Assets/Code/Example/Platformer/Entity/EntityHealth.cs +++ b/Assets/Code/Example/Platformer/Entity/EntityHealth.cs @@ -1,15 +1,14 @@ +using UnityEngine; + namespace Code.Example.Platformer.Entity { - public class EntityHealth + public class EntityHealth : MonoBehaviour { - private int _health, _maxHealth; + private int _health; + private int _maxHealth; + public void SetMaxHealth(int maxHealth) => _maxHealth = maxHealth; public bool IsDead { get; private set; } - public EntityHealth(int initialHealth) - { - _health = initialHealth; - } - public void GiveDamage(int damage) { _health -= damage; diff --git a/Assets/Code/Example/Platformer/Entity/PlatformerEnemyFactory.cs b/Assets/Code/Example/Platformer/Entity/PlatformerEnemyFactory.cs index 57b4cf8..75af65a 100644 --- a/Assets/Code/Example/Platformer/Entity/PlatformerEnemyFactory.cs +++ b/Assets/Code/Example/Platformer/Entity/PlatformerEnemyFactory.cs @@ -12,7 +12,7 @@ namespace Code.Example.Platformer.Entity { public interface IPlatformerEnemyFactory { - UniTaskVoid LoadEnemy(PlatformerEntityType enemyType); + UniTaskVoid WarmEnemy(PlatformerEntityType enemyType); void ReleaseEnemy(PlatformerEntityType racerType); UniTaskVoid SpawnEnemy( @@ -45,12 +45,11 @@ namespace Code.Example.Platformer.Entity await _enemyConfigsHandle.ToUniTask(); _enemyConfigs = _enemyConfigsHandle.Result.ToDictionary(x => x.EntityData.type); - _enemyConfigs.Remove(PlatformerEntityType.Player); _eventBus.RaiseEvent(x => x.PlatformerEnemyFactoryInitialized()); } - public async UniTaskVoid LoadEnemy(PlatformerEntityType enemyType) + public async UniTaskVoid WarmEnemy(PlatformerEntityType enemyType) { if (enemyType == PlatformerEntityType.Player) return; @@ -66,10 +65,14 @@ namespace Code.Example.Platformer.Entity Addressables.LoadAssetAsync(_enemyConfigs[enemyType].prefabReference)); await _enemyPrefabsHandle[enemyType].ToUniTask(); - var racer = _enemyPrefabsHandle[enemyType].Result.GetComponent(); - racer.SetData(_enemyConfigs[enemyType].EntityData); - - _eventBus.RaiseEvent(x => x.PlatformerEnemyLoaded(enemyType, racer)); + + var entity = _enemyPrefabsHandle[enemyType].Result.GetComponent(); + entity.SetData(_enemyConfigs[enemyType].EntityData); + + var health = _enemyPrefabsHandle[enemyType].Result.GetComponent(); + health.SetMaxHealth(_enemyConfigs[enemyType].EntityData.maxHealth); + + _eventBus.RaiseEvent(x => x.PlatformerEnemyLoaded(enemyType, entity)); } public void ReleaseEnemy(PlatformerEntityType racerType) diff --git a/Assets/Code/Example/Platformer/Entity/PlayerEntity.cs b/Assets/Code/Example/Platformer/Entity/PlayerEntity.cs index 074190c..c392327 100644 --- a/Assets/Code/Example/Platformer/Entity/PlayerEntity.cs +++ b/Assets/Code/Example/Platformer/Entity/PlayerEntity.cs @@ -88,7 +88,7 @@ namespace Code.Example.Platformer.Entity foreach (var damaged in damagedOnes) { - damaged.gameObject.GetComponent().GetDamage(1); + damaged.gameObject.GetComponent().GiveDamage(1); _audioService.PlayOneShot(AudioNames.UISounds, 2); } } diff --git a/Assets/Code/Example/Platformer/PlatformerState.cs b/Assets/Code/Example/Platformer/PlatformerState.cs index f4b38d3..6b8f58f 100644 --- a/Assets/Code/Example/Platformer/PlatformerState.cs +++ b/Assets/Code/Example/Platformer/PlatformerState.cs @@ -74,9 +74,9 @@ namespace Code.Example.Platformer _firstLevelData = container.Resolve(); _enemyFactory = container.Resolve(); - _enemyFactory.LoadEnemy(PlatformerEntityType.Bee); - _enemyFactory.LoadEnemy(PlatformerEntityType.Boar); - _enemyFactory.LoadEnemy(PlatformerEntityType.Snail); + _enemyFactory.WarmEnemy(PlatformerEntityType.Bee); + _enemyFactory.WarmEnemy(PlatformerEntityType.Boar); + _enemyFactory.WarmEnemy(PlatformerEntityType.Snail); _loading.DoProgress(); }