Serialize FP
Options
erre
✭
Hi,
I have a question about serialization of FP fields.
I have tried and Unity perfectly serialize object kind:
But if I have somthing like this:
it doesnt' t work and I have an exception on serialization.
How can I handle this situation? Can i Serialize a float and convert to a FP when MonoBehaviour is started?
Thank you,
Andrea.
P.S. The entire exception is:
ArgumentException: Field m_A defined on type SerializerTest+InternalObj is not a field on the target object which is of type SerializerTest.
Parameter name: obj
System.Reflection.MonoField.GetValue (System.Object obj) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoField.cs:110)
TrueSync.TSFPDrawer.OnGUI (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Assets/TrueSync/Unity/Editor/TSFPDrawer.cs:14)
UnityEditor.PropertyDrawer.OnGUISafe (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at C:/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyDrawer.cs:23)
UnityEditor.PropertyHandler.OnGUI (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren) (at C:/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:134)
UnityEditor.EditorGUI.PropertyFieldInternal (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren) (at C:/buildslave/unity/build/Editor/Mono/EditorGUI.cs:5047)
UnityEditor.EditorGUI.PropertyField (Rect position, UnityEditor.SerializedProperty property, Boolean includeChildren) (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorGUIBindings.gen.cs:1016)
UnityEditor.EditorGUI.PropertyField (Rect position, UnityEditor.SerializedProperty property) (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorGUIBindings.gen.cs:1011)
UnityEditor.Editor.OptimizedInspectorGUIImplementation (Rect contentRect) (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorBindings.gen.cs:234)
UnityEditor.GenericInspector.OnOptimizedInspectorGUI (Rect contentRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/GenericInspector.cs:33)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1215)
UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[] editors) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1030)
UnityEditor.InspectorWindow.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:352)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
I have a question about serialization of FP fields.
I have tried and Unity perfectly serialize object kind:
public class MyClass : MonoBehaviour
{
[SerializeField]
private FP m_A = 0;
}
But if I have somthing like this:
public class MyClass : MonoBehaviour
{
[Serializeable]
private class InternalObj
{
[SerializeField]
private FP m_A = 0;
}
[SerializeField]
private InternalObj m_A = null;
}
it doesnt' t work and I have an exception on serialization.
How can I handle this situation? Can i Serialize a float and convert to a FP when MonoBehaviour is started?
Thank you,
Andrea.
P.S. The entire exception is:
ArgumentException: Field m_A defined on type SerializerTest+InternalObj is not a field on the target object which is of type SerializerTest.
Parameter name: obj
System.Reflection.MonoField.GetValue (System.Object obj) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoField.cs:110)
TrueSync.TSFPDrawer.OnGUI (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Assets/TrueSync/Unity/Editor/TSFPDrawer.cs:14)
UnityEditor.PropertyDrawer.OnGUISafe (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at C:/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyDrawer.cs:23)
UnityEditor.PropertyHandler.OnGUI (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren) (at C:/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:134)
UnityEditor.EditorGUI.PropertyFieldInternal (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren) (at C:/buildslave/unity/build/Editor/Mono/EditorGUI.cs:5047)
UnityEditor.EditorGUI.PropertyField (Rect position, UnityEditor.SerializedProperty property, Boolean includeChildren) (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorGUIBindings.gen.cs:1016)
UnityEditor.EditorGUI.PropertyField (Rect position, UnityEditor.SerializedProperty property) (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorGUIBindings.gen.cs:1011)
UnityEditor.Editor.OptimizedInspectorGUIImplementation (Rect contentRect) (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorBindings.gen.cs:234)
UnityEditor.GenericInspector.OnOptimizedInspectorGUI (Rect contentRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/GenericInspector.cs:33)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1215)
UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[] editors) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1030)
UnityEditor.InspectorWindow.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:352)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
0
Comments
-
Hello @erre, you could use the "float" approach for now, probably the next release of TrueSync will include a fix for the exception you got. Thanks for the feedback.0
-
Hi,
Thank you. For now, I have fixed in this way:public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); EditorGUI.BeginChangeCheck(); SerializedProperty serializedValueProperty = property.FindPropertyRelative("_serializedValue"); string value = serializedValueProperty.stringValue; // Extract number. long l = long.Parse(value); FP fpValue = FP.FromRaw(l); // Editor. fpValue = EditorGUI.FloatField(position, label, (float)fpValue); // Serialize. if (EditorGUI.EndChangeCheck()) { string serializedValue = fpValue.RawValue.ToString(); serializedValueProperty.stringValue = serializedValue; } EditorGUI.EndProperty(); }
and it works perfectly.
Anyway, thanks for support.0