Просмотр исходного кода

1.修复il2cpp下使用mongo bson的问题,去掉emit
2.修复NumericComponent组件的bug

tanghai 6 лет назад
Родитель
Сommit
3eacbdaa5a

+ 2 - 8
Unity/Assets/Model/Base/Helper/MongoHelper.cs

@@ -22,8 +22,6 @@ namespace ETModel
 
 				BsonClassMap.LookupClassMap(type);
 			}
-
-			BsonSerializer.RegisterSerializer(new EnumSerializer<NumericType>(BsonType.String));
 		}
 
 		public static string ToJson(object obj)
@@ -118,12 +116,8 @@ namespace ETModel
             ArraySerializer<int> aint = new ArraySerializer<int>();
             ArraySerializer<string> astring = new ArraySerializer<string>();
             ArraySerializer<long> along = new ArraySerializer<long>();
-
-            EnumerableInterfaceImplementerSerializer<List<int>> e =
-                new EnumerableInterfaceImplementerSerializer<List<int>>();
-
-            EnumerableInterfaceImplementerSerializer<List<int>, int> elistint =
-                new EnumerableInterfaceImplementerSerializer<List<int>, int>();
+            EnumerableInterfaceImplementerSerializer<List<int>> e = new EnumerableInterfaceImplementerSerializer<List<int>>();
+            EnumerableInterfaceImplementerSerializer<List<int>, int> elistint = new EnumerableInterfaceImplementerSerializer<List<int>, int>();
         }
 
 	}

+ 14 - 3
Unity/Assets/Model/Module/Numeric/NumericComponent.cs

@@ -13,7 +13,7 @@ namespace ETModel
 
 	public class NumericComponent: Component
 	{
-		public readonly Dictionary<int, int> NumericDic = new Dictionary<int, int>();
+		public Dictionary<int, int> NumericDic = new Dictionary<int, int>();
 
 		public void Awake()
 		{
@@ -24,11 +24,21 @@ namespace ETModel
 		{
 			return (float)GetByKey((int)numericType) / 10000;
 		}
+		
+		public float GetAsFloat(int numericType)
+		{
+			return (float)GetByKey(numericType) / 10000;
+		}
 
 		public int GetAsInt(NumericType numericType)
 		{
 			return GetByKey((int)numericType);
 		}
+		
+		public int GetAsInt(int numericType)
+		{
+			return GetByKey(numericType);
+		}
 
 		public void Set(NumericType nt, float value)
 		{
@@ -82,8 +92,9 @@ namespace ETModel
 
 			// 一个数值可能会多种情况影响,比如速度,加个buff可能增加速度绝对值100,也有些buff增加10%速度,所以一个值可以由5个值进行控制其最终结果
 			// final = (((base + add) * (100 + pct) / 100) + finalAdd) * (100 + finalPct) / 100;
-			this.NumericDic[final] = ((this.GetByKey(bas) + this.GetByKey(add)) * (100 + this.GetByKey(pct)) / 100 + this.GetByKey(finalAdd)) * (100 + this.GetByKey(finalPct)) / 100;
-			Game.EventSystem.Run(EventIdType.NumbericChange, this.Entity.Id, (NumericType) final, final);
+			int result = (int)(((this.GetByKey(bas) + this.GetByKey(add)) * (100 + this.GetAsFloat(pct)) / 100f + this.GetByKey(finalAdd)) * (100 + this.GetAsFloat(finalPct)) / 100f * 10000);
+			this.NumericDic[final] = result;
+			Game.EventSystem.Run(EventIdType.NumbericChange, this.Entity.Id, (NumericType) final, result);
 		}
 	}
 }

+ 13 - 49
Unity/Assets/ThirdParty/MongoDB/MongoDB.Bson/Serialization/BsonMemberMap.cs

@@ -14,9 +14,7 @@
 */
 
 using System;
-using System.Linq.Expressions;
 using System.Reflection;
-using System.Reflection.Emit;
 using MongoDB.Bson.Serialization.Serializers;
 
 namespace MongoDB.Bson.Serialization
