Skip to content

Game.UI.Widgets.ListAdapter

Assembly:
Game

Namespace:
Game.UI.Widgets

Type:
public class ListAdapter

Base:
ListAdapterBase

Summary:
Adapter implementation for editing IList instances in the UI editor system. This class provides concrete behaviour for inserting, deleting and clearing elements of a runtime IList via the base ListAdapterBase infrastructure. It uses the base class's accessor/generator/elementType fields (defined on ListAdapterBase) and exposes a listType property to control the concrete list implementation created when a null list is encountered. A convenience factory FromList constructs a ListAdapter backed by a concrete List instance.


Fields

  • (None declared in this class)
    This class does not declare private fields itself; it relies on fields defined in the base class ListAdapterBase (for example: accessor, generator, elementType, length, level).

Properties

  • public Type listType { get; set; }
    Specifies the concrete IList type to create when the underlying list value is null and an insertion is requested. Typical value is typeof(List) for lists of T. If not set, CreateInstance (from the base) must be able to construct a usable IList instance.

Constructors

  • public ListAdapter()
    Implicit parameterless constructor. Instances are typically created via the static factory FromList or by the editor generation system; no special constructor logic is defined in this class.

Methods

  • public override void InsertElement(int index)
    Inserts a new default element at the specified index. Behavior:
  • Asserts that index >= 0 and index <= length (uses UNITY_ASSERTIONS).
  • Obtains the IList via base.accessor.GetTypedValue().
  • If the list is null, creates a new list instance of type listType via ListAdapterBase.CreateInstance(listType) and assigns it back through the accessor.
  • Creates a new element instance using the base CreateInstance for the configured elementType and inserts it into the list at index.

  • public override void DeleteElement(int index)
    Removes the element at the given index from the underlying IList (calls RemoveAt on the IList returned by base.accessor.GetTypedValue()).

  • public override void Clear()
    Clears the underlying IList if it is not null (calls Clear()).

  • public static ListAdapter FromList<T>([NotNull] List<T> list, IEditorGenerator generator)
    Factory helper that creates a ListAdapter bound to an existing List. It sets:

  • accessor to a DelegateAccessor that returns the provided list,
  • generator to the provided IEditorGenerator,
  • elementType to typeof(T),
  • listType to typeof(List),
  • level to 0. This is a convenient way to wrap a concrete List for editing via the ListAdapter.

Usage Example

// Create a list and an IEditorGenerator (generator must be provided by the editor system)
List<MyItem> myItems = new List<MyItem>();
IEditorGenerator generator = /* obtain or implement generator */;

// Create a ListAdapter for the list
ListAdapter adapter = ListAdapter.FromList(myItems, generator);

// Insert a new element at index 0 (will create a default instance of MyItem)
adapter.InsertElement(0);

// Delete the element we just added
adapter.DeleteElement(0);

// Clear the list
adapter.Clear();

Notes and implementation details: - Index checks use Unity assertions (UNITY_ASSERTIONS define present in source). - List and element instances are created via ListAdapterBase.CreateInstance(Type) and the base's elementType handling; the concrete creation behaviour depends on that base implementation. - The adapter relies on the base's accessor to get/set the IList reference; the accessor abstraction lets the adapter operate on fields/properties/delegates uniformly.