diff options
author | chai <215380520@qq.com> | 2024-05-23 10:08:29 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-05-23 10:08:29 +0800 |
commit | 8722a9920c1f6119bf6e769cba270e63097f8e25 (patch) | |
tree | 2eaf9865de7fb1404546de4a4296553d8f68cc3b /Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Core/Serialization/SimpleZipReplacement.cs | |
parent | 3ba4020b69e5971bb0df7ee08b31d10ea4d01937 (diff) |
+ astar project
Diffstat (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Core/Serialization/SimpleZipReplacement.cs')
-rw-r--r-- | Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Core/Serialization/SimpleZipReplacement.cs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Core/Serialization/SimpleZipReplacement.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Core/Serialization/SimpleZipReplacement.cs new file mode 100644 index 0000000..28f69b2 --- /dev/null +++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Core/Serialization/SimpleZipReplacement.cs @@ -0,0 +1,80 @@ +#if ASTAR_NO_ZIP +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +namespace Pathfinding.Serialization.Zip { + public enum ZipOption { + Always + } + + public class ZipFile { + public System.Text.Encoding AlternateEncoding; + public ZipOption AlternateEncodingUsage = ZipOption.Always; + public int ParallelDeflateThreshold = 0; + + Dictionary<string, ZipEntry> dict = new Dictionary<string, ZipEntry>(); + + public void AddEntry (string name, byte[] bytes) { + dict[name] = new ZipEntry(name, bytes); + } + + public bool ContainsEntry (string name) { + return dict.ContainsKey(name); + } + + public void Save (System.IO.Stream stream) { + var writer = new System.IO.BinaryWriter(stream); + + writer.Write(dict.Count); + foreach (KeyValuePair<string, ZipEntry> pair in dict) { + writer.Write(pair.Key); + writer.Write(pair.Value.bytes.Length); + writer.Write(pair.Value.bytes); + } + } + + public static ZipFile Read (System.IO.Stream stream) { + ZipFile file = new ZipFile(); + + var reader = new System.IO.BinaryReader(stream); + int count = reader.ReadInt32(); + + for (int i = 0; i < count; i++) { + var name = reader.ReadString(); + var length = reader.ReadInt32(); + var bytes = reader.ReadBytes(length); + + file.dict[name] = new ZipEntry(name, bytes); + } + + return file; + } + + public ZipEntry this[string index] { + get { + ZipEntry v; + dict.TryGetValue(index, out v); + return v; + } + } + + public void Dispose () { + } + } + + public class ZipEntry { + internal string name; + internal byte[] bytes; + + public ZipEntry (string name, byte[] bytes) { + this.name = name; + this.bytes = bytes; + } + + public void Extract (System.IO.Stream stream) { + stream.Write(bytes, 0, bytes.Length); + } + } +} +#endif |