@@ -570,13 +568,12 @@ namespace MongoDB.Bson.Serialization
 
         private Action<object, object> GetFieldSetter()
         {
-            var fieldInfo = (FieldInfo)_memberInfo;
+            FieldInfo fieldInfo = (FieldInfo) _memberInfo;
 
             if (IsReadOnly)
             {
-                var message = string.Format(
-                    "The field '{0} {1}' of class '{2}' is readonly. To avoid this exception, call IsReadOnly to ensure that setting a value is allowed.",
-                    fieldInfo.FieldType.FullName, fieldInfo.Name, fieldInfo.DeclaringType.FullName);
+                string message =
+                        $"The field '{fieldInfo.FieldType.FullName} {fieldInfo.Name}' of class '{fieldInfo.DeclaringType.FullName}' is readonly. To avoid this exception, call IsReadOnly to ensure that setting a value is allowed.";
                 throw new BsonSerializationException(message);
             }
 
@@ -585,61 +582,28 @@ namespace MongoDB.Bson.Serialization
 
         private Func<object, object> GetGetter()
         {
-            var propertyInfo = _memberInfo as PropertyInfo;
+            PropertyInfo propertyInfo = _memberInfo as PropertyInfo;
             if (propertyInfo != null)
             {
-                var getMethodInfo = propertyInfo.GetMethod;
+                MethodInfo getMethodInfo = propertyInfo.GetMethod;
                 if (getMethodInfo == null)
                 {
-                    var message = string.Format(
-                        "The property '{0} {1}' of class '{2}' has no 'get' accessor.",
-                        propertyInfo.PropertyType.FullName, propertyInfo.Name, propertyInfo.DeclaringType.FullName);
+                    string message =
+                            $"The property '{propertyInfo.PropertyType.FullName} {propertyInfo.Name}' of class '{propertyInfo.DeclaringType.FullName}' has no 'get' accessor.";
                     throw new BsonSerializationException(message);
                 }
-            }
 
-            // lambdaExpression = (obj) => (object) ((TClass) obj).Member
-            var objParameter = Expression.Parameter(typeof(object), "obj");
-            var lambdaExpression = Expression.Lambda<Func<object, object>>(
-                Expression.Convert(
-                    Expression.MakeMemberAccess(
-                        Expression.Convert(objParameter, _memberInfo.DeclaringType),
-                        _memberInfo
-                    ),
-                    typeof(object)
-                ),
-                objParameter
-            );
+                return obj => { return propertyInfo.GetValue(obj); };
+            }
 
-            return lambdaExpression.Compile();
+            FieldInfo fieldInfo = _memberInfo as FieldInfo;
+            return obj => { return fieldInfo.GetValue(obj); };
         }
 
         private Action<object, object> GetPropertySetter()
         {
-            var propertyInfo = (PropertyInfo)_memberInfo;
-            var setMethodInfo = propertyInfo.SetMethod;
-            if (IsReadOnly)
-            {
-                var message = string.Format(
-                    "The property '{0} {1}' of class '{2}' has no 'set' accessor. To avoid this exception, call IsReadOnly to ensure that setting a value is allowed.",
-                    propertyInfo.PropertyType.FullName, propertyInfo.Name, propertyInfo.DeclaringType.FullName);
-                throw new BsonSerializationException(message);
-            }
-
-            // lambdaExpression = (obj, value) => ((TClass) obj).SetMethod((TMember) value)
-            var objParameter = Expression.Parameter(typeof(object), "obj");
-            var valueParameter = Expression.Parameter(typeof(object), "value");
-            var lambdaExpression = Expression.Lambda<Action<object, object>>(
-                Expression.Call(
-                    Expression.Convert(objParameter, _memberInfo.DeclaringType),
-                    setMethodInfo,
-                    Expression.Convert(valueParameter, _memberType)
-                ),
-                objParameter,
-                valueParameter
-            );
-
-            return lambdaExpression.Compile();
+            PropertyInfo propertyInfo = (PropertyInfo) _memberInfo;
+            return (obj, value) => { propertyInfo.SetValue(obj, value); };
         }
 
         private void ThrowFrozenException()