InitSceneStartEvent_InitGame.cs 1.1 KB

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