using Entitas; using UnityEngine; using Game; //死亡流程控制 public class DieSystem : IExecuteSystem, IInitializeSystem { private IGroup _entities; public void Initialize() { _entities = Util.GetGroup(GameMatcher.Hp); } public void Execute() { foreach (var entity in _entities) { UpdateDie(entity); } } private void UpdateDie(GameEntity entity) { var hp = entity.hp; if (hp.IsAlive) { return; } if (Util.IsPause(entity)) { return; } if (hp.IsDying) { hp.DyingTime -= Time.deltaTime; if (hp.DyingTime <= 0) { hp.DyingTime = 0; hp.IsDying = false; if (entity.IsMaster()) { UIManager.Instance.Open(EuiPage.Die); } else { //创建尸体特效 entity.CastShadow(1000, ECastShadowType.DeadBody); //掉落pt CreatePt(entity.Pos()); //死亡事件通知 entity.OnDie(); Util.DestroyEntity(entity); } } } else { if (entity.hasMove && !entity.move.IsGround) { return; } //死亡动画 entity.animation.DieMsg = true; //浮空 entity.move.Velocity = new Vector3((entity.move.Velocity.x > 0 ? 1 : -1) * 3, 3, 0); hp.DyingTime = GameConst.DyingTime; hp.IsDying = true; entity.view.GameObjectLogic.SetActive(false); } } private void CreatePt(Vector3 pos) { pos = new Vector3(pos.x, 0, pos.z); var count = GameRandom.Randint(0, 4); for (int i = 0; i < count; i++) { var pointPos = pos + GameRandom.RandomVector3(-0.2f, 0.2f); var dir = pointPos - pos; var cfgId = GameRandom.Roll(0.7f) ? GameConst.PtRedId : GameConst.PtBlueId; Util.CreateEntity(cfgId, (entity) => { entity.point.CastSpeed = dir; Util.SetEntityPos(entity, pointPos); }); } } }