GameLogicCreator.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. namespace XGame.Framework
  3. {
  4. internal static class GameLogicCreator
  5. {
  6. public static IGameLogicProxy Create()
  7. {
  8. var config = XGameConfig.Load();
  9. var gameLogicTypeName = config?.gameLogicTypeName ?? string.Empty;
  10. XGameConfig.Unload(config);
  11. var gameLogic = CreateGameLogic(gameLogicTypeName);
  12. var proxy = new CLRGameLogicProxy(gameLogic);
  13. proxy.Init();
  14. return proxy;
  15. }
  16. private static IGameLogic CreateGameLogic(string gameLogicTypeName)
  17. {
  18. if (string.IsNullOrEmpty(gameLogicTypeName))
  19. {
  20. Log.Error($"GameLogic 名字为空. Name:{gameLogicTypeName}");
  21. return null;
  22. }
  23. var type = Type.GetType(gameLogicTypeName);
  24. if (type == null)
  25. {
  26. Log.Error($"GameLogic Type为空. Name:{gameLogicTypeName}");
  27. return null;
  28. }
  29. var instance = Activator.CreateInstance(type) as IGameLogic;
  30. if (instance == null)
  31. {
  32. Log.Error($"GameLogic 实例化失败. Name:{gameLogicTypeName}");
  33. }
  34. return instance;
  35. }
  36. }
  37. }