CmdFactory.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. namespace XGame.Editor.Build
  3. {
  4. internal static class CmdFactory
  5. {
  6. public static IBuildCommand Create(BuildContext context)
  7. {
  8. var type = GetFirstType(context);
  9. if (type != null)
  10. {
  11. // 还有Cmd接着执行
  12. var command = Activator.CreateInstance(type) as IBuildCommand;
  13. if (command is IBuildContextAdapter adapter)
  14. {
  15. adapter.Context = context;
  16. }
  17. return command;
  18. }
  19. return null;
  20. }
  21. private static Type GetFirstType(BuildContext context)
  22. {
  23. var cmdTypeNames = context.cmdTypeNames;
  24. if (cmdTypeNames != null && cmdTypeNames.Count > 0)
  25. {
  26. var typeName = cmdTypeNames[0];
  27. var type = Type.GetType(typeName);
  28. cmdTypeNames.RemoveAt(0);
  29. return type;
  30. }
  31. return null;
  32. }
  33. }
  34. }