/// <summary> /// An item has been added to the collection. /// </summary> protected virtual void AddItemToCollection(TAddItem item, ref TCollection collection, IReorderableListAdaptor adaptor) { if (typeof(TItem).IsAssignableFrom(typeof(TAddItem)) == false) { Debug.LogError("Please override AddItemToCollection; " + typeof(TAddItem).CSharpName() + " cannot be converted to " + typeof(TItem).CSharpName()); return; } if (collection.GetType().IsArray) { // TODO: This is a hack. We should remove it. We update the array // reference in OnPostEdit, so we have to add the item to // the actual array we will later update. ArrayAdaptor <TItem> arrayAdaptor = adaptor as ArrayAdaptor <TItem>; if (arrayAdaptor == null || adaptor is PageAdaptor) { var pageAdaptor = (PageAdaptor)adaptor; arrayAdaptor = (ArrayAdaptor <TItem>)pageAdaptor.BackingAdaptor; } adaptor.Add(); arrayAdaptor.StoredArray[arrayAdaptor.Count - 1] = (TItem)(object)item; } else { collection.Add((TItem)(object)item); } }
/// <summary> /// Add item at end of list and raises the event <see cref="ItemInserted"/>. /// </summary> /// <param name="adaptor">Reorderable list adaptor.</param> protected void AddItem(IReorderableListAdaptor adaptor) { adaptor.Add(); AutoFocusItem(s_ContextControlID, adaptor.Count - 1); GUI.changed = true; ReorderableListGUI.IndexOfChangedItem = -1; var args = new ItemInsertedEventArgs(adaptor, adaptor.Count - 1, false); OnItemInserted(args); }
public void Add() { BackingAdaptor.Add(); }