Table of Contents

Class SerializedSwiftList<T>

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

T

A Unity-serializable item type.

Inheritance
SerializedSwiftList<T>
Implements
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

int

this[int]

Gets the item at the specified index.

public T this[int index] { get; }

Parameters

index int

The zero-based item index.

Property Value

T

The item at index.

Exceptions

ArgumentOutOfRangeException

index is 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

item T

The 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

index int

Index of the item to remove.

Exceptions

ArgumentOutOfRangeException

index is outside the list.

SetItems(params T[])

Replaces the serialized contents with a copy of the supplied items.

public void SetItems(params T[] items)

Parameters

items T[]

Items to persist and expose through the runtime list.

Exceptions

ArgumentNullException

items is 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.