using UnityEngine; using System.IO; using System.Collections.Generic; namespace H2Engine { [System.Serializable] public class MapData { public const string MapEditorData_Suffix = "MapData_"; public int id; public MapTrigger[] triggers; public Dictionary eventDict = new Dictionary(); public MapTrasfer[] transfers; public static MapData LoadFormFile(int mapID) { string _path = null; if (AssetSource.refdataFromEditor) { #if UNITY_EDITOR _path = StringUtility.Contact(ResourcesPath.CONFIG_FODLER, "/", MapEditorData_Suffix, mapID, ".txt"); #endif } else { _path = AssetVersionUtility.GetAssetFilePath(StringUtility.Contact("config/", MapEditorData_Suffix, mapID, ".txt")); } MapData _mapData = null; if (File.Exists(_path)) { using (var _fileStream = File.OpenRead(_path)) { using (var _br = new BinaryReader(_fileStream)) { _mapData = new MapData(); _mapData.Load(_br); } } } return _mapData; } public void Load(BinaryReader br) { id = br.ReadInt32(); int _count = br.ReadInt32(); triggers = new MapTrigger[_count]; for (int i = 0; i < _count; ++i) { triggers[i] = new MapTrigger(); triggers[i].Load(br); } _count = br.ReadInt32(); for (int i = 0; i < _count; ++i) { var _type = (Evt.E_EventType)br.ReadByte(); Evt _event = null; if (_type == Evt.E_EventType.Enemy) { _event = new Evt_RefreshMonster(); } else if (_type == Evt.E_EventType.SceneObject) { _event = new Evt_RefreshSceneObject(); } if (_event != null) { _event.type = _type; _event.Load(br); eventDict[_event.id] = _event; } } _count = br.ReadInt32(); transfers = new MapTrasfer[_count]; for (int i = 0; i < _count; ++i) { transfers[i] = new MapTrasfer(); transfers[i].Load(br); } } } }