Class SerializedSwiftSparseSet
- Namespace
- SwiftCollections.Unity
Unity-serializable adapter for persisted compact integer-ID membership consumed as a SwiftSparseSet.
[Serializable]
public sealed class SerializedSwiftSparseSet : ISerializationCallbackReceiver
- Inheritance
-
SerializedSwiftSparseSet
- Implements
-
ISerializationCallbackReceiver
- Inherited Members
Properties
Count
Gets the number of stored IDs.
public int Count { get; }
Property Value
Runtime
Gets the live runtime sparse set rebuilt from Unity serialized data.
public SwiftSparseSet Runtime { get; }
Property Value
Remarks
Direct runtime mutations are copied into serialized backing data before Unity serialization.
Methods
Add(int)
Adds an ID to the runtime set and updates the serialized backing array.
public bool Add(int item)
Parameters
itemintThe non-negative ID to add.
Returns
- bool
truewhen the ID was added; otherwisefalse.
Exceptions
- ArgumentOutOfRangeException
itemis negative.
Clear()
Removes all IDs from the runtime set and serialized backing array.
public void Clear()
Contains(int)
Returns whether the set contains the specified ID.
public bool Contains(int item)
Parameters
itemintThe non-negative ID to find.
Returns
- bool
truewhen the ID exists; otherwisefalse.
Exceptions
- ArgumentOutOfRangeException
itemis negative.
GetEnumerator()
Returns an enumerator for the runtime sparse set.
public SwiftSparseSet.SwiftSparseSetEnumerator GetEnumerator()
Returns
- SwiftSparseSet.SwiftSparseSetEnumerator
A SwiftCollections sparse set enumerator.
OnAfterDeserialize()
Rebuilds runtime contents after Unity deserialization.
public void OnAfterDeserialize()
Exceptions
- ArgumentOutOfRangeException
A serialized ID is negative.
- InvalidOperationException
Serialized IDs contain duplicates.
OnBeforeSerialize()
Copies live runtime contents into Unity's serialized backing data.
public void OnBeforeSerialize()
Remove(int)
Removes an ID from the runtime set and updates the serialized backing array.
public bool Remove(int item)
Parameters
itemintThe non-negative ID to remove.
Returns
- bool
truewhen the ID was removed; otherwisefalse.
Exceptions
- ArgumentOutOfRangeException
itemis negative.
SetItems(params int[])
Replaces the serialized contents with a copy of the supplied IDs.
public void SetItems(params int[] items)
Parameters
itemsint[]The unique, non-negative IDs to persist.
Exceptions
- ArgumentNullException
itemsis null.- ArgumentOutOfRangeException
An ID is negative.
- InvalidOperationException
itemscontains duplicate IDs.
ToArray()
Returns a copy of the serialized IDs.
public int[] ToArray()
Returns
- int[]
A new array containing the current IDs.
ToSwiftSparseSet()
Returns a copy as a standalone SwiftSparseSet.
public SwiftSparseSet ToSwiftSparseSet()
Returns
- SwiftSparseSet
A new sparse set containing the current IDs.