using UnityEditor; using UnityEngine; public class MapEditor : EditorWindow { bool groupEnabled; // Add menu item named "My Window" to the Window menu [MenuItem("BattleArray/Map Editor")] public static void ShowWindow() { //Show existing window instance. If one doesn't exist, make one. EditorWindow.GetWindow(typeof(MapEditor)); } void OnGUI() { GUILayout.Label ("Map Editor", EditorStyles.boldLabel); if(GUILayout.Button("Start Edit")) { if(EditorUtility.DisplayDialog("Map Editor", "Is start edit map?", "Yes", "Cancel")) { StartEdit(); } } GUILayout.Label ("Brush Size : "+MapEditorController.brushSize); MapEditorController.brushSize = (int)GUILayout.HorizontalSlider(MapEditorController.brushSize, 1f, 10f); if(GUILayout.Button("Save map data")) SaveMap(); GUILayout.Label ("Chongqing DashGame Lt.", EditorStyles.boldLabel); } private void StartEdit() { BattleController battleController = GameObject.FindObjectOfType(); if(battleController != null) { MapEditorController mapEditor = battleController.GetComponent(); if (mapEditor == null) { mapEditor = battleController.gameObject.AddComponent (); mapEditor.CreateAStarNodeObj (battleController.GetMap ()); } } else { Debug.LogError("Only work exist BattleController"); } } private void SaveMap() { MapEditorController mapEditorController = GameObject.FindObjectOfType (); if (mapEditorController != null) { mapEditorController.save(); AssetDatabase.ImportAsset(@"Assets/Resources/Maps/" + mapEditorController.map.id.ToString() + ".txt", ImportAssetOptions.ForceUpdate); } else { Debug.LogError("Only work exist MapEditorController"); } } }