Ejemplo n.º 1
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;
            }
        }
    }