You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.7 KiB
56 lines
1.7 KiB
1 month ago
|
using Entitas;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace CoreGame.Render
|
||
|
{
|
||
|
public class DoDropSystem : IExecuteSystem
|
||
|
{
|
||
|
readonly IGroup<CombatEntity> m_Group;
|
||
|
public DoDropSystem(Contexts contexts)
|
||
|
{
|
||
|
// 获取所有带有DropFlag的实体,一定有dropData
|
||
|
m_Group = contexts.combat.GetGroup(CombatMatcher.DoDrop);
|
||
|
}
|
||
|
|
||
|
public void Execute(float deltaTime)
|
||
|
{
|
||
|
m_Group.GetEntities(Contexts.s_CacheEntities);
|
||
|
if (Contexts.s_CacheEntities.Count == 0)
|
||
|
return;
|
||
|
|
||
|
var entities = Contexts.s_CacheEntities;
|
||
|
for (int i = 0; i < entities.Count; i++)
|
||
|
{
|
||
|
DropItem(entities[i], deltaTime);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void DropItem(CombatEntity entity, float dt)
|
||
|
{
|
||
|
var doDrop = entity.doDrop;
|
||
|
doDrop.accTime += dt;
|
||
|
if (doDrop.accTime > doDrop.duration)
|
||
|
{
|
||
|
entity.RemoveDoDrop();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var et = entity.transformProxy;
|
||
|
if (et == null)
|
||
|
return;
|
||
|
|
||
|
var t = doDrop.accTime / doDrop.duration;
|
||
|
var start = doDrop.startPos;
|
||
|
var end = doDrop.targetPos;
|
||
|
var pos = Mathf.Pow(1 - t, 2) * start + 2 * t * (1 - t) * doDrop.bezierCtrl1 + Mathf.Pow(t, 2) * end;
|
||
|
et.SetPosition(pos);
|
||
|
var lerp = Mathf.Lerp(doDrop.startScale, doDrop.targetScale, doDrop.accTime / doDrop.duration);
|
||
|
et.SetLocalScale(Vector2.one * lerp);
|
||
|
// if (BattleModule.Instance.worldType != WorldType.Battle)
|
||
|
{
|
||
|
et.Sync();
|
||
|
et.Flush();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|