BattleMgr_Update.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using CommonLang.Geometry;
  2. using ET.Client;
  3. using ET.EventType;
  4. using System;
  5. namespace ET
  6. {
  7. //战斗中,每一帧要干的活
  8. public partial class BattleMgr
  9. {
  10. public void doUpdate()
  11. {
  12. SyncUnitPos();
  13. }
  14. private Vector3 VecTmp = new Vector3();
  15. private void SyncUnitPos()
  16. {
  17. if(UnitMgr.Instance != null)
  18. {
  19. foreach (var obj in UnitMgr.Instance.AllUnits)
  20. {
  21. if (obj is BattleUnit unit)
  22. {
  23. var zu = unit.ZUnit;
  24. VecTmp.Set(zu.X, zu.Y, zu.Z);
  25. if (!VecTmp.Equal(unit.LastPos, 0.01f) || MathF.Abs(unit.LastRotation - zu.Direction) > 0.01f)
  26. {
  27. EventSystem.Instance.Publish<SyncUnitPosEvent>(SyncUnitPosEvent.Static.Clone(unit.Id, VecTmp, zu.Direction));
  28. unit.LastPos.Set(VecTmp);
  29. unit.LastRotation = zu.Direction;
  30. }
  31. }
  32. else if (obj is BattleSpell spell)
  33. {
  34. //TODO: spell
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }