C#里決議 protobuf 用了 protobuf-net, 一直使用正常的。。 但最近在蘋果手機上, 出現莫名其妙問題。
最后發現是 傳的Int64欄位 決議出來要么很大很大一個,反正不對。。
跟蹤 發現
PropertyDecorator.cs里
object newVal = Tail.Read(oldVal, source);
if (readOptionsWriteValue && newVal != null) // if the tail returns a null, intepret that as *no assign*
{
if (shadowSetter == null)
{
property.SetValue(value, newVal, null);
}
else
{
shadowSetter.Invoke(value, new object[] { newVal });
}
}
newVal 讀到的是對的。。。。
走到 property.SetValue (反射機制 賦值), 結果里面得到的值就是一個很大很亂的數值。。。。
看來不能用 protobuf-net 或者不要用 有64位欄位。
有沒有好的Unity里用 protobuf 的解決方案?
目前我們用的是Unity3D 5.3
應該是Mono實作反射機制有問題。 直接寫了一個測驗代碼:
public class Test_Reflect
{
long id = 0;
public long ID
{
get { return id; }
set {
ClientLog.Log("@@@@ set_ID:" + value);
id = value; }
}
public void set_id1(long _i)
{
ClientLog.Log("@@@@ set_id1:" + _i);
id = _i;
}
public void set_id2(System.Int64 _i)
{
ClientLog.Log("@@@@ set_id2:" + _i);
id = _i;
}
}
Test_Reflect tr = new Test_Reflect();
long tt = 1000000000L;
foreach (PropertyInfo property in tr.GetType().GetProperties())
{
//輸出屬性的型別和變數名
ClientLog.Log("@@@@ test reflect "+property.Name + " : " + property.PropertyType.ToString());
property.SetValue(tr, tt, null);
}
tr.GetType().GetMethod("set_id1").Invoke(tr, new object[] { tt+1 });
tr.GetType().GetMethod("set_id2").Invoke(tr, new object[] { tt + 2 });
在IOS設備上運行, 只要經過反射機制得到的值都是不對的。。。。
uj5u.com熱心網友回復:
沒人知道 原因或者解決方案嗎?目前 只能規避了, 不用64位欄位;或者全部放到lua里決議協議; 或者C#里必須要用64位 就傳字串了。。。
uj5u.com熱心網友回復:
下protobuf的原始碼放到unity中使用而不是dll檔案,使用dll檔案ios上是不能使用,因為ios平臺不允許程式運行時加載其他東西轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/64411.html
標籤:Unity3D
上一篇:請教一個雙顯示幕不同重繪率的問題
