GameLogicCreator.cs 1.1 KB

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