Great timeline system (Age of AI WON)
This commit is contained in:
1 parent
2ce0391c16
commit
e312131725
182 files changed
+380070
-470221
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.UI;
|
||||
@@ -21,11 +22,9 @@ namespace Code.OfficeGame.BattleMode.Health.UI
|
||||
[SerializeField] private Color fullColor;
|
||||
[SerializeField] private Color deadColor;
|
||||
|
||||
[SerializeField]
|
||||
[Range(0.1f,0.9f)]
|
||||
[SerializeField, Range(0.1f, 0.9f)]
|
||||
private float criticalPercent;
|
||||
|
||||
private DisposableBag _healthSubscriptions;
|
||||
|
||||
private Camera _camera;
|
||||
private Transform _target;
|
||||
|
||||
@@ -34,67 +33,70 @@ namespace Code.OfficeGame.BattleMode.Health.UI
|
||||
{
|
||||
_camera = cameraStateMachine.Camera;
|
||||
}
|
||||
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (!_target || !_camera) return;
|
||||
|
||||
Vector3 screenPos = _camera.WorldToScreenPoint(_target.position);
|
||||
|
||||
bool isVisible = screenPos.z > 0;
|
||||
|
||||
if (isVisible)
|
||||
if (screenPos.z > 0)
|
||||
transform.position = screenPos;
|
||||
}
|
||||
|
||||
public void SetTarget(Transform target)
|
||||
{
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public void SubscribeHealthPanel(EntityHealth entityHealth)
|
||||
{
|
||||
entityHealth.HealthData
|
||||
.Subscribe(SetHealthStatus)
|
||||
.AddTo(ref _healthSubscriptions);
|
||||
public void SetTarget(Transform target) => _target = target;
|
||||
|
||||
_previousHealthData = entityHealth.HealthData.CurrentValue;
|
||||
}
|
||||
|
||||
private HealthData _previousHealthData;
|
||||
|
||||
private void SetHealthStatus(HealthData healthData)
|
||||
public IDisposable BindToTimeline(BattleTimeline timeline, EntityId entityId)
|
||||
{
|
||||
if (healthData.CurrentHealth <= 0)
|
||||
var bag = new DisposableBag();
|
||||
|
||||
void Refresh()
|
||||
{
|
||||
int slot = timeline.GetSlotIndex(entityId);
|
||||
if (slot < 0 || timeline.Track.FrameCount == 0) return;
|
||||
|
||||
var viewSnap = timeline.Track.GetFrame(timeline.DisplayFrame.CurrentValue);
|
||||
var endSnap = timeline.Track.GetFrame(timeline.Track.LastFrame);
|
||||
|
||||
var viewHp = viewSnap.Entities[slot].PhysicsAndVisuals.CurrentHealth;
|
||||
var endHp = endSnap.Entities[slot].PhysicsAndVisuals.CurrentHealth;
|
||||
|
||||
ApplyHealthStatus(viewHp, endHp);
|
||||
}
|
||||
|
||||
timeline.DisplayFrame.Subscribe(_ => Refresh()).AddTo(ref bag);
|
||||
timeline.OnTrackRebaked.Subscribe(_ => Refresh()).AddTo(ref bag);
|
||||
Refresh();
|
||||
|
||||
return bag;
|
||||
}
|
||||
|
||||
private void ApplyHealthStatus(HealthData viewHp, HealthData predictedEndHp)
|
||||
{
|
||||
float max = Mathf.Max(1, viewHp.MaxHealth);
|
||||
float viewPct = Mathf.Clamp01(viewHp.CurrentHealth / max);
|
||||
float endPct = Mathf.Clamp01(predictedEndHp.CurrentHealth / max);
|
||||
|
||||
if (viewHp.CurrentHealth <= 0)
|
||||
{
|
||||
healthText.color = deadColor;
|
||||
healthText.SetText("Dead");
|
||||
|
||||
if(BattleTimeline.IsSilentSimulation)
|
||||
silentHealthBar.fillAmount = 1;
|
||||
else healthBar.fillAmount = 1;
|
||||
|
||||
healthBar.fillAmount = 0f;
|
||||
silentHealthBar.fillAmount = 0f;
|
||||
return;
|
||||
}
|
||||
|
||||
float healthPercentage = (float)healthData.CurrentHealth / healthData.MaxHealth;
|
||||
|
||||
if(BattleTimeline.IsSilentSimulation)
|
||||
if(_previousHealthData.CurrentHealth != healthData.CurrentHealth) silentHealthBar.fillAmount = healthPercentage;
|
||||
else silentHealthBar.fillAmount = 0;
|
||||
else
|
||||
{
|
||||
healthBar.fillAmount = healthPercentage;
|
||||
_previousHealthData = healthData;
|
||||
}
|
||||
// SB
|
||||
// Основной бар — HP на текущем кадре ползунка;
|
||||
// silentHealthBar — подложка прогнозируемого остатка/урона в конце превью
|
||||
healthBar.fillAmount = viewPct;
|
||||
silentHealthBar.fillAmount = predictedEndHp.CurrentHealth < viewHp.CurrentHealth ? viewPct : 0f;
|
||||
|
||||
healthText.SetText($"{healthData.CurrentHealth}/{healthData.MaxHealth}");
|
||||
// Если хотите показывать именно остаток после урона на healthBar, а потерянный кусок на silentHealthBar:
|
||||
// healthBar.fillAmount = endPct;
|
||||
// silentHealthBar.fillAmount = viewPct;
|
||||
|
||||
if (healthPercentage <= criticalPercent)
|
||||
healthBar.color = criticalColor;
|
||||
else
|
||||
healthBar.color = fullColor;
|
||||
healthText.color = Color.white;
|
||||
healthText.SetText($"{viewHp.CurrentHealth}/{viewHp.MaxHealth}");
|
||||
healthBar.color = viewPct <= criticalPercent ? criticalColor : fullColor;
|
||||
}
|
||||
|
||||
public override UniTask Open(CancellationToken cts = default)
|
||||
@@ -108,10 +110,5 @@ namespace Code.OfficeGame.BattleMode.Health.UI
|
||||
gameObject.SetActive(false);
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
_healthSubscriptions.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user