MapEditor.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using UnityEditor;
  2. using UnityEngine;
  3. public class MapEditor : EditorWindow
  4. {
  5. bool groupEnabled;
  6. // Add menu item named "My Window" to the Window menu
  7. [MenuItem("BattleArray/Map Editor")]
  8. public static void ShowWindow()
  9. {
  10. //Show existing window instance. If one doesn't exist, make one.
  11. EditorWindow.GetWindow(typeof(MapEditor));
  12. }
  13. void OnGUI()
  14. {
  15. GUILayout.Label ("Map Editor", EditorStyles.boldLabel);
  16. if(GUILayout.Button("Start Edit"))
  17. {
  18. if(EditorUtility.DisplayDialog("Map Editor", "Is start edit map?", "Yes", "Cancel"))
  19. {
  20. StartEdit();
  21. }
  22. }
  23. GUILayout.Label ("Brush Size : "+MapEditorController.brushSize);
  24. MapEditorController.brushSize = (int)GUILayout.HorizontalSlider(MapEditorController.brushSize, 1f, 10f);
  25. if(GUILayout.Button("Save map data"))
  26. SaveMap();
  27. GUILayout.Label ("Chongqing DashGame Lt.", EditorStyles.boldLabel);
  28. }
  29. private void StartEdit()
  30. {
  31. BattleController battleController = GameObject.FindObjectOfType<BattleController>();
  32. if(battleController != null)
  33. {
  34. MapEditorController mapEditor = battleController.GetComponent<MapEditorController>();
  35. if (mapEditor == null) {
  36. mapEditor = battleController.gameObject.AddComponent<MapEditorController> ();
  37. mapEditor.CreateAStarNodeObj (battleController.GetMap ());
  38. }
  39. }
  40. else
  41. {
  42. Debug.LogError("Only work exist BattleController");
  43. }
  44. }
  45. private void SaveMap()
  46. {
  47. MapEditorController mapEditorController = GameObject.FindObjectOfType<MapEditorController> ();
  48. if (mapEditorController != null)
  49. {
  50. mapEditorController.save();
  51. AssetDatabase.ImportAsset(@"Assets/Resources/Maps/" + mapEditorController.map.id.ToString() + ".txt", ImportAssetOptions.ForceUpdate);
  52. }
  53. else
  54. {
  55. Debug.LogError("Only work exist MapEditorController");
  56. }
  57. }
  58. }