Game Development Reference
In-Depth Information
Note
To use
SerializedProperty
, we need to put the property between
serial-
izedObject.Update();
and
serializedOb-
ject.ApplyModifiedProperties();
. This will make sure that the property is
updated and saves it when we have change the value.
Using
SerializedProperty
seems to be more complex than the target, so why are
we using it? The advantage of
SerializedProperty
is that it will handle the multi-
object editing, undo, and prefab override for us, to which we can attach
@CanEditMul-
tipleObjects
(in JavaScript) or
[CanEditMultipleObjects]
(in C#) to make
our script editor multiple objects.
If we copy our current
WaypointsContainer
script and select both the objects, we
will see the message in the inspector say
Multi-object editing not supported
as we can
see in the following screenshot:
To make it work, we just add the line
@CanEditMultipleObjects
(in JavaScript) or
[CanEditMultipleObjects]
(in C#) in the
WaypointsContainerEditor
script before the class. Let's have a look at the following line:
seo_object = new SerializedObject (target);
We change this line to the following:
seo_object = new SerializedObject (targets);
Otherwise, replace the keyword
seo_object
with
serializedObject
and remove
the
seo_object
property.