Timeline UI

This commit is contained in:
ThomasCharester committed 2026-10-27 20:47:16 +03:00
1 parent c8626a9806
commit 2697212f05
177 files changed
+52513 -41627

No files matched your search

@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System.Threading;
using Code.OfficeGame.BattleMode.Actions;
using Code.OfficeGame.BattleMode.UI;
using Cysharp.Threading.Tasks;
using R3;
using UnityEngine;
namespace Code.OfficeGame.BattleMode.Timeline
@@ -11,23 +13,53 @@ namespace Code.OfficeGame.BattleMode.Timeline
public const int TicksPerSecond = 60;
public const float TickDelta = 1f / TicksPerSecond;
public int CurrentBattleFrame { get; private set; }
private readonly ReactiveProperty<int> _currentBattleFrame = new(0);
public ReadOnlyReactiveProperty<int> CurrentBattleFrame => _currentBattleFrame;
private readonly BattleTimelinePanel _timelinePanel;
private List<EntityTimelineActor> _entities;
private DisposableBag _battleSubscriptions;
public async UniTask RunBattleLoopAsync(List<EntityTimelineActor> entities, CancellationToken ct)
public BattleTimeline(BattleTimelinePanel timelinePanel)
{
_timelinePanel = timelinePanel;
}
public async UniTask RunBattleLoopAsync(List<EntityTimelineActor> entities, CancellationToken ctx)
{
_entities = entities;
CurrentBattleFrame = 0;
_currentBattleFrame.Value = 0;
await DecideActions(_entities, ct);
// Контейнер подписок на время текущего боя (автоматически очистится при выходе из метода)
_battleSubscriptions = new DisposableBag();
while (!IsBattleOver() && !ct.IsCancellationRequested)
try
{
List<EntityTimelineActor> entitiesNeedOrders = await PlayTimelineUntilPause(ct);
_currentBattleFrame
.Subscribe(_timelinePanel.OnFrameTick)
.AddTo(ref _battleSubscriptions);
await DecideActions(entitiesNeedOrders, ct);
foreach (var entity in entities)
entity.OnActionSet
.Subscribe(action =>
{
// Переводим длительность действия в абсолютный кадр окончания на таймлайне
action.Frame += _currentBattleFrame.Value;
_timelinePanel.SetAction(action);
})
.AddTo(ref _battleSubscriptions);
await DecideActions(_entities, ctx);
while (!IsBattleOver() && !ctx.IsCancellationRequested)
{
List<EntityTimelineActor> entitiesNeedOrders = await PlayTimelineUntilPause(ctx);
await DecideActions(entitiesNeedOrders, ctx);
}
}
finally
{
_battleSubscriptions.Dispose();
}
}
@@ -65,28 +97,21 @@ namespace Code.OfficeGame.BattleMode.Timeline
private void SimulateSingleFrame(List<EntityTimelineActor> outReadyEntities)
{
CurrentBattleFrame++;
_currentBattleFrame.Value++;
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);
}
}
Physics.Simulate(TickDelta);
Physics.SyncTransforms();
}
private bool IsBattleOver() => false;