Table of Contents

Class SerializableHashSet<T>

Namespace
ElectricDrill.AstraRpgFramework.Utils
Assembly
com.electricdrill.astra-rpg-framework.Runtime.dll

A serializable hash set implementation that can be displayed and edited in the Unity Inspector. Provides all standard hash set functionality while maintaining Unity serialization compatibility.

[Serializable]
public class SerializableHashSet<T>

Type Parameters

T

The type of elements in the hash set

Inheritance
object
SerializableHashSet<T>

Properties

Count

Gets the number of elements contained in the hash set.

public int Count { get; }

Property Value

int

IsReadOnly

Gets a value indicating whether the hash set is read-only.

public bool IsReadOnly { get; }

Property Value

bool

Methods

Add(T)

Adds the specified element to the set. The element is appended at the end of the display order.

public void Add(T item)

Parameters

item T

The element to add

Clear()

Removes all elements from the set.

public void Clear()

Contains(T)

Determines whether the hash set contains the specified element.

public bool Contains(T item)

Parameters

item T

The element to locate

Returns

bool

True if the hash set contains the element; otherwise, false

CopyTo(T[], int)

Copies the elements of the set to an array in display order, starting at the specified array index.

public void CopyTo(T[] array, int arrayIndex)

Parameters

array T[]

The destination array

arrayIndex int

The zero-based index in array at which copying begins

GetEnumerator()

Returns an enumerator that iterates through the set in the user-defined display order, skipping any unassigned (null) slots that may be pending assignment in the inspector.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

GetObjectData(SerializationInfo, StreamingContext)

Populates a SerializationInfo with the data needed to serialize the hash set.

public void GetObjectData(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

The SerializationInfo to populate

context StreamingContext

The destination for this serialization

OnAfterDeserialize()

Reconstructs the internal hash set from the serialized list, deduplicates it, and preserves any null entry (pending assignment slot) so the inspector "+" button works. Called automatically by Unity after deserialization occurs.

IMPORTANT: Unity forbids calling GetName() (and therefore any Unity Object equality/hash method) during this callback. The hash set is therefore rebuilt lazily on first access via ElectricDrill.AstraRpgFramework.Utils.SerializableHashSet<T>.GetHashSet() instead of here.

public void OnAfterDeserialize()

OnBeforeSerialize()

Syncs the serialized list with the runtime hash set while preserving the existing item order. New items are appended at the end; items no longer in the set are removed. Null entries (pending assignment slots added via the inspector "+") are preserved in-place. Called automatically by Unity before serialization occurs.

public void OnBeforeSerialize()

Remove(T)

Removes the specified element from the set.

public bool Remove(T item)

Parameters

item T

The element to remove

Returns

bool

True if the element was successfully removed; otherwise, false

RemoveWhere(Predicate<T>)

Removes all elements that match the conditions defined by the specified predicate.

public int RemoveWhere(Predicate<T> match)

Parameters

match Predicate<T>

The predicate that defines the conditions of the elements to remove

Returns

int

The number of elements that were removed