MapViewCodeGen.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4. using XGame.Framework.Map;
  5. using XGame.Framework.ObjectCollection;
  6. namespace XGame.Editor.Map
  7. {
  8. internal class MapViewCodeGen : CodeGenerator
  9. {
  10. public bool Gen(MapBehaviour behaviour, string componentName)
  11. {
  12. if (string.IsNullOrEmpty(componentName))
  13. {
  14. EditorUtility.DisplayDialog("代码生成错误", "Component名字不能为空!", "确认");
  15. return false;
  16. }
  17. if (!VerifyPrefab(behaviour.gameObject))
  18. {
  19. return false;
  20. }
  21. try
  22. {
  23. InitPath("Map");
  24. var mapName = ToTitleCase(behaviour.gameObject.name);
  25. if (!GenCommonCode(mapName, componentName, mapName + "View", "MapViewTemplate"))
  26. {
  27. return false;
  28. }
  29. if (!GenCommonCode(mapName, componentName, componentName + "Component", "MapComponentTemplate"))
  30. {
  31. return false;
  32. }
  33. if (!GenViewModelCode(behaviour.Collector as ObjectCollector, mapName, componentName, mapName + "VM", "MapVMTemplate"))
  34. {
  35. return false;
  36. }
  37. AssetDatabase.SaveAssets();
  38. AssetDatabase.Refresh();
  39. }
  40. catch (Exception ex)
  41. {
  42. Debug.LogException(ex);
  43. return false;
  44. }
  45. return true;
  46. }
  47. }
  48. }