Entry.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Threading;
  3. namespace ET.Client
  4. {
  5. public static class Entry
  6. {
  7. public static void Start()
  8. {
  9. StartAsync().Coroutine();
  10. }
  11. private static async ETTask StartAsync()
  12. {
  13. try
  14. {
  15. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  16. {
  17. Log.Error(e.ExceptionObject.ToString());
  18. };
  19. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  20. CodeLoader.Instance.Update += Game.Update;
  21. CodeLoader.Instance.LateUpdate += Game.LateUpdate;
  22. CodeLoader.Instance.OnApplicationQuit += Game.Close;
  23. MongoHelper.Register(Game.EventSystem.GetTypes());
  24. Game.ILog = new UnityLogger();
  25. ETTask.ExceptionHandler += Log.Error;
  26. Options.Instance = new Options();
  27. await Game.EventSystem.Callback<ETTask>(CallbackType.InitShare);
  28. switch (CodeLoader.Instance.GlobalConfig.CodeMode)
  29. {
  30. case CodeMode.Client:
  31. await Game.EventSystem.Callback<ETTask>(CallbackType.InitClient);
  32. break;
  33. case CodeMode.Server:
  34. await Game.EventSystem.Callback<ETTask>(CallbackType.InitServer);
  35. break;
  36. case CodeMode.ClientServer:
  37. await Game.EventSystem.Callback<ETTask>(CallbackType.InitServer);
  38. await Game.EventSystem.Callback<ETTask>(CallbackType.InitClient);
  39. break;
  40. default:
  41. throw new ArgumentOutOfRangeException();
  42. }
  43. Log.Info("Init Finish!");
  44. }
  45. catch (Exception e)
  46. {
  47. Log.Error(e);
  48. }
  49. }
  50. }
  51. }