1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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<BattleController>();
- if(battleController != null)
- {
- MapEditorController mapEditor = battleController.GetComponent<MapEditorController>();
- if (mapEditor == null) {
- mapEditor = battleController.gameObject.AddComponent<MapEditorController> ();
- mapEditor.CreateAStarNodeObj (battleController.GetMap ());
- }
- }
- else
- {
- Debug.LogError("Only work exist BattleController");
- }
- }
- private void SaveMap()
- {
- MapEditorController mapEditorController = GameObject.FindObjectOfType<MapEditorController> ();
- if (mapEditorController != null)
- {
- mapEditorController.save();
- AssetDatabase.ImportAsset(@"Assets/Resources/Maps/" + mapEditorController.map.id.ToString() + ".txt", ImportAssetOptions.ForceUpdate);
- }
- else
- {
- Debug.LogError("Only work exist MapEditorController");
- }
- }
- }
|