提交 3eacbdaa 编写于 作者: T tanghai

1.修复il2cpp下使用mongo bson的问题,去掉emit

2.修复NumericComponent组件的bug
上级 a1c37f22
...@@ -22,8 +22,6 @@ namespace ETModel ...@@ -22,8 +22,6 @@ namespace ETModel
BsonClassMap.LookupClassMap(type); BsonClassMap.LookupClassMap(type);
} }
BsonSerializer.RegisterSerializer(new EnumSerializer<NumericType>(BsonType.String));
} }
public static string ToJson(object obj) public static string ToJson(object obj)
...@@ -118,12 +116,8 @@ namespace ETModel ...@@ -118,12 +116,8 @@ namespace ETModel
ArraySerializer<int> aint = new ArraySerializer<int>(); ArraySerializer<int> aint = new ArraySerializer<int>();
ArraySerializer<string> astring = new ArraySerializer<string>(); ArraySerializer<string> astring = new ArraySerializer<string>();
ArraySerializer<long> along = new ArraySerializer<long>(); ArraySerializer<long> along = new ArraySerializer<long>();
EnumerableInterfaceImplementerSerializer<List<int>> e = new EnumerableInterfaceImplementerSerializer<List<int>>();
EnumerableInterfaceImplementerSerializer<List<int>> e = EnumerableInterfaceImplementerSerializer<List<int>, int> elistint = new EnumerableInterfaceImplementerSerializer<List<int>, int>();
new EnumerableInterfaceImplementerSerializer<List<int>>();
EnumerableInterfaceImplementerSerializer<List<int>, int> elistint =
new EnumerableInterfaceImplementerSerializer<List<int>, int>();
} }
} }
......
...@@ -13,7 +13,7 @@ namespace ETModel ...@@ -13,7 +13,7 @@ namespace ETModel
public class NumericComponent: Component 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() public void Awake()
{ {
...@@ -24,11 +24,21 @@ namespace ETModel ...@@ -24,11 +24,21 @@ namespace ETModel
{ {
return (float)GetByKey((int)numericType) / 10000; return (float)GetByKey((int)numericType) / 10000;
} }
public float GetAsFloat(int numericType)
{
return (float)GetByKey(numericType) / 10000;
}
public int GetAsInt(NumericType numericType) public int GetAsInt(NumericType numericType)
{ {
return GetByKey((int)numericType); return GetByKey((int)numericType);
} }
public int GetAsInt(int numericType)
{
return GetByKey(numericType);
}
public void Set(NumericType nt, float value) public void Set(NumericType nt, float value)
{ {
...@@ -82,8 +92,9 @@ namespace ETModel ...@@ -82,8 +92,9 @@ namespace ETModel
// 一个数值可能会多种情况影响,比如速度,加个buff可能增加速度绝对值100,也有些buff增加10%速度,所以一个值可以由5个值进行控制其最终结果 // 一个数值可能会多种情况影响,比如速度,加个buff可能增加速度绝对值100,也有些buff增加10%速度,所以一个值可以由5个值进行控制其最终结果
// final = (((base + add) * (100 + pct) / 100) + finalAdd) * (100 + finalPct) / 100; // 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; int result = (int)(((this.GetByKey(bas) + this.GetByKey(add)) * (100 + this.GetAsFloat(pct)) / 100f + this.GetByKey(finalAdd)) * (100 + this.GetAsFloat(finalPct)) / 100f * 10000);
Game.EventSystem.Run(EventIdType.NumbericChange, this.Entity.Id, (NumericType) final, final); this.NumericDic[final] = result;
Game.EventSystem.Run(EventIdType.NumbericChange, this.Entity.Id, (NumericType) final, result);
} }
} }
} }
\ No newline at end of file
...@@ -14,9 +14,7 @@ ...@@ -14,9 +14,7 @@
*/ */
using System; using System;
using System.Linq.Expressions;
using System.Reflection; using System.Reflection;
using System.Reflection.Emit;
using MongoDB.Bson.Serialization.Serializers; using MongoDB.Bson.Serialization.Serializers;
namespace MongoDB.Bson.Serialization namespace MongoDB.Bson.Serialization
...@@ -570,13 +568,12 @@ namespace MongoDB.Bson.Serialization ...@@ -570,13 +568,12 @@ namespace MongoDB.Bson.Serialization
private Action<object, object> GetFieldSetter() private Action<object, object> GetFieldSetter()
{ {
var fieldInfo = (FieldInfo)_memberInfo; FieldInfo fieldInfo = (FieldInfo) _memberInfo;
if (IsReadOnly) if (IsReadOnly)
{ {
var message = string.Format( string message =
"The field '{0} {1}' of class '{2}' is readonly. To avoid this exception, call IsReadOnly to ensure that setting a value is allowed.", $"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.";
fieldInfo.FieldType.FullName, fieldInfo.Name, fieldInfo.DeclaringType.FullName);
throw new BsonSerializationException(message); throw new BsonSerializationException(message);
} }
...@@ -585,61 +582,28 @@ namespace MongoDB.Bson.Serialization ...@@ -585,61 +582,28 @@ namespace MongoDB.Bson.Serialization
private Func<object, object> GetGetter() private Func<object, object> GetGetter()
{ {
var propertyInfo = _memberInfo as PropertyInfo; PropertyInfo propertyInfo = _memberInfo as PropertyInfo;
if (propertyInfo != null) if (propertyInfo != null)
{ {
var getMethodInfo = propertyInfo.GetMethod; MethodInfo getMethodInfo = propertyInfo.GetMethod;
if (getMethodInfo == null) if (getMethodInfo == null)
{ {
var message = string.Format( string message =
"The property '{0} {1}' of class '{2}' has no 'get' accessor.", $"The property '{propertyInfo.PropertyType.FullName} {propertyInfo.Name}' of class '{propertyInfo.DeclaringType.FullName}' has no 'get' accessor.";
propertyInfo.PropertyType.FullName, propertyInfo.Name, propertyInfo.DeclaringType.FullName);
throw new BsonSerializationException(message); throw new BsonSerializationException(message);
} }
}
// lambdaExpression = (obj) => (object) ((TClass) obj).Member return obj => { return propertyInfo.GetValue(obj); };
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 lambdaExpression.Compile(); FieldInfo fieldInfo = _memberInfo as FieldInfo;
return obj => { return fieldInfo.GetValue(obj); };
} }
private Action<object, object> GetPropertySetter() private Action<object, object> GetPropertySetter()
{ {
var propertyInfo = (PropertyInfo)_memberInfo; PropertyInfo propertyInfo = (PropertyInfo) _memberInfo;
var setMethodInfo = propertyInfo.SetMethod; return (obj, value) => { propertyInfo.SetValue(obj, value); };
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();
} }
private void ThrowFrozenException() private void ThrowFrozenException()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册