Platformer example started
This commit is contained in:
1 parent
efcfaae647
commit
9f026b76d6
325 files changed
+23540
-270
No files matched your search
@@ -10,7 +10,8 @@ namespace Code.Infrastructure.App
|
||||
{
|
||||
Bootstrap,
|
||||
Gameplay,
|
||||
MainMenu
|
||||
MainMenu,
|
||||
Platformer
|
||||
}
|
||||
|
||||
public class AppStateMachineContext
|
||||
|
||||
@@ -9,6 +9,7 @@ using Code.Infrastructure.UI;
|
||||
using Code.Infrastructure.Volume;
|
||||
using Reflex.Core;
|
||||
using Reflex.Enums;
|
||||
using Reflex.Injectors;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
@@ -26,7 +27,8 @@ namespace Code.Infrastructure.App
|
||||
IVolumeLoaded,
|
||||
IAudioSourcePoolInitializedHandle,
|
||||
IAudioConfigsLoadedHandle,
|
||||
ICinematicMachineHandle
|
||||
ICinematicMachineHandle,
|
||||
ILayerMasksInitializedHandle
|
||||
{
|
||||
public void InstallBindings(ContainerBuilder containerBuilder)
|
||||
{
|
||||
@@ -64,7 +66,6 @@ namespace Code.Infrastructure.App
|
||||
Resolution.Eager);
|
||||
containerBuilder.RegisterType(typeof(AudioService), new[] { typeof(IAudioService) }, Lifetime.Singleton,
|
||||
Resolution.Eager);
|
||||
|
||||
}
|
||||
|
||||
private void InitLoadings()
|
||||
@@ -79,8 +80,9 @@ namespace Code.Infrastructure.App
|
||||
// Audio Factory
|
||||
// Audio Pool
|
||||
// Cinemachine Camera
|
||||
_initialLoading = new Loading(10, () => EssentialLoadEnded(_thatRightContainer));
|
||||
|
||||
// Layer masks
|
||||
_initialLoading = new Loading(11, () => EssentialLoadEnded(_thatRightContainer));
|
||||
|
||||
_ui2CamLoading = new Loading(2,
|
||||
() =>
|
||||
{
|
||||
@@ -99,7 +101,9 @@ namespace Code.Infrastructure.App
|
||||
_thatRightContainer = container;
|
||||
|
||||
container.Resolve<EventBus.EventBus>().Subscribe(this);
|
||||
|
||||
|
||||
ConstructorInjector.Construct(typeof(LayerMasks), container);
|
||||
|
||||
var cameraFactory = container.Resolve<CameraFactory>();
|
||||
cameraFactory.CreateCameraStateMachine(container.Resolve<CameraStateMachine>())
|
||||
.Forget();
|
||||
@@ -109,7 +113,8 @@ namespace Code.Infrastructure.App
|
||||
{
|
||||
container.Resolve<EventBus.EventBus>().Unsubscribe(this);
|
||||
container.Resolve<AppStateMachine>().SwitchState(AppStates.Bootstrap)
|
||||
.AllowStateTransition(AppStates.Gameplay);
|
||||
.AllowStateTransition(AppStates.Gameplay)
|
||||
.AllowStateTransition(AppStates.Platformer);
|
||||
container.Resolve<AppStateMachineContext>().StateMachine = container.Resolve<AppStateMachine>();
|
||||
}
|
||||
|
||||
@@ -127,7 +132,8 @@ namespace Code.Infrastructure.App
|
||||
{
|
||||
_thatRightContainer.Resolve<CameraStateMachineContext>().cameraLoadedData = data;
|
||||
_thatRightContainer.Resolve<CameraStateMachine>().SwitchState(CameraMode.None)
|
||||
.AllowStateTransition(CameraMode.ThirdPerson);
|
||||
.AllowStateTransition(CameraMode.ThirdPerson)
|
||||
.AllowStateTransition(CameraMode.Platformer);
|
||||
|
||||
data.Camera.GetUniversalAdditionalCameraData().renderPostProcessing = true;
|
||||
|
||||
@@ -198,5 +204,10 @@ namespace Code.Infrastructure.App
|
||||
{
|
||||
_initialLoading.DoProgress();
|
||||
}
|
||||
|
||||
public void LayerMasksInitialized()
|
||||
{
|
||||
_initialLoading.DoProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ using Code.Infrastructure.SceneLoader;
|
||||
using Reflex.Core;
|
||||
using Reflex.Enums;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using Resolution = Reflex.Enums.Resolution;
|
||||
|
||||
namespace Code.Infrastructure.App.SceneInstallers
|
||||
@@ -23,6 +22,8 @@ namespace Code.Infrastructure.App.SceneInstallers
|
||||
containerBuilder.RegisterValue(raceTrackData);
|
||||
containerBuilder.RegisterType(typeof(RaceGame), Lifetime.Scoped,
|
||||
Resolution.Lazy);
|
||||
containerBuilder.RegisterType(typeof(PlayerPrefsRacePoopshitter), Lifetime.Scoped,
|
||||
Resolution.Lazy);
|
||||
|
||||
containerBuilder.OnContainerBuilt += PostInstall;
|
||||
}
|
||||
|
||||
@@ -48,11 +48,13 @@ namespace Code.Infrastructure.App.States
|
||||
// Factory
|
||||
// PlayerCounter
|
||||
// WinScreen
|
||||
// ScoreScreen
|
||||
// CinemachineCamera
|
||||
_gameplayLoading = new Loading(6, GameplayLoadingCompleted);
|
||||
_gameplayLoading = new Loading(7, GameplayLoadingCompleted);
|
||||
|
||||
Context.UIService.TryLoadPanel(UIPanelType.PlayerScoreCounter);
|
||||
Context.UIService.TryLoadPanel(UIPanelType.WinScreen);
|
||||
Context.UIService.TryLoadPanel(UIPanelType.PlayerScores);
|
||||
Context.SceneLoader.LoadSceneAsync(SceneId.Gameplay, LoadSceneMode.Single).Forget();
|
||||
Context.InputService.EnableMap(ActionMappings.Gameplay);
|
||||
Context.CameraFactory.LoadCinemachineCamera(CameraMode.ThirdPerson).Forget();
|
||||
@@ -73,14 +75,15 @@ namespace Code.Infrastructure.App.States
|
||||
_raceGame.PlacedRacers[0].gameObject.transform;
|
||||
|
||||
Context.UIService.ClosePanel(UIPanelType.Loading);
|
||||
|
||||
_raceGame.StartRacers();
|
||||
}
|
||||
|
||||
protected override void OnExitState()
|
||||
{
|
||||
Context.InputService.DisableMap(ActionMappings.Gameplay);
|
||||
{
|
||||
Context.UIService.TryRemovePanel(UIPanelType.PlayerScoreCounter);
|
||||
Context.UIService.TryRemovePanel(UIPanelType.WinScreen);
|
||||
Context.UIService.TryRemovePanel(UIPanelType.PlayerScores);
|
||||
Context.CameraFactory.ReleaseCinemachineCamera(CameraMode.ThirdPerson);
|
||||
Context.InputService.DisableMap(ActionMappings.Gameplay);
|
||||
|
||||
@@ -125,9 +128,14 @@ namespace Code.Infrastructure.App.States
|
||||
for (var i = 0; i < cachedScores.Count; i++)
|
||||
if (cachedScores[i].Key.Data.type == RacerType.Player) id = i + 1;
|
||||
|
||||
UNTILTHEYFIXCONTAINERS.Resolve<PlayerPrefsRacePoopshitter>().AddRace(new(_raceGame.RaceTime, id));
|
||||
|
||||
var winText = $@"{id} МЕСТО\n";
|
||||
winScreen.SetText(winText);
|
||||
|
||||
|
||||
var getPanel = Context.UIService.TryGetPanel(UIPanelType.PlayerScores);
|
||||
((PlayerScores)getPanel)
|
||||
.SetText(UNTILTHEYFIXCONTAINERS.Resolve<PlayerPrefsRacePoopshitter>().GetRaces());
|
||||
Context.UIService.ClosePanel(UIPanelType.PlayerScoreCounter);
|
||||
Context.UIService.OpenPanel(UIPanelType.WinScreen);
|
||||
|
||||
@@ -137,7 +145,11 @@ namespace Code.Infrastructure.App.States
|
||||
private async UniTaskVoid EndTheGame()
|
||||
{
|
||||
await UniTask.WaitForSeconds(3f);
|
||||
Context.UIService.ClosePanel(UIPanelType.WinScreen);
|
||||
|
||||
Context.UIService.OpenPanel(UIPanelType.PlayerScores);
|
||||
await UniTask.WaitForSeconds(5f);
|
||||
|
||||
Context.UIService.OpenPanel(UIPanelType.Loading);
|
||||
Context.StateMachine.SwitchState(AppStates.MainMenu).AllowStateTransition(AppStates.Gameplay);
|
||||
}
|
||||
@@ -151,7 +163,7 @@ namespace Code.Infrastructure.App.States
|
||||
|
||||
public void UILoaded(UIPanelType uiPanelType)
|
||||
{
|
||||
if(uiPanelType == UIPanelType.WinScreen)
|
||||
if(uiPanelType is UIPanelType.WinScreen or UIPanelType.PlayerScores)
|
||||
{
|
||||
_gameplayLoading.DoProgress();
|
||||
return;
|
||||
|
||||
@@ -13,18 +13,16 @@ namespace Code.Infrastructure.App.States
|
||||
[State(typeof(AppStates),typeof(AppStateMachineContext))]
|
||||
[StateRaisingEvent]
|
||||
public partial class MainMenuState : IUIPanelLoaded, IReadyToPlayHandle, IOnMainMenuSceneLoadedHandler
|
||||
{
|
||||
private EventBus.EventBus _eventBus;
|
||||
{
|
||||
public MainMenuState(AppStateMachineContext context, EventBus.EventBus eventBus) : base(context,eventBus)
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
{
|
||||
}
|
||||
|
||||
public override AppStates myState => AppStates.MainMenu;
|
||||
private Loading _loading;
|
||||
protected override void OnEnterState()
|
||||
{
|
||||
_eventBus.Subscribe(this);
|
||||
EventBus.Subscribe(this);
|
||||
|
||||
_loading = new Loading(2, LoadComplete);
|
||||
|
||||
@@ -38,7 +36,7 @@ namespace Code.Infrastructure.App.States
|
||||
{
|
||||
// Context.AudioFactory.ReleaseAudios(AudioNames.UISounds);
|
||||
Context.UIService.TryRemovePanel(UIPanelType.DebugSceneChooser);
|
||||
_eventBus.Unsubscribe(this);
|
||||
EventBus.Unsubscribe(this);
|
||||
}
|
||||
|
||||
public void UILoaded(UIPanelType uiPanelType)
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace Code.Infrastructure.Camera
|
||||
public enum CameraMode
|
||||
{
|
||||
None,
|
||||
ThirdPerson
|
||||
ThirdPerson,
|
||||
Platformer
|
||||
}
|
||||
|
||||
[Config("Configs/Camera/CameraConfig")]
|
||||
|
||||
@@ -6,29 +6,11 @@ namespace Code.Infrastructure.Camera.CameraStates
|
||||
// [State(typeof(CameraMode),typeof(CameraStateMachineContext))]
|
||||
public abstract class BaseCameraState : BaseState<CameraMode, CameraStateMachineContext>
|
||||
{
|
||||
protected EventBus.EventBus _eventBus;
|
||||
|
||||
|
||||
// Трансформ объекта, за которым следует камера
|
||||
protected Transform FollowTransform;
|
||||
protected EventBus.EventBus EventBus;
|
||||
|
||||
// Позиция следования: текущая сглаженная позиция и горизонтальное направление камеры
|
||||
protected Vector3 CurrentFollowPosition;
|
||||
|
||||
// Целевой вертикальный угол камеры (наклон вверх/вниз)
|
||||
protected float TargetVerticalAngle;
|
||||
|
||||
// Текущая и целевая дистанция камеры от цели
|
||||
protected float CurrentDistance, TargetDistance;
|
||||
|
||||
// Исходные значения дистанции для восстановления
|
||||
protected float OriginalDefaultDistance, OriginalMinDistance, OriginalMaxDistance;
|
||||
|
||||
// Горизонтальное направление камеры (проекция forward на плоскость)
|
||||
protected Vector3 PlanarDirection { get; set; }
|
||||
protected BaseCameraState(CameraStateMachineContext context, EventBus.EventBus eventBus) : base(context, eventBus)
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
EventBus = eventBus;
|
||||
}
|
||||
|
||||
// Основной метод обновления камеры, вызываемый извне каждый кадр
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Code.Infrastructure.Generators;
|
||||
using Code.Infrastructure.Loadings;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Infrastructure.Camera.CameraStates
|
||||
@@ -6,6 +7,7 @@ namespace Code.Infrastructure.Camera.CameraStates
|
||||
[State(typeof(CameraMode),typeof(CameraStateMachineContext), true)]
|
||||
public partial class NoneCameraState : BaseCameraState
|
||||
{
|
||||
private Loading _loading;
|
||||
public NoneCameraState(CameraStateMachineContext context, EventBus.EventBus eventBus) : base(context, eventBus)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Code.Infrastructure.Configs
|
||||
{
|
||||
public enum LayerMaskType
|
||||
{
|
||||
PlatformerGround
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0aab84d976cf4045b47f347ad8d77c79
|
||||
timeCreated: 1770907660
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Code.Infrastructure.Generators;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace Code.Infrastructure.Configs
|
||||
{
|
||||
[Config("Configs/LayerMasksConfig", true)]
|
||||
public struct LayerMasksConfig
|
||||
{
|
||||
[ToConfig] public LayerMask mask;
|
||||
[ToConfig] public LayerMaskType type;
|
||||
}
|
||||
|
||||
public class LayerMasks
|
||||
{
|
||||
public static Dictionary<LayerMaskType, LayerMask> Masks { get; } = new();
|
||||
|
||||
private static void SetMasks(IList<LayerMasksConfigConfig> configs)
|
||||
{
|
||||
foreach (var config in configs.Where(config => !Masks.ContainsKey(config.type)))
|
||||
Masks.Add(config.type, config.mask);
|
||||
}
|
||||
|
||||
public LayerMasks(IConfigLocator configLocator, EventBus.EventBus eventBus)
|
||||
{
|
||||
SetupMasks(configLocator, eventBus).Forget();
|
||||
}
|
||||
private async UniTaskVoid SetupMasks(IConfigLocator configLocator, EventBus.EventBus eventBus)
|
||||
{
|
||||
var handle =
|
||||
Addressables.LoadAssetsAsync<LayerMasksConfigConfig>(
|
||||
configLocator.TryGetManyConfigAssetReferences<LayerMasksConfigConfig>(), null, Addressables.MergeMode.Union);
|
||||
|
||||
await handle.ToUniTask();
|
||||
|
||||
SetMasks(handle.Result);
|
||||
|
||||
Addressables.Release(handle);
|
||||
|
||||
eventBus.RaiseEvent<ILayerMasksInitializedHandle>(x => x.LayerMasksInitialized());
|
||||
}
|
||||
}
|
||||
|
||||
public interface ILayerMasksInitializedHandle : IGlobalSubscriber
|
||||
{
|
||||
void LayerMasksInitialized();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fe6e42771fc4a48a37acbe4fa992e4a
|
||||
timeCreated: 1770906616
|
||||
@@ -8,8 +8,8 @@ namespace Code.Infrastructure.Input
|
||||
void EnableMap(ActionMappings actionMap);
|
||||
void DisableMap(ActionMappings actionMap);
|
||||
void BindActionPerformed(int mapId, int actionId, Action<InputAction.CallbackContext> action);
|
||||
void BindActionCancel(int mapId, int actionId, Action<InputAction.CallbackContext> action);
|
||||
void BindActionCancelled(int mapId, int actionId, Action<InputAction.CallbackContext> action);
|
||||
void UnbindActionPerformed(int mapId, int actionId, Action<InputAction.CallbackContext> action);
|
||||
void UnbindActionCanceled(int mapId, int actionId, Action<InputAction.CallbackContext> action);
|
||||
void UnbindActionCancelled(int mapId, int actionId, Action<InputAction.CallbackContext> action);
|
||||
}
|
||||
}
|
||||
@@ -43,14 +43,14 @@ namespace Code.Infrastructure.Input
|
||||
public void BindActionPerformed(int mapId, int actionId, Action<InputAction.CallbackContext> action) => inputActionAsset
|
||||
.actionMaps[mapId].actions[actionId].performed += action;
|
||||
|
||||
public void BindActionCancel(int mapId, int actionId, Action<InputAction.CallbackContext> action) => inputActionAsset
|
||||
public void BindActionCancelled(int mapId, int actionId, Action<InputAction.CallbackContext> action) => inputActionAsset
|
||||
.actionMaps[mapId].actions[actionId].canceled += action;
|
||||
|
||||
public void UnbindActionPerformed(int mapId, int actionId, Action<InputAction.CallbackContext> action) =>
|
||||
inputActionAsset
|
||||
.actionMaps[mapId].actions[actionId].performed -= action;
|
||||
|
||||
public void UnbindActionCanceled(int mapId, int actionId, Action<InputAction.CallbackContext> action) =>
|
||||
public void UnbindActionCancelled(int mapId, int actionId, Action<InputAction.CallbackContext> action) =>
|
||||
inputActionAsset
|
||||
.actionMaps[mapId].actions[actionId].canceled -= action;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Code.Infrastructure.SceneLoader
|
||||
{
|
||||
MainMenu,
|
||||
Gameplay,
|
||||
SoundTest
|
||||
SoundTest,
|
||||
Platformer
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace Code.Infrastructure.UI.Panels
|
||||
{
|
||||
public class LoadingPanel : UIPanel
|
||||
{
|
||||
[SerializeField] private Image image;
|
||||
[SerializeField] private RawImage image;
|
||||
[SerializeField] private Color shownColor;
|
||||
[SerializeField] private Color hiddenColor;
|
||||
public override void Open(Action callback = null)
|
||||
|
||||
@@ -5,8 +5,11 @@ namespace Code.Infrastructure.UI
|
||||
Logo,
|
||||
Loading,
|
||||
DebugSceneChooser,
|
||||
// Race
|
||||
PlayerScoreCounter,
|
||||
WinScreen,
|
||||
PlayerScores,
|
||||
//
|
||||
DebugMenu
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user