InitSceneStartEvent_InitGame.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Reflection;
  3. using Base;
  4. using UnityEngine;
  5. using Object = Base.Object;
  6. namespace Controller
  7. {
  8. /// <summary>
  9. /// 初始化游戏
  10. /// </summary>
  11. [Event(EventIdType.InitSceneStart)]
  12. public class InitSceneStartEvent_InitGame: IEvent
  13. {
  14. public async void Run()
  15. {
  16. GameObject code = (GameObject)Resources.Load("Code/Code");
  17. byte[] assBytes = code.Get<TextAsset>("Controller.dll").bytes;
  18. byte[] mdbBytes = code.Get<TextAsset>("Controller.dll.mdb").bytes;
  19. Assembly assembly = Assembly.Load(assBytes, mdbBytes);
  20. Object.ObjectManager.Register("Controller", assembly);
  21. Object.ObjectManager.Register("Base", typeof(Game).Assembly);
  22. Game.Scene.AddComponent<MessageComponent>();
  23. Game.Scene.AddComponent<ChildrenComponent>();
  24. try
  25. {
  26. S2C_FetchServerTime s2CFetchServerTime = await Game.Scene.GetComponent<MessageComponent>().CallAsync<S2C_FetchServerTime>(new C2S_FetchServerTime());
  27. Log.Info($"server time is: {s2CFetchServerTime.ServerTime}");
  28. }
  29. catch (RpcException e)
  30. {
  31. Log.Error(e.ToString());
  32. }
  33. catch (Exception e)
  34. {
  35. Log.Error(e.ToString());
  36. }
  37. }
  38. }
  39. }