BattleObject.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using CommonAI.ZoneClient;
  2. using ET;
  3. using ET.Client;
  4. using ET.EventType;
  5. public class BattleObject
  6. {
  7. protected ZoneObject ZoneObject;
  8. public uint Id { get { return ZoneObject.ObjectID; } }
  9. public BattleObject() { }
  10. public virtual void OnAwake(ZoneObject zo)
  11. {
  12. ZoneObject = zo;
  13. EventSystem.Instance.Publish(CurrentScene, new OnNewZoneObject() { Object = this });
  14. }
  15. public virtual void OnSleep()
  16. {
  17. AsyncSleep().Coroutine();
  18. }
  19. protected async ETTask AsyncSleep()
  20. {
  21. await EventSystem.Instance.PublishAsync(CurrentScene, new OnDestroyZoneObject() { Object = this });
  22. ObjectPool.Instance.Recycle(this);
  23. }
  24. private static Scene _CurrentSceneCache = null;
  25. public static Scene CurrentScene
  26. {
  27. get
  28. {
  29. if (_CurrentSceneCache == null)
  30. {
  31. var cs = ClientSceneManagerComponent.Instance.GetChild<Scene>(UnitListComponent.Instance.DomainZone());
  32. _CurrentSceneCache = cs.GetComponent<CurrentScenesComponent>().Scene;
  33. }
  34. return _CurrentSceneCache;
  35. }
  36. }
  37. [Event(SceneType.Current)]
  38. public class AfterCreateCurrentScene_Battle : AEvent<ET.EventType.AfterCreateCurrentScene>
  39. {
  40. protected override async ETTask Run(Scene scene, ET.EventType.AfterCreateCurrentScene args)
  41. {
  42. _CurrentSceneCache = scene;
  43. await ETTask.CompletedTask;
  44. }
  45. }
  46. }