Class SerializedSwiftList<T>
- Namespace
- SwiftCollections.Unity
Unity-serializable adapter for persisted authoring data that is consumed as a SwiftList<T>.
[Serializable]
public sealed class SerializedSwiftList<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, ISerializationCallbackReceiver
Type Parameters
TA Unity-serializable item type.
- Inheritance
-
SerializedSwiftList<T>
- Implements
-
IEnumerable<T>ISerializationCallbackReceiver
- Inherited Members
Remarks
Use this type for MonoBehaviour, ScriptableObject, prefab, or asset fields that must persist through Unity serialization. Runtime systems can read Runtime or call ToSwiftList().
Properties
Count
Gets the number of items in the runtime list.
public int Count { get; }
Property Value
this[int]
Gets the item at the specified index.
public T this[int index] { get; }
Parameters
indexintThe zero-based item index.
Property Value
- T
The item at
index.
Exceptions
- ArgumentOutOfRangeException
indexis outside the list.
Runtime
Gets the live runtime list rebuilt from Unity serialized data.
public SwiftList<T> Runtime { get; }
Property Value
- SwiftList<T>
Remarks
Direct runtime mutations are copied into serialized backing data before Unity serialization.
Methods
Add(T)
Adds an item to the runtime list and updates the serialized backing array.
public void Add(T item)
Parameters
itemTThe item to add.
Clear()
Removes all items from the runtime list and serialized backing array.
public void Clear()
GetEnumerator()
Returns an enumerator for the runtime list.
public SwiftList<T>.SwiftListEnumerator GetEnumerator()
Returns
- SwiftList<T>.SwiftListEnumerator
A SwiftCollections list enumerator.
OnAfterDeserialize()
Rebuilds runtime contents after Unity deserialization.
public void OnAfterDeserialize()
OnBeforeSerialize()
Copies live runtime contents into Unity's serialized backing data.
public void OnBeforeSerialize()
RemoveAt(int)
Removes the item at the specified index and updates the serialized backing array.
public void RemoveAt(int index)
Parameters
indexintIndex of the item to remove.
Exceptions
- ArgumentOutOfRangeException
indexis outside the list.
SetItems(params T[])
Replaces the serialized contents with a copy of the supplied items.
public void SetItems(params T[] items)
Parameters
itemsT[]Items to persist and expose through the runtime list.
Exceptions
- ArgumentNullException
itemsis null.
ToArray()
Returns a copy of the serialized items.
public T[] ToArray()
Returns
- T[]
A new array containing the current items.
ToSwiftList()
Returns a copy as a standalone SwiftList<T>.
public SwiftList<T> ToSwiftList()
Returns
- SwiftList<T>
A new SwiftList containing the current items.