private void CreateNew(string name) { string path = folder; string guid = AssetDatabase.CreateFolder(path, name); path = AssetDatabase.GUIDToAssetPath(guid); name = Path.GetFileName(path); _data = ScriptableObjectUtility.CreateAsset <MapEditorData>(path, name); CaseContentGrid grid = ScriptableObjectUtility.CreateAsset <CaseContentGrid>(path, name + "_grid"); _data.Grid = grid; int colorsSize = 2; _data.Colors = new List <ColorContent>(colorsSize); for (int i = 0; i < colorsSize; i++) { _data.Colors.Add(new ColorContent((ECaseContent)i)); } mapEditor.Data = _data; _serializedData = new SerializedObject(_data); _serializedGrid = new SerializedObject(_data.Grid); }
private void Load(string fileName) { _data = AssetDatabase.LoadAssetAtPath <MapEditorData>(folder + "/" + fileName); mapEditor.Data = _data; mapEditor.Data.Grid.Bufferize(); }
//载入地图编辑器数据 private void LoadData() { UnityEngine.TextAsset s = null; #if UNITY_EDITOR s = UnityEditor.AssetDatabase.LoadAssetAtPath <TextAsset>("Assets/PublishRes/DesignTools/MapEditorData" + ".json"); allEditorData = JsonMapper.ToObject <MapEditorData>(s.text); #endif }
void OnEnable() { _instance = this; SceneView.onSceneGUIDelegate += OnScene; _data = mapEditor.Data; _showContentColors = new AnimBool(false); _showContentColors.valueChanged.AddListener(Repaint); if (_data != null) { Load(); } }
private void DrawLoad() { EditorGUILayout.HelpBox("Load the data and display its values in this window.", MessageType.Info); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Data", GUILayout.MaxWidth(60)); _data = (MapEditorData)EditorGUILayout.ObjectField(_data, typeof(MapEditorData), false); if (GUILayout.Button("Load", GUILayout.MaxWidth(100))) { Load(); } EditorGUILayout.EndHorizontal(); }
static void DisplayGizmos(MapEditorModel mapEditorModel) { MapEditorData data = mapEditorModel.Data; if (data == null) { return; } if (data.Grid.DrawGrid) { GridDrawer.DrawGizmosGrid(mapEditorModel.Data.Grid); } if (data.DrawCase) { DrawGizmosCases(mapEditorModel); } }
void OnGUI() { EditorGUILayout.Space(); mapCell = EditorGUILayout.ObjectField(mapCell, typeof(HexCell), true) as HexCell; cellLabelPrefab = EditorGUILayout.ObjectField(cellLabelPrefab, typeof(Text), true) as Text; chunkPrefab = EditorGUILayout.ObjectField(chunkPrefab, typeof(HexGridChunk), true) as HexGridChunk; noiseSource = EditorGUILayout.ObjectField(noiseSource, typeof(Texture), true) as Texture2D; mapSizeX = EditorGUILayout.IntField("地图长:", mapSizeX); mapSizeY = EditorGUILayout.IntField("地图宽:", mapSizeY); EditorGUILayout.Space(); if (GUILayout.Button("生成地图预览")) { if (mapCell == null) { Debug.LogError("没有地图格子预制体"); return; } GenerateMap(); isCreate = true; } if (isCreate) { for (int i = 0; i < HexMapEditor.HexGrid.chunks.Length; i++) { HexMapEditor.HexGrid.chunks[i].LateRefresh(); } } if (GUILayout.Button("打开怪物资源")) { SceneEditorWindow.CreateDungeonEditor(); } if (GUILayout.Button("打开地图数据编辑")) { HexMapCellTypeWindow.CreateCellTypeEditor(); } if (GUILayout.Button("保存当前场景数据到Json")) { MapEditorData.ExportJSON(); } }
public override void OnInspectorGUI() { MyMap mme = target as MyMap; s_transform = mme.gameObject.transform; serializedObject.Update(); EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Map Width is: ", EditorStyles.boldLabel); float savedLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 80; EditorGUI.indentLevel += 2; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(serializedObject.FindProperty("Width")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); mme.RecalculateMapBounds(); } EditorGUI.indentLevel -= 2; EditorGUIUtility.labelWidth = savedLabelWidth; EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Map Height is: ", EditorStyles.boldLabel); savedLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 80; EditorGUI.indentLevel += 2; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(serializedObject.FindProperty("Height")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); mme.RecalculateMapBounds(); } EditorGUI.indentLevel -= 2; EditorGUIUtility.labelWidth = savedLabelWidth; EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Map Cell size: ", EditorStyles.boldLabel); savedLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 100; EditorGUI.indentLevel += 2; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(serializedObject.FindProperty("ShowGrid")); EditorGUILayout.PropertyField(serializedObject.FindProperty("CellSize")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); mme.RecalculateMapBounds(); } EditorGUILayout.EndVertical(); if (mme.CurrentSelectedCell != null && mme.CurrentSelectedCell.CellObj != null) { EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Selected Map Cell " + mme.CurrentSelectedCell.CellObj.name, EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); SerializedProperty cellProperty = serializedObject.FindProperty("CurrentSelectedCell"); SerializedProperty statusProperty = cellProperty.FindPropertyRelative("Status"); int index = (int)mme.CurrentSelectedCell.Status; mme.CurrentSelectedCell.Status = (MapCellStatus)EditorGUILayout.Popup("格子状态:", index, Enum.GetNames(typeof(MapCellStatus))); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); mme.UpdateMapCells(); } EditorGUILayout.EndVertical(); } EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); if (mme.Width == 0 || mme.Height == 0) { EditorGUILayout.BeginVertical(); EditorGUI.indentLevel -= 2; EditorGUILayout.LabelField("Load Map Proto", EditorStyles.boldLabel); if (GUILayout.Button("Load Map Proto")) { if (mme.Width == 0 || mme.Height == 0) { string path = EditorUtility.OpenFilePanel("choose map data", "", "bytes"); if (path.Length != 0) { FileStream fs = new FileStream(path, FileMode.Open); long size = fs.Length; byte[] array = new byte[size]; fs.Read(array, 0, array.Length); fs.Close(); MapEditorData mapData = MapEditorData.Parser.ParseFrom(array); float cellW = mapData.CellWidth; float cellH = mapData.CellHeight; mme.CellSize = new Vector2(cellW, cellH); mme.Width = mapData.Width; mme.Height = mapData.Height; mme.RecalculateMapBounds(); foreach (MapEditorCellData cell in mapData.MapCells) { mme.m_mapCells[cell.X, cell.Y].Status = cell.Status; } mme.UpdateMapCells(); SceneView.RepaintAll(); } } } EditorGUILayout.EndVertical(); } else { EditorGUILayout.BeginVertical(); EditorGUI.indentLevel -= 2; EditorGUILayout.LabelField("Export to proto", EditorStyles.boldLabel); if (GUILayout.Button("Export")) { if (mme.Width == 0 || mme.Height == 0) { Debug.Log("the map is empty!!!!"); } else { MapEditorData mapEditorData = new MapEditorData(); mapEditorData.Width = mme.Width; mapEditorData.Height = mme.Height; mapEditorData.CellWidth = mme.CellSize.x; mapEditorData.CellHeight = mme.CellSize.y; for (int i = 0; i < mme.Width; i++) { for (int j = 0; j < mme.Height; j++) { MapEditorCellData cellData = new MapEditorCellData(); cellData.X = mme.m_mapCells[i, j].X; cellData.Y = mme.m_mapCells[i, j].Y; cellData.Status = mme.m_mapCells[i, j].Status; mapEditorData.MapCells.Add(cellData); } } byte[] mapArray = PackCodec.Serialize(mapEditorData); string path = EditorUtility.SaveFilePanel("save map data", "", "mapData.bytes", "bytes"); if (path.Length != 0) { FileStream fs = new FileStream(path, FileMode.Create); fs.Write(mapArray, 0, mapArray.Length); fs.Close(); } } } EditorGUILayout.EndVertical(); } }