Exemplo n.º 1
0
    public IEnumerator CoSearch(string text, IYleApiClient searcher)
    {
        foreach (Transform child in content)
        {
            Destroy(child.gameObject);
        }

        content.DetachChildren();
        expandedView = null;

        if (string.IsNullOrWhiteSpace(text))
        {
            currentText = null;
        }
        else
        {
            var newText = Uri.EscapeDataString(text.Trim());

            if (newText != currentText)
            {
                currentText = newText;

                yield return(StartCoroutine(SearchItems(searcher)));
            }
        }
    }
Exemplo n.º 2
0
    public IEnumerator LoadMore(Vector2 vector, IYleApiClient searcher)
    {
        if (!loadInProgress && !string.IsNullOrWhiteSpace(currentText) && vector.y <= 0.1)
        {
            Debug.Log("Searching more items...");

            yield return(StartCoroutine(SearchItems(searcher)));
        }
    }
Exemplo n.º 3
0
    private IEnumerator SearchItems(IYleApiClient searcher)
    {
        if (!loadInProgress)
        {
            try
            {
                loadInProgress = true;

                Debug.Log($"Searching \"{currentText}\", offset = {content.childCount}...");

                yield return(searcher.Search(currentText, content.childCount, loadCount));

                if (!searcher.Success)
                {
                    Debug.LogError(searcher.Error);
                }
                else
                {
                    Debug.Log($"Success, found {searcher.Result.Count} items.");

                    foreach (var item in searcher.Result)
                    {
                        var instance = Instantiate(itemPrefab.gameObject);
                        var view     = new ItemView(instance);

                        view.SetTexts(item);

                        instance.transform.SetParent(content, false);

                        view.OnExpand += () =>
                        {
                            expandedView?.Collapse();

                            expandedView = view;
                        };
                    }
                }
            }
            finally
            {
                loadInProgress = false;
            }
        }
    }