Beispiel #1
0
    private IEnumerator LoadPersons()
    {
        modalPanel.ShowProgress("Loading users. Please wait ...");

        // Clear persons from the list
        if (persons != null)
        {
            persons.Clear();
        }
        foreach (GameObject panel in personsPanels.Values)
        {
            DestroyPersonPanel(panel);
        }

        personsPanels.Clear();

        AsyncTask <List <Person> > task = new AsyncTask <List <Person> >(() =>
        {
            // load persons here
            CloudUserManager groupMgr = CloudUserManager.Instance;

            // wait for the group manager to start
            int waitPeriods = 10;
            while (groupMgr == null && waitPeriods > 0)
            {
                Thread.Sleep(500);
                waitPeriods--;

                groupMgr = CloudUserManager.Instance;
            }

            return(groupMgr ? groupMgr.GetUsersList() : null);
        });

        task.Start();
        yield return(null);

        while (task.State == TaskState.Running)
        {
            yield return(null);
        }

        modalPanel.Hide();
        persons = task.Result;

        if (persons != null)
        {
            // sort the person names alphabetically
            persons = persons.OrderBy(p => p.name).ToList();

            foreach (Person p in persons)
            {
                InstantiatePersonPanel(p);
            }
        }
        else
        {
            if (!string.IsNullOrEmpty(task.ErrorMessage))
            {
                Debug.LogError(task.ErrorMessage);
            }
            else
            {
                Debug.LogError("Error loading users' list. Check the FaceManager- and UserGroupManager-components.");
            }
        }

        yield return(null);
    }