Миксер
Почини интерфейс
This commit is contained in:
1 parent
1aceea1b79
commit
60c28f54f2
74 files changed
+8060
-1059
No files matched your search
@@ -1,5 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Code.Infrastructure.Audio;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using PrimeTween;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Platformer.Entity.Enemies
|
||||
@@ -14,7 +17,36 @@ namespace Code.Example.Platformer.Entity.Enemies
|
||||
[SerializeField] private Transform _currentTarget;
|
||||
|
||||
private Tween _patrolAction;
|
||||
private float _attackThreshold = 0.5f;
|
||||
|
||||
[Inject] private IAudioService _audioService;
|
||||
|
||||
[SerializeField] private EntityHealth health;
|
||||
private void Start()
|
||||
{
|
||||
health.OnEntityDamage = OnEntityDamage;
|
||||
health.OnEntityDeath = OnEntityDeath;
|
||||
}
|
||||
|
||||
private void OnEntityDeath()
|
||||
{
|
||||
animator.SetBool(Died, true);
|
||||
animator.SetTrigger(OnDeath);
|
||||
Die().Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid Die()
|
||||
{
|
||||
await UniTask.WaitForSeconds(1);
|
||||
_audioService.PlayOneShot(AudioNames.Platformer, 3 , AudioGroupType.SFX);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
private void OnEntityDamage(int obj)
|
||||
{
|
||||
_audioService.PlayOneShot(AudioNames.Platformer, 2, AudioGroupType.SFX);
|
||||
UnityEngine.Debug.Log(gameObject.name + " damaged");
|
||||
animator.SetTrigger(OnHit);
|
||||
}
|
||||
protected override void Move()
|
||||
{
|
||||
if (onPatrol && !_patrolAction.isAlive)
|
||||
@@ -25,6 +57,7 @@ namespace Code.Example.Platformer.Entity.Enemies
|
||||
}
|
||||
else if(_currentTarget)
|
||||
{
|
||||
TryAttack();
|
||||
|
||||
var direction = _currentTarget.position - transform.position;
|
||||
direction.Normalize();
|
||||
@@ -39,6 +72,11 @@ namespace Code.Example.Platformer.Entity.Enemies
|
||||
}
|
||||
}
|
||||
|
||||
private void TryAttack()
|
||||
{
|
||||
if ((transform.position - _currentTarget.position).magnitude < _attackThreshold) _currentTarget.GetComponent<EntityHealth>().GiveDamage(1);
|
||||
}
|
||||
|
||||
private void OnControlPointReached()
|
||||
{
|
||||
if (++_currentPatrolPoint >= partolPoints.Count) _currentPatrolPoint = 0;
|
||||
|
||||
@@ -18,6 +18,10 @@ namespace Code.Example.Platformer.Entity.Enemies
|
||||
[SerializeField] private EntityHealth health;
|
||||
|
||||
[Inject] private IAudioService _audioService;
|
||||
|
||||
private Transform _target;
|
||||
private float _attackThreshold = 0.5f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
health.OnEntityDamage = OnEntityDamage;
|
||||
@@ -34,12 +38,12 @@ namespace Code.Example.Platformer.Entity.Enemies
|
||||
private async UniTaskVoid Die()
|
||||
{
|
||||
await UniTask.WaitForSeconds(1);
|
||||
_audioService.PlayOneShot(AudioNames.Platformer, 3 );
|
||||
_audioService.PlayOneShot(AudioNames.Platformer, 3 , AudioGroupType.SFX);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
private void OnEntityDamage(int obj)
|
||||
{
|
||||
_audioService.PlayOneShot(AudioNames.Platformer, 2);
|
||||
_audioService.PlayOneShot(AudioNames.Platformer, 2, AudioGroupType.SFX);
|
||||
UnityEngine.Debug.Log(gameObject.name + " damaged");
|
||||
animator.SetTrigger(OnHit);
|
||||
}
|
||||
@@ -83,11 +87,9 @@ namespace Code.Example.Platformer.Entity.Enemies
|
||||
|
||||
private void TryAttack()
|
||||
{
|
||||
if ((transform.position - _target.position).magnitude < attackThreshold) _target.GetComponent<EntityHealth>().GiveDamage(1);
|
||||
if ((transform.position - _target.position).magnitude < _attackThreshold) _target.GetComponent<EntityHealth>().GiveDamage(1);
|
||||
}
|
||||
|
||||
private Transform _target;
|
||||
private float attackThreshold = 0.5f;
|
||||
|
||||
public void GotTarget(Transform target)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Platformer.Entity.Enemies
|
||||
{
|
||||
public class PlayerCollisionDamager : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerStay2D(Collider2D other)
|
||||
{
|
||||
other.GetComponent<EntityHealth>().GiveDamage(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55c5190afe54409f89d7a16c315e48f9
|
||||
timeCreated: 1774276433
|
||||
@@ -1,4 +1,7 @@
|
||||
using Code.Infrastructure.Audio;
|
||||
using Code.Infrastructure.Configs;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Platformer.Entity.Enemies
|
||||
@@ -9,6 +12,35 @@ namespace Code.Example.Platformer.Entity.Enemies
|
||||
[SerializeField] private Vector2 groundRight;
|
||||
[SerializeField] private bool _directionRight;
|
||||
|
||||
[SerializeField] private EntityHealth health;
|
||||
[Inject] private IAudioService _audioService;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
health.OnEntityDamage = OnEntityDamage;
|
||||
health.OnEntityDeath = OnEntityDeath;
|
||||
}
|
||||
|
||||
private void OnEntityDeath()
|
||||
{
|
||||
animator.SetBool(Died, true);
|
||||
animator.SetTrigger(OnDeath);
|
||||
Die().Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid Die()
|
||||
{
|
||||
await UniTask.WaitForSeconds(1);
|
||||
_audioService.PlayOneShot(AudioNames.Platformer, 3 , AudioGroupType.SFX);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
private void OnEntityDamage(int obj)
|
||||
{
|
||||
_audioService.PlayOneShot(AudioNames.Platformer, 2, AudioGroupType.SFX);
|
||||
UnityEngine.Debug.Log(gameObject.name + " damaged");
|
||||
animator.SetTrigger(OnHit);
|
||||
}
|
||||
|
||||
protected override void Move()
|
||||
{
|
||||
CheckupDirection();
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
using Code.Infrastructure.Configs;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Platformer.Entity
|
||||
{
|
||||
public abstract class Entity : MonoBehaviour
|
||||
public interface IGameplayFreezeable : IGlobalSubscriber
|
||||
{
|
||||
void Freeze();
|
||||
void UnFreeze();
|
||||
}
|
||||
public abstract class Entity : MonoBehaviour, IGameplayFreezeable
|
||||
{
|
||||
protected static readonly int VelocityY = Animator.StringToHash("VelocityY");
|
||||
protected static readonly int VelocityX = Animator.StringToHash("VelocityX");
|
||||
@@ -12,26 +19,47 @@ namespace Code.Example.Platformer.Entity
|
||||
protected static readonly int OnDeath = Animator.StringToHash("OnDeath");
|
||||
protected static readonly int Died = Animator.StringToHash("Died");
|
||||
|
||||
[SerializeField] protected Rigidbody2D rigidbody2D;
|
||||
[SerializeField] protected new Rigidbody2D rigidbody2D;
|
||||
[SerializeField] protected Animator animator;
|
||||
[SerializeField] protected SpriteRenderer spriteRenderer;
|
||||
[SerializeField] private Vector2 groundPoint;
|
||||
|
||||
private PlatformerEntityData _data; // TODO
|
||||
protected bool isFreezed;
|
||||
protected bool isFreezed = true;
|
||||
protected bool onGround;
|
||||
private EventBus _eventBus;
|
||||
|
||||
private Vector2 _frozenVelocity;
|
||||
|
||||
public void SetData(PlatformerEntityData data)
|
||||
{
|
||||
_data = data;
|
||||
}
|
||||
|
||||
[Inject]
|
||||
private void Construct(EventBus eventBus)
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
_eventBus.Subscribe(this);
|
||||
}
|
||||
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
_eventBus.Unsubscribe(this);
|
||||
}
|
||||
|
||||
public void Freeze()
|
||||
{
|
||||
_frozenVelocity = rigidbody2D.linearVelocity;
|
||||
rigidbody2D.linearVelocity = Vector2.zero;
|
||||
|
||||
rigidbody2D.bodyType = RigidbodyType2D.Kinematic;
|
||||
isFreezed = true;
|
||||
}
|
||||
public void UnFreeze()
|
||||
{
|
||||
rigidbody2D.linearVelocity = _frozenVelocity;
|
||||
|
||||
rigidbody2D.bodyType = RigidbodyType2D.Dynamic;
|
||||
isFreezed = false;
|
||||
}
|
||||
|
||||
@@ -47,9 +47,7 @@ namespace Code.Example.Platformer.Entity
|
||||
IsDead = true;
|
||||
OnEntityDeath?.Invoke();
|
||||
}
|
||||
|
||||
_eventBus.RaiseEvent<IEntityDamagedHandler>(x=> x.EntityDamaged(gameObject, damage, IsDead));
|
||||
|
||||
|
||||
WaitThreshold().Forget();
|
||||
}
|
||||
|
||||
@@ -60,17 +58,7 @@ namespace Code.Example.Platformer.Entity
|
||||
else _health += heal;
|
||||
|
||||
OnEntityHeal?.Invoke(_health);
|
||||
|
||||
_eventBus.RaiseEvent<IEntityHealedHandler>(x=> x.EntityHealed(gameObject, heal));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public interface IEntityDamagedHandler : IGlobalSubscriber
|
||||
{
|
||||
void EntityDamaged(GameObject entity, int damageCount, bool isDied);
|
||||
}
|
||||
public interface IEntityHealedHandler : IGlobalSubscriber
|
||||
{
|
||||
void EntityHealed(GameObject entity, int healCount);
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,8 @@ namespace Code.Example.Platformer.Entity
|
||||
health.Setup(_enemyConfigs[enemyType].EntityData.maxHealth, _enemyConfigs[enemyType].EntityData.damageRecieveThreshold);
|
||||
|
||||
GameObjectInjector.InjectObject(gameObject, Container.RootContainer);
|
||||
|
||||
_eventBus.RaiseEvent<IPlatformerEnemySpawnedHandle>(x=>x.PlatformerEnemySpawned(entity));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -118,4 +120,8 @@ namespace Code.Example.Platformer.Entity
|
||||
{
|
||||
public void PlatformerEnemyLoaded(PlatformerEntityType type, Entity entity);
|
||||
}
|
||||
public interface IPlatformerEnemySpawnedHandle : IGlobalSubscriber
|
||||
{
|
||||
public void PlatformerEnemySpawned(Entity entity);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Code.Infrastructure.Configs;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Cysharp.Threading.Tasks;
|
||||
@@ -9,7 +7,6 @@ using Reflex.Injectors;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Code.Example.Platformer.Entity
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using Code.Infrastructure.Audio;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Configs;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Code.Infrastructure.Input;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
@@ -15,8 +14,9 @@ namespace Code.Example.Platformer.Entity
|
||||
private IInputService _inputService;
|
||||
|
||||
[Inject]
|
||||
private void Construct(IInputService inputService, IAudioService audioService)
|
||||
private void Construct(IInputService inputService, IAudioService audioService, EventBus eventBus)
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
_audioService = audioService;
|
||||
|
||||
_inputService = inputService;
|
||||
@@ -32,8 +32,9 @@ namespace Code.Example.Platformer.Entity
|
||||
//cameraFactory.GetCinematicCamera(CameraMode.Platformer).Follow = transform; , CameraFactory cameraFactory
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
if(!health.IsDead) UnbindControls();
|
||||
}
|
||||
|
||||
@@ -72,7 +73,7 @@ namespace Code.Example.Platformer.Entity
|
||||
|
||||
_acceleration = 1f;
|
||||
|
||||
_audioService.PlayOneShot(AudioNames.Platformer, 6);
|
||||
_audioService.PlayOneShot(AudioNames.Platformer, 6, AudioGroupType.SFX);
|
||||
}
|
||||
|
||||
[SerializeField] private Vector2 attackOffset;
|
||||
@@ -83,7 +84,7 @@ namespace Code.Example.Platformer.Entity
|
||||
//
|
||||
|
||||
//
|
||||
_audioService.PlayOneShot(AudioNames.Platformer, 1);
|
||||
_audioService.PlayOneShot(AudioNames.Platformer, 1, AudioGroupType.SFX);
|
||||
animator.SetBool(OnAttack, true);
|
||||
}
|
||||
|
||||
@@ -114,6 +115,7 @@ namespace Code.Example.Platformer.Entity
|
||||
public void AttackEnd() => animator.SetBool(OnAttack, false);
|
||||
|
||||
[SerializeField] private EntityHealth health;
|
||||
private EventBus _eventBus;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -124,6 +126,19 @@ namespace Code.Example.Platformer.Entity
|
||||
private void OnEntityDamage(int obj)
|
||||
{
|
||||
UnityEngine.Debug.Log("Player damaged");
|
||||
|
||||
_audioService.PlayOneShot(AudioNames.Platformer, 8, AudioGroupType.SFX);
|
||||
|
||||
_audioService.ApplyParameter(
|
||||
"PlatformerDamage",
|
||||
1f,
|
||||
0.5f,
|
||||
() => _audioService.ApplyParameter(
|
||||
"PlatformerDamage",
|
||||
5000f,
|
||||
1f));
|
||||
|
||||
_eventBus.RaiseEvent<IPlayerDamagedHandle>(x=>x.PlayerDamaged());
|
||||
}
|
||||
|
||||
private void OnEntityDeath()
|
||||
@@ -133,7 +148,19 @@ namespace Code.Example.Platformer.Entity
|
||||
animator.SetBool(Died, true);
|
||||
|
||||
UnbindControls();
|
||||
|
||||
_eventBus.RaiseEvent<IPlayerDiedHandle>(x=>x.PlayerDied());
|
||||
// Destroy(gameObject, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPlayerDiedHandle : IGlobalSubscriber
|
||||
{
|
||||
void PlayerDied();
|
||||
}
|
||||
|
||||
public interface IPlayerDamagedHandle : IGlobalSubscriber
|
||||
{
|
||||
void PlayerDamaged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab2cbe7f4c0142f980f9640c57d27030
|
||||
timeCreated: 1774277361
|
||||
Reference in new issue
Block a user