Procházet zdrojové kódy

迁移了整个实时加载动态库的框架过来

tanghai před 9 roky
rodič
revize
67a215a17f
100 změnil soubory, kde provedl 2946 přidání a 68 odebrání
  1. binární
      Unity/Assets/Plugins/ICSharpCode.SharpZipLib.dll
  2. 58 0
      Unity/Assets/Plugins/ICSharpCode.SharpZipLib.dll.meta
  3. 0 5
      Unity/Assets/Plugins/MongoDB/MongoDB.Bson/Properties.meta
  4. binární
      Unity/Assets/Res/Code/Controller.dll.bytes
  5. binární
      Unity/Assets/Res/Code/Controller.dll.mdb.bytes
  6. binární
      Unity/Assets/Res/Code/Model.dll.bytes
  7. 0 8
      Unity/Assets/Res/Code/Model.dll.bytes.meta
  8. binární
      Unity/Assets/Res/Code/Model.dll.mdb.bytes
  9. binární
      Unity/Assets/Resources/Code.prefab
  10. 0 0
      Unity/Assets/Resources/Code.prefab.meta
  11. binární
      Unity/Assets/Resources/Config.prefab
  12. 3 3
      Unity/Assets/Resources/Config.prefab.meta
  13. binární
      Unity/Assets/Scenes/Unity.unity
  14. 2 2
      Unity/Assets/Scripts/Base/Config.meta
  15. 91 0
      Unity/Assets/Scripts/Base/Config/ACategory.cs
  16. 12 0
      Unity/Assets/Scripts/Base/Config/ACategory.cs.meta
  17. 19 0
      Unity/Assets/Scripts/Base/Config/AConfig.cs
  18. 12 0
      Unity/Assets/Scripts/Base/Config/AConfig.cs.meta
  19. 144 0
      Unity/Assets/Scripts/Base/DoubleMap.cs
  20. 12 0
      Unity/Assets/Scripts/Base/DoubleMap.cs.meta
  21. 59 0
      Unity/Assets/Scripts/Base/FileHelper.cs
  22. 12 0
      Unity/Assets/Scripts/Base/FileHelper.cs.meta
  23. 2 3
      Unity/Assets/Scripts/Base/GameObjectHelper.cs
  24. 1 1
      Unity/Assets/Scripts/Base/GameObjectHelper.cs.meta
  25. 2 2
      Unity/Assets/Scripts/Base/Helper.meta
  26. 0 0
      Unity/Assets/Scripts/Base/Helper/ArrayHelper.cs
  27. 12 0
      Unity/Assets/Scripts/Base/Helper/ArrayHelper.cs.meta
  28. 0 0
      Unity/Assets/Scripts/Base/Helper/ByteHelper.cs
  29. 12 0
      Unity/Assets/Scripts/Base/Helper/ByteHelper.cs.meta
  30. 30 0
      Unity/Assets/Scripts/Base/Helper/EnumHelper.cs
  31. 12 0
      Unity/Assets/Scripts/Base/Helper/EnumHelper.cs.meta
  32. 1 1
      Unity/Assets/Scripts/Base/Helper/IdGenerater.cs
  33. 12 0
      Unity/Assets/Scripts/Base/Helper/IdGenerater.cs.meta
  34. 0 0
      Unity/Assets/Scripts/Base/Helper/MD5Helper.cs
  35. 12 0
      Unity/Assets/Scripts/Base/Helper/MD5Helper.cs.meta
  36. 0 0
      Unity/Assets/Scripts/Base/Helper/MongoHelper.cs
  37. 12 0
      Unity/Assets/Scripts/Base/Helper/MongoHelper.cs.meta
  38. 0 0
      Unity/Assets/Scripts/Base/Helper/ProtobufHelper.cs
  39. 12 0
      Unity/Assets/Scripts/Base/Helper/ProtobufHelper.cs.meta
  40. 0 0
      Unity/Assets/Scripts/Base/Helper/RandomHelper.cs
  41. 12 0
      Unity/Assets/Scripts/Base/Helper/RandomHelper.cs.meta
  42. 62 0
      Unity/Assets/Scripts/Base/Helper/StringHelper.cs
  43. 12 0
      Unity/Assets/Scripts/Base/Helper/StringHelper.cs.meta
  44. 37 0
      Unity/Assets/Scripts/Base/Helper/TimeHelper.cs
  45. 12 0
      Unity/Assets/Scripts/Base/Helper/TimeHelper.cs.meta
  46. 97 0
      Unity/Assets/Scripts/Base/Helper/ZipHelper.cs
  47. 12 0
      Unity/Assets/Scripts/Base/Helper/ZipHelper.cs.meta
  48. 11 40
      Unity/Assets/Scripts/Base/Log.cs
  49. 111 0
      Unity/Assets/Scripts/Base/MultiMap.cs
  50. 12 0
      Unity/Assets/Scripts/Base/MultiMap.cs.meta
  51. 9 0
      Unity/Assets/Scripts/Base/Network.meta
  52. 48 0
      Unity/Assets/Scripts/Base/Network/AChannel.cs
  53. 12 0
      Unity/Assets/Scripts/Base/Network/AChannel.cs.meta
  54. 50 0
      Unity/Assets/Scripts/Base/Network/AService.cs
  55. 12 0
      Unity/Assets/Scripts/Base/Network/AService.cs.meta
  56. 9 0
      Unity/Assets/Scripts/Base/Network/TNet.meta
  57. 11 0
      Unity/Assets/Scripts/Base/Network/TNet/IPoller.cs
  58. 12 0
      Unity/Assets/Scripts/Base/Network/TNet/IPoller.cs.meta
  59. 80 0
      Unity/Assets/Scripts/Base/Network/TNet/PacketParser.cs
  60. 12 0
      Unity/Assets/Scripts/Base/Network/TNet/PacketParser.cs.meta
  61. 129 0
      Unity/Assets/Scripts/Base/Network/TNet/TBuffer.cs
  62. 12 0
      Unity/Assets/Scripts/Base/Network/TNet/TBuffer.cs.meta
  63. 202 0
      Unity/Assets/Scripts/Base/Network/TNet/TChannel.cs
  64. 12 0
      Unity/Assets/Scripts/Base/Network/TNet/TChannel.cs.meta
  65. 38 0
      Unity/Assets/Scripts/Base/Network/TNet/TPoller.cs
  66. 12 0
      Unity/Assets/Scripts/Base/Network/TNet/TPoller.cs.meta
  67. 94 0
      Unity/Assets/Scripts/Base/Network/TNet/TService.cs
  68. 12 0
      Unity/Assets/Scripts/Base/Network/TNet/TService.cs.meta
  69. 181 0
      Unity/Assets/Scripts/Base/Network/TNet/TSocket.cs
  70. 12 0
      Unity/Assets/Scripts/Base/Network/TNet/TSocket.cs.meta
  71. 72 0
      Unity/Assets/Scripts/Base/Network/TimerManager.cs
  72. 12 0
      Unity/Assets/Scripts/Base/Network/TimerManager.cs.meta
  73. 9 0
      Unity/Assets/Scripts/Base/Network/UNet.meta
  74. 31 0
      Unity/Assets/Scripts/Base/Network/UNet/Library.cs
  75. 12 0
      Unity/Assets/Scripts/Base/Network/UNet/Library.cs.meta
  76. 105 0
      Unity/Assets/Scripts/Base/Network/UNet/NativeMethods.cs
  77. 12 0
      Unity/Assets/Scripts/Base/Network/UNet/NativeMethods.cs.meta
  78. 76 0
      Unity/Assets/Scripts/Base/Network/UNet/NativeStructs.cs
  79. 12 0
      Unity/Assets/Scripts/Base/Network/UNet/NativeStructs.cs.meta
  80. 27 0
      Unity/Assets/Scripts/Base/Network/UNet/UAddress.cs
  81. 12 0
      Unity/Assets/Scripts/Base/Network/UNet/UAddress.cs.meta
  82. 69 0
      Unity/Assets/Scripts/Base/Network/UNet/UChannel.cs
  83. 12 0
      Unity/Assets/Scripts/Base/Network/UNet/UChannel.cs.meta
  84. 72 0
      Unity/Assets/Scripts/Base/Network/UNet/UPacket.cs
  85. 12 0
      Unity/Assets/Scripts/Base/Network/UNet/UPacket.cs.meta
  86. 160 0
      Unity/Assets/Scripts/Base/Network/UNet/UPoller.cs
  87. 12 0
      Unity/Assets/Scripts/Base/Network/UNet/UPoller.cs.meta
  88. 98 0
      Unity/Assets/Scripts/Base/Network/UNet/UService.cs
  89. 12 0
      Unity/Assets/Scripts/Base/Network/UNet/UService.cs.meta
  90. 125 0
      Unity/Assets/Scripts/Base/Network/UNet/USocket.cs
  91. 12 0
      Unity/Assets/Scripts/Base/Network/UNet/USocket.cs.meta
  92. 41 0
      Unity/Assets/Scripts/Base/Network/UNet/USocketManager.cs
  93. 12 0
      Unity/Assets/Scripts/Base/Network/UNet/USocketManager.cs.meta
  94. 9 0
      Unity/Assets/Scripts/Base/Object.meta
  95. 1 1
      Unity/Assets/Scripts/Base/Object/Component.cs
  96. 12 0
      Unity/Assets/Scripts/Base/Object/Component.cs.meta
  97. 1 1
      Unity/Assets/Scripts/Base/Object/Entity.cs
  98. 12 0
      Unity/Assets/Scripts/Base/Object/Entity.cs.meta
  99. 1 1
      Unity/Assets/Scripts/Base/Object/IAwake.cs
  100. 12 0
      Unity/Assets/Scripts/Base/Object/IAwake.cs.meta

binární
Unity/Assets/Plugins/ICSharpCode.SharpZipLib.dll


+ 58 - 0
Unity/Assets/Plugins/ICSharpCode.SharpZipLib.dll.meta

@@ -0,0 +1,58 @@
+fileFormatVersion: 2
+guid: de67d260a82e87742b9c3c297379ffb3
+timeCreated: 1474948268
+licenseType: Pro
+PluginImporter:
+  serializedVersion: 1
+  iconMap: {}
+  executionOrder: {}
+  isPreloaded: 0
+  platformData:
+    Any:
+      enabled: 1
+      settings: {}
+    Editor:
+      enabled: 0
+      settings:
+        CPU: AnyCPU
+        DefaultValueInitialized: true
+        OS: AnyOS
+    Linux:
+      enabled: 0
+      settings:
+        CPU: x86
+    Linux64:
+      enabled: 0
+      settings:
+        CPU: x86_64
+    LinuxUniversal:
+      enabled: 0
+      settings:
+        CPU: None
+    OSXIntel:
+      enabled: 0
+      settings:
+        CPU: AnyCPU
+    OSXIntel64:
+      enabled: 0
+      settings:
+        CPU: AnyCPU
+    OSXUniversal:
+      enabled: 0
+      settings:
+        CPU: None
+    Win:
+      enabled: 1
+      settings:
+        CPU: AnyCPU
+    Win64:
+      enabled: 1
+      settings:
+        CPU: AnyCPU
+    WindowsStoreApps:
+      enabled: 0
+      settings:
+        CPU: AnyCPU
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 5
Unity/Assets/Plugins/MongoDB/MongoDB.Bson/Properties.meta

