├── .gitignore ├── Assets ├── Code │ ├── AHInt.cs │ ├── DataStream.cs │ ├── Editor │ │ ├── LevelOptionInspector.cs │ │ ├── LogPosition.cs │ │ ├── MELoadLevelData.cs │ │ ├── MESaveLevelData.cs │ │ └── MapEditor.cs │ ├── MapObj │ │ ├── LevelOption.cs │ │ ├── MSBaseObject.cs │ │ ├── MSBaseObjectData.cs │ │ └── MSLevelOptionDataModel.cs │ ├── Test.cs │ └── Tools.cs ├── Plugins │ ├── LitJson.dll │ └── SharpZipLib.dll ├── Resources │ ├── LevelData │ │ ├── level2.lmd │ │ └── newlevel.lmd │ └── Prefabs │ │ └── MapObj │ │ ├── cube.prefab │ │ └── sphere.prefab └── Test.unity └── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset └── UnityConnectSettings.asset /.gitignore: -------------------------------------------------------------------------------- 1 | ty generated # 2 | 3 | iosclient/ 4 | # =============== # 5 | [Tt]emp/ 6 | [Oo]bj/ 7 | UnityGenerated/ 8 | [Bb]uild/ 9 | [Ll]ibrary/ 10 | UWP/ 11 | # ===================================== # 12 | # Visual Studio / MonoDevelop generated # 13 | # ===================================== # 14 | ExportedObj/ 15 | *.svd 16 | *.userprefs 17 | *.csproj 18 | *.pidb 19 | *.suo 20 | *.sln 21 | *.svd 22 | *.user 23 | *.unityproj 24 | *.tmp 25 | *.booproj 26 | 27 | 28 | # Unity3D Generated File On Crash Reports 29 | sysinfo.txt 30 | *.meta 31 | 32 | # ============ # 33 | # OS generated # 34 | # ============ # 35 | .DS_Store 36 | .DS_Store? 37 | ._* 38 | .Spotlight-V100 39 | .Trashes 40 | Icon? 41 | ehthumbs.db 42 | Thumbs.db -------------------------------------------------------------------------------- /Assets/Code/AHInt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public struct AHInt 4 | { 5 | private static int cryptoKey = 963852; 6 | 7 | private int currentCryptoKey; 8 | private int hiddenValue; 9 | 10 | public int v 11 | { 12 | get { return InternalEncryptDecrypt(); } 13 | set { currentCryptoKey = cryptoKey; hiddenValue = EncryptDecrypt(value); } 14 | } 15 | 16 | public AHInt(int value) 17 | { 18 | currentCryptoKey = cryptoKey; 19 | hiddenValue = EncryptDecrypt(value); 20 | } 21 | 22 | public static void SetNewCryptoKey(int newKey) 23 | { 24 | cryptoKey = newKey; 25 | } 26 | 27 | public int GetEncrypted() 28 | { 29 | if (currentCryptoKey != cryptoKey) 30 | { 31 | hiddenValue = InternalEncryptDecrypt(); 32 | hiddenValue = EncryptDecrypt(hiddenValue, cryptoKey); 33 | currentCryptoKey = cryptoKey; 34 | } 35 | return hiddenValue; 36 | } 37 | 38 | public void SetEncrypted(int encrypted) 39 | { 40 | hiddenValue = encrypted; 41 | } 42 | 43 | public static int EncryptDecrypt(int value) 44 | { 45 | return EncryptDecrypt(value, 0); 46 | } 47 | 48 | public static int EncryptDecrypt(int value, int key) 49 | { 50 | if (key == 0) 51 | { 52 | return value ^ cryptoKey; 53 | } 54 | else 55 | { 56 | return value ^ key; 57 | } 58 | } 59 | 60 | private int InternalEncryptDecrypt() 61 | { 62 | int key = cryptoKey; 63 | 64 | if (currentCryptoKey != cryptoKey) 65 | { 66 | key = currentCryptoKey; 67 | } 68 | 69 | return EncryptDecrypt(hiddenValue, key); 70 | } 71 | 72 | 73 | // Operators 74 | 75 | public static implicit operator AHInt(int value) 76 | { 77 | return new AHInt(value); 78 | } 79 | 80 | public static implicit operator int(AHInt value) 81 | { 82 | return value.v; 83 | } 84 | 85 | public static AHInt operator ++ (AHInt input) 86 | { 87 | input.hiddenValue = EncryptDecrypt(input.InternalEncryptDecrypt() + 1); 88 | return input; 89 | } 90 | 91 | public static AHInt operator -- (AHInt input) 92 | { 93 | input.hiddenValue = EncryptDecrypt(input.InternalEncryptDecrypt() - 1); 94 | return input; 95 | } 96 | 97 | public static AHInt operator + (AHInt a, AHInt b) { return new AHInt(a.v + b.v); } 98 | public static AHInt operator - (AHInt a, AHInt b) { return new AHInt(a.v - b.v); } 99 | public static AHInt operator * (AHInt a, AHInt b) { return new AHInt(a.v * b.v); } 100 | public static AHInt operator / (AHInt a, AHInt b) { return new AHInt(a.v / b.v); } 101 | 102 | public static AHInt operator + (AHInt a, int b) { return new AHInt(a.v + b); } 103 | public static AHInt operator - (AHInt a, int b) { return new AHInt(a.v - b); } 104 | public static AHInt operator * (AHInt a, int b) { return new AHInt(a.v * b); } 105 | public static AHInt operator / (AHInt a, int b) { return new AHInt(a.v / b); } 106 | 107 | public static AHInt operator + (int a, AHInt b) { return new AHInt(a + b.v); } 108 | public static AHInt operator - (int a, AHInt b) { return new AHInt(a - b.v); } 109 | public static AHInt operator * (int a, AHInt b) { return new AHInt(a * b.v); } 110 | public static AHInt operator / (int a, AHInt b) { return new AHInt(a / b.v); } 111 | 112 | public static int operator * (AHInt a, float b) { return (int)(a.v * b); } //@ 113 | 114 | public static bool operator < (AHInt a, AHInt b) { return a.v < b.v; } 115 | public static bool operator <= (AHInt a, AHInt b) { return a.v <= b.v; } 116 | public static bool operator > (AHInt a, AHInt b) { return a.v > b.v; } 117 | public static bool operator >= (AHInt a, AHInt b) { return a.v >= b.v; } 118 | 119 | public static bool operator < (AHInt a, int b) { return a.v < b; } 120 | public static bool operator <= (AHInt a, int b) { return a.v <= b; } 121 | public static bool operator > (AHInt a, int b) { return a.v > b; } 122 | public static bool operator >= (AHInt a, int b) { return a.v >= b; } 123 | 124 | public override bool Equals(object o) 125 | { 126 | if (o is AHInt) 127 | { 128 | AHInt b = (AHInt)o; 129 | return this.v == b.v; 130 | } 131 | else 132 | { 133 | return false; 134 | } 135 | } 136 | 137 | public bool Equals(AHInt b) 138 | { 139 | return (object)b != null && v == b.v; 140 | } 141 | 142 | public override int GetHashCode() 143 | { 144 | return v.GetHashCode(); 145 | } 146 | 147 | public override string ToString() 148 | { 149 | return InternalEncryptDecrypt().ToString(); 150 | } 151 | 152 | public string ToString(string format) 153 | { 154 | return InternalEncryptDecrypt().ToString(format); 155 | } 156 | 157 | #if !UNITY_FLASH 158 | public string ToString(IFormatProvider provider) 159 | { 160 | return InternalEncryptDecrypt().ToString(provider); 161 | } 162 | 163 | public string ToString(string format, IFormatProvider provider) 164 | { 165 | return InternalEncryptDecrypt().ToString(format, provider); 166 | } 167 | #endif 168 | } 169 | -------------------------------------------------------------------------------- /Assets/Code/DataStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using UnityEngine; 4 | 5 | public class DataStream 6 | { 7 | private BinaryReader mBinReader; 8 | private BinaryWriter mBinWriter; 9 | private MemoryStream mMemStream; 10 | private bool mBEMode;//big endian mode 11 | 12 | public DataStream(bool isBigEndian) 13 | { 14 | mMemStream = new MemoryStream(); 15 | InitWithMemoryStream(mMemStream, isBigEndian); 16 | } 17 | 18 | public DataStream(byte[] buffer, bool isBigEndian) 19 | { 20 | mMemStream = new MemoryStream(buffer); 21 | InitWithMemoryStream(mMemStream, isBigEndian); 22 | } 23 | 24 | public DataStream(byte[] buffer, int index, int count, bool isBigEndian) 25 | { 26 | mMemStream = new MemoryStream(buffer, index, count); 27 | InitWithMemoryStream(mMemStream, isBigEndian); 28 | } 29 | 30 | private void InitWithMemoryStream(MemoryStream ms, bool isBigEndian) 31 | { 32 | mBinReader = new BinaryReader(mMemStream); 33 | mBinWriter = new BinaryWriter(mMemStream); 34 | mBEMode = isBigEndian; 35 | } 36 | 37 | public void Close() 38 | { 39 | mMemStream.Close(); 40 | mBinReader.Close(); 41 | mBinWriter.Close(); 42 | } 43 | 44 | public void SetBigEndian(bool isBigEndian) 45 | { 46 | mBEMode = isBigEndian; 47 | } 48 | 49 | public bool IsBigEndian() 50 | { 51 | return mBEMode; 52 | } 53 | 54 | public long Position 55 | { 56 | get 57 | { 58 | return mMemStream.Position; 59 | } 60 | set 61 | { 62 | mMemStream.Position = value; 63 | } 64 | } 65 | 66 | public long Length 67 | { 68 | get 69 | { 70 | return mMemStream.Length; 71 | } 72 | } 73 | 74 | public byte[] ToByteArray() 75 | { 76 | return mMemStream.ToArray(); 77 | } 78 | 79 | 80 | 81 | public long Seek(long offset, SeekOrigin loc) 82 | { 83 | return mMemStream.Seek(offset, loc); 84 | } 85 | 86 | public void WriteRaw(byte[] bytes) 87 | { 88 | mBinWriter.Write(bytes); 89 | } 90 | 91 | public void WriteRaw(byte[] bytes, int offset, int count) 92 | { 93 | mBinWriter.Write(bytes, offset, count); 94 | } 95 | 96 | public void WriteByte(byte value) 97 | { 98 | mBinWriter.Write(value); 99 | } 100 | 101 | public byte ReadByte() 102 | { 103 | return mBinReader.ReadByte(); 104 | } 105 | 106 | public void WriteInt16(UInt16 value) 107 | { 108 | WriteInteger(BitConverter.GetBytes(value)); 109 | } 110 | 111 | public UInt16 ReadInt16() 112 | { 113 | UInt16 val = mBinReader.ReadUInt16(); 114 | if (mBEMode) 115 | return BitConverter.ToUInt16(FlipBytes(BitConverter.GetBytes(val)), 0); 116 | return val; 117 | } 118 | 119 | public void WriteInt32(UInt32 value) 120 | { 121 | WriteInteger(BitConverter.GetBytes(value)); 122 | } 123 | 124 | public UInt32 ReadInt32() 125 | { 126 | UInt32 val = mBinReader.ReadUInt32(); 127 | if (mBEMode) 128 | return BitConverter.ToUInt32(FlipBytes(BitConverter.GetBytes(val)), 0); 129 | return val; 130 | } 131 | 132 | public void WriteInt64(UInt64 value) 133 | { 134 | WriteInteger(BitConverter.GetBytes(value)); 135 | } 136 | 137 | public UInt64 ReadInt64() 138 | { 139 | UInt64 val = mBinReader.ReadUInt64(); 140 | if (mBEMode) 141 | return BitConverter.ToUInt64(FlipBytes(BitConverter.GetBytes(val)), 0); 142 | return val; 143 | } 144 | 145 | public void WriteString8(string value) 146 | { 147 | System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); 148 | byte[] bytes = encoding.GetBytes(value); 149 | mBinWriter.Write((byte)bytes.Length); 150 | mBinWriter.Write(bytes); 151 | } 152 | 153 | public string ReadString8() 154 | { 155 | int len = ReadByte(); 156 | byte[] bytes = mBinReader.ReadBytes(len); 157 | System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); 158 | return encoding.GetString(bytes); 159 | } 160 | 161 | public void WriteString16(string value) 162 | { 163 | System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); 164 | byte[] data = encoding.GetBytes(value); 165 | WriteInteger(BitConverter.GetBytes((Int16)data.Length)); 166 | mBinWriter.Write(data); 167 | } 168 | 169 | public string ReadString16() 170 | { 171 | ushort len = ReadInt16(); 172 | byte[] bytes = mBinReader.ReadBytes(len); 173 | System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); 174 | return encoding.GetString(bytes); 175 | } 176 | 177 | private void WriteInteger(byte[] bytes) 178 | { 179 | if (mBEMode) 180 | FlipBytes(bytes); 181 | mBinWriter.Write(bytes); 182 | } 183 | 184 | private byte[] FlipBytes(byte[] bytes) 185 | { 186 | for (int i = 0, j = bytes.Length - 1; i < j; ++i, --j) 187 | { 188 | byte temp = bytes[i]; 189 | bytes[i] = bytes[j]; 190 | bytes[j] = temp; 191 | } 192 | return bytes; 193 | } 194 | 195 | public void WriteSByte(sbyte value) 196 | { 197 | mBinWriter.Write(value); 198 | } 199 | 200 | public sbyte ReadSByte() 201 | { 202 | return mBinReader.ReadSByte(); 203 | } 204 | 205 | public void WriteSInt16(Int16 value) 206 | { 207 | WriteInteger(BitConverter.GetBytes(value)); 208 | } 209 | 210 | public Int16 ReadSInt16() 211 | { 212 | Int16 val = mBinReader.ReadInt16(); 213 | if (mBEMode) 214 | return BitConverter.ToInt16(FlipBytes(BitConverter.GetBytes(val)), 0); 215 | return val; 216 | } 217 | 218 | public void WriteSInt32(Int32 value) 219 | { 220 | WriteInteger(BitConverter.GetBytes(value)); 221 | } 222 | 223 | public Int32 ReadSInt32() 224 | { 225 | Int32 val = mBinReader.ReadInt32(); 226 | if (mBEMode) 227 | return BitConverter.ToInt32(FlipBytes(BitConverter.GetBytes(val)), 0); 228 | return val; 229 | } 230 | 231 | public void WriteSInt64(Int64 value) 232 | { 233 | WriteInteger(BitConverter.GetBytes(value)); 234 | } 235 | 236 | public Int64 ReadSInt64() 237 | { 238 | Int64 val = mBinReader.ReadInt64(); 239 | if (mBEMode) 240 | return BitConverter.ToInt64(FlipBytes(BitConverter.GetBytes(val)), 0); 241 | return val; 242 | } 243 | 244 | public void WriteUByte(byte value) 245 | { 246 | mBinWriter.Write(value); 247 | } 248 | 249 | public byte ReadUByte() 250 | { 251 | return mBinReader.ReadByte(); 252 | } 253 | 254 | public void WriteUInt16(UInt16 value) 255 | { 256 | WriteInteger(BitConverter.GetBytes(value)); 257 | } 258 | 259 | public UInt16 ReadUInt16() 260 | { 261 | UInt16 val = mBinReader.ReadUInt16(); 262 | if (mBEMode) 263 | return BitConverter.ToUInt16(FlipBytes(BitConverter.GetBytes(val)), 0); 264 | return val; 265 | } 266 | 267 | public void WriteUInt32(UInt32 value) 268 | { 269 | WriteInteger(BitConverter.GetBytes(value)); 270 | } 271 | 272 | public UInt32 ReadUInt32() 273 | { 274 | UInt32 val = mBinReader.ReadUInt32(); 275 | if (mBEMode) 276 | return BitConverter.ToUInt32(FlipBytes(BitConverter.GetBytes(val)), 0); 277 | return val; 278 | } 279 | 280 | public void WriteUInt64(UInt64 value) 281 | { 282 | WriteInteger(BitConverter.GetBytes(value)); 283 | } 284 | 285 | public UInt64 ReadUInt64() 286 | { 287 | UInt64 val = mBinReader.ReadUInt64(); 288 | if (mBEMode) 289 | return BitConverter.ToUInt64(FlipBytes(BitConverter.GetBytes(val)), 0); 290 | return val; 291 | } 292 | } -------------------------------------------------------------------------------- /Assets/Code/Editor/LevelOptionInspector.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | 6 | //[CustomEditor(typeof(LevelOption))] 7 | public class LevelOptionInspector : Editor { 8 | LevelOption lo; 9 | 10 | void OnEnable() 11 | { 12 | //获取当前编辑自定义Inspector的对象 13 | lo = (LevelOption)target; 14 | } 15 | 16 | 17 | public override void OnInspectorGUI() 18 | { 19 | //设置整个界面是以垂直方向来布局 20 | EditorGUILayout.BeginVertical(); 21 | 22 | //空两行 23 | EditorGUILayout.Space(); 24 | EditorGUILayout.Space(); 25 | // public string levelName = ""; 26 | 27 | //public float version = 0.0f; 28 | 29 | //public float width = 1.0f; 30 | //public float height = 1.0f; 31 | 32 | //public int mapHeight = 10; 33 | //public int mapWidth = 100; 34 | lo.levelName = EditorGUILayout.TextField("关卡名称", lo.levelName); 35 | lo.version = EditorGUILayout.FloatField("版本号", lo.version); 36 | 37 | //任务列表 38 | int count = EditorGUILayout.IntField("任务数量", lo.missionList.Count); 39 | 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Assets/Code/Editor/LogPosition.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEditor; 5 | 6 | public class LogPosition : EditorWindow { 7 | 8 | //最终输出的数据 9 | static string logtext; 10 | 11 | //增加菜单栏选项 12 | [MenuItem("LOGPOSITION/LOG")] 13 | public static void OpenLoadLevel(){ 14 | //重置数据 15 | logtext = ""; 16 | //获取编辑器中当前选中的物体 17 | GameObject obj = Selection.activeGameObject; 18 | 19 | //如果没有选择任何物体,弹出提示并退出 20 | if(obj == null){ 21 | EditorUtility.DisplayDialog("ERROR", "No select obj!!", "ENTRY"); 22 | return; 23 | } 24 | 25 | //遍历所有子物体,并记录数据 26 | ForeachObjAndSave(obj); 27 | Debug.Log(logtext); 28 | 29 | //复制到剪贴板 30 | TextEditor editor = new TextEditor(); 31 | editor.content = new GUIContent(logtext); 32 | editor.SelectAll(); 33 | editor.Copy(); 34 | } 35 | 36 | //遍历所有子物体 37 | static void ForeachObjAndSave(GameObject obj){ 38 | foreach (Transform child in obj.transform) 39 | { 40 | logtext+= (child.localPosition.x + "," + child.localPosition.y + "," + child.localPosition.z + "\n"); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Assets/Code/Editor/MELoadLevelData.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | using UnityEditor; 5 | using System.IO; 6 | using System.Collections.Generic; 7 | 8 | using LitJson; 9 | 10 | public class MELoadLevelData : EditorWindow { 11 | 12 | public static List fileDataList = new List(); 13 | 14 | public Vector2 scrollPosition = Vector2.zero; 15 | 16 | void Awake() 17 | { 18 | title = "载入关卡"; 19 | } 20 | 21 | [MenuItem("关卡编辑器/载入关卡")] 22 | public static void OpenLoadLevel(){ 23 | fileDataList.Clear(); 24 | 25 | string[] files = Directory.GetFiles(Tools.GetLevelDataFilePath("")); 26 | for(int i = 0 ; i < files.Length ; i++){ 27 | string[] fileFolders = files[i].Split('/'); 28 | 29 | string[] filenames = fileFolders[fileFolders.Length - 1].Split('.'); 30 | 31 | if(filenames.Length == 2){ 32 | if(filenames[1] == "lmd"){ 33 | fileDataList.Add(filenames[0]); 34 | } 35 | } 36 | 37 | } 38 | Open(); 39 | } 40 | 41 | [MenuItem("关卡编辑器/新关卡")] 42 | public static void NewLevel(){ 43 | MSLevelOptionDataModel od = new MSLevelOptionDataModel(); 44 | od.version = Tools.GAME_DATA_VERSION; 45 | od.levelName = "newlevel"; 46 | od.mapWidth = 100; 47 | od.mapHeight = 100; 48 | 49 | 50 | List delarr = new List(); 51 | bool isfind = false; 52 | foreach (GameObject sceneObject in Object.FindObjectsOfType(typeof(GameObject))){ 53 | if( sceneObject.name == "LevelOption"){ 54 | LevelOption me = sceneObject.GetComponent(); 55 | od.SetLevelOption(me); 56 | Tools.GAME_DATA_VERSION = od.version; 57 | 58 | isfind = true; 59 | }else if(sceneObject.name != "Main Camera"){ 60 | delarr.Add(sceneObject); 61 | 62 | } 63 | } 64 | foreach(GameObject obj in delarr){ 65 | DestroyImmediate(obj); 66 | } 67 | if(!isfind){ 68 | GameObject tGO = new GameObject("LevelOption"); 69 | LevelOption lo = tGO.AddComponent(); 70 | od.SetLevelOption(lo); 71 | Tools.GAME_DATA_VERSION = od.version; 72 | } 73 | } 74 | 75 | public static EditorWindow Open() 76 | { 77 | MELoadLevelData window = (MELoadLevelData)GetWindow(); 78 | window.Show(); 79 | return window; 80 | } 81 | 82 | public static EditorWindow Closeed(){ 83 | MELoadLevelData window = (MELoadLevelData)GetWindow(); 84 | window.Close(); 85 | return window; 86 | } 87 | 88 | void OnGUI() 89 | { 90 | scrollPosition = GUILayout.BeginScrollView( 91 | scrollPosition, 92 | GUILayout.Width(position.width), 93 | GUILayout.Height(position.height) 94 | ); 95 | 96 | 97 | for(int i = 0 ;i < fileDataList.Count ; i ++){ 98 | if (GUILayout.Button(fileDataList[i], GUILayout.Width(220), GUILayout.Height(32))) 99 | { 100 | SelectLevel(i); 101 | } 102 | } 103 | GUILayout.EndScrollView(); 104 | 105 | } 106 | 107 | void SelectLevel(int index){ 108 | Debug.Log("sel index : " + index); 109 | LoadLevel(fileDataList[index]); 110 | } 111 | 112 | public void ReloadScene(DataStream datastream){ 113 | 114 | Debug.Log("ReloadScene"); 115 | 116 | MSLevelOptionDataModel od = new MSLevelOptionDataModel(); 117 | od.deserialize(datastream); 118 | //od.version = (float)datastream.ReadSInt32() / 10000f; 119 | //od.levelName = datastream.ReadString16(); 120 | //od.mapWidth = datastream.ReadSInt32(); 121 | //od.mapHeight = datastream.ReadSInt32(); 122 | 123 | 124 | List delarr = new List(); 125 | LevelOption me = null; 126 | foreach (GameObject sceneObject in Object.FindObjectsOfType(typeof(GameObject))){ 127 | if( sceneObject.name == "LevelOption"){ 128 | me = sceneObject.GetComponent(); 129 | od.SetLevelOption(me); 130 | 131 | Tools.GAME_DATA_VERSION = od.version; 132 | }else if(sceneObject.name != "Main Camera" && sceneObject.name != "Directional light"){ 133 | delarr.Add(sceneObject); 134 | } 135 | } 136 | 137 | //创建关卡配置物体 138 | if(me == null){ 139 | GameObject tGO = new GameObject("LevelOption"); 140 | me = tGO.AddComponent(); 141 | od.SetLevelOption(me); 142 | Tools.GAME_DATA_VERSION = od.version; 143 | } 144 | 145 | foreach(GameObject obj in delarr){ 146 | DestroyImmediate(obj); 147 | } 148 | int objcount = datastream.ReadSInt32(); 149 | 150 | Dictionary dic = new Dictionary(); 151 | Debug.Log("objcount : " + objcount); 152 | for(int i = 0 ; i < objcount ;i ++){ 153 | //MSBaseObject.CreateObj(datastream); 154 | //从字节流中获取id 155 | int type = datastream.ReadSInt32(); 156 | string id = datastream.ReadString16(); 157 | 158 | GameObject go; 159 | 160 | if(type == -1){ 161 | //组物体 162 | go = new GameObject("LevelOption"); 163 | }else{ 164 | 165 | Object tempObj = Resources.Load("Prefabs/MapObj/" + id) as GameObject; 166 | if (tempObj == null) { 167 | Debug.Log(type + "/" + id + " is null!"); 168 | } 169 | go = (GameObject)Instantiate(tempObj); 170 | } 171 | 172 | MSBaseObject baseobj = go.GetComponent(); 173 | 174 | if(baseobj == null){ 175 | baseobj = go.AddComponent(); 176 | } 177 | //baseobj.itemtype = type; 178 | baseobj.itemid = id; 179 | 180 | baseobj.Deserialize(datastream); 181 | baseobj.init() ; 182 | 183 | 184 | if(dic.ContainsKey(baseobj.parent)){ 185 | go.transform.parent = dic[baseobj.parent].transform; 186 | }else{ 187 | go.transform.parent = me.transform; 188 | } 189 | 190 | dic.Add(baseobj.myData.instanceID,baseobj); 191 | } 192 | } 193 | 194 | public void LoadLevel(string fileName){ 195 | byte[] levelGzipData = Tools.ReadByteToFile(Tools.GetLevelDataFilePath(fileName+".lmd")); 196 | byte[] levelData = Tools.UnGZip(levelGzipData); 197 | DataStream datastream = new DataStream(levelData,true); 198 | 199 | ReloadScene(datastream); 200 | Closeed(); 201 | } 202 | 203 | 204 | 205 | } 206 | -------------------------------------------------------------------------------- /Assets/Code/Editor/MESaveLevelData.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | using System.IO; 5 | using System.Collections.Generic; 6 | 7 | 8 | public class MESaveLevelData : Editor 9 | { 10 | public static List msobjlist = new List(); 11 | 12 | [MenuItem("关卡编辑器/保存关卡")] 13 | public static void SaveLevel(){ 14 | Debug.Log("SaveLevel"); 15 | msobjlist.Clear(); 16 | // 场景路径 17 | /* 18 | string scenePath = AssetDatabase.GetAssetPath(selectObject); 19 | 20 | Debug.Log("====================================="); 21 | Debug.Log(sceneName + " path : " + scenePath ); 22 | // 打开这个关卡 23 | EditorApplication.OpenScene(scenePath); 24 | */ 25 | 26 | MSLevelOptionDataModel od = null; 27 | DataStream stream = new DataStream(true); 28 | 29 | //获取场景中全部道具 30 | Object[] objects = Object.FindObjectsOfType(typeof(GameObject)); 31 | 32 | foreach (GameObject sceneObject in objects){ 33 | if(sceneObject.name == "LevelOption"){ 34 | LevelOption editor = sceneObject.GetComponent(); 35 | if(editor != null){ 36 | od = new MSLevelOptionDataModel(); 37 | od.SetValByLevelOption(editor); 38 | 39 | od.serialize(stream); 40 | 41 | Tools.GAME_DATA_VERSION = od.version; 42 | } 43 | 44 | ForeachObjAndSave(sceneObject); 45 | } 46 | } 47 | 48 | Debug.Log("save list count:"+msobjlist.Count); 49 | stream.WriteSInt32(msobjlist.Count); 50 | 51 | foreach(MSBaseObject msobj in msobjlist){ 52 | msobj.Serialize(stream); 53 | } 54 | 55 | if(od == null){ 56 | Debug.LogError("can't find the level option!"); 57 | return ; 58 | } 59 | 60 | WriteDataToFile(od,stream); 61 | } 62 | 63 | static void ForeachObjAndSave(GameObject obj){ 64 | foreach (Transform child in obj.transform) 65 | { 66 | MSBaseObject msobj = child.GetComponent(); 67 | 68 | if(msobj == null){ 69 | //if(child.childCount <= 0) continue; 70 | //msobj = child.gameObject.AddComponent(); 71 | //msobj.myData.objID = -1; 72 | continue; 73 | } 74 | 75 | msobj.myData.Name = child.name; 76 | msobj.SaveData(); 77 | msobj.myData.instanceID = child.GetInstanceID(); 78 | msobj.parent = child.parent.GetInstanceID(); 79 | Debug.Log("obj : " + msobj.itemid); 80 | msobjlist.Add(msobj); 81 | 82 | ForeachObjAndSave(child.gameObject); 83 | 84 | } 85 | } 86 | 87 | static void WriteDataToFile(MSLevelOptionDataModel od ,DataStream data){ 88 | string filePath = Tools.GetLevelDataFilePath(od.levelName + ".lmd"); 89 | 90 | byte[] objData = data.ToByteArray(); 91 | byte[] objGzipData = Tools.CompressGZip(objData); 92 | Tools.WriteByteToFile(objGzipData,filePath ); 93 | 94 | Debug.Log("save path : " + filePath); 95 | EditorUtility.DisplayDialog("导出关卡" + od.levelName + "成功!", filePath, "确定"); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /Assets/Code/Editor/MapEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | 5 | [ExecuteInEditMode] 6 | public class MapEditor : MonoBehaviour { 7 | 8 | public string levelName = ""; 9 | 10 | public float version = 0.0f; 11 | 12 | public float width = 10.0f; 13 | public float height = 1.0f; 14 | 15 | public int baseHeight = 6; 16 | 17 | public int mapHeight = 10; 18 | public int mapWidth = 100; 19 | 20 | public bool isShowBGLine = true; 21 | 22 | public bool isAutoPos = false; 23 | //public float autoDPos = 0.1f; 24 | 25 | // Use this for initialization 26 | void Start () { 27 | 28 | } 29 | 30 | // Update is called once per frame 31 | void Update () { 32 | AutoSetPos(); 33 | 34 | } 35 | 36 | 37 | void OnDrawGizmos() 38 | { 39 | 40 | if(isShowBGLine ){ 41 | DrawBGLine(); 42 | } 43 | 44 | } 45 | 46 | public void DrawBGLine(){ 47 | Gizmos.color = new Color(0f,0f,0f,1f); 48 | 49 | Gizmos.DrawLine(new Vector3(0, baseHeight , -1f),new Vector3(mapWidth, baseHeight , -1f)); 50 | Gizmos.DrawLine(new Vector3(mapWidth, baseHeight , -1f),new Vector3(mapWidth, mapHeight +baseHeight, -1f)); 51 | Gizmos.DrawLine(new Vector3(mapWidth, mapHeight +baseHeight, -1f),new Vector3(0, mapHeight+baseHeight , -1f)); 52 | Gizmos.DrawLine(new Vector3(0, mapHeight + baseHeight , -1f),new Vector3(0, baseHeight , -1f)); 53 | 54 | 55 | Gizmos.color = new Color(1f,1f,0f,0.2f); 56 | 57 | 58 | for (float y = baseHeight; y < mapHeight+baseHeight; y += height) 59 | { 60 | Gizmos.DrawLine(new Vector3(0, y , -1f), 61 | new Vector3(mapWidth, y , -1f)); 62 | 63 | Handles.Label(new Vector3(-1f,y+0.5f , 0f), "" + y); 64 | } 65 | 66 | for (float x = 0; x < mapWidth; x += width) 67 | { 68 | Gizmos.DrawLine(new Vector3(x,baseHeight, -1f), 69 | new Vector3(x,mapHeight+baseHeight, -1f)); 70 | 71 | Handles.Label(new Vector3(x,baseHeight-0.2f, 0f), "" + x); 72 | } 73 | } 74 | 75 | public void AutoSetPos(){ 76 | if(!isAutoPos ){ 77 | return; 78 | } 79 | 80 | //foreach (GameObject sceneObject in Object.FindObjectsOfType(typeof(GameObject))){ 81 | 82 | foreach (GameObject sceneObject in Selection.gameObjects){ 83 | SetObjPos(sceneObject,sceneObject.transform.position); 84 | } 85 | } 86 | 87 | public int GetSymbol(float val,float target){ 88 | if(val > 0 && target < 0){ 89 | return -1; 90 | }else if(val < 0 && target > 0){ 91 | return -1; 92 | } 93 | return 1; 94 | } 95 | 96 | public static void SetObjPos(GameObject obj,Vector3 pos){ 97 | 98 | MapEditor me = GameObject.Find("levelOption").transform.GetComponent(); 99 | 100 | if(me == null){ 101 | EditorUtility.DisplayDialog("ERROR", "Cant't find the 'levelOption' !!", "ENTRY"); 102 | return; 103 | } 104 | 105 | float autoDPosx = me.width; 106 | float autoDPosy = me.height; 107 | 108 | float alignedx = 0; 109 | float alignedy = 0; 110 | 111 | if(autoDPosx == 0){ 112 | alignedx = pos.x; 113 | }else{ 114 | alignedx = Mathf.Floor(pos.x/autoDPosx)*autoDPosx + autoDPosx/2.0f; 115 | } 116 | if(autoDPosy == 0){ 117 | alignedy = pos.y; 118 | }else{ 119 | alignedy = Mathf.Floor(pos.y/autoDPosy)*autoDPosy + autoDPosy/2.0f; 120 | } 121 | Vector3 aligned = new Vector3(alignedx,alignedy, 0.0f); 122 | obj.transform.position = aligned; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Assets/Code/MapObj/LevelOption.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | public class LevelOption : MonoBehaviour { 6 | 7 | public string levelName = ""; 8 | 9 | public float version = 0.0f; 10 | 11 | public float width = 1.0f; 12 | public float height = 1.0f; 13 | 14 | public int mapHeight = 10; 15 | public int mapWidth = 100; 16 | 17 | public List missionList = new List(); 18 | 19 | //public float autoDPos = 0.1f; 20 | 21 | // Use this for initialization 22 | void Start () { 23 | 24 | } 25 | 26 | // Update is called once per frame 27 | void Update () { 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Assets/Code/MapObj/MSBaseObject.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | /** 5 | * 游戏中全部对象继承自此类 6 | */ 7 | public class MSBaseObject : MonoBehaviour { 8 | public MSBaseObjectData myData = new MSBaseObjectData(); 9 | 10 | private int itemtype = 0; 11 | public string itemid=""; 12 | 13 | public int parent; 14 | 15 | public static MSBaseObject CreateObj(DataStream datastream){ 16 | //从字节流中获取id 17 | int type = datastream.ReadSInt32(); 18 | string id = datastream.ReadString16(); 19 | 20 | //获取配置表文件 21 | MSBaseObject baseobj = CreateById(type,id); 22 | 23 | baseobj.Deserialize(datastream); 24 | baseobj.init() ; 25 | 26 | return baseobj; 27 | } 28 | 29 | public static MSBaseObject CreateById(int type,string id){ 30 | //获取配置表文件 31 | 32 | GameObject go= Resources.Load("Prefabs/MapObj/" + id) as GameObject; 33 | GameObject tempObj = (GameObject)Instantiate(go); 34 | 35 | MSBaseObject baseobj = tempObj.GetComponent(); 36 | baseobj.itemtype = type; 37 | baseobj.itemid = id; 38 | if(baseobj == null){ 39 | baseobj = tempObj.AddComponent(); 40 | } 41 | return baseobj; 42 | } 43 | 44 | 45 | public void init(){ 46 | name = myData.Name; 47 | 48 | transform.position = myData.Position; 49 | transform.rotation = Quaternion.Euler(myData.Rotation); 50 | transform.localScale = myData.Scale; 51 | 52 | } 53 | 54 | public void SaveData(){ 55 | myData.Position = ( transform.position ); 56 | myData.Rotation = ( transform.rotation.eulerAngles ); 57 | myData.Scale = ( transform.localScale ); 58 | } 59 | 60 | public virtual void Serialize(DataStream writer) 61 | { 62 | writer.WriteSInt32(itemtype); 63 | writer.WriteString16(itemid); 64 | Debug.Log("itemid : " + itemid); 65 | myData.Serialize(writer); 66 | writer.WriteSInt32(parent); 67 | 68 | } 69 | 70 | public virtual void Deserialize(DataStream reader) 71 | { 72 | myData.Deserialize(reader); 73 | parent = reader.ReadSInt32(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Assets/Code/MapObj/MSBaseObjectData.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System; 4 | 5 | 6 | [Serializable] 7 | public class V3{ 8 | public float x; 9 | public float y; 10 | public float z; 11 | 12 | public V3(){ 13 | } 14 | 15 | public V3(float x,float y,float z){ 16 | this.x = x; 17 | this.y = y; 18 | this.z = z; 19 | } 20 | 21 | public void InitByVector3(Vector3 v){ 22 | this.x = v.x; 23 | this.y = v.y; 24 | this.z = v.z; 25 | } 26 | 27 | public Vector3 GetVector3(){ 28 | Vector3 ret = new Vector3(); 29 | ret.x = x; 30 | ret.y = y; 31 | ret.z = z; 32 | return ret; 33 | } 34 | } 35 | 36 | [Serializable] 37 | public class MSBaseObjectData { 38 | private const int floatRetainPlace = 1000; 39 | private string name = ""; 40 | 41 | public string Name{ 42 | get{return name;} 43 | set{name = value;} 44 | } 45 | 46 | public int objID ; 47 | 48 | public int instanceID; 49 | 50 | private V3 position = new V3(); 51 | public Vector3 Position{ 52 | get{return position.GetVector3();} 53 | set{position.InitByVector3(value);} 54 | } 55 | 56 | private V3 rotation = new V3(); 57 | public Vector3 Rotation{ 58 | get{return rotation.GetVector3();} 59 | set{rotation.InitByVector3(value);} 60 | } 61 | private V3 scale = new V3(); 62 | public Vector3 Scale{ 63 | get{return scale.GetVector3();} 64 | set{scale.InitByVector3(value);} 65 | } 66 | 67 | public virtual void Serialize(DataStream writer) 68 | { 69 | 70 | writer.WriteString16(name); 71 | writer.WriteSInt32((int)objID); 72 | writer.WriteSInt32((int)instanceID); 73 | 74 | writer.WriteSInt32((int)(Position.x * floatRetainPlace)); 75 | writer.WriteSInt32((int)(Position.y * floatRetainPlace)); 76 | writer.WriteSInt32((int)(Position.z * floatRetainPlace)); 77 | writer.WriteSInt32((int)(Rotation.x * floatRetainPlace)); 78 | writer.WriteSInt32((int)(Rotation.y * floatRetainPlace)); 79 | writer.WriteSInt32((int)(Rotation.z * floatRetainPlace)); 80 | writer.WriteSInt32((int)(Scale.x * floatRetainPlace)); 81 | writer.WriteSInt32((int)(Scale.y * floatRetainPlace)); 82 | writer.WriteSInt32((int)(Scale.z * floatRetainPlace)); 83 | 84 | } 85 | 86 | public virtual void Deserialize(DataStream reader) 87 | { 88 | name = reader.ReadString16(); 89 | objID = reader.ReadSInt32(); 90 | instanceID = reader.ReadSInt32(); 91 | 92 | Position = new Vector3((float)reader.ReadSInt32() / floatRetainPlace, 93 | (float)reader.ReadSInt32() / floatRetainPlace, 94 | (float)reader.ReadSInt32() / floatRetainPlace); 95 | 96 | Rotation = new Vector3((float)reader.ReadSInt32() / floatRetainPlace, 97 | (float)reader.ReadSInt32() / floatRetainPlace, 98 | (float)reader.ReadSInt32() / floatRetainPlace); 99 | 100 | Scale = new Vector3((float)reader.ReadSInt32() / floatRetainPlace, 101 | (float)reader.ReadSInt32() / floatRetainPlace, 102 | (float)reader.ReadSInt32() / floatRetainPlace); 103 | 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /Assets/Code/MapObj/MSLevelOptionDataModel.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System; 5 | 6 | [Serializable] 7 | public class LevelMessionData{ 8 | public int missionId; 9 | public int count; 10 | public string data; 11 | 12 | public static LevelMessionData deserialize(DataStream datastream) 13 | { 14 | LevelMessionData data = new LevelMessionData(); 15 | data.missionId = datastream.ReadSInt32(); 16 | data.count = datastream.ReadSInt32(); 17 | data.data = datastream.ReadString16(); 18 | return data; 19 | } 20 | 21 | public void serialize(DataStream datastream) 22 | { 23 | datastream.WriteSInt32(missionId); 24 | datastream.WriteSInt32(count); 25 | datastream.WriteString16(data); 26 | } 27 | 28 | } 29 | [Serializable] 30 | public class MSLevelOptionDataModel { 31 | public float version = 1; 32 | public string levelName; 33 | public int mapWidth; 34 | public int mapHeight; 35 | public List missionList = new List(); 36 | 37 | public void deserialize(DataStream datastream) 38 | { 39 | version = (float)datastream.ReadSInt32() / 10000f; 40 | levelName = datastream.ReadString16(); 41 | mapWidth = datastream.ReadSInt32(); 42 | mapHeight = datastream.ReadSInt32(); 43 | 44 | int count = datastream.ReadSInt32(); 45 | for (int i = 0; i < count; i ++){ 46 | missionList.Add(LevelMessionData.deserialize(datastream)); 47 | } 48 | } 49 | 50 | public void serialize(DataStream datastream) 51 | { 52 | datastream.WriteSInt32((int)(version * 10000)); 53 | datastream.WriteString16(levelName); 54 | datastream.WriteSInt32(mapWidth); 55 | datastream.WriteSInt32(mapHeight); 56 | 57 | int count = missionList.Count; 58 | datastream.WriteSInt32(count); 59 | Debug.Log("serialize : " + count); 60 | for (int i = 0; i < count; i++) 61 | { 62 | missionList[i].serialize(datastream); 63 | } 64 | } 65 | 66 | 67 | public void SetLevelOption(LevelOption lo) 68 | { 69 | lo.version = version; 70 | lo.levelName = levelName; 71 | lo.mapWidth = mapWidth; 72 | lo.mapHeight = mapHeight; 73 | lo.missionList = missionList; 74 | } 75 | 76 | public void SetValByLevelOption(LevelOption lo) 77 | { 78 | version = Tools.GAME_DATA_VERSION; 79 | levelName = lo.levelName; 80 | mapWidth = lo.mapWidth; 81 | mapHeight = lo.mapHeight; 82 | missionList = lo.missionList; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Assets/Code/Test.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using System.IO; 5 | using System.Text; 6 | 7 | public class Test : MonoBehaviour { 8 | 9 | // Use this for initialization 10 | void Start () { 11 | AHIntTest(); 12 | } 13 | 14 | // Update is called once per frame 15 | void Update () { 16 | 17 | } 18 | 19 | public static void AHIntTest(){ 20 | AHInt test = 1; 21 | test += 2; 22 | int x = 3; 23 | test += x; 24 | Debug.Log("[AHIntTest] : " + test); 25 | } 26 | 27 | 28 | public static void Base64Test(){ 29 | string base64string = Tools.ToBase64String("aaaa11233Base64编码和解码"); 30 | 31 | string unbase64string = Tools.UnBase64String(base64string); 32 | 33 | Debug.Log("base64string : " + base64string); 34 | Debug.Log("unbase64string : " + unbase64string); 35 | } 36 | public static void GZipTest() 37 | { 38 | string testdata = "aaaa11233GZip压缩和解压"; 39 | 40 | byte[] gzipdata = Tools.CompressGZip(Encoding.UTF8.GetBytes(testdata)); 41 | byte[] undata = Tools.UnGZip(gzipdata); 42 | 43 | Debug.Log("[GZipTest] : data" + Encoding.UTF8.GetString(undata)); 44 | } 45 | 46 | 47 | public static void SerializeDicTest(){ 48 | 49 | Dictionary test = new Dictionary(); 50 | 51 | test.Add("1",1); 52 | test.Add("2",2); 53 | test.Add("3",4); 54 | 55 | byte[] testbyte = Tools.SerializeObject(test); 56 | 57 | Dictionary testdic = (Dictionary)Tools.DeserializeObject(testbyte); 58 | 59 | Debug.Log("[SerializeDicTest] : " + testdic["3"]); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Assets/Code/Tools.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using System.IO; 5 | using ICSharpCode.SharpZipLib.GZip; 6 | 7 | using System; 8 | using System.Text; 9 | using System.Runtime.Serialization.Formatters.Binary; 10 | 11 | 12 | public static class Tools { 13 | 14 | public static float GAME_DATA_VERSION = 0.0f;// 15 | 16 | public static string GetLevelDataFilePath(string filename) 17 | { 18 | return Application.dataPath + "/Resources/LevelData/" + filename; 19 | } 20 | 21 | 22 | /// 23 | /// 把对象序列化为字节数组 24 | /// 25 | public static byte[] SerializeObject(object obj) 26 | { 27 | if (obj == null) 28 | return null; 29 | //内存实例 30 | MemoryStream ms = new MemoryStream(); 31 | //创建序列化的实例 32 | BinaryFormatter formatter = new BinaryFormatter(); 33 | formatter.Serialize(ms, obj);//序列化对象,写入ms流中 34 | byte[] bytes = ms.GetBuffer(); 35 | return bytes; 36 | } 37 | 38 | /// 39 | /// 把字节数组反序列化成对象 40 | /// UserDataMode userdata = (UserDataMode)GameCommon.DeserializeObject(data); 41 | /// 42 | public static object DeserializeObject(byte[] bytes) 43 | { 44 | object obj = null; 45 | if (bytes == null) 46 | return obj; 47 | //利用传来的byte[]创建一个内存流 48 | MemoryStream ms = new MemoryStream(bytes); 49 | ms.Position = 0; 50 | BinaryFormatter formatter = new BinaryFormatter(); 51 | obj = formatter.Deserialize(ms);//把内存流反序列成对象 52 | ms.Close(); 53 | return obj; 54 | } 55 | /// 56 | /// 把字典序列化 57 | /// 58 | /// 59 | /// 60 | public static byte[] SerializeDic(Dictionary dic) 61 | { 62 | if (dic.Count == 0) 63 | return null; 64 | MemoryStream ms = new MemoryStream(); 65 | BinaryFormatter formatter = new BinaryFormatter(); 66 | formatter.Serialize(ms, dic);//把字典序列化成流 67 | byte[] bytes = ms.GetBuffer(); 68 | 69 | return bytes; 70 | } 71 | /// 72 | /// 反序列化返回字典 73 | /// 74 | /// 75 | /// 76 | public static Dictionary DeserializeDic(byte[] bytes) 77 | { 78 | Dictionary dic = null; 79 | if (bytes == null) 80 | return dic; 81 | //利用传来的byte[]创建一个内存流 82 | MemoryStream ms = new MemoryStream(bytes); 83 | BinaryFormatter formatter = new BinaryFormatter(); 84 | //把流中转换为Dictionary 85 | dic = (Dictionary)formatter.Deserialize(ms); 86 | return dic; 87 | } 88 | 89 | /// 90 | /// 把字List序列化 91 | /// 92 | /// 93 | /// 94 | public static byte[] SerializeList(List dic) 95 | { 96 | if (dic.Count == 0) 97 | return null; 98 | MemoryStream ms = new MemoryStream(); 99 | BinaryFormatter formatter = new BinaryFormatter(); 100 | formatter.Serialize(ms, dic);//把字典序列化成流 101 | byte[] bytes = ms.GetBuffer(); 102 | 103 | return bytes; 104 | } 105 | /// 106 | /// 反序列化返回List 107 | /// 108 | /// 109 | /// 110 | public static List DeserializeList(byte[] bytes) 111 | { 112 | List list = null; 113 | if (bytes == null) 114 | return list; 115 | //利用传来的byte[]创建一个内存流 116 | MemoryStream ms = new MemoryStream(bytes); 117 | BinaryFormatter formatter = new BinaryFormatter(); 118 | //把流中转换为List 119 | list = (List)formatter.Deserialize(ms); 120 | return list; 121 | } 122 | 123 | //base64字符串解码 124 | public static string UnBase64String(string value) 125 | { 126 | if (value == null || value == "") 127 | { 128 | return ""; 129 | } 130 | byte[] bytes = Convert.FromBase64String(value); 131 | return Encoding.UTF8.GetString(bytes); 132 | } 133 | 134 | //base64字符串编码 135 | public static string ToBase64String(string value) 136 | { 137 | if (value == null || value == "") 138 | { 139 | return ""; 140 | } 141 | byte[] bytes = Encoding.UTF8.GetBytes(value); 142 | return Convert.ToBase64String(bytes); 143 | } 144 | 145 | /// 146 | /// 二进制数据写入文件 Writes the byte to file. 147 | /// 148 | /// Data. 149 | /// path. 150 | public static void WriteByteToFile(byte[] data, string path) 151 | { 152 | 153 | FileStream fs = new FileStream(path, FileMode.Create); 154 | fs.Write(data, 0, data.Length); 155 | fs.Close(); 156 | } 157 | 158 | /// 159 | /// 读取文件二进制数据 Reads the byte to file. 160 | /// 161 | /// The byte to file. 162 | /// Path. 163 | public static byte[] ReadByteToFile(string path) 164 | { 165 | //如果文件不存在,就提示错误 166 | if (!File.Exists(path)) 167 | { 168 | Debug.Log("读取失败!不存在此文件"); 169 | return null; 170 | } 171 | FileStream fs = new FileStream(path, FileMode.Open); 172 | BinaryReader br = new BinaryReader(fs); 173 | byte[] data = br.ReadBytes((int)br.BaseStream.Length); 174 | 175 | fs.Close(); 176 | return data; 177 | } 178 | /// 179 | /// 解压 Uns the G zip. 180 | /// 181 | /// The G zip. 182 | /// Byte array. 183 | public static byte[] UnGZip(byte[] byteArray) 184 | { 185 | GZipInputStream gzi = new GZipInputStream(new MemoryStream(byteArray)); 186 | 187 | //包数据解大小上限为50000 188 | MemoryStream re = new MemoryStream(50000); 189 | int count; 190 | byte[] data = new byte[50000]; 191 | while ((count = gzi.Read(data, 0, data.Length)) != 0) 192 | { 193 | re.Write(data, 0, count); 194 | } 195 | byte[] overarr = re.ToArray(); 196 | return overarr; 197 | } 198 | /// 199 | /// 200 | /// 压缩 Compresses the G zip. 201 | /// 202 | /// The G zip. 203 | /// Raw data. 204 | public static byte[] CompressGZip(byte[] rawData) 205 | { 206 | MemoryStream ms = new MemoryStream(); 207 | GZipOutputStream compressedzipStream = new GZipOutputStream(ms); 208 | compressedzipStream.Write(rawData, 0, rawData.Length); 209 | compressedzipStream.Close(); 210 | return ms.ToArray(); 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /Assets/Plugins/LitJson.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/Assets/Plugins/LitJson.dll -------------------------------------------------------------------------------- /Assets/Plugins/SharpZipLib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/Assets/Plugins/SharpZipLib.dll -------------------------------------------------------------------------------- /Assets/Resources/LevelData/level2.lmd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/Assets/Resources/LevelData/level2.lmd -------------------------------------------------------------------------------- /Assets/Resources/LevelData/newlevel.lmd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/Assets/Resources/LevelData/newlevel.lmd -------------------------------------------------------------------------------- /Assets/Resources/Prefabs/MapObj/cube.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/Assets/Resources/Prefabs/MapObj/cube.prefab -------------------------------------------------------------------------------- /Assets/Resources/Prefabs/MapObj/sphere.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/Assets/Resources/Prefabs/MapObj/sphere.prefab -------------------------------------------------------------------------------- /Assets/Test.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/Assets/Test.unity -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.6.3f1 2 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuFeng1011/UnityMapEditor/026e7f4f1c74a0b169fdba816149b205c91bffbf/ProjectSettings/UnityConnectSettings.asset --------------------------------------------------------------------------------