2015-08-03 542 views
2

我想用Newtonsoft.Json序列化整個GameObject。 當我序列化對象與JsonConvert它拋出一個錯誤:Unity 5 GameObject序列化

NotSupportedException: rigidbody property has been deprecated 
    UnityEngine.GameObject.get_rigidbody() (at C:/buildslave/unity/build/Runtime/Export/UnityEngineGameObject_Deprecated.cs:23) 
(wrapper dynamic-method) UnityEngine.GameObject.Getrigidbody (object) <IL 0x00006, 0x00073> 
Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue (object) (at Assets/JsonDotNet/Source/Serialization/DynamicValueProvider.cs:104) 
Rethrow as JsonSerializationException: Error getting value from 'rigidbody' on 'UnityEngine.GameObject'. 
Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue (System.Object target) (at Assets/JsonDotNet/Source/Serialization/DynamicValueProvider.cs:108) 
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContract collectionValueContract) (at Assets/JsonDotNet/Source/Serialization/JsonSerializerInternalWriter.cs:338) 

這是爲什麼發生?

有問題,在這裏:

public object GetValue(object target) 
    { 
     try 
     { 
     if (_getter == null) 
      _getter = DynamicReflectionDelegateFactory.Instance.CreateGet<object>(_memberInfo); 

     return _getter(target); 
     } 
     catch (Exception ex) 
     { 
     throw new JsonSerializationException("Error getting value from '{0}' on '{1}'.".FormatWith(CultureInfo.InvariantCulture, _memberInfo.Name, target.GetType()), ex); 
     } 
    } 

這是DynamicValueProvider.cs

回答

1

我不知道Newtonsoft.Json的一部分,但是從錯誤信息判斷 - 遊戲對象屬性rigidbody一直在Unity 5中已棄用,以及其他一些常見屬性獲取器,請參閱herehere

所有致電rigidbody的呼叫都必須替換爲GetComponent<Rigidbody>()

+0

問題在於增加的部分。 – metalowy