@@ -1,5 +0,0 @@
-fileFormatVersion: 2
-guid: c8e6a86214ae08642b0da7d5f862e02d
-folderAsset: yes
-DefaultImporter:
-  userData: 

binární
Unity/Assets/Res/Code/Controller.dll.bytes


binární
Unity/Assets/Res/Code/Controller.dll.mdb.bytes


binární
Unity/Assets/Res/Code/Model.dll.bytes


+ 0 - 8
Unity/Assets/Res/Code/Model.dll.bytes.meta

@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 3dc523ca09fd1c6408076ffce961ea0d
-timeCreated: 1463896781
-licenseType: Pro
-TextScriptImporter:
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

binární
Unity/Assets/Res/Code/Model.dll.mdb.bytes


binární
Unity/Assets/Resources/Code.prefab


+ 0 - 0
Unity/Assets/Resources/Code/Code.prefab.meta → Unity/Assets/Resources/Code.prefab.meta


binární
Unity/Assets/Resources/Code/Code.prefab → Unity/Assets/Resources/Config.prefab


+ 3 - 3
Unity/Assets/Res/Code/Model.dll.mdb.bytes.meta → Unity/Assets/Resources/Config.prefab.meta

@@ -1,8 +1,8 @@
 fileFormatVersion: 2
-guid: af23f59e3be155a4e88e4dde65a33d40
-timeCreated: 1463896781
+guid: f5aff6e47e6bc6f4ab8d7a79a41b9a74
+timeCreated: 1474946800
 licenseType: Pro
-TextScriptImporter:
+NativeFormatImporter:
   userData: 
   assetBundleName: 
   assetBundleVariant: 

binární
Unity/Assets/Scenes/Unity.unity


+ 2 - 2
Unity/Assets/Resources/Code.meta → Unity/Assets/Scripts/Base/Config.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
-guid: 65b2666f16b7112468eb996c8a991cd7
+guid: f73b17142efc12244a9d9893fcc7f532
 folderAsset: yes
-timeCreated: 1463827414
+timeCreated: 1474947006
 licenseType: Pro
 DefaultImporter:
   userData: 

+ 91 - 0
Unity/Assets/Scripts/Base/Config/ACategory.cs

