Exemplo n.º 1
0
    private void SetDraggingItem(EditableListItem item)
    {
        if (draggingItem == item)
        {
            return;
        }

        if (draggingItem != null)
        {
            draggingItem.SetDraggingFeedback(false);
            foreach (Transform component in ui.dragItemHint)
            {
                Object.Destroy(component.gameObject);
            }
        }

        draggingItem = item;
        if (draggingItem != null)
        {
            ui.dragItemHint.gameObject.SetActive(true);
            int index = listItems.IndexOf(draggingItem);
            draggingItem.SetDraggingFeedback(true);
            RectTransform content = Object.Instantiate(draggingItem.GetContentContainer(), ui.dragItemHint);
            Object.Destroy(content.GetComponent <EditableListItem>());
        }
        else
        {
            ui.dragItemHint.gameObject.SetActive(false);
            ui.dragTargetHint.gameObject.SetActive(false);
        }
    }
Exemplo n.º 2
0
    public void Refresh()
    {
        SetDraggingItem(null);

        for (int i = 0; i < Mathf.Min(adapter.GetCount(), listItems.Count); i++)
        {
            adapter.Populate(i, contents[listItems[i]]);
        }

        for (int i = listItems.Count; i < adapter.GetCount(); i++)
        {
            EditableListItem newItem = CreateListItem();

            C content = adapter.Inflate(newItem.GetContentContainer());
            contents[newItem] = content;
            adapter.Populate(i, content);

            newItem.transform.SetSiblingIndex(i);
            listItems.Insert(i, newItem);
        }

        for (int i = listItems.Count - 1; i >= 0 && i >= adapter.GetCount(); i--)
        {
            EditableListItem item = listItems[i];
            listItems.RemoveAt(i);
            contents.Remove(item);
            item.RequestDestroy();
        }
    }