gpt4 book ai didi

c# - Unity 5 游戏对象序列化

转载 作者:太空宇宙 更新时间:2023-11-03 13:02:58 26 4
gpt4 key购买 nike

我正在尝试使用 Newtonsoft.Json 序列化整个游戏对象。当我使用 JsonConvert 序列化对象时,它会抛出一个错误:

    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 的一部分

最佳答案

我不知道 Newtonsoft.Json,但从错误消息来看 - GameObject 属性 rigidbody已在 Unity 5 中弃用以及一些其他常见的属性 getter ,请参阅 herehere .

所有调用 rigidbody必须替换为 GetComponent<Rigidbody>()相反。

关于c# - Unity 5 游戏对象序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31786488/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com