@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using UnityEngine;
+
+namespace Base
+{
+	public abstract class ACategory<T>: ICategory where T : AConfig
+	{
+		protected Dictionary<long, T> dict;
+
+		public virtual void BeginInit()
+		{
+			this.dict = new Dictionary<long, T>();
+
+			string path = $@"Config/{typeof (T).Name}";
+			string configStr;
+			try
+			{
+				configStr = ((GameObject)Resources.Load("Config")).Get<TextAsset>(typeof(T).Name).text;
+			}
+			catch (Exception)
+			{
+				throw new GameException($"load config file fail, path: {path}");
+			}
+
+			foreach (string str in configStr.Split(new[] { "\r\n" }, StringSplitOptions.None))
+			{
+				try
+				{
+					string str2 = str.Trim();
+					if (str2 == "")
+					{
+						continue;
+					}
+					T t = MongoHelper.FromJson<T>(str2);
+					this.dict.Add(t.id, t);
+				}
+				catch (Exception e)
+				{
+					throw new GameException($"parser json fail: {str}", e);
+				}
+			}
+		}
+
+		public Type ConfigType
+		{
+			get
+			{
+				return typeof (T);
+			}
+		}
+
+		public virtual void EndInit()
+		{
+		}
+
+		public T this[long type]
+		{
+			get
+			{
+				T t;
+				if (!this.dict.TryGetValue(type, out t))
+				{
+					throw new ConfigException($"{typeof (T)} 没有找到配置, key: {type}");
+				}
+				return t;
+			}
+		}
+
+		public T TryGet(int type)
+		{
+			T t;
+			if (!this.dict.TryGetValue(type, out t))
+			{
+				return null;
+			}
+			return t;
+		}
+
+		public T[] GetAll()
+		{
+			return this.dict.Values.ToArray();
+		}
+
+		public T GetOne()
+		{
+			return this.dict.Values.First();
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Config/ACategory.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 2f769b2838d3a384e88c8b0627564a46
+timeCreated: 1474947006
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 19 - 0
Unity/Assets/Scripts/Base/Config/AConfig.cs

@@ -0,0 +1,19 @@
+using System.ComponentModel;
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace Base
+{
+	public abstract class AConfig: ISupportInitialize
+	{
+		[BsonId]
+		public long id { get; set; }
+
+		public virtual void BeginInit()
+		{
+		}
+
+		public virtual void EndInit()
+		{
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Config/AConfig.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: af363bf85da8f694796a3438be6df56b
+timeCreated: 1474947006
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 144 - 0
Unity/Assets/Scripts/Base/DoubleMap.cs

@@ -0,0 +1,144 @@
+using System;
+using System.Collections.Generic;
+
+namespace Base
+{
+	public class DoubleMap<K, V>
+	{
+		private readonly Dictionary<K, V> kv = new Dictionary<K, V>();
+		private readonly Dictionary<V, K> vk = new Dictionary<V, K>();
+
+		public DoubleMap()
+		{
+		}
+
+		public DoubleMap(int capacity)
+		{
+			kv = new Dictionary<K, V>(capacity);
+			vk = new Dictionary<V, K>(capacity);
+		}
+
+		public void ForEach(Action<K, V> action)
+		{
+			if (action == null)
+			{
+				return;
+			}
+			Dictionary<K, V>.KeyCollection keys = kv.Keys;
+			foreach (K key in keys)
+			{
+				action(key, kv[key]);
+			}
+		}
+
+		public List<K> Keys
+		{
+			get
+			{
+				return new List<K>(kv.Keys);
+			}
+		}
+
+		public List<V> Values
+		{
+			get
+			{
+				return new List<V>(vk.Keys);
+			}
+		}
+
+		public void Add(K key, V value)
+		{
+			if (key == null || value == null || kv.ContainsKey(key) || vk.ContainsKey(value))
+			{
+				return;
+			}
+			kv.Add(key, value);
+			vk.Add(value, key);
+		}
+
+		public V GetValueByKey(K key)
+		{
+			if (key != null && kv.ContainsKey(key))
+			{
+				return kv[key];
+			}
+			return default(V);
+		}
+
+		public K GetKeyByValue(V value)
+		{
+			if (value != null && vk.ContainsKey(value))
+			{
+				return vk[value];
+			}
+			return default(K);
+		}
+
+		public void RemoveByKey(K key)
+		{
+			if (key == null)
+			{
+				return;
+			}
+			V value;
+			if (!kv.TryGetValue(key, out value))
+			{
+				return;
+			}
+
+			kv.Remove(key);
+			vk.Remove(value);
+		}
+
+		public void RemoveByValue(V value)
+		{
+			if (value == null)
+			{
+				return;
+			}
+
+			K key;
+			if (!vk.TryGetValue(value, out key))
+			{
+				return;
+			}
+
+			kv.Remove(key);
+			vk.Remove(value);
+		}
+
+		public void Clear()
+		{
+			kv.Clear();
+			vk.Clear();
+		}
+
+		public bool ContainsKey(K key)
+		{
+			if (key == null)
+			{
+				return false;
+			}
+			return kv.ContainsKey(key);
+		}
+
+		public bool ContainsValue(V value)
+		{
+			if (value == null)
+			{
+				return false;
+			}
+			return vk.ContainsKey(value);
+		}
+
+		public bool Contains(K key, V value)
+		{
+			if (key == null || value == null)
+			{
+				return false;
+			}
+			return kv.ContainsKey(key) && vk.ContainsKey(value);
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/DoubleMap.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 4490fa27a0147ae41b8c923f8daa7bc1
+timeCreated: 1474943113
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 59 - 0
Unity/Assets/Scripts/Base/FileHelper.cs

@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace Base
+{
+	public static class FileHelper
+	{
+		public static void CleanDirectory(string dir)
+		{
+			foreach (string subdir in Directory.GetDirectories(dir))
+			{
+				Directory.Delete(subdir, true);		
+			}
+
+			foreach (string subFile in Directory.GetFiles(dir))
+			{
+				File.Delete(subFile);
+			}
+		}
+
+		public static void CopyDirectory(string srcDir, string tgtDir)
+		{
+			DirectoryInfo source = new DirectoryInfo(srcDir);
+			DirectoryInfo target = new DirectoryInfo(tgtDir);
+	
+			if (target.FullName.StartsWith(source.FullName, StringComparison.CurrentCultureIgnoreCase))
+			{
+				throw new Exception("父目录不能拷贝到子目录!");
+			}
+	
+			if (!source.Exists)
+			{
+				return;
+			}
+	
+			if (!target.Exists)
+			{
+				target.Create();
+			}
+	
+			FileInfo[] files = source.GetFiles();
+	
+			for (int i = 0; i < files.Length; i++)
+			{
+				File.Copy(files[i].FullName, target.FullName + @"\" + files[i].Name, true);
+			}
+	
+			DirectoryInfo[] dirs = source.GetDirectories();
+	
+			for (int j = 0; j < dirs.Length; j++)
+			{
+				CopyDirectory(dirs[j].FullName, target.FullName + @"\" + dirs[j].Name);
+			}
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/FileHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 74cc512af7309484fa066b16175c6331
+timeCreated: 1474943113
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 3
Unity/Assets/Scripts/Base/GameObjectHelper.cs

@@ -1,12 +1,11 @@
 using System;
-using System.Linq;
 using UnityEngine;
 
 namespace Base
 {
 	public static class GameObjectHelper
 	{
-		public static T Get<T>(this GameObject gameObject, string key) where T : class
+		public static T Get<T>(this GameObject gameObject, string key) where T: class 
 		{
 			try
 			{
@@ -14,7 +13,7 @@ namespace Base
 			}
 			catch (Exception e)
 			{
-				throw new Exception($"获取 {gameObject.name} ReferenceCollector key {key} 失败", e);
+				throw new ConfigException($"获取{gameObject.name}的ReferenceCollector key失败, key: {key}", e);
 			}
 		}
 	}

+ 1 - 1
Unity/Assets/Scripts/Base/GameObjectHelper.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 245caefc6aecc8c46b325426151d8db3
-timeCreated: 1463827654
+timeCreated: 1474945321
 licenseType: Pro
 MonoImporter:
   serializedVersion: 2

+ 2 - 2
Unity/Assets/Plugins/protobuf-net/Web.meta → Unity/Assets/Scripts/Base/Helper.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
-guid: 99f76c12b5edaae4486f57e5cf3b967c
+guid: ed9c96775abf00744a273222165c1a03
 folderAsset: yes
-timeCreated: 1433473415
+timeCreated: 1474942922
 licenseType: Pro
 DefaultImporter:
   userData: 

+ 0 - 0
Unity/Model/Helper/ArrayHelper.cs → Unity/Assets/Scripts/Base/Helper/ArrayHelper.cs


+ 12 - 0
Unity/Assets/Scripts/Base/Helper/ArrayHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 27d07fce480358144b4bf720ff3831ee
+timeCreated: 1474942922
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 0
Unity/Model/Helper/ByteHelper.cs → Unity/Assets/Scripts/Base/Helper/ByteHelper.cs


+ 12 - 0
Unity/Assets/Scripts/Base/Helper/ByteHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 33f44962744fcd64d98b9bcd0fc41bf9
+timeCreated: 1474942922
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 30 - 0
Unity/Assets/Scripts/Base/Helper/EnumHelper.cs

@@ -0,0 +1,30 @@
+using System;
+
+namespace Base
+{
+	public static class EnumHelper
+	{
+		public static int EnumIndex<T>(int value)
+		{
+			int i = 0;
+			foreach (object v in Enum.GetValues(typeof (T)))
+			{
+				if ((int) v == value)
+				{
+					return i;
+				}
+				++i;
+			}
+			return -1;
+		}
+
+		public static T FromString<T>(string str)
+		{
+            if (!Enum.IsDefined(typeof(T), str))
+            {
+                return default(T);
+            }
+            return (T)Enum.Parse(typeof(T), str);
+        }
+    }
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Helper/EnumHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: d1f7baecded0cf041bb61181909a1619
+timeCreated: 1474948030
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Model/Helper/IdGenerater.cs → Unity/Assets/Scripts/Base/Helper/IdGenerater.cs

@@ -1,4 +1,4 @@
-namespace Model
+namespace Base
 {
 	public static class IdGenerater
 	{

+ 12 - 0
Unity/Assets/Scripts/Base/Helper/IdGenerater.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 1418e246bc45e154ea76c01c5638e667
+timeCreated: 1474942922
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 0
Unity/Model/Helper/MD5Helper.cs → Unity/Assets/Scripts/Base/Helper/MD5Helper.cs


+ 12 - 0
Unity/Assets/Scripts/Base/Helper/MD5Helper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 9c37f13dde60869459e624143ae45a3c
+timeCreated: 1474942922
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 0
Unity/Model/Helper/MongoHelper.cs → Unity/Assets/Scripts/Base/Helper/MongoHelper.cs


+ 12 - 0
Unity/Assets/Scripts/Base/Helper/MongoHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 878c2d7cd891aa34da37b23d39793640
+timeCreated: 1474942922
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 0
Unity/Model/Helper/ProtobufHelper.cs → Unity/Assets/Scripts/Base/Helper/ProtobufHelper.cs


+ 12 - 0
Unity/Assets/Scripts/Base/Helper/ProtobufHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: c4855b19fa50a654f8c5f7a14ebf293e
+timeCreated: 1474942922
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 0
Unity/Model/Helper/RandomHelper.cs → Unity/Assets/Scripts/Base/Helper/RandomHelper.cs


+ 12 - 0
Unity/Assets/Scripts/Base/Helper/RandomHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: c7bd0b921d0715a4caa7a59d261e8803
+timeCreated: 1474942922
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 62 - 0
Unity/Assets/Scripts/Base/Helper/StringHelper.cs

@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Text;
+
+namespace Base
+{
+	public static class StringHelper
+	{
+		public static IEnumerable<byte> ToBytes(this string str)
+		{
+			byte[] byteArray = Encoding.Default.GetBytes(str);
+			return byteArray;
+		}
+
+		public static byte[] ToByteArray(this string str)
+		{
+			byte[] byteArray = Encoding.Default.GetBytes(str);
+			return byteArray;
+		}
+
+	    public static byte[] ToUtf8(this string str)
+	    {
+            byte[] byteArray = Encoding.UTF8.GetBytes(str);
+            return byteArray;
+        }
+
+		public static byte[] HexToBytes(this string hexString)
+		{
+			if (hexString.Length % 2 != 0)
+			{
+				throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The binary key cannot have an odd number of digits: {0}", hexString));
+			}
+
+			var hexAsBytes = new byte[hexString.Length / 2];
+			for (int index = 0; index < hexAsBytes.Length; index++)
+			{
+				string byteValue = "";
+				byteValue += hexString[index * 2];
+				byteValue += hexString[index * 2 + 1];
+				hexAsBytes[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
+			}
+			return hexAsBytes;
+		}
+
+		public static string Fmt(this string text, params object[] args)
+		{
+			return string.Format(text, args);
+		}
+
+		public static string ListToString<T>(this List<T> list)
+		{
+			StringBuilder sb = new StringBuilder();
+			foreach (T t in list)
+			{
+				sb.Append(t);
+				sb.Append(",");
+			}
+			return sb.ToString();
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Helper/StringHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: d7b4a3306f5899c48966bcc2aea42a61
+timeCreated: 1474947336
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 37 - 0
Unity/Assets/Scripts/Base/Helper/TimeHelper.cs

@@ -0,0 +1,37 @@
+using System;
+
+namespace Base
+{
+	public static class TimeHelper
+	{
+		private static readonly DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+		/// <summary>
+		/// 客户端时间
+		/// </summary>
+		/// <returns></returns>
+		public static long ClientNow()
+		{
+			return Convert.ToInt64((DateTime.UtcNow - epoch).TotalMilliseconds);
+		}
+
+		public static long ClientNowTicks()
+		{	
+			return Convert.ToInt64((DateTime.UtcNow - epoch).Ticks);
+		}
+
+		/// <summary>
+		/// 登陆前是客户端时间,登陆后是同步过的服务器时间
+		/// </summary>
+		/// <returns></returns>
+		public static long Now()
+		{
+			TimeComponent gameTimeComponent = Game.Scene?.GetComponent<TimeComponent>();
+			if (gameTimeComponent == null)
+			{
+				return TimeHelper.ClientNow();
+			}
+			long t = gameTimeComponent.Now();
+			return t;
+		}
+    }
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Helper/TimeHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: d84339e3b40f2b9418d7c60a62f9c50a
+timeCreated: 1474945123
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 97 - 0
Unity/Assets/Scripts/Base/Helper/ZipHelper.cs

@@ -0,0 +1,97 @@
+using System.IO;
+using ICSharpCode.SharpZipLib.Zip.Compression;
+
+namespace Base
+{
+	public static class ZipHelper
+	{
+		public static byte[] Compress(byte[] content)
+		{
+			//return content;
+			Deflater compressor = new Deflater();
+			compressor.SetLevel(Deflater.BEST_COMPRESSION);
+
+			compressor.SetInput(content);
+			compressor.Finish();
+
+			using (MemoryStream bos = new MemoryStream(content.Length))
+			{
+				var buf = new byte[1024];
+				while (!compressor.IsFinished)
+				{
+					int n = compressor.Deflate(buf);
+					bos.Write(buf, 0, n);
+				}
+				return bos.ToArray();
+			}
+		}
+
+		public static byte[] Decompress(byte[] content)
+		{
+			return Decompress(content, 0, content.Length);
+		}
+
+		public static byte[] Decompress(byte[] content, int offset, int count)
+		{
+			//return content;
+			Inflater decompressor = new Inflater();
+			decompressor.SetInput(content, offset, count);
+
+			using (MemoryStream bos = new MemoryStream(content.Length))
+			{
+				var buf = new byte[1024];
+				while (!decompressor.IsFinished)
+				{
+					int n = decompressor.Inflate(buf);
+					bos.Write(buf, 0, n);
+				}
+				return bos.ToArray();
+			}
+		}
+	}
+}
+
+/*
+using System.IO;
+using System.IO.Compression;
+
+namespace Model
+{
+	public static class ZipHelper
+	{
+		public static byte[] Compress(byte[] content)
+		{
+			using (MemoryStream ms = new MemoryStream())
+			using (DeflateStream stream = new DeflateStream(ms, CompressionMode.Compress, true))
+			{
+				stream.Write(content, 0, content.Length);
+				return ms.ToArray();
+			}
+		}
+
+		public static byte[] Decompress(byte[] content)
+		{
+			return Decompress(content, 0, content.Length);
+		}
+
+		public static byte[] Decompress(byte[] content, int offset, int count)
+		{
+			using (MemoryStream ms = new MemoryStream())
+			using (DeflateStream stream = new DeflateStream(new MemoryStream(content, offset, count), CompressionMode.Decompress, true))
+			{
+				byte[] buffer = new byte[1024];
+				while (true)
+				{
+					int bytesRead = stream.Read(buffer, 0, 1024);
+					if (bytesRead == 0)
+					{
+						break;
+					}
+					ms.Write(buffer, 0, bytesRead);
+				}
+				return ms.ToArray();
+			}
+		}
+	}
+}
+*/

+ 12 - 0
Unity/Assets/Scripts/Base/Helper/ZipHelper.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 75d07d90984a5dc4698c98d2fe3809bf
+timeCreated: 1474948216
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 11 - 40
Unity/Assets/Scripts/Base/Log.cs

@@ -1,59 +1,30 @@
-using System;
-using System.IO;
-using System.Text;
-using UnityEngine;
-
-namespace Base
+namespace Base
 {
 	public static class Log
 	{
-#if !UNITY_EDITOR
-		public static readonly StreamWriter sw;
-
-		static Log()
+        public static void Warning(string msg)
 		{
-			sw = new StreamWriter($"./Game_Data/log-{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}.txt", false, Encoding.Unicode, 1024);
-		}
-#endif
-
-		public static void Warning(string msg)
-		{
-			DateTime dateTime = DateTime.Now;
-			string s = $"{dateTime.ToString("yyyy-MM-dd HH:mm:ss")} {msg}";
-
-#if !UNITY_EDITOR
-			sw.WriteLine(s);
-#endif
-			UnityEngine.Debug.LogWarning(s);
-
+			Share.Scene.GetComponent<LogComponent>().Warning(msg);
 		}
 
 		public static void Info(string msg)
 		{
-			DateTime dateTime = DateTime.Now;
-			string s = $"{dateTime.ToString("yyyy-MM-dd HH:mm:ss")} {msg}";
-
-#if !UNITY_EDITOR
-			sw.WriteLine(s);
-#else
-			UnityEngine.Debug.Log(s);
-#endif
+			Share.Scene.GetComponent<LogComponent>().Info(msg);
 		}
 
 		public static void Error(string msg)
 		{
-			DateTime dateTime = DateTime.Now;
-			string s = $"{dateTime.ToString("yyyy-MM-dd HH:mm:ss")} {msg}";
-			UnityEngine.Debug.LogError(s);
+			Share.Scene.GetComponent<LogComponent>().Error(msg);
 		}
 
 		public static void Debug(string msg)
 		{
-#if UNITY_EDITOR
-			DateTime dateTime = DateTime.Now;
-			string s = $"{dateTime.ToString("yyyy-MM-dd HH:mm:ss")} {msg}";
-			UnityEngine.Debug.Log(s);
-#endif
+			Share.Scene.GetComponent<LogComponent>().Debug(msg);
+		}
+
+		public static void Flush()
+		{
+			Share.Scene.GetComponent<LogComponent>().Flush();
 		}
 	}
 }

+ 111 - 0
Unity/Assets/Scripts/Base/MultiMap.cs

@@ -0,0 +1,111 @@
+using System.Collections.Generic;
+
+namespace Base
+{
+	public class MultiMap<T, K>
+	{
+		private readonly SortedDictionary<T, List<K>> dictionary = new SortedDictionary<T, List<K>>();
+
+		public SortedDictionary<T, List<K>>.KeyCollection Keys
+		{
+			get
+			{
+				return this.dictionary.Keys;
+			}
+		}
+
+		public void Add(T t, K k)
+		{
+			List<K> list;
+			this.dictionary.TryGetValue(t, out list);
+			if (list == null)
+			{
+				list = new List<K>();
+			}
+			list.Add(k);
+			this.dictionary[t] = list;
+		}
+
+		public bool Remove(T t, K k)
+		{
+			List<K> list;
+			this.dictionary.TryGetValue(t, out list);
+			if (list == null)
+			{
+				return false;
+			}
+			if (!list.Remove(k))
+			{
+				return false;
+			}
+			if (list.Count == 0)
+			{
+				this.dictionary.Remove(t);
+			}
+			return true;
+		}
+
+		public bool Remove(T t)
+		{
+			return this.dictionary.Remove(t);
+		}
+
+		/// <summary>
+		/// 不返回内部的list,copy一份出来
+		/// </summary>
+		/// <param name="t"></param>
+		/// <returns></returns>
+		public K[] GetAll(T t)
+		{
+			List<K> list;
+			this.dictionary.TryGetValue(t, out list);
+			if (list == null)
+			{
+				return new K[0];
+			}
+			var newList = new List<K>();
+			foreach (K k in list)
+			{
+				newList.Add(k);
+			}
+			return newList.ToArray();
+		}
+
+		/// <summary>
+		/// 返回内部的list
+		/// </summary>
+		/// <param name="t"></param>
+		/// <returns></returns>
+		public List<K> this[T t]
+		{
+			get
+			{
+				List<K> list;
+				this.dictionary.TryGetValue(t, out list);
+				return list;
+			}
+		}
+
+		public K GetOne(T t)
+		{
+			List<K> list;
+			this.dictionary.TryGetValue(t, out list);
+			if ((list != null) && (list.Count > 0))
+			{
+				return list[0];
+			}
+			return default(K);
+		}
+
+		public bool Contains(T t, K k)
+		{
+			List<K> list;
+			this.dictionary.TryGetValue(t, out list);
+			if (list == null)
+			{
+				return false;
+			}
+			return list.Contains(k);
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/MultiMap.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 7092b642480a58741a65a8c49d2e082c
+timeCreated: 1474943113
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Unity/Assets/Scripts/Base/Network.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 89949efe62b53a044928bcf3075aad2f
+folderAsset: yes
+timeCreated: 1474943042
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 48 - 0
Unity/Assets/Scripts/Base/Network/AChannel.cs

@@ -0,0 +1,48 @@
+using System;
+using System.Collections.Generic;
+
+namespace Base
+{
+	[Flags]
+	public enum PacketFlags
+	{
+		None = 0,
+		Reliable = 1 << 0,
+		Unsequenced = 1 << 1,
+		NoAllocate = 1 << 2
+	}
+
+	public abstract class AChannel: Entity<AChannel>
+	{
+		protected AService service;
+
+		protected AChannel(AService service)
+		{
+			this.service = service;
+		}
+
+		public abstract void ConnectAsync();
+
+		/// <summary>
+		/// 发送消息
+		/// </summary>
+		public abstract void Send(byte[] buffer, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable);
+
+		public abstract void Send(List<byte[]> buffers, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable);
+
+		/// <summary>
+		/// 接收消息
+		/// </summary>
+		public abstract byte[] Recv();
+
+		public override void Dispose()
+		{
+			if (this.Id == 0)
+			{
+				return;
+			}
+
+			base.Dispose();
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/AChannel.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 05a074f965a8c214f8f1f1af1ecf4dcc
+timeCreated: 1440989101
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 50 - 0
Unity/Assets/Scripts/Base/Network/AService.cs

@@ -0,0 +1,50 @@
+using System;
+using System.Net.Sockets;
+
+namespace Base
+{
+	public enum NetworkProtocol
+	{
+		TCP,
+		UDP
+	}
+
+	public abstract class AService: IDisposable
+	{
+		/// <summary>
+		/// 将函数调用加入IService线程
+		/// </summary>
+		/// <param name="action"></param>
+		public abstract void Add(Action action);
+
+		public abstract AChannel GetChannel(long id);
+
+		public abstract AChannel GetChannel(string host, int port);
+
+		public abstract AChannel GetChannel(string address);
+		
+		public abstract void Remove(long channelId);
+
+		public abstract void Update();
+
+		private readonly TimerManager timerManager = new TimerManager();
+
+		public TimerManager Timer
+		{
+			get
+			{
+				return timerManager;
+			}
+		}
+
+		public Action<long, SocketError> OnError;
+
+		public void OnChannelError(long channelId, SocketError error)
+		{
+			this.OnError?.Invoke(channelId, error);
+			this.Remove(channelId);
+		}
+
+		public abstract void Dispose();
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/AService.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: b5af0de1c471e6c43989dc0349cc2bba
+timeCreated: 1440989101
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Unity/Assets/Scripts/Base/Network/TNet.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 2b578de151e7f46489a1326f6b38658c
+folderAsset: yes
+timeCreated: 1440989101
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 11 - 0
Unity/Assets/Scripts/Base/Network/TNet/IPoller.cs

@@ -0,0 +1,11 @@
+using System;
+
+namespace Base
+{
+	public interface IPoller
+	{
+		void Add(Action action);
+
+		void Update();
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/TNet/IPoller.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 1d609f021d8833b4c8f9cc79d267a1a6
+timeCreated: 1429240758
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 80 - 0
Unity/Assets/Scripts/Base/Network/TNet/PacketParser.cs

@@ -0,0 +1,80 @@
+using System;
+
+namespace Base
+{
+	internal enum ParserState
+	{
+		PacketSize,
+		PacketBody
+	}
+
+	internal class PacketParser
+	{
+		private readonly TBuffer buffer;
+
+		private uint packetSize;
+		private readonly byte[] packetSizeBuffer = new byte[4];
+		private ParserState state;
+		private byte[] packet;
+		private bool isOK;
+
+		public PacketParser(TBuffer buffer)
+		{
+			this.buffer = buffer;
+		}
+
+		public bool Parse()
+		{
+			if (this.isOK)
+			{
+				return true;
+			}
+
+			bool finish = false;
+			while (!finish)
+			{
+				switch (this.state)
+				{
+					case ParserState.PacketSize:
+						if (this.buffer.Count < 4)
+						{
+							finish = true;
+						}
+						else
+						{
+							this.buffer.RecvFrom(this.packetSizeBuffer);
+							this.packetSize = BitConverter.ToUInt32(this.packetSizeBuffer, 0);
+							if (packetSize > 1024 * 1024)
+							{
+								throw new GameException($"packet too large, size: {this.packetSize}");
+							}
+							this.state = ParserState.PacketBody;
+						}
+						break;
+					case ParserState.PacketBody:
+						if (this.buffer.Count < this.packetSize)
+						{
+							finish = true;
+						}
+						else
+						{
+							this.packet = new byte[this.packetSize];
+							this.buffer.RecvFrom(this.packet);
+							this.isOK = true;
+							this.state = ParserState.PacketSize;
+							finish = true;
+						}
+						break;
+				}
+			}
+			return this.isOK;
+		}
+
+		public byte[] GetPacket()
+		{
+			byte[] result = this.packet;
+			this.isOK = false;
+			return result;
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/TNet/PacketParser.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 8b71d12882faac44992e531533491a5f
+timeCreated: 1429240758
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 129 - 0
Unity/Assets/Scripts/Base/Network/TNet/TBuffer.cs

@@ -0,0 +1,129 @@
+using System;
+using System.Collections.Generic;
+
+namespace Base
+{
+	public class TBuffer
+	{
+		public const int ChunkSize = 8192;
+
+		private readonly LinkedList<byte[]> bufferList = new LinkedList<byte[]>();
+
+		public int LastIndex { get; set; }
+
+		public int FirstIndex { get; set; }
+
+		public TBuffer()
+		{
+			this.bufferList.AddLast(new byte[ChunkSize]);
+		}
+
+		public int Count
+		{
+			get
+			{
+				int c = 0;
+				if (this.bufferList.Count == 0)
+				{
+					c = 0;
+				}
+				else
+				{
+					c = (this.bufferList.Count - 1) * ChunkSize + this.LastIndex - this.FirstIndex;
+				}
+				if (c < 0)
+				{
+					Log.Error("TBuffer count < 0: {0}, {1}, {2}".Fmt(bufferList.Count, this.LastIndex, this.FirstIndex));
+				}
+				return c;
+			}
+		}
+
+		public void AddLast()
+		{
+			this.bufferList.AddLast(new byte[ChunkSize]);
+		}
+
+		public void RemoveFirst()
+		{
+			this.bufferList.RemoveFirst();
+		}
+
+		public byte[] First
+		{
+			get
+			{
+				if (this.bufferList.First == null)
+				{
+					this.AddLast();
+				}
+				return this.bufferList.First.Value;
+			}
+		}
+
+		public byte[] Last
+		{
+			get
+			{
+				if (this.bufferList.Last == null)
+				{
+					this.AddLast();
+				}
+				return this.bufferList.Last.Value;
+			}
+		}
+
+		public void RecvFrom(byte[] buffer)
+		{
+			if (this.Count < buffer.Length || buffer.Length == 0)
+			{
+				throw new GameException($"bufferList size < n, bufferList: {this.Count} buffer length: {buffer.Length}");
+			}
+			int alreadyCopyCount = 0;
+			while (alreadyCopyCount < buffer.Length)
+			{
+				int n = buffer.Length - alreadyCopyCount;
+				if (ChunkSize - this.FirstIndex > n)
+				{
+					Array.Copy(this.bufferList.First.Value, this.FirstIndex, buffer, alreadyCopyCount, n);
+					this.FirstIndex += n;
+					alreadyCopyCount += n;
+				}
+				else
+				{
+					Array.Copy(this.bufferList.First.Value, this.FirstIndex, buffer, alreadyCopyCount, ChunkSize - this.FirstIndex);
+					alreadyCopyCount += ChunkSize - this.FirstIndex;
+					this.FirstIndex = 0;
+					this.bufferList.RemoveFirst();
+				}
+			}
+		}
+
+		public void SendTo(byte[] buffer)
+		{
+			int alreadyCopyCount = 0;
+			while (alreadyCopyCount < buffer.Length)
+			{
+				if (this.LastIndex == ChunkSize)
+				{
+					this.bufferList.AddLast(new byte[ChunkSize]);
+					this.LastIndex = 0;
+				}
+
+				int n = buffer.Length - alreadyCopyCount;
+				if (ChunkSize - this.LastIndex > n)
+				{
+					Array.Copy(buffer, alreadyCopyCount, this.bufferList.Last.Value, this.LastIndex, n);
+					this.LastIndex += buffer.Length - alreadyCopyCount;
+					alreadyCopyCount += n;
+				}
+				else
+				{
+					Array.Copy(buffer, alreadyCopyCount, this.bufferList.Last.Value, this.LastIndex, ChunkSize - this.LastIndex);
+					alreadyCopyCount += ChunkSize - this.LastIndex;
+					this.LastIndex = ChunkSize;
+				}
+			}
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/TNet/TBuffer.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: ea037025225a9c74b8ddb5349b0c18a6
+timeCreated: 1429240758
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 202 - 0
Unity/Assets/Scripts/Base/Network/TNet/TChannel.cs

@@ -0,0 +1,202 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Sockets;
+
+namespace Base
+{
+	public class TChannel: AChannel
+	{
+		private const int SendInterval = 0;
+		private TSocket socket;
+
+		private readonly TBuffer recvBuffer = new TBuffer();
+		private readonly TBuffer sendBuffer = new TBuffer();
+
+		private long sendTimer;
+		private readonly PacketParser parser;
+		private readonly string remoteAddress;
+		private bool isConnected;
+
+		public Action<long, SocketError> OnError;
+
+		public TChannel(TSocket socket, string host, int port, TService service): base(service)
+		{
+			this.socket = socket;
+			this.parser = new PacketParser(this.recvBuffer);
+			this.remoteAddress = host + ":" + port;
+		}
+
+		public override void Dispose()
+		{
+			if (this.Id == 0)
+			{
+				return;
+			}
+
+			long id = this.Id;
+
+			base.Dispose();
+
+			this.socket.Dispose();
+			this.service.Remove(id);
+		}
+
+		public override void ConnectAsync()
+		{
+			string[] ss = this.remoteAddress.Split(':');
+			int port = int.Parse(ss[1]);
+			bool result = this.socket.ConnectAsync(ss[0], port);
+			if (!result)
+			{
+				this.OnConnected(this.Id, SocketError.Success);
+				return;
+			}
+			this.socket.OnConn += e => OnConnected(this.Id, e);
+		}
+
+		private void OnConnected(long channelId, SocketError error)
+		{
+			if (this.service.GetChannel(channelId) == null)
+			{
+				return;
+			}
+			if (error != SocketError.Success)
+			{
+				Log.Error($"connect error: {error}");
+                return;
+			}
+			this.isConnected = true;
+			this.SetStartSendFlag();
+			this.StartRecv();
+		}
+
+		private void SetStartSendFlag()
+		{
+			if (this.sendTimer == 0)
+			{
+				this.sendTimer = this.service.Timer.Add(TimeHelper.ClientNow() + SendInterval, this.StartSend);
+			}
+		}
+
+		public override void Send(byte[] buffer, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
+		{
+			byte[] size = BitConverter.GetBytes(buffer.Length);
+			this.sendBuffer.SendTo(size);
+			this.sendBuffer.SendTo(buffer);
+			if (this.isConnected)
+			{
+				this.SetStartSendFlag();
+			}
+		}
+
+		public override void Send(List<byte[]> buffers, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
+		{
+			int size = buffers.Select(b => b.Length).Sum();
+			byte[] sizeBuffer = BitConverter.GetBytes(size);
+			this.sendBuffer.SendTo(sizeBuffer);
+			foreach (byte[] buffer in buffers)
+			{
+				this.sendBuffer.SendTo(buffer);
+			}
+			if (this.isConnected)
+			{
+				this.SetStartSendFlag();
+			}
+		}
+
+		public long SendTimer
+		{
+			get
+			{
+				return this.sendTimer;
+			}
+		}
+
+		public override byte[] Recv()
+		{
+			if (this.parser.Parse())
+			{
+				return this.parser.GetPacket();
+			}
+			return null;
+		}
+
+		private void StartSend()
+		{
+			if (this.sendBuffer.Count == 0)
+			{
+				this.sendTimer = 0;
+				return;
+			}
+
+			int sendSize = TBuffer.ChunkSize - this.sendBuffer.FirstIndex;
+			if (sendSize > this.sendBuffer.Count)
+			{
+				sendSize = this.sendBuffer.Count;
+			}
+
+			if (!this.socket.SendAsync(this.sendBuffer.First, this.sendBuffer.FirstIndex, sendSize))
+			{
+				this.OnSend(this.Id, sendSize, SocketError.Success);
+				return;
+			}
+			this.socket.OnSend = (n, e) => this.OnSend(this.Id, n, e);
+		}
+
+		private void OnSend(long channelId, int n, SocketError error)
+		{
+			if (this.service.GetChannel(channelId) == null)
+			{
+				return;
+			}
+			this.socket.OnSend = null;
+			if (error != SocketError.Success)
+			{
+				Log.Info($"socket send fail, error: {error}, n: {n}");
+				this.OnError(this.Id, error);
+				return;
+			}
+			this.sendBuffer.FirstIndex += n;
+			if (this.sendBuffer.FirstIndex == TBuffer.ChunkSize)
+			{
+				this.sendBuffer.FirstIndex = 0;
+				this.sendBuffer.RemoveFirst();
+			}
+			this.StartSend();
+		}
+
+		private void StartRecv()
+		{
+			int size = TBuffer.ChunkSize - this.recvBuffer.LastIndex;
+			if (!this.socket.RecvAsync(this.recvBuffer.Last, this.recvBuffer.LastIndex, size))
+			{
+				this.OnRecv(this.Id, size, SocketError.Success);
+			}
+			this.socket.OnRecv = (n, e) => this.OnRecv(this.Id, n, e);
+		}
+
+		private void OnRecv(long channelId, int n, SocketError error)
+		{
+			if (this.service.GetChannel(channelId) == null)
+			{
+				return;
+			}
+			this.socket.OnRecv = null;
+			if (error != SocketError.Success)
+			{
+				Log.Info($"socket recv fail, error: {error}, {n}");
+				this.OnError(this.Id, error);
+				return;
+			}
+
+			this.recvBuffer.LastIndex += n;
+			if (this.recvBuffer.LastIndex == TBuffer.ChunkSize)
+			{
+				this.recvBuffer.AddLast();
+				this.recvBuffer.LastIndex = 0;
+			}
+			StartRecv();
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/TNet/TChannel.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 4cacc90d7e561c64a8ea0e9079163bb9
+timeCreated: 1429240758
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 38 - 0
Unity/Assets/Scripts/Base/Network/TNet/TPoller.cs

@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+
+namespace Base
+{
+	public class TPoller: IPoller
+	{
+		// 线程同步队列,发送接收socket回调都放到该队列,由poll线程统一执行
+		private Queue<Action> queue = new Queue<Action>();
+
+		private Queue<Action> localQueue = new Queue<Action>();
+
+		private readonly object lockObject = new object();
+
+		public void Add(Action action)
+		{
+			lock (lockObject)
+			{
+				this.queue.Enqueue(action);
+			}
+		}
+
+		public void Update()
+		{
+			lock (lockObject)
+			{
+				localQueue = queue;
+				queue = new Queue<Action>();
+			}
+
+			while (this.localQueue.Count > 0)
+			{
+				Action a = this.localQueue.Dequeue();
+				a();
+			}
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/TNet/TPoller.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 1d917d28f96a22b46aecc463e97e8328
+timeCreated: 1429240758
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 94 - 0
Unity/Assets/Scripts/Base/Network/TNet/TService.cs

@@ -0,0 +1,94 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Base
+{
+	public sealed class TService: AService
+	{
+		private IPoller poller = new TPoller();
+		
+		private readonly Dictionary<long, TChannel> idChannels = new Dictionary<long, TChannel>();
+
+		private void Dispose(bool disposing)
+		{
+			if (this.poller == null)
+			{
+				return;
+			}
+
+			if (disposing)
+			{
+				foreach (long id in this.idChannels.Keys.ToArray())
+				{
+					TChannel channel = this.idChannels[id];
+					channel.Dispose();
+				}
+			}
+
+			this.poller = null;
+		}
+
+		~TService()
+		{
+			this.Dispose(false);
+		}
+
+		public override void Dispose()
+		{
+			this.Dispose(true);
+			GC.SuppressFinalize(this);
+		}
+
+		public override void Add(Action action)
+		{
+			this.poller.Add(action);
+		}
+
+		public override AChannel GetChannel(long id)
+		{
+			TChannel channel = null;
+			this.idChannels.TryGetValue(id, out channel);
+			return channel;
+		}
+
+		public override void Remove(long id)
+		{
+			TChannel channel;
+			if (!this.idChannels.TryGetValue(id, out channel))
+			{
+				return;
+			}
+			if (channel == null)
+			{
+				return;
+			}
+			this.idChannels.Remove(id);
+			this.Timer.Remove(channel.SendTimer);
+			channel.Dispose();
+		}
+
+		public override AChannel GetChannel(string host, int port)
+		{
+			TChannel channel = null;
+			TSocket newSocket = new TSocket(this.poller);
+			channel = new TChannel(newSocket, host, port, this);
+			channel.OnError += this.OnChannelError;
+			this.idChannels[channel.Id] = channel;
+			return channel;
+		}
+
+		public override AChannel GetChannel(string address)
+		{
+			string[] ss = address.Split(':');
+			int port = int.Parse(ss[1]);
+			return this.GetChannel(ss[0], port);
+		}
+
+		public override void Update()
+		{
+			this.poller.Update();
+			this.Timer.Update();
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/TNet/TService.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 9c6cb526a0e4374438cbcbaa70239e4a
+timeCreated: 1429240758
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 181 - 0
Unity/Assets/Scripts/Base/Network/TNet/TSocket.cs

@@ -0,0 +1,181 @@
+using System;
+using System.Net;
+using System.Net.Sockets;
+
+namespace Base
+{
+	/// <summary>
+	/// 封装Socket,将回调push到主线程处理
+	/// </summary>
+	public class TSocket: IDisposable
+	{
+		private readonly IPoller poller;
+		private Socket socket;
+		private readonly SocketAsyncEventArgs innArgs = new SocketAsyncEventArgs();
+		private readonly SocketAsyncEventArgs outArgs = new SocketAsyncEventArgs();
+
+		public Action<SocketError> OnConn;
+		public Action<int, SocketError> OnRecv;
+		public Action<int, SocketError> OnSend;
+		public Action<SocketError> OnDisconnect;
+		private string remoteAddress;
+
+		public TSocket(IPoller poller)
+		{
+			this.poller = poller;
+			this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+			this.innArgs.Completed += this.OnComplete;
+			this.outArgs.Completed += this.OnComplete;
+		}
+
+		public string RemoteAddress
+		{
+			get
+			{
+				return remoteAddress;
+			}
+		}
+
+		public Socket Socket
+		{
+			get
+			{
+				return this.socket;
+			}
+		}
+
+		protected void Dispose(bool disposing)
+		{
+			if (this.socket == null)
+			{
+				return;
+			}
+
+			if (disposing)
+			{
+				this.socket.Close();
+			}
+
+			this.socket = null;
+		}
+
+		~TSocket()
+		{
+			this.Dispose(false);
+		}
+
+		public void Dispose()
+		{
+			this.Dispose(true);
+			GC.SuppressFinalize(this);
+		}
+
+		private void OnComplete(object sender, SocketAsyncEventArgs e)
+		{
+			Action action;
+			switch (e.LastOperation)
+			{
+				case SocketAsyncOperation.Connect:
+					action = () => OnConnectComplete(e);
+					break;
+				case SocketAsyncOperation.Receive:
+					action = () => OnRecvComplete(e);
+					break;
+				case SocketAsyncOperation.Send:
+					action = () => OnSendComplete(e);
+					break;
+				case SocketAsyncOperation.Disconnect:
+					action = () => OnDisconnectComplete(e);
+					break;
+				default:
+					throw new GameException($"socket error: {e.LastOperation}");
+			}
+
+			this.poller.Add(action);
+		}
+
+		public bool ConnectAsync(string host, int port)
+		{
+			remoteAddress = $"{host}:{port}";
+			this.outArgs.RemoteEndPoint = new IPEndPoint(IPAddress.Parse(host), port);
+			if (this.socket.ConnectAsync(this.outArgs))
+			{
+				return true;
+			}
+			OnConnectComplete(this.outArgs);
+			return false;
+		}
+
+		private void OnConnectComplete(SocketAsyncEventArgs e)
+		{
+			if (this.OnConn == null)
+			{
+				return;
+			}
+			this.OnConn(e.SocketError);
+		}
+
+		public bool RecvAsync(byte[] buffer, int offset, int count)
+		{
+			try
+			{
+				this.innArgs.SetBuffer(buffer, offset, count);
+			}
+			catch (Exception e)
+			{
+				throw new GameException($"socket set buffer error: {buffer.Length}, {offset}, {count}", e);
+			}
+			if (this.socket.ReceiveAsync(this.innArgs))
+			{
+				return true;
+			}
+			OnRecvComplete(this.innArgs);
+			return false;
+		}
+
+		private void OnRecvComplete(SocketAsyncEventArgs e)
+		{
+			if (this.OnRecv == null)
+			{
+				return;
+			}
+			this.OnRecv(e.BytesTransferred, e.SocketError);
+		}
+
+		public bool SendAsync(byte[] buffer, int offset, int count)
+		{
+			try
+			{
+				this.outArgs.SetBuffer(buffer, offset, count);
+			}
+			catch (Exception e)
+			{
+				throw new GameException($"socket set buffer error: {buffer.Length}, {offset}, {count}", e);
+			}
+			if (this.socket.SendAsync(this.outArgs))
+			{
+				return true;
+			}
+			OnSendComplete(this.outArgs);
+			return false;
+		}
+
+		private void OnSendComplete(SocketAsyncEventArgs e)
+		{
+			if (this.OnSend == null)
+			{
+				return;
+			}
+			this.OnSend(e.BytesTransferred, e.SocketError);
+		}
+
+		private void OnDisconnectComplete(SocketAsyncEventArgs e)
+		{
+			if (this.OnDisconnect == null)
+			{
+				return;
+			}
+			this.OnDisconnect(e.SocketError);
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/TNet/TSocket.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 1246431e11499344b8c036e69e2a71dd
+timeCreated: 1429240758
+licenseType: Free
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 72 - 0
Unity/Assets/Scripts/Base/Network/TimerManager.cs

@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+
+namespace Base
+{
+	public class TimerManager
+	{
+		private class Timer
+		{
+			public long Id { get; set; }
+			public long Time { get; set; }
+			public Action Action { get; set; }
+		}
+
+		private readonly Dictionary<long, Timer> timers = new Dictionary<long, Timer>();
+
+		/// <summary>
+		/// key: time, value: timer id
+		/// </summary>
+		private readonly MultiMap<long, long> timeGuid = new MultiMap<long, long>();
+
+		private readonly Queue<long> timeoutTimer = new Queue<long>();
+
+		public long Add(long time, Action action)
+		{
+			Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = time, Action = action };
+			this.timers[timer.Id] = timer;
+			this.timeGuid.Add(timer.Time, timer.Id);
+			return timer.Id;
+		}
+
+		public void Remove(long id)
+		{
+			Timer timer;
+			if (!this.timers.TryGetValue(id, out timer))
+			{
+				return;
+			}
+			this.timers.Remove(timer.Id);
+			this.timeGuid.Remove(timer.Time, timer.Id);
+		}
+
+		public void Update()
+		{
+			long timeNow = TimeHelper.ClientNow();
+			foreach (long time in this.timeGuid.Keys)
+			{
+				if (time > timeNow)
+				{
+					break;
+				}
+				this.timeoutTimer.Enqueue(time);
+			}
+
+			while (this.timeoutTimer.Count > 0)
+			{
+				long key = this.timeoutTimer.Dequeue();
+				long[] timeoutIds = this.timeGuid.GetAll(key);
+				foreach (long id in timeoutIds)
+				{
+					Timer timer;
+					if (!this.timers.TryGetValue(id, out timer))
+					{
+						continue;
+					}
+					this.Remove(id);
+					timer.Action();
+				}
+			}
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/TimerManager.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 25874ee32fa73c64c902d800b4543be3
+timeCreated: 1474948189
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Unity/Assets/Scripts/Base/Network/UNet.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: ade7fc5c4181e7649bddfadfc570c72f
+folderAsset: yes
+timeCreated: 1440989101
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 31 - 0
Unity/Assets/Scripts/Base/Network/UNet/Library.cs

@@ -0,0 +1,31 @@
+namespace Base
+{
+	internal static class Library
+	{
+		public static void Initialize()
+		{
+			int ret = NativeMethods.ENetInitialize();
+			if (ret < 0)
+			{
+				throw new GameException($"Initialization failed, ret: {ret}");
+			}
+		}
+
+		public static void Deinitialize()
+		{
+			NativeMethods.ENetDeinitialize();
+		}
+
+		public static uint Time
+		{
+			get
+			{
+				return NativeMethods.ENetTimeGet();
+			}
+			set
+			{
+				NativeMethods.ENetTimeSet(value);
+			}
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/UNet/Library.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 3d5dfbf30769f024da1a91ea2a6fc26b
+timeCreated: 1431427020
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 105 - 0
Unity/Assets/Scripts/Base/Network/UNet/NativeMethods.cs

@@ -0,0 +1,105 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace Base
+{
+	public static class NativeMethods
+	{
+		private const string LIB = "ENet";
+
+		public const int ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255;
+		public const int ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xfff;
+
+		[DllImport(LIB, EntryPoint = "enet_address_set_host")]
+		internal static extern int ENetAddressSetHost(ref ENetAddress address, string hostName);
+
+		[DllImport(LIB, EntryPoint = "enet_address_get_host")]
+		internal static extern int ENetAddressGetHost(ref ENetAddress address, StringBuilder hostName, uint nameLength);
+
+		[DllImport(LIB, EntryPoint = "enet_address_get_host_ip")]
+		internal static extern int ENetAddressGetHostIp(ref ENetAddress address, StringBuilder hostIp, uint ipLength);
+
+		[DllImport(LIB, EntryPoint = "enet_deinitialize")]
+		internal static extern void ENetDeinitialize();
+
+		[DllImport(LIB, EntryPoint = "enet_initialize")]
+		internal static extern int ENetInitialize();
+
+		[DllImport(LIB, EntryPoint = "enet_host_create")]
+		internal static extern IntPtr ENetHostCreate(
+				ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
+
+		[DllImport(LIB, EntryPoint = "enet_host_create")]
+		internal static extern IntPtr ENetHostCreate(IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
+
+		[DllImport(LIB, EntryPoint = "enet_host_destroy")]
+		internal static extern void ENetHostDestroy(IntPtr host);
+
+		[DllImport(LIB, EntryPoint = "enet_host_connect")]
+		internal static extern IntPtr ENetHostConnect(IntPtr host, ref ENetAddress address, uint channelCount, uint data);
+
+		[DllImport(LIB, EntryPoint = "enet_host_broadcast")]
+		internal static extern void ENetHostBroadcast(IntPtr host, byte channelID, IntPtr packet);
+
+		[DllImport(LIB, EntryPoint = "enet_host_compress")]
+		internal static extern void ENetHostCompress(IntPtr host, IntPtr compressor);
+
+		[DllImport(LIB, EntryPoint = "enet_host_compress_with_range_coder")]
+		internal static extern int ENetHostCompressWithRangeCoder(IntPtr host);
+
+		[DllImport(LIB, EntryPoint = "enet_host_channel_limit")]
+		internal static extern void ENetHostChannelLimit(IntPtr host, uint channelLimit);
+
+		[DllImport(LIB, EntryPoint = "enet_host_bandwidth_limit")]
+		internal static extern void ENetHostBandwidthLimit(IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
+
+		[DllImport(LIB, EntryPoint = "enet_host_flush")]
+		internal static extern void ENetHostFlush(IntPtr host);
+
+		[DllImport(LIB, EntryPoint = "enet_host_check_events")]
+		internal static extern int ENetHostCheckEvents(IntPtr host, ENetEvent ev);
+
+		[DllImport(LIB, EntryPoint = "enet_host_service")]
+		internal static extern int ENetHostService(IntPtr host, ENetEvent ev, uint timeout);
+
+		[DllImport(LIB, EntryPoint = "enet_time_get")]
+		internal static extern uint ENetTimeGet();
+
+		[DllImport(LIB, EntryPoint = "enet_time_set")]
+		internal static extern void ENetTimeSet(uint newTimeBase);
+
+		[DllImport(LIB, EntryPoint = "enet_packet_create")]
+		internal static extern IntPtr ENetPacketCreate(byte[] data, uint dataLength, PacketFlags flags);
+
+		[DllImport(LIB, EntryPoint = "enet_packet_destroy")]
+		internal static extern void ENetPacketDestroy(IntPtr packet);
+
+		[DllImport(LIB, EntryPoint = "enet_packet_resize")]
+		internal static extern int ENetPacketResize(IntPtr packet, uint dataLength);
+
+		[DllImport(LIB, EntryPoint = "enet_peer_throttle_configure")]
+		internal static extern void ENetPeerThrottleConfigure(IntPtr peer, uint interval, uint acceleration, uint deceleration);
+
+		[DllImport(LIB, EntryPoint = "enet_peer_send")]
+		internal static extern int ENetPeerSend(IntPtr peer, byte channelID, IntPtr packet);
+
+		[DllImport(LIB, EntryPoint = "enet_peer_receive")]
+		internal static extern IntPtr ENetPeerReceive(IntPtr peer, out byte channelID);
+
+		[DllImport(LIB, EntryPoint = "enet_peer_reset")]
+		internal static extern void ENetPeerReset(IntPtr peer);
+
+		[DllImport(LIB, EntryPoint = "enet_peer_ping")]
+		internal static extern void ENetPeerPing(IntPtr peer);
+
+		[DllImport(LIB, EntryPoint = "enet_peer_disconnect_now")]
+		internal static extern void ENetPeerDisconnectNow(IntPtr peer, uint data);
+
+		[DllImport(LIB, EntryPoint = "enet_peer_disconnect")]
+		internal static extern void ENetPeerDisconnect(IntPtr peer, uint data);
+
+		[DllImport(LIB, EntryPoint = "enet_peer_disconnect_later")]
+		internal static extern void ENetPeerDisconnectLater(IntPtr peer, uint data);
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/UNet/NativeMethods.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 35389856785ea104698c98410fef22d6
+timeCreated: 1431427020
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 76 - 0
Unity/Assets/Scripts/Base/Network/UNet/NativeStructs.cs

@@ -0,0 +1,76 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace Base
+{
+	internal enum EventType
+	{
+		None = 0,
+		Connect = 1,
+		Disconnect = 2,
+		Receive = 3
+	}
+
+	internal enum PeerState
+	{
+		Uninitialized = -1,
+		Disconnected = 0,
+		Connecting = 1,
+		AcknowledgingConnect = 2,
+		ConnectionPending = 3,
+		ConnectionSucceeded = 4,
+		Connected = 5,
+		DisconnectLater = 6,
+		Disconnecting = 7,
+		AcknowledgingDisconnect = 8,
+		Zombie = 9
+	}
+
+	[StructLayout(LayoutKind.Sequential)]
+	internal struct ENetAddress
+	{
+		public uint Host;
+		public ushort Port;
+	}
+
+	// ENetEvent
+	[StructLayout(LayoutKind.Sequential)]
+	internal class ENetEvent
+	{
+		public EventType Type;
+		public IntPtr Peer;
+		public byte ChannelID;
+		public uint Data;
+		public IntPtr Packet;
+	}
+
+	[StructLayout(LayoutKind.Sequential)]
+	internal class ENetListNode
+	{
+		public IntPtr Next;
+		public IntPtr Previous;
+	}
+
+	[StructLayout(LayoutKind.Sequential)]
+	internal struct ENetPacket
+	{
+		public IntPtr ReferenceCount; // size_t
+		public uint Flags;
+		public IntPtr Data;
+		public IntPtr DataLength; // size_t
+	}
+
+	[StructLayout(LayoutKind.Sequential)]
+	internal struct ENetPeer
+	{
+		public ENetListNode DispatchList;
+		public IntPtr Host;
+		public ushort OutgoingPeerID;
+		public ushort IncomingPeerID;
+		public uint ConnectID;
+		public byte OutgoingSessionID;
+		public byte IncomingSessionID;
+		public ENetAddress Address;
+		public IntPtr Data;
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/UNet/NativeStructs.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 0c22827e08133ae47aaba041ccbd7b66
+timeCreated: 1431427020
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 27 - 0
Unity/Assets/Scripts/Base/Network/UNet/UAddress.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Net;
+
+namespace Base
+{
+	internal struct UAddress
+	{
+		private readonly uint ip;
+		private readonly ushort port;
+
+		public UAddress(string host, int port)
+		{
+			IPAddress address = IPAddress.Parse(host);
+			this.ip = BitConverter.ToUInt32(address.GetAddressBytes(), 0);
+			this.port = (ushort) port;
+		}
+
+		public ENetAddress Struct
+		{
+			get
+			{
+				ENetAddress address = new ENetAddress { Host = this.ip, Port = this.port };
+				return address;
+			}
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/UNet/UAddress.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 25434e9690978f34eb6554089e5df159
+timeCreated: 1431427020
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 69 - 0
Unity/Assets/Scripts/Base/Network/UNet/UChannel.cs

@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Base
+{
+	internal class UChannel: AChannel
+	{
+		private USocket socket;
+		private readonly string remoteAddress;
+
+		public UChannel(USocket socket, string host, int port, UService service): base(service)
+		{
+			this.socket = socket;
+			this.service = service;
+			this.remoteAddress = host + ":" + port;
+		}
+
+		public override void Dispose()
+		{
+			if (this.Id == 0)
+			{
+				return;
+			}
+
+			long id = this.Id;
+
+			base.Dispose();
+
+			this.socket.Dispose();
+
+			this.service.Remove(id);
+		}
+
+		public override void ConnectAsync()
+		{
+			string[] ss = this.remoteAddress.Split(':');
+			ushort port = ushort.Parse(ss[1]);
+			this.socket.ConnectAsync(ss[0], port);
+		}
+
+		public override void Send(byte[] buffer, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
+		{
+			this.socket.SendAsync(buffer, channelID, flags);
+		}
+
+		public override void Send(List<byte[]> buffers, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
+		{
+			int size = buffers.Select(b => b.Length).Sum();
+			var buffer = new byte[size];
+			int index = 0;
+			foreach (byte[] bytes in buffers)
+			{
+				Array.Copy(bytes, 0, buffer, index, bytes.Length);
+				index += bytes.Length;
+			}
+			this.socket.SendAsync(buffer, channelID, flags);
+		}
+
+		public override byte[] Recv()
+		{
+			if (this.socket?.RecvQueue.Count == 0)
+			{
+				return null;
+			}
+			return this.socket?.RecvQueue.Dequeue();
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/UNet/UChannel.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: dc32f8527e761f74ba132eab17660a4a
+timeCreated: 1431427021
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 72 - 0
Unity/Assets/Scripts/Base/Network/UNet/UPacket.cs

@@ -0,0 +1,72 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace Base
+{
+	internal sealed class UPacket: IDisposable
+	{
+		public UPacket(IntPtr packet)
+		{
+			this.PacketPtr = packet;
+		}
+
+		public UPacket(byte[] data, PacketFlags flags = PacketFlags.None)
+		{
+			if (data == null)
+			{
+				throw new ArgumentNullException(nameof(data));
+			}
+			this.PacketPtr = NativeMethods.ENetPacketCreate(data, (uint) data.Length, flags);
+			if (this.PacketPtr == IntPtr.Zero)
+			{
+				throw new GameException("Packet creation call failed");
+			}
+		}
+
+		~UPacket()
+		{
+			this.Dispose(false);
+		}
+
+		public void Dispose()
+		{
+			this.Dispose(true);
+		}
+
+		private void Dispose(bool disposing)
+		{
+			if (this.PacketPtr == IntPtr.Zero)
+			{
+				return;
+			}
+
+			NativeMethods.ENetPacketDestroy(this.PacketPtr);
+			this.PacketPtr = IntPtr.Zero;
+		}
+
+		private ENetPacket Struct
+		{
+			get
+			{
+				return (ENetPacket) Marshal.PtrToStructure(this.PacketPtr, typeof (ENetPacket));
+			}
+			set
+			{
+				Marshal.StructureToPtr(value, this.PacketPtr, false);
+			}
+		}
+
+		public IntPtr PacketPtr { get; set; }
+
+		public byte[] Bytes
+		{
+			get
+			{
+				ENetPacket enetPacket = this.Struct;
+				var bytes = new byte[(long) enetPacket.DataLength];
+				Marshal.Copy(enetPacket.Data, bytes, 0, (int) enetPacket.DataLength);
+				return bytes;
+			}
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/UNet/UPacket.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 9ce921dae0159cb44a2f23fb52a7b69c
+timeCreated: 1431427020
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 160 - 0
Unity/Assets/Scripts/Base/Network/UNet/UPoller.cs

@@ -0,0 +1,160 @@
+using System;
+using System.Collections.Generic;
+
+namespace Base
+{
+	internal sealed class UPoller : IDisposable
+	{
+		static UPoller()
+		{
+			Library.Initialize();
+		}
+
+		private IntPtr host;
+
+		// 线程同步队列,发送接收socket回调都放到该队列,由poll线程统一执行
+		private Queue<Action> concurrentQueue = new Queue<Action>();
+
+		private Queue<Action> localQueue;
+
+		private ENetEvent eNetEventCache;
+
+		private readonly object lockObject = new object();
+
+		public UPoller()
+		{
+			this.USocketManager = new USocketManager();
+			this.host = NativeMethods.ENetHostCreate(IntPtr.Zero, NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID, 0, 0, 0);
+
+			if (this.host == IntPtr.Zero)
+			{
+				throw new GameException("Host creation call failed.");
+			}
+		}
+
+		~UPoller()
+		{
+			this.Dispose(false);
+		}
+
+		public void Dispose()
+		{
+			this.Dispose(true);
+		}
+
+		private void Dispose(bool disposing)
+		{
+			if (this.host == IntPtr.Zero)
+			{
+				return;
+			}
+
+			NativeMethods.ENetHostDestroy(this.host);
+
+			this.host = IntPtr.Zero;
+		}
+
+		public USocketManager USocketManager { get; }
+
+		public IntPtr Host
+		{
+			get
+			{
+				return this.host;
+			}
+		}
+
+		private ENetEvent GetEvent()
+		{
+			if (this.eNetEventCache == null)
+			{
+				this.eNetEventCache = new ENetEvent();
+			}
+			if (NativeMethods.ENetHostCheckEvents(this.host, this.eNetEventCache) <= 0)
+			{
+				return null;
+			}
+			ENetEvent eNetEvent = this.eNetEventCache;
+			this.eNetEventCache = null;
+			return eNetEvent;
+		}
+
+		public void Flush()
+		{
+			NativeMethods.ENetHostFlush(this.host);
+		}
+
+		public void Add(Action action)
+		{
+			this.concurrentQueue.Enqueue(action);
+		}
+
+		private void OnEvents()
+		{
+			lock (lockObject)
+			{
+				localQueue = concurrentQueue;
+				concurrentQueue = new Queue<Action>();
+			}
+
+			while (this.localQueue.Count > 0)
+			{
+				Action a = this.localQueue.Dequeue();
+				a();
+			}
+		}
+
+		private int Service()
+		{
+			int ret = NativeMethods.ENetHostService(this.host, null, 0);
+			return ret;
+		}
+
+		public void Update()
+		{
+			this.OnEvents();
+
+			if (this.Service() < 0)
+			{
+				return;
+			}
+
+			while (true)
+			{
+				ENetEvent eNetEvent = this.GetEvent();
+				if (eNetEvent == null)
+				{
+					return;
+				}
+
+				switch (eNetEvent.Type)
+				{
+					case EventType.Connect:
+						{
+							// 这是一个connect peer
+							if (this.USocketManager.ContainsKey(eNetEvent.Peer))
+							{
+								USocket uSocket = this.USocketManager[eNetEvent.Peer];
+								uSocket.OnConnected(eNetEvent);
+							}
+							break;
+						}
+					case EventType.Receive:
+						{
+							USocket uSocket = this.USocketManager[eNetEvent.Peer];
+							uSocket.OnReceived(eNetEvent);
+							break;
+						}
+					case EventType.Disconnect:
+						{
+							USocket uSocket = this.USocketManager[eNetEvent.Peer];
+							this.USocketManager.Remove(uSocket.PeerPtr);
+							uSocket.PeerPtr = IntPtr.Zero;
+							uSocket.OnDisconnect(eNetEvent);
+							break;
+						}
+				}
+			}
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/UNet/UPoller.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 019e23efabdb4e24590c4735d5e78df4
+timeCreated: 1431427020
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 98 - 0
Unity/Assets/Scripts/Base/Network/UNet/UService.cs

@@ -0,0 +1,98 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Sockets;
+
+namespace Base
+{
+	public sealed class UService: AService
+	{
+		private UPoller poller;
+		
+		private readonly Dictionary<long, UChannel> idChannels = new Dictionary<long, UChannel>();
+
+		/// <summary>
+		/// 只能做client
+		/// </summary>
+		public UService()
+		{
+			this.poller = new UPoller();
+		}
+
+		private void Dispose(bool disposing)
+		{
+			if (this.poller == null)
+			{
+				return;
+			}
+
+			if (disposing)
+			{
+				foreach (long id in this.idChannels.Keys.ToArray())
+				{
+					UChannel channel = this.idChannels[id];
+					channel.Dispose();
+				}
+				this.poller.Dispose();
+			}
+
+			this.poller = null;
+		}
+
+		public override void Dispose()
+		{
+			this.Dispose(true);
+			GC.SuppressFinalize(this);
+		}
+
+		public override void Add(Action action)
+		{
+			this.poller.Add(action);
+		}
+
+		public override AChannel GetChannel(string host, int port)
+		{
+			UChannel channel = null;
+
+			USocket newSocket = new USocket(this.poller);
+			channel = new UChannel(newSocket, host, port, this);
+			newSocket.Disconnect += () => this.OnChannelError(channel.Id, SocketError.SocketError);
+			this.idChannels[channel.Id] = channel;
+			return channel;
+		}
+
+		public override AChannel GetChannel(string address)
+		{
+			string[] ss = address.Split(':');
+			int port = int.Parse(ss[1]);
+			return this.GetChannel(ss[0], port);
+		}
+
+		public override AChannel GetChannel(long id)
+		{
+			UChannel channel = null;
+			this.idChannels.TryGetValue(id, out channel);
+			return channel;
+		}
+
+		public override void Remove(long id)
+		{
+			UChannel channel;
+			if (!this.idChannels.TryGetValue(id, out channel))
+			{
+				return;
+			}
+			if (channel == null)
+			{
+				return;
+			}
+			this.idChannels.Remove(id);
+			channel.Dispose();
+		}
+
+		public override void Update()
+		{
+			this.poller.Update();
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/UNet/UService.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 467cbc524035d6644b5bd164eded38a4
+timeCreated: 1431427020
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 125 - 0
Unity/Assets/Scripts/Base/Network/UNet/USocket.cs

@@ -0,0 +1,125 @@
+using System;
+using System.Collections.Generic;
+
+namespace Base
+{
+	internal class BufferInfo
+	{
+		public byte[] Buffer { get; set; }
+		public byte ChannelID { get; set; }
+		public PacketFlags Flags { get; set; }
+	}
+
+	internal sealed class USocket: IDisposable
+	{
+		private readonly UPoller poller;
+		private readonly Queue<byte[]> recvQueue = new Queue<byte[]>();
+		private readonly Queue<BufferInfo> sendQueue = new Queue<BufferInfo>();
+		private bool isConnected;
+		private string remoteAddress;
+		public Action Disconnect;
+
+		public USocket(IntPtr peerPtr, UPoller poller)
+		{
+			this.poller = poller;
+			this.PeerPtr = peerPtr;
+		}
+
+		public USocket(UPoller poller)
+		{
+			this.poller = poller;
+		}
+
+		private void Dispose(bool disposing)
+		{
+			if (this.PeerPtr == IntPtr.Zero)
+			{
+				return;
+			}
+
+			poller.USocketManager.Remove(this.PeerPtr);
+			NativeMethods.ENetPeerDisconnectNow(this.PeerPtr, 0);
+			this.PeerPtr = IntPtr.Zero;
+		}
+
+		~USocket()
+		{
+			this.Dispose(false);
+		}
+
+		public void Dispose()
+		{
+			this.Dispose(true);
+		}
+
+		public IntPtr PeerPtr { get; set; }
+
+		public string RemoteAddress
+		{
+			get
+			{
+				return remoteAddress;
+			}
+		}
+
+		public Queue<byte[]> RecvQueue
+		{
+			get
+			{
+				return recvQueue;
+			}
+		}
+
+		public void ConnectAsync(string host, ushort port)
+		{
+			this.remoteAddress = host + ":" + port;
+			UAddress address = new UAddress(host, port);
+			ENetAddress nativeAddress = address.Struct;
+
+			this.PeerPtr = NativeMethods.ENetHostConnect(this.poller.Host, ref nativeAddress, 2, 0);
+			if (this.PeerPtr == IntPtr.Zero)
+			{
+				throw new GameException($"host connect call failed, {host}:{port}");
+			}
+			this.poller.USocketManager.Add(this.PeerPtr, this);
+		}
+
+		public void SendAsync(byte[] data, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
+		{
+			if (!isConnected)
+			{
+				sendQueue.Enqueue(new BufferInfo { Buffer = data, ChannelID = channelID, Flags = flags });
+				return;
+			}
+			UPacket packet = new UPacket(data, flags);
+			NativeMethods.ENetPeerSend(this.PeerPtr, channelID, packet.PacketPtr);
+			// enet_peer_send函数会自动删除packet,设置为0,防止Dispose或者析构函数再次删除
+			packet.PacketPtr = IntPtr.Zero;
+		}
+
+		internal void OnConnected(ENetEvent eNetEvent)
+		{
+			isConnected = true;
+			while (this.sendQueue.Count > 0)
+			{
+				BufferInfo info = this.sendQueue.Dequeue();
+				this.SendAsync(info.Buffer, info.ChannelID, info.Flags);
+			}
+		}
+
+		internal void OnReceived(ENetEvent eNetEvent)
+		{
+			// 将包放到缓存队列
+			using (UPacket packet = new UPacket(eNetEvent.Packet))
+			{
+				byte[] bytes = packet.Bytes;
+				this.RecvQueue.Enqueue(bytes);
+			}
+		}
+
+		internal void OnDisconnect(ENetEvent eNetEvent)
+		{
+			Disconnect();
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/UNet/USocket.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 7611e7b646e2fa9448d445fded0c621a
+timeCreated: 1431427020
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 41 - 0
Unity/Assets/Scripts/Base/Network/UNet/USocketManager.cs

@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+
+namespace Base
+{
+	internal class USocketManager
+	{
+		private readonly Dictionary<IntPtr, USocket> sockets = new Dictionary<IntPtr, USocket>();
+
+		public void Add(IntPtr peerPtr, USocket uSocket)
+		{
+			this.sockets.Add(peerPtr, uSocket);
+		}
+
+		public void Remove(IntPtr peerPtr)
+		{
+			this.sockets.Remove(peerPtr);
+		}
+
+		public bool ContainsKey(IntPtr peerPtr)
+		{
+			if (this.sockets.ContainsKey(peerPtr))
+			{
+				return true;
+			}
+			return false;
+		}
+
+		public USocket this[IntPtr peerPtr]
+		{
+			get
+			{
+				if (!this.sockets.ContainsKey(peerPtr))
+				{
+					throw new KeyNotFoundException("No Peer Key");
+				}
+				return this.sockets[peerPtr];
+			}
+		}
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Base/Network/UNet/USocketManager.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 046affd300b9d2444974c08908b0eb88
+timeCreated: 1431427020
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
Unity/Assets/Scripts/Base/Object.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: bfb63bc23132cfe47aaac731331ca16e
+folderAsset: yes
+timeCreated: 1474942922
+licenseType: Pro
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Model/Object/Component.cs → Unity/Assets/Scripts/Base/Object/Component.cs

@@ -1,6 +1,6 @@
 using MongoDB.Bson.Serialization.Attributes;
 
-namespace Model
+namespace Base
 {
 	/// <summary>
 	/// Component的Id与Owner Entity Id一样

+ 12 - 0
Unity/Assets/Scripts/Base/Object/Component.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: adf193ef36db369469293a2f53c76aa4
+timeCreated: 1474942922
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Model/Object/Entity.cs → Unity/Assets/Scripts/Base/Object/Entity.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using Base;
 using MongoDB.Bson.Serialization.Attributes;
 
-namespace Model
+namespace Base
 {
 	public abstract class Entity<T>: Object where T : Entity<T>
 	{

+ 12 - 0
Unity/Assets/Scripts/Base/Object/Entity.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 5bb5f664ee9566b40a7fad24bab21d2f
+timeCreated: 1474942922
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Model/Object/IAwake.cs → Unity/Assets/Scripts/Base/Object/IAwake.cs

@@ -1,4 +1,4 @@
-namespace Model
+namespace Base
 {
 	/// <summary>
 	/// World的Componet实现该接口后,会在World.Start时调用该Start方法

+ 12 - 0
Unity/Assets/Scripts/Base/Object/IAwake.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: c70dab810e082bc49aa93d60d5bb7305
+timeCreated: 1474942922
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů