Example #1
0
    /// <summary>
    /// Refresh the scrolling list's content for both list.
    ///
    /// This function will query from the Tango API for the Tango space Area Description. Also, when it populates
    /// the scrolling list content, it will connect the delegate for each button in the list. The delegate is
    /// responsible for the actual import/export  through the Tango API.
    /// </summary>
    private void _PopulateList()
    {
        foreach (Transform t in m_listContentParent.transform)
        {
            Destroy(t.gameObject);
        }

        // Update Tango space Area Description list.
        AreaDescription[] areaDescriptionList = AreaDescription.GetList();

        if (areaDescriptionList == null)
        {
            return;
        }

        foreach (AreaDescription areaDescription in areaDescriptionList)
        {
            GameObject newElement = Instantiate(m_listElement) as GameObject;
            AreaDescriptionListElement listElement = newElement.GetComponent <AreaDescriptionListElement>();
            listElement.m_toggle.group             = m_toggleGroup;
            listElement.m_areaDescriptionName.text = areaDescription.GetMetadata().m_name;
            listElement.m_areaDescriptionUUID.text = areaDescription.m_uuid;

            // Ensure the lambda makes a copy of areaDescription.
            AreaDescription lambdaParam = areaDescription;
            listElement.m_toggle.onValueChanged.AddListener((value) => _OnToggleChanged(lambdaParam, value));
            newElement.transform.SetParent(m_listContentParent.transform, false);
        }
    }
    /// <summary>
    /// Refresh the UI list of Area Descriptions.
    /// </summary>
    public void RefreshAreaDescriptionList()
    {
        AreaDescription[] areaDescriptions = AreaDescription.GetList();
        _SelectAreaDescription(null);

        // Always remove all old children.
        foreach (Transform child in m_listParent)
        {
            Destroy(child.gameObject);
        }

        if (areaDescriptions != null)
        {
            // Add new children
            ToggleGroup toggleGroup = GetComponent <ToggleGroup>();
            foreach (AreaDescription areaDescription in areaDescriptions)
            {
                AreaDescriptionListElement button = GameObject.Instantiate(m_listElement) as AreaDescriptionListElement;
                button.m_areaDescriptionName.text = areaDescription.GetMetadata().m_name;
                button.m_areaDescriptionUUID.text = areaDescription.m_uuid;
                button.m_toggle.group             = toggleGroup;

                // Ensure the lambda gets a copy of the reference to areaDescription in its current state.
                // (See https://resnikb.wordpress.com/2009/06/17/c-lambda-and-foreach-variable/)
                AreaDescription lambdaParam = areaDescription;
                button.m_toggle.onValueChanged.AddListener((value) => _OnAreaDescriptionToggleChanged(lambdaParam, value));
                button.transform.SetParent(m_listParent, false);
            }

            m_listEmptyText.gameObject.SetActive(false);
        }
        else
        {
            m_listEmptyText.gameObject.SetActive(true);
        }
    }