- Home /
Unity Editor SerializedProperty how to assign to array with larger data directly.
I have a problem about the SerializedProperty when is array. i always set one value to one element of SerializedProperty (array) with GetArrayElementAtIndex().xxxValue. but now i have some data from other list, it always a lot. so i do this way:
List<string> dataFromOther = new List<string>();
//mySerializedProperty is Array of SerializedProperty == Custom.dataList
//now i have a data List from other,i need serialize in serializedProperty.
mySerializedProperty.arraySize = dataFromOther.Count;
for (int i = 0; i < dataFromOther.Count; ++i)
{
mySerializedProperty.GetArrayElementAtIndex(i).stringValue = dataFromOther[i];
}
I traverse the dataFromOther List to assign every value to SerializedProperty every value. As you see. it slow in my Editor. it trouble with me.
and i want to assign directly. Because is Custom is Serializableand mySerializedProperty is dataList of string. so code like this: List dataFromOther = new List(); custom.dataList=dataFromOther .
this look like good, but i test it, and find it not to save.And last i try to use reflection. it always not save.
i know mix the way of Editor Serialize and the way of convert to actual class to assign directly. it result always strange.
For the problem, How can i do it ? I need a fast way to assign to SerializedProperty (is array) from other array data.
Answer by AnC_CN · Sep 21, 2017 at 04:50 AM
sorry i ask a duplicate question. Use reflection and Undo.Record to assign directly, but mix actual class type and SerializedProperty with carefully ,sometimes it is strange.
refer http://answers.unity3d.com/questions/1408957/unity-custom-editor-when-i-motify-bytearray-field.html