Пример #1
0
    /// <summary>
    /// Updates the UI listing, it creates the necessary items not yet listed, update existing items and remove unused entries
    /// </summary>
    public void UpdateUI()
    {
        List <int> processedIDS = new List <int>();

        // update existing items and add new items
        foreach (Photon.Realtime.Player _player in PhotonNetwork.PlayerList)
        {
            if (_items.ContainsKey(_player.ActorNumber))             // update
            {
                _items[_player.ActorNumber].RefreshData(_player);
                processedIDS.Add(_player.ActorNumber);
            }
            else               // create new
            {
                GameObject _item = (GameObject)Instantiate(PlayerItemPrefab);
                _item.transform.SetParent(UIList.transform);

                PlayerItem _playerItem = _item.GetComponent <PlayerItem>();
                _items.Add(_player.ActorNumber, _playerItem);
                _items[_player.ActorNumber].RefreshData(_player);

                _playerItem.AnimateRevealItem();

                processedIDS.Add(_player.ActorNumber);
            }
        }

        // now deal with items that needs to be deleted.
        // work in reverse so that we can delete entries without worries.
        foreach (var _item in _items.Reverse())
        {
            if (!processedIDS.Contains(_item.Key))
            {
                _items[_item.Key].AnimateRemoveItem();
                _items.Remove(_item.Key);
            }
        }
    }