Timeline works YAY
This commit is contained in:
1 parent
6114192055
commit
7098d938a7
84 files changed
+96509
-51755
No files matched your search
@@ -7,6 +7,7 @@ using Code.Infrastructure.Generators;
|
||||
using Code.Infrastructure.Input;
|
||||
using Code.Infrastructure.SceneLoader;
|
||||
using Code.Infrastructure.Utils;
|
||||
using Code.OfficeGame.BattleMode.Actions.Player;
|
||||
using Code.OfficeGame.Player;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using KinematicCharacterController;
|
||||
@@ -42,14 +43,7 @@ namespace Code.Game.TestingLevel
|
||||
|
||||
await Context.Camera.SwitchState(CameraMode.OpenMovement);
|
||||
|
||||
if (Context.StateMachine.CurrentState == AppStates.BattleState)
|
||||
{
|
||||
var theContainer = Context.SceneContainerManager.ScenesContainers[SceneId.Testing];
|
||||
|
||||
ReturnPlayerControls(theContainer);
|
||||
|
||||
return;
|
||||
}
|
||||
if (Context.StateMachine.CurrentState == AppStates.BattleState) return;
|
||||
|
||||
Context.AudioService.SetAudioListener(Context.Camera.Camera.GetComponent<AudioListener>());
|
||||
|
||||
@@ -71,6 +65,7 @@ namespace Code.Game.TestingLevel
|
||||
var playerMovementController = player.GetComponent<PlayerMovementController>();
|
||||
var playerControlsProvider = player.GetComponent<PlayerControlsProvider>();
|
||||
var playerAnimatorProvider = player.GetComponent<PlayerAnimator>();
|
||||
var playerTimelineActor = player.GetComponent<PlayerTimelineActor>();
|
||||
|
||||
playerMovementController.Freeze = true;
|
||||
|
||||
@@ -84,6 +79,7 @@ namespace Code.Game.TestingLevel
|
||||
builder.RegisterValue(playerMovementController);
|
||||
builder.RegisterValue(playerControlsProvider);
|
||||
builder.RegisterValue(playerAnimatorProvider);
|
||||
builder.RegisterValue(playerTimelineActor);
|
||||
}
|
||||
|
||||
await UniTask.WhenAll(
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
public abstract class BattleAction
|
||||
{
|
||||
public bool Finished { get; protected set; }
|
||||
public abstract void Tick(float tickDelta);
|
||||
public abstract UniTask DecideAction();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9dcb8a4911af4d4eac5ec4e36ba3931e
|
||||
timeCreated: 1792691630
|
||||
@@ -0,0 +1,26 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using KinematicCharacterController;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
public class BattleActionMove : BattleAction
|
||||
{
|
||||
private NavMeshPath _path = new();
|
||||
private Vector3 _endPosition;
|
||||
public override void Tick(float tickDelta)
|
||||
{
|
||||
KinematicCharacterSystem.Simulate(
|
||||
tickDelta,
|
||||
KinematicCharacterSystem.CharacterMotors,
|
||||
KinematicCharacterSystem.PhysicsMovers
|
||||
);
|
||||
}
|
||||
|
||||
public override async UniTask DecideAction()
|
||||
{
|
||||
_endPosition = new Vector3(0,0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00995677816949ec99d2bd3546ec6597
|
||||
timeCreated: 1792691686
|
||||
@@ -0,0 +1,21 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
public class BattleActionWait : BattleAction
|
||||
{
|
||||
private int _waitFrames;
|
||||
public override void Tick(float tickDelta)
|
||||
{
|
||||
_waitFrames--;
|
||||
if (_waitFrames <= 0) Finished = true;
|
||||
}
|
||||
|
||||
public override async UniTask DecideAction()
|
||||
{
|
||||
Finished = false;
|
||||
|
||||
_waitFrames = 120;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5af678ef30f04b7093df4488ed133bff
|
||||
timeCreated: 1792691714
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
public struct BattleActionWaitParameters
|
||||
{
|
||||
public int FrameCount;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fa4aebfa3f24cc3aec7dfc2c2ffab37
|
||||
timeCreated: 1792478259
|
||||
@@ -1,19 +0,0 @@
|
||||
using Code.OfficeGame.BattleMode.Timeline;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
public static class BattleEntityActionMethods
|
||||
{
|
||||
public static TimelineBattleAction Move(EntityActionMaker entityActionMaker, Vector3 position)
|
||||
{
|
||||
|
||||
return new TimelineBattleAction(){};
|
||||
}
|
||||
public static TimelineBattleAction Wait(EntityActionMaker entityActionMaker, BattleActionWaitParameters position)
|
||||
{
|
||||
|
||||
return new TimelineBattleAction(){};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 527237749fe248a7a5cf0c357e370a4e
|
||||
timeCreated: 1792477820
|
||||
@@ -1,12 +0,0 @@
|
||||
using Code.OfficeGame.BattleMode.Timeline;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
public class EntityActionMaker : MonoBehaviour
|
||||
{
|
||||
public TimelineBattleAction TimelineCurrentAction { get; private set;}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
public abstract class EntityTimelineActor : MonoBehaviour
|
||||
{
|
||||
public BattleAction CurrentAction { get; protected set;}
|
||||
public bool Finished => CurrentAction == null || CurrentAction.Finished;
|
||||
|
||||
public abstract UniTask DecideAction(CancellationToken ct);
|
||||
|
||||
public Animator animator;
|
||||
|
||||
protected Dictionary<BattleActionType, BattleAction> BattleActions = new();
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cef19ac17a4548c891293420fafa0b3f
|
||||
timeCreated: 1792693326
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Actions.Player
|
||||
{
|
||||
public class PlayerTimelineActor : EntityTimelineActor
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
BattleActions.Add(BattleActionType.Wait, new BattleActionWait());
|
||||
}
|
||||
|
||||
public override async UniTask DecideAction(CancellationToken ct)
|
||||
{
|
||||
var decidedAction = BattleActionType.Wait; // T
|
||||
|
||||
Debug.Log("player decided to wait");
|
||||
|
||||
await BattleActions[decidedAction].DecideAction();
|
||||
|
||||
CurrentAction = BattleActions[decidedAction];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9f637cef8714ef1b5ec779d21630ebd
|
||||
timeCreated: 1792693336
|
||||
@@ -1,9 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Code.Game.Cleaning.Player;
|
||||
using Code.Infrastructure.App;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Generators;
|
||||
using Code.Infrastructure.Input;
|
||||
using Code.Infrastructure.SceneLoader;
|
||||
using Code.OfficeGame.BattleMode.Actions;
|
||||
using Code.OfficeGame.BattleMode.Actions.Player;
|
||||
using Code.OfficeGame.BattleMode.Timeline;
|
||||
using Code.OfficeGame.Player;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using KinematicCharacterController;
|
||||
@@ -22,6 +27,9 @@ namespace Code.Game.OfficeGame.GameStates
|
||||
|
||||
public override AppStates MyState => AppStates.BattleState;
|
||||
|
||||
private BattleTimeline _battleTimeline = new BattleTimeline();
|
||||
private CancellationTokenSource _battleTokenSource = new CancellationTokenSource();
|
||||
|
||||
public override async UniTask EnterState()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
@@ -37,6 +45,8 @@ namespace Code.Game.OfficeGame.GameStates
|
||||
|
||||
if (Context.StateMachine.CurrentState == AppStates.Testing)
|
||||
{
|
||||
_battleTokenSource = new();
|
||||
|
||||
Physics.simulationMode = SimulationMode.Script;
|
||||
KinematicCharacterSystem.EnsureCreation();
|
||||
KinematicCharacterSystem.Settings.AutoSimulation = false;
|
||||
@@ -46,6 +56,10 @@ namespace Code.Game.OfficeGame.GameStates
|
||||
|
||||
await Context.Camera.SwitchState(CameraMode.BattleMode);
|
||||
}
|
||||
|
||||
List<EntityTimelineActor> entities = new List<EntityTimelineActor>(){container.Resolve<PlayerTimelineActor>()};
|
||||
|
||||
_battleTimeline.RunBattleLoopAsync(entities,_battleTokenSource.Token).Forget();
|
||||
}
|
||||
|
||||
private void TogglePlayerBattleMode(Container container, bool enabled)
|
||||
@@ -62,7 +76,10 @@ namespace Code.Game.OfficeGame.GameStates
|
||||
public override async UniTask ExitState()
|
||||
{
|
||||
if (Context.StateMachine.NextState == AppStates.Testing)
|
||||
{
|
||||
{
|
||||
_battleTokenSource.Cancel();
|
||||
_battleTokenSource.Dispose();
|
||||
|
||||
Physics.simulationMode = SimulationMode.FixedUpdate;
|
||||
KinematicCharacterSystem.Settings.AutoSimulation = true;
|
||||
KinematicCharacterSystem.Settings.Interpolate = true;
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Code.OfficeGame.BattleMode.Actions;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Timeline
|
||||
{
|
||||
public class BattleTimeline
|
||||
{
|
||||
public const int TicksPerSecond = 60;
|
||||
public const float TickDelta = 1f / TicksPerSecond;
|
||||
|
||||
public int CurrentBattleFrame { get; private set; }
|
||||
|
||||
private List<EntityTimelineActor> _entities;
|
||||
|
||||
public async UniTask RunBattleLoopAsync(List<EntityTimelineActor> entities, CancellationToken ct)
|
||||
{
|
||||
_entities = entities;
|
||||
|
||||
CurrentBattleFrame = 0;
|
||||
|
||||
await DecideActions(_entities, ct);
|
||||
|
||||
while (!IsBattleOver() && !ct.IsCancellationRequested)
|
||||
{
|
||||
List<EntityTimelineActor> entitiesNeedOrders = await PlayTimelineUntilPause(ct);
|
||||
|
||||
await DecideActions(entitiesNeedOrders, ct);
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTask DecideActions(List<EntityTimelineActor> entityActionMakers, CancellationToken ct)
|
||||
{
|
||||
foreach (var entity in entityActionMakers)
|
||||
{
|
||||
Debug.Log($"Deciding action for {entity.name}");
|
||||
await entity.DecideAction(ct);
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTask<List<EntityTimelineActor>> PlayTimelineUntilPause(CancellationToken ct)
|
||||
{
|
||||
float accumulator = 0f;
|
||||
var readyEntities = new List<EntityTimelineActor>();
|
||||
|
||||
while (readyEntities.Count == 0 && !ct.IsCancellationRequested)
|
||||
{
|
||||
await UniTask.Yield(PlayerLoopTiming.Update, ct);
|
||||
|
||||
accumulator += Time.unscaledDeltaTime;
|
||||
|
||||
while (accumulator >= TickDelta)
|
||||
{
|
||||
accumulator -= TickDelta;
|
||||
SimulateSingleFrame(readyEntities);
|
||||
|
||||
if (readyEntities.Count > 0) return readyEntities;
|
||||
}
|
||||
}
|
||||
|
||||
return readyEntities;
|
||||
}
|
||||
|
||||
private void SimulateSingleFrame(List<EntityTimelineActor> outReadyEntities)
|
||||
{
|
||||
CurrentBattleFrame++;
|
||||
Debug.Log($"Current frame: {CurrentBattleFrame}");
|
||||
foreach (var entity in _entities)
|
||||
{
|
||||
entity.CurrentAction.Tick(TickDelta);
|
||||
}
|
||||
|
||||
foreach (var entity in _entities)
|
||||
{
|
||||
entity.animator.Update(TickDelta);
|
||||
}
|
||||
|
||||
Physics.Simulate(TickDelta);
|
||||
Physics.SyncTransforms();
|
||||
|
||||
foreach (var entity in _entities)
|
||||
{
|
||||
if (entity.Finished)
|
||||
{
|
||||
outReadyEntities.Add(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsBattleOver() => false;
|
||||
}
|
||||
}
|
||||
File renamed without changes.
-5
@@ -2,11 +2,6 @@ using UnityEngine;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Timeline
|
||||
{
|
||||
public class TimelineBattle
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public struct TimelineBattleAction
|
||||
{
|
||||
public int Frame;
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f275ffa891ca472d85cae21f4440d4ae
|
||||
timeCreated: 1792691865
|
||||
@@ -156,6 +156,7 @@ GameObject:
|
||||
- component: {fileID: 6013242802768923917}
|
||||
- component: {fileID: 3159895984765548440}
|
||||
- component: {fileID: 4790439060519472847}
|
||||
- component: {fileID: 7637701434054888247}
|
||||
m_Layer: 3
|
||||
m_Name: Player
|
||||
m_TagString: Player
|
||||
@@ -309,6 +310,19 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 05290340b907438c8fcb9d5f0e75624f, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::Code.OfficeGame.Player.PlayerAnimator
|
||||
--- !u!114 &7637701434054888247
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8373156178643037624}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f9f637cef8714ef1b5ec779d21630ebd, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::Code.OfficeGame.BattleMode.Actions.Player.PlayerTimelineActor
|
||||
animator: {fileID: 4090455171902986455}
|
||||
--- !u!1001 &3260788586600530971
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
Reference in new issue
Block a user