InitSceneStartEvent_InitGame.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. Game.Scene.AddComponent<MessageComponent>();
  22. try
  23. {
  24. S2C_FetchServerTime s2CFetchServerTime = await Game.Scene.GetComponent<MessageComponent>().CallAsync<S2C_FetchServerTime>(new C2S_FetchServerTime());
  25. Log.Info($"server time is: {s2CFetchServerTime.ServerTime}");
  26. }
  27. catch (RpcException e)
  28. {
  29. Log.Error(e.ToString());
  30. }
  31. catch (Exception e)
  32. {
  33. Log.Error(e.ToString());
  34. }
  35. }
  36. }
  37. }