Миксер
Почини интерфейс
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
|
||||
@@ -9,12 +9,18 @@ using Code.Infrastructure.Input;
|
||||
using Code.Infrastructure.Loadings;
|
||||
using Code.Infrastructure.SceneLoader;
|
||||
using Code.Infrastructure.UI;
|
||||
using Code.Infrastructure.UI.Panels;
|
||||
using Reflex.Core;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Code.Example.Platformer
|
||||
{
|
||||
public interface IPlayerReachedFinishHandle : IGlobalSubscriber
|
||||
{
|
||||
void PlayerReachedFinish();
|
||||
}
|
||||
|
||||
[State(typeof(AppStates),typeof(AppStateMachineContext))]
|
||||
[StateRaisingEvent]
|
||||
public partial class PlatformerState :
|
||||
@@ -26,7 +32,11 @@ namespace Code.Example.Platformer
|
||||
IPlatformerPlayerLoadedHandle,
|
||||
IPlatformerPlayerSpawnedHandle,
|
||||
IReadyToPlayHandle,
|
||||
IPlayerReachedFinishHandle
|
||||
IPlayerReachedFinishHandle,
|
||||
ILoadingPanelOpenedHandle,
|
||||
ILoadingPanelClosedHandle,
|
||||
IPlatformerEnemySpawnedHandle,
|
||||
IPlayerDiedHandle
|
||||
{
|
||||
private IPlatformerEnemyFactory _enemyFactory;
|
||||
private IPlatformerPlayerFactory _playerFactory;
|
||||
@@ -37,7 +47,7 @@ namespace Code.Example.Platformer
|
||||
|
||||
private Container _fixdamncontainer;
|
||||
|
||||
private Loading _loading;
|
||||
private Loading _loading;
|
||||
|
||||
public PlatformerState(AppStateMachineContext context, EventBus eventBus) : base(context, eventBus)
|
||||
{
|
||||
@@ -49,30 +59,11 @@ namespace Code.Example.Platformer
|
||||
{
|
||||
EventBus.Subscribe(this);
|
||||
|
||||
// Dependency scene
|
||||
// Level scene
|
||||
// Camera
|
||||
// Enemy snail
|
||||
// Enemy bee
|
||||
// Enemy boar
|
||||
// Player
|
||||
// Music
|
||||
_loading = new(8, InitialLoadingCompleted);
|
||||
// LoadingScreen
|
||||
_loading = new(1, StartInitialLoading);
|
||||
|
||||
Context.UIService.OpenPanel(UIPanelType.Loading);
|
||||
Context.SceneLoader.LoadSceneAsync(SceneId.Platformer, LoadSceneMode.Single).Forget();
|
||||
Context.InputService.EnableMap(ActionMappings.Platformer);
|
||||
Context.CameraFactory.LoadCinemachineCamera(CameraMode.Platformer).Forget();
|
||||
}
|
||||
private void InitialLoadingCompleted()
|
||||
{
|
||||
Context.UIService.ClosePanel(UIPanelType.Loading);
|
||||
|
||||
_enemyFactory.SpawnEnemy(PlatformerEntityType.Boar, _currentLevelData.enemySpawnPoints[0].position);
|
||||
|
||||
_playerFactory.SpawnPlayer(_currentLevelData.playerCheckPoints[0].position);
|
||||
}
|
||||
|
||||
|
||||
protected override void OnExitState()
|
||||
{
|
||||
@@ -83,10 +74,51 @@ namespace Code.Example.Platformer
|
||||
_playerFactory.ReleasePlayer();
|
||||
|
||||
Context.CameraFactory.ReleaseCinemachineCamera(CameraMode.Platformer);
|
||||
EventBus.Unsubscribe(this);
|
||||
Context.InputService.DisableMap(ActionMappings.Platformer);
|
||||
|
||||
_audioFactory.ReleaseAudios(AudioNames.Platformer);
|
||||
|
||||
EventBus.Unsubscribe(this);
|
||||
}
|
||||
|
||||
private void StartInitialLoading()
|
||||
{
|
||||
|
||||
// Dependency scene
|
||||
// Level scene
|
||||
// Camera
|
||||
// Enemy snail
|
||||
// Enemy bee
|
||||
// Enemy boar
|
||||
// Player
|
||||
// Music
|
||||
_loading = new(8, InitialLoadingCompleted);
|
||||
|
||||
Context.AudioService.ChangeGroupVolume(
|
||||
AudioGroupType.Music,
|
||||
1f,
|
||||
0.5f,
|
||||
() => Context.AudioService.PlayRepeatedly(AudioNames.Platformer,0, AudioGroupType.Music));
|
||||
|
||||
Context.SceneLoader.LoadSceneAsync(SceneId.Platformer, LoadSceneMode.Single).Forget();
|
||||
Context.InputService.EnableMap(ActionMappings.Platformer);
|
||||
Context.CameraFactory.LoadCinemachineCamera(CameraMode.Platformer).Forget();
|
||||
}
|
||||
|
||||
private void InitialLoadingCompleted()
|
||||
{
|
||||
_loading = new Loading(2, CloseLevel1LoadingScreen);
|
||||
|
||||
_enemyFactory.SpawnEnemy(PlatformerEntityType.Snail, _currentLevelData.enemySpawnPoints[0].position);
|
||||
|
||||
_playerFactory.SpawnPlayer(_currentLevelData.playerCheckPoints[0].position);
|
||||
}
|
||||
|
||||
private void CloseLevel1LoadingScreen()
|
||||
{
|
||||
Context.UIService.ClosePanel(UIPanelType.Loading);
|
||||
|
||||
EventBus.RaiseEvent<IGameplayFreezeable>(x=> x.UnFreeze());
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +142,13 @@ namespace Code.Example.Platformer
|
||||
_playerEntity = entity;
|
||||
|
||||
Context.CameraFactory.GetCinematicCamera(CameraMode.Platformer).Follow = entity.transform;
|
||||
|
||||
_loading.DoProgress();
|
||||
}
|
||||
|
||||
public void PlatformerEnemySpawned(Entity.Entity entity)
|
||||
{
|
||||
_loading.DoProgress();
|
||||
}
|
||||
|
||||
public void OnReadyToPlay(AudioNames groupName)
|
||||
@@ -119,25 +158,40 @@ namespace Code.Example.Platformer
|
||||
|
||||
public void PlayerReachedFinish()
|
||||
{
|
||||
_loading = new(1, Level2LoadingCompleted);
|
||||
_loading = new Loading(1, StartLevel2Loading);
|
||||
|
||||
Context.AudioService.ChangeGroupVolume(
|
||||
AudioGroupType.Music,
|
||||
0f,
|
||||
0.5f,
|
||||
() => Context.AudioService.CancelMusic(AudioNames.Platformer, 0));
|
||||
|
||||
Context.UIService.OpenPanel(UIPanelType.Loading);
|
||||
|
||||
_playerEntity.Freeze();
|
||||
EventBus.RaiseEvent<IGameplayFreezeable>(x=> x.Freeze());
|
||||
|
||||
SceneManager.MoveGameObjectToScene(_playerEntity.gameObject, Context.SceneLoader.GetScene(SceneId.Platformer));
|
||||
}
|
||||
|
||||
private void StartLevel2Loading()
|
||||
{
|
||||
_loading = new(2, StartLevel2Gameplay);
|
||||
|
||||
Context.SceneLoader.UnloadSceneAsync(SceneId.Platformer2).Forget();
|
||||
Context.SceneLoader.LoadSceneAsync(SceneId.Platformer3, LoadSceneMode.Additive).Forget();
|
||||
}
|
||||
|
||||
private void Level2LoadingCompleted()
|
||||
|
||||
private void StartLevel2Gameplay()
|
||||
{
|
||||
Context.UIService.ClosePanel(UIPanelType.Loading);
|
||||
Context.AudioService.ChangeGroupVolume(
|
||||
AudioGroupType.Music,
|
||||
1f,
|
||||
0.5f,
|
||||
() => Context.AudioService.PlayRepeatedly(AudioNames.Platformer,7, AudioGroupType.Music));
|
||||
|
||||
_enemyFactory.SpawnEnemy(PlatformerEntityType.Boar, _currentLevelData.enemySpawnPoints[0].position);
|
||||
Context.UIService.ClosePanel(UIPanelType.Loading);
|
||||
|
||||
_playerEntity.transform.position = _currentLevelData.playerCheckPoints[0].position;
|
||||
_playerEntity.UnFreeze();
|
||||
EventBus.RaiseEvent<IGameplayFreezeable>(x=> x.UnFreeze());
|
||||
}
|
||||
|
||||
public void OnPlatformerSceneLoaded()
|
||||
@@ -179,6 +233,13 @@ namespace Code.Example.Platformer
|
||||
|
||||
public void OnPlatformer3SceneLoaded()
|
||||
{
|
||||
SceneManager.SetActiveScene(Context.SceneLoader.GetScene(SceneId.Platformer3));
|
||||
|
||||
_enemyFactory.SpawnEnemy(PlatformerEntityType.Boar, _currentLevelData.enemySpawnPoints[0].position);
|
||||
|
||||
_playerEntity.transform.position = _currentLevelData.playerCheckPoints[0].position;
|
||||
|
||||
_loading.DoProgress();
|
||||
}
|
||||
|
||||
public void OnPlatformer3SceneInitialized(Container container)
|
||||
@@ -187,10 +248,20 @@ namespace Code.Example.Platformer
|
||||
|
||||
_loading.DoProgress();
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPlayerReachedFinishHandle : IGlobalSubscriber
|
||||
{
|
||||
void PlayerReachedFinish();
|
||||
public void LoadingPanelOpened(UIPanel panel)
|
||||
{
|
||||
_loading.DoProgress();
|
||||
}
|
||||
|
||||
public void LoadingPanelClosed()
|
||||
{
|
||||
}
|
||||
|
||||
public void PlayerDied()
|
||||
{
|
||||
Context.StateMachine.SwitchState(AppStates.MainMenu)
|
||||
.AllowStateTransition(AppStates.Platformer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,17 +19,17 @@ namespace Code.Example.Race.UI
|
||||
_eventBus = eventBus;
|
||||
_eventBus.Subscribe(this);
|
||||
}
|
||||
public override void Open(Action callback = null)
|
||||
public override void Open()
|
||||
{
|
||||
playerScore.gameObject.SetActive(true);
|
||||
callback?.Invoke();
|
||||
// callback?.Invoke();
|
||||
// image.DOColor(shownColor, 1f).onComplete = () => callback?.Invoke();
|
||||
}
|
||||
|
||||
public override void Close(Action callback = null)
|
||||
public override void Close()
|
||||
{
|
||||
playerScore.gameObject.SetActive(false);
|
||||
callback?.Invoke();
|
||||
// callback?.Invoke();
|
||||
// image.DOColor(hiddenColor, 1f).onComplete += () => callback?.Invoke();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,16 +24,16 @@ namespace Code.Example.Race.UI
|
||||
scoreText.text += $@"{score.place} место за {t:mm\:ss\:fff}\n";
|
||||
}
|
||||
}
|
||||
public override void Open(Action callback = null)
|
||||
public override void Open()
|
||||
{
|
||||
Tween.Color(image,shownColor, 1f);
|
||||
Tween.Color(scoreText,shownColor, 1f).OnComplete( () => callback?.Invoke());
|
||||
// Tween.Color(scoreText,shownColor, 1f).OnComplete( () => callback?.Invoke());
|
||||
}
|
||||
|
||||
public override void Close(Action callback = null)
|
||||
public override void Close()
|
||||
{
|
||||
Tween.Color(image,hiddenColor, 1f);
|
||||
Tween.Color(scoreText,hiddenColor, 1f).OnComplete( () => callback?.Invoke());
|
||||
// Tween.Color(scoreText,hiddenColor, 1f).OnComplete( () => callback?.Invoke());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,16 +15,16 @@ namespace Code.Example.Race.UI
|
||||
[SerializeField] private Color hiddenColor;
|
||||
|
||||
public void SetText(string text) => winText.text = text;
|
||||
public override void Open(Action callback = null)
|
||||
public override void Open()
|
||||
{
|
||||
Tween.Color(image,shownColor, 1f);
|
||||
Tween.Color(winText,shownColor, 1f).OnComplete( () => callback?.Invoke());
|
||||
// Tween.Color(winText,shownColor, 1f).OnComplete( () => callback?.Invoke());
|
||||
}
|
||||
|
||||
public override void Close(Action callback = null)
|
||||
public override void Close()
|
||||
{
|
||||
Tween.Color(image,hiddenColor, 1f);
|
||||
Tween.Color(winText,hiddenColor, 1f).OnComplete( () => callback?.Invoke());
|
||||
// Tween.Color(winText,hiddenColor, 1f).OnComplete( () => callback?.Invoke());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,8 @@ namespace Code.Infrastructure.App
|
||||
IAudioSourcePoolInitializedHandle,
|
||||
IAudioConfigsLoadedHandle,
|
||||
ICinematicMachineHandle,
|
||||
ILayerMasksInitializedHandle
|
||||
ILayerMasksInitializedHandle,
|
||||
IAudioServiceHandle
|
||||
{
|
||||
public void InstallBindings(ContainerBuilder containerBuilder)
|
||||
{
|
||||
@@ -86,7 +87,8 @@ namespace Code.Infrastructure.App
|
||||
// Audio Pool
|
||||
// Cinemachine Camera
|
||||
// Layer masks
|
||||
_initialLoading = new Loading(11, () => EssentialLoadEnded(_thatRightContainer));
|
||||
// Audio Service
|
||||
_initialLoading = new Loading(12, () => EssentialLoadEnded(_thatRightContainer));
|
||||
|
||||
_ui2CamLoading = new Loading(2,
|
||||
() =>
|
||||
@@ -208,5 +210,10 @@ namespace Code.Infrastructure.App
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void AudioServiceLoaded()
|
||||
{
|
||||
_initialLoading.DoProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,13 +30,20 @@ namespace Code.Infrastructure.App.States
|
||||
{
|
||||
// Context.AudioFactory.ReleaseAudios(AudioNames.UISounds);
|
||||
Context.UIService.TryRemovePanel(UIPanelType.DebugSceneChooser);
|
||||
Context.AudioService.CancelMusic(AudioNames.UISounds,0);
|
||||
|
||||
Context.AudioService.ChangeGroupVolume(
|
||||
AudioGroupType.Music,
|
||||
0,
|
||||
0.5f,
|
||||
() => Context.AudioService.CancelMusic(AudioNames.UISounds,0));
|
||||
|
||||
|
||||
_eventBus.Unsubscribe(this);
|
||||
}
|
||||
|
||||
public void OnReadyToPlay(AudioNames groupName)
|
||||
{
|
||||
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0);
|
||||
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0, AudioGroupType.Music);
|
||||
}
|
||||
|
||||
public void MenuChoosePanelCreated(UIPanel panel)
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Code.Infrastructure.App.States
|
||||
Context.UIService.TryLoadCreatePanel(UIPanelType.DebugSceneChooser);
|
||||
// Context.AudioFactory.LoadAudioClips(AudioNames.UISounds);
|
||||
Context.SceneLoader.LoadSceneAsync(SceneId.MainMenu, LoadSceneMode.Single).Forget();
|
||||
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0);
|
||||
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0, AudioGroupType.Music);
|
||||
}
|
||||
|
||||
protected override void OnExitState()
|
||||
@@ -49,7 +49,7 @@ namespace Code.Infrastructure.App.States
|
||||
public void OnReadyToPlay(AudioNames groupName)
|
||||
{
|
||||
_loading.DoProgress();
|
||||
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0);
|
||||
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0, AudioGroupType.Music);
|
||||
}
|
||||
|
||||
public void OnMainMenuSceneLoaded()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Code.Infrastructure.Configs;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Cysharp.Threading.Tasks;
|
||||
@@ -102,5 +101,6 @@ namespace Code.Infrastructure.Audio
|
||||
{
|
||||
void AudioClipsLoaded(AudioNames groupName, Dictionary<int, AudioClip> toDictionary);
|
||||
void AudioClipsUnLoaded(AudioNames groupName);
|
||||
public void ApplyParameter(string effectName, float value, float time, Action callback = null);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ namespace Code.Infrastructure.Audio
|
||||
public enum AudioGroupType
|
||||
{
|
||||
Master,
|
||||
|
||||
SFX,
|
||||
Music,
|
||||
UIFX
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Code.Infrastructure.Generators;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
namespace Code.Infrastructure.Audio
|
||||
{
|
||||
@@ -11,9 +11,14 @@ namespace Code.Infrastructure.Audio
|
||||
[ToConfig] public int id;
|
||||
[ToConfig] public AssetReference fileReference;
|
||||
}
|
||||
[Config("Configs/Audio/AudioSourceSettings")]
|
||||
[Config("Configs/Audio/AudioSource")]
|
||||
public class AudioSourcePrefab
|
||||
{
|
||||
[ToConfig] public AssetReference sourcePrefab;
|
||||
}
|
||||
[Config("Configs/Audio/AudioMixer")]
|
||||
public class AudioMixerConfig
|
||||
{
|
||||
[ToConfig] public AudioMixer mixerAsset;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Code.Infrastructure.Configs;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using PrimeTween;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
namespace Code.Infrastructure.Audio
|
||||
@@ -12,16 +16,18 @@ namespace Code.Infrastructure.Audio
|
||||
AudioClip GetClip(AudioNames groupName, int id);
|
||||
void PlayTest();
|
||||
|
||||
UniTaskVoid PlayOneShot(AudioNames groupName, int id, Vector3 position = new Vector3(),
|
||||
UniTaskVoid PlayOneShot(AudioNames groupName, int id, AudioGroupType audioGroupType, Vector3 position = new Vector3(),
|
||||
AudioSourceType sourceType = AudioSourceType.NoBlend,
|
||||
AudioSource audioSource = null);
|
||||
|
||||
UniTaskVoid PlayRepeatedly(AudioNames groupName, int id,
|
||||
UniTaskVoid PlayRepeatedly(AudioNames groupName, int id, AudioGroupType audioGroupType,
|
||||
AudioSourceType sourceType = AudioSourceType.NoBlend, AudioSource audioSource = null, CancellationTokenSource cancellationTokenSource = null);
|
||||
|
||||
bool CheckClip(AudioNames groupName, int id);
|
||||
void CancelMusic(AudioNames groupName, int id);
|
||||
void ReleaseCancellationSource(AudioNames groupName, int id);
|
||||
void ApplyParameter(string effectName, float value, float time, Action callback = null);
|
||||
void ChangeGroupVolume(AudioGroupType groupType, float value, float time, Action callback = null);
|
||||
}
|
||||
|
||||
public partial class AudioService : IAudioClipsEventHandle, IAudioService
|
||||
@@ -33,7 +39,7 @@ namespace Code.Infrastructure.Audio
|
||||
private AudioMixer _mixer;
|
||||
|
||||
private Dictionary<AudioGroupType, AudioMixerGroup> _audioMixerGroups = new();
|
||||
public AudioService(EventBus.EventBus eventBus, IAudioFactory audioFactory, IAudioSourcePool pool)
|
||||
public AudioService(EventBus.EventBus eventBus, IAudioFactory audioFactory, IAudioSourcePool pool, IConfigLocator configLocator)
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
_audioFactory = audioFactory;
|
||||
@@ -44,16 +50,27 @@ namespace Code.Infrastructure.Audio
|
||||
for (int i = 0; i < typeof(AudioNames).GetEnumValues().Length; i++)
|
||||
_audioClips.Add((AudioNames)i, new Dictionary<int, AudioClip>());
|
||||
|
||||
//InitializeMixer();
|
||||
LoadMixerAsset(configLocator.TryGetConfigAssetReference<AudioMixerConfigConfig>()).Forget();
|
||||
}
|
||||
|
||||
private partial void InitializeMixer();
|
||||
|
||||
private async UniTaskVoid LoadMixerAsset(AssetReference audioMixerConfig)
|
||||
{
|
||||
var audioMixer = await Addressables.LoadAssetAsync<AudioMixerConfigConfig>(audioMixerConfig);
|
||||
|
||||
_mixer = audioMixer.mixerAsset;
|
||||
|
||||
InitializeMixer();
|
||||
|
||||
_eventBus.RaiseEvent<IAudioServiceHandle>(x=> x.AudioServiceLoaded());
|
||||
}
|
||||
public void PlayTest()
|
||||
{
|
||||
_pool.GetSource(AudioSourceType.NoBlend).PlayOneShot(GetClip(AudioNames.UISounds, 0));
|
||||
}
|
||||
|
||||
public async UniTaskVoid PlayOneShot(AudioNames groupName, int id, Vector3 position = new Vector3(),
|
||||
public async UniTaskVoid PlayOneShot(AudioNames groupName, int id, AudioGroupType audioGroupType, Vector3 position = new Vector3(),
|
||||
AudioSourceType sourceType = AudioSourceType.NoBlend,
|
||||
AudioSource audioSource = null)
|
||||
{
|
||||
@@ -62,6 +79,7 @@ namespace Code.Infrastructure.Audio
|
||||
if (!audioSource) audioSource = _pool.GetSource(sourceType);
|
||||
|
||||
audioSource.transform.position = position;
|
||||
audioSource.outputAudioMixerGroup = _audioMixerGroups[audioGroupType];
|
||||
audioSource.PlayOneShot(GetClip(groupName, id));
|
||||
|
||||
await UniTask.NextFrame();
|
||||
@@ -74,7 +92,7 @@ namespace Code.Infrastructure.Audio
|
||||
|
||||
public void CancelMusic(AudioNames groupName, int id) => _cancellationTokenSources[new KeyValuePair<AudioNames, int>(groupName, id)].Cancel();
|
||||
public void ReleaseCancellationSource(AudioNames groupName, int id) => _cancellationTokenSources[new KeyValuePair<AudioNames, int>(groupName, id)] = null;
|
||||
public async UniTaskVoid PlayRepeatedly(AudioNames groupName, int id,
|
||||
public async UniTaskVoid PlayRepeatedly(AudioNames groupName, int id, AudioGroupType audioGroupType,
|
||||
AudioSourceType sourceType = AudioSourceType.NoBlend, AudioSource audioSource = null, CancellationTokenSource cancellationTokenSource = null)
|
||||
{
|
||||
if (!CheckClip(groupName, id)) return;
|
||||
@@ -87,7 +105,7 @@ namespace Code.Infrastructure.Audio
|
||||
|
||||
if (!audioSource) audioSource = _pool.GetSource(sourceType);
|
||||
if(!audioSource.resource) audioSource.resource = GetClip(groupName, id);
|
||||
|
||||
audioSource.outputAudioMixerGroup = _audioMixerGroups[audioGroupType];
|
||||
audioSource.Play();
|
||||
|
||||
await UniTask.NextFrame();
|
||||
@@ -107,7 +125,7 @@ namespace Code.Infrastructure.Audio
|
||||
return;
|
||||
}
|
||||
|
||||
PlayRepeatedly(groupName, id, sourceType, audioSource, cancellationTokenSource).Forget();
|
||||
PlayRepeatedly(groupName, id, AudioGroupType.Music, sourceType, audioSource, cancellationTokenSource).Forget();
|
||||
}
|
||||
|
||||
public AudioClip GetClip(AudioNames groupName, int id) => _audioClips[groupName][id];
|
||||
@@ -124,10 +142,26 @@ namespace Code.Infrastructure.Audio
|
||||
_audioClips[groupName].Clear();
|
||||
_audioClips[groupName] = null;
|
||||
}
|
||||
|
||||
public void ApplyParameter(string effectName, float value, float time, Action callback = null)
|
||||
{
|
||||
_mixer.GetFloat(effectName, out float startValue);
|
||||
Tween.Custom(startValue, value, time, newValue => {
|
||||
_mixer.SetFloat(effectName, newValue);
|
||||
}).OnComplete(callback);
|
||||
}
|
||||
public void ChangeGroupVolume(AudioGroupType groupType, float value, float time, Action callback = null)
|
||||
{
|
||||
ApplyParameter(_audioMixerGroups[groupType].name, Mathf.Log10(value == 0f ? 0.001f : value) * 20, time, callback);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IReadyToPlayHandle : IGlobalSubscriber
|
||||
{
|
||||
void OnReadyToPlay(AudioNames groupName);
|
||||
}
|
||||
public interface IAudioServiceHandle : IGlobalSubscriber
|
||||
{
|
||||
void AudioServiceLoaded();
|
||||
}
|
||||
}
|
||||
@@ -51,4 +51,5 @@ namespace Code.Infrastructure.Generators
|
||||
public class AudioMixerEnum : Attribute
|
||||
{
|
||||
}
|
||||
public class UIEventOpenClose : Attribute{}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#if UNITY_EDITOR
|
||||
using Code.Infrastructure.UI;
|
||||
using Code.Infrastructure.UI;
|
||||
using Unity.VisualScripting;
|
||||
using UnityCodeGen;
|
||||
using UnityEditor;
|
||||
|
||||
@@ -43,6 +44,33 @@ namespace Code.Infrastructure.Generators
|
||||
}}
|
||||
";
|
||||
|
||||
if(st.HasAttribute(typeof(UIEventOpenClose)))
|
||||
{
|
||||
fireStatesCode += $@"
|
||||
protected override void FireOpenedEvent()
|
||||
{{
|
||||
_eventBus.RaiseEvent<I{st.Name}OpenedHandle>(h => h.{st.Name}Opened(this));
|
||||
}}
|
||||
|
||||
protected override void FireClosedEvent()
|
||||
{{
|
||||
_eventBus.RaiseEvent<I{st.Name}ClosedHandle>(h => h.{st.Name}Closed());
|
||||
base.FireClosedEvent();
|
||||
}}
|
||||
";
|
||||
fireStatesInterfacesCode += $@"
|
||||
|
||||
public interface I{st.Name}OpenedHandle : IGlobalSubscriber
|
||||
{{
|
||||
void {st.Name}Opened(UIPanel panel);
|
||||
}}
|
||||
|
||||
public interface I{st.Name}ClosedHandle : IGlobalSubscriber
|
||||
{{
|
||||
void {st.Name}Closed();
|
||||
}}
|
||||
";
|
||||
}
|
||||
var statesCode = $@"
|
||||
|
||||
// retard-generated
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Infrastructure.Loadings
|
||||
{
|
||||
@@ -26,7 +25,7 @@ namespace Code.Infrastructure.Loadings
|
||||
_progress--;
|
||||
_loadProgress?.Invoke(this);
|
||||
|
||||
if(_progress <= 0) // Зачем инвертировать, если так читается лучше, райдер соси
|
||||
if(_progress == 0) // Зачем инвертировать, если так читается лучше, райдер соси
|
||||
{
|
||||
Completed = true;
|
||||
_completed();
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
using System;
|
||||
using System;
|
||||
using Code.Infrastructure.Generators;
|
||||
using PrimeTween;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Code.Infrastructure.UI.Panels
|
||||
{
|
||||
[UIEventOpenClose]
|
||||
public partial class LoadingPanel : UIPanel
|
||||
{
|
||||
[SerializeField] private RawImage image;
|
||||
[SerializeField] private Color shownColor;
|
||||
[SerializeField] private Color hiddenColor;
|
||||
public override void Open(Action callback = null)
|
||||
public override void Open()
|
||||
{
|
||||
Tween.Color(image,shownColor, 1f).OnComplete( () => callback?.Invoke());
|
||||
Tween.Color(image,shownColor, 1f).OnComplete(FireOpenedEvent);
|
||||
}
|
||||
|
||||
public override void Close(Action callback = null)
|
||||
public override void Close()
|
||||
{
|
||||
Tween.Color(image,hiddenColor, 1f).OnComplete( () => callback?.Invoke());
|
||||
Tween.Color(image,hiddenColor, 1f).OnComplete(FireClosedEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,24 @@
|
||||
using System;
|
||||
using Code.Infrastructure.Generators;
|
||||
using PrimeTween;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Code.Infrastructure.UI.Panels
|
||||
{
|
||||
[UIEventOpenClose]
|
||||
public partial class LogoPanel : UIPanel
|
||||
{
|
||||
[SerializeField] private Image image;
|
||||
[SerializeField] private Color shownColor;
|
||||
[SerializeField] private Color hiddenColor;
|
||||
public override void Open(Action callback = null)
|
||||
public override void Open()
|
||||
{
|
||||
Tween.Color(image,shownColor, 1f).OnComplete( () => callback?.Invoke());
|
||||
Tween.Color(image,shownColor, 1f).OnComplete(FireOpenedEvent);
|
||||
}
|
||||
|
||||
public override void Close(Action callback = null)
|
||||
public override void Close()
|
||||
{
|
||||
Tween.Color(image,hiddenColor, 1f).OnComplete( () => callback?.Invoke());
|
||||
Tween.Color(image,hiddenColor, 1f).OnComplete(FireClosedEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,28 @@
|
||||
using System;
|
||||
using Code.Debug;
|
||||
using Code.Infrastructure.Audio;
|
||||
using Code.Infrastructure.Generators;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Infrastructure.UI.Panels
|
||||
{
|
||||
[UIEventOpenClose]
|
||||
public partial class MenuChoosePanel : UIPanel
|
||||
{
|
||||
[Inject] IAudioService _audioService;
|
||||
[SerializeField] private SceneChooser sceneChooser;
|
||||
public void PlaySelectSound() => _audioService.PlayOneShot(AudioNames.UISounds, 7);
|
||||
public void PlayDeselectSound() => _audioService.PlayOneShot(AudioNames.UISounds, 8);
|
||||
public void PlayClickSound() => _audioService.PlayOneShot(AudioNames.UISounds, 1);
|
||||
public override void Open(Action callback = null)
|
||||
public void PlaySelectSound() => _audioService.PlayOneShot(AudioNames.UISounds, 7, AudioGroupType.UIFX);
|
||||
public void PlayDeselectSound() => _audioService.PlayOneShot(AudioNames.UISounds, 8, AudioGroupType.UIFX);
|
||||
public void PlayClickSound() => _audioService.PlayOneShot(AudioNames.UISounds, 1, AudioGroupType.UIFX);
|
||||
public override void Open()
|
||||
{
|
||||
sceneChooser.EnableButtons();
|
||||
callback?.Invoke();
|
||||
FireOpenedEvent();
|
||||
}
|
||||
|
||||
public override void Close(Action callback = null)
|
||||
public override void Close()
|
||||
{
|
||||
|
||||
callback?.Invoke();
|
||||
FireClosedEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -11,11 +10,17 @@ namespace Code.Infrastructure.UI
|
||||
[SerializeField] protected bool injectMeSenpai;
|
||||
public bool InjectMeSenpai => injectMeSenpai;
|
||||
[Inject] protected EventBus.EventBus _eventBus;
|
||||
public abstract void Open(Action callback = null);
|
||||
public abstract void Close(Action callback = null);
|
||||
public abstract void Open();
|
||||
public abstract void Close();
|
||||
|
||||
// Вызвать вручную \ добавить в коллбек для вызова ивента в EventBus
|
||||
public virtual void FireCreatedEvent(){}
|
||||
// Вызвать вручную \ добавить в коллбек для вызова ивента в EventBus
|
||||
public virtual void FireRemovedEvent(){}
|
||||
// Вызвать вручную \ добавить в коллбек для вызова ивента в EventBus
|
||||
protected virtual void FireOpenedEvent(){}
|
||||
// Вызвать вручную \ добавить в коллбек для вызова ивента в EventBus
|
||||
protected virtual void FireClosedEvent(){gameObject.SetActive(false);}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -52,10 +52,7 @@ namespace Code.Infrastructure.UI
|
||||
// TODO Close event
|
||||
public void ClosePanel(UIPanelType uiPanelType)
|
||||
{
|
||||
_loadedSinglePanels[uiPanelType].Close(() =>
|
||||
{
|
||||
_loadedSinglePanels[uiPanelType].gameObject.SetActive(false);
|
||||
});
|
||||
_loadedSinglePanels[uiPanelType].Close();
|
||||
}
|
||||
|
||||
public void TryLoadCreatePanel(UIPanelType uiPanelType, Transform parent = null) => _factory.LoadPanel(uiPanelType, parent);
|
||||
@@ -89,20 +86,11 @@ namespace Code.Infrastructure.UI
|
||||
UnityEngine.Debug.LogError("Это для единичных панелей олух");
|
||||
return;
|
||||
}
|
||||
_loadedSinglePanels[uiPanelType].Close(() =>
|
||||
{
|
||||
_loadedSinglePanels[uiPanelType].gameObject.SetActive(false);
|
||||
RemovePanel(uiPanelType);
|
||||
});
|
||||
_loadedSinglePanels[uiPanelType].Close();
|
||||
}
|
||||
public void TryRemovePanel(UIPanel panel)
|
||||
{
|
||||
panel.Close(() =>
|
||||
{
|
||||
panel.gameObject.SetActive(false);
|
||||
RemovePanel(panel);
|
||||
// _eventBus.RaiseEvent<IUIMultiplePanelHandle>(x=> x.UIMultiplePanelRemoved(panel));
|
||||
});
|
||||
panel.Close();
|
||||
}
|
||||
|
||||
private void RemovePanel(UIPanelType panelType)
|
||||
|
||||
Reference in new issue
Block a user