Browse Source

使用ENABLE_IL2CPP宏

tanghai 8 years ago
parent
commit
e3067001ef

+ 1 - 1
Client-Server.sln

@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 15
-VisualStudioVersion = 15.0.26730.15
+VisualStudioVersion = 15.0.27004.2006
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Plugins", "Unity\Unity.Plugins.csproj", "{D1FDB199-0FB7-099D-3771-C6A942E4E326}"
 EndProject

+ 2 - 2
Unity/Assets/Plugins/MongoDB/MongoDB.Bson/Serialization/BsonClassMap.cs

@@ -1277,10 +1277,10 @@ namespace MongoDB.Bson.Serialization
                 ConstructorInfo defaultConstructor = classTypeInfo.GetConstructors(bindingFlags)
                     .Where(c => c.GetParameters().Length == 0)
                     .SingleOrDefault();
-#if UNITY_IOS
+#if ENABLE_IL2CPP
                 _creator = () => defaultConstructor.Invoke(null);
 #else
-                if (defaultConstructor != null)
+				if (defaultConstructor != null)
                 {
                     // lambdaExpression = () => (object) new TClass()
                     body = Expression.New(defaultConstructor);

+ 6 - 6
Unity/Assets/Plugins/MongoDB/MongoDB.Bson/Serialization/BsonMemberMap.cs

@@ -16,7 +16,7 @@
 using System;
 using System.Linq.Expressions;
 using System.Reflection;
-#if !UNITY_IOS
+#if !ENABLE_IL2CPP
 using System.Reflection.Emit;		
 #endif
 using MongoDB.Bson.Serialization.Serializers;
@@ -582,7 +582,7 @@ namespace MongoDB.Bson.Serialization
                 throw new BsonSerializationException(message);
             }
 
-#if UNITY_IOS
+#if ENABLE_IL2CPP
 	        return (obj, value) => { fieldInfo.SetValue(obj, value); };
 #else
 			var sourceType = fieldInfo.DeclaringType;
@@ -602,7 +602,7 @@ namespace MongoDB.Bson.Serialization
 
 		private Func<object, object> GetGetter()
         {
-#if UNITY_IOS
+#if ENABLE_IL2CPP
             PropertyInfo propertyInfo = _memberInfo as PropertyInfo;
             if (propertyInfo != null)
             {
@@ -620,7 +620,7 @@ namespace MongoDB.Bson.Serialization
             FieldInfo fieldInfo = _memberInfo as FieldInfo;
             return (obj) => { return fieldInfo.GetValue(obj); };
 #else
-            var propertyInfo = _memberInfo as PropertyInfo;
+			var propertyInfo = _memberInfo as PropertyInfo;
             if (propertyInfo != null)
             {
                 var getMethodInfo = propertyInfo.GetMethod;
@@ -653,12 +653,12 @@ namespace MongoDB.Bson.Serialization
 
         private Action<object, object> GetPropertySetter()
         {
-#if UNITY_IOS
+#if ENABLE_IL2CPP
             var propertyInfo = (PropertyInfo) _memberInfo;
 
             return (obj, value) => { propertyInfo.SetValue(obj, value); };
 #else
-            var propertyInfo = (PropertyInfo)_memberInfo;
+			var propertyInfo = (PropertyInfo)_memberInfo;
             var setMethodInfo = propertyInfo.SetMethod;
             if (IsReadOnly)
             {

+ 65 - 0
Unity/Assets/Scripts/Entity/Session.cs

@@ -157,6 +157,71 @@ namespace Model
 			};
 		}
 
+		/// <summary>
+		/// Rpc调用,发送一个消息,等待返回一个消息
+		/// </summary>
+		public Task<AResponse> Call(ARequest request, bool isHotfix)
+		{
+			request.RpcId = ++RpcId;
+			this.SendMessage(request);
+
+			var tcs = new TaskCompletionSource<AResponse>();
+			this.requestCallback[RpcId] = (message) =>
+			{
+				try
+				{
+					AResponse response = (AResponse)message;
+					if (response.Error > 100)
+					{
+						tcs.SetException(new RpcException(response.Error, response.Message));
+						return;
+					}
+					//Log.Debug($"recv: {MongoHelper.ToJson(response)}");
+					tcs.SetResult(response);
+				}
+				catch (Exception e)
+				{
+					tcs.SetException(new Exception($"Rpc Error: {message.GetType().FullName}", e));
+				}
+			};
+
+			return tcs.Task;
+		}
+
+		/// <summary>
+		/// Rpc调用
+		/// </summary>
+		public Task<AResponse> Call(ARequest request, bool isHotfix, CancellationToken cancellationToken)
+		{
+			request.RpcId = ++RpcId;
+			this.SendMessage(request);
+
+			var tcs = new TaskCompletionSource<AResponse>();
+
+			this.requestCallback[RpcId] = (message) =>
+			{
+				try
+				{
+					AResponse response = (AResponse)message;
+					if (response.Error > 100)
+					{
+						tcs.SetException(new RpcException(response.Error, response.Message));
+						return;
+					}
+					//Log.Debug($"recv: {MongoHelper.ToJson(response)}");
+					tcs.SetResult(response);
+				}
+				catch (Exception e)
+				{
+					tcs.SetException(new Exception($"Rpc Error: {message.GetType().FullName}", e));
+				}
+			};
+
+			cancellationToken.Register(() => { this.requestCallback.Remove(RpcId); });
+
+			return tcs.Task;
+		}
+
 		/// <summary>
 		/// Rpc调用,发送一个消息,等待返回一个消息
 		/// </summary>

+ 1 - 0
Unity/Assets/link.xml

@@ -2,4 +2,5 @@
   <assembly fullname="Assembly-CSharp" preserve="all"/>
   <assembly fullname="Assembly-CSharp-firstpass" preserve="all"/>
   <assembly fullname="UnityEngine" preserve="all"/>
+  <assembly fullname="System" preserve="all"/>
 </linker>