示例#1
0
    public void UpdateHall(GameHallModel model)
    {
        this.model = model;
        if (model.isFull)                   // 两人都显示
        {
            playerBHeader.enabled   = true; // 此时玩家B需要显示
            playerBNameText.enabled = true;

            roomIdText.text      = model.roomId.ToString();
            playerAHeader.sprite = Resources.Load("images/" + model.playerAHeaderIndex, new Sprite().GetType()) as Sprite;
            playerBHeader.sprite = Resources.Load("images/" + model.playerBHeaderIndex, new Sprite().GetType()) as Sprite;
            playerANameText.text = model.playerAName;
            playerBNameText.text = model.playerBName;

            enterBtn.interactable = false;
        }
        else  // 房间没满,只需要显示玩家A
        {
            roomIdText.text         = model.roomId.ToString();
            playerAHeader.sprite    = Resources.Load("images/" + model.playerAHeaderIndex, new Sprite().GetType()) as Sprite;
            playerBHeader.enabled   = false; // 不显示玩家A
            playerANameText.text    = model.playerAName;
            playerBNameText.enabled = false;

            enterBtn.interactable = true;
        }
    }
    // 模拟从服务器获取信息
    void Load()
    {
        GameHallModel model1 = new GameHallModel(1000, 6000, "我是第一个玩家");
        GameHallModel model2 = new GameHallModel(1001, 6001, "我是第二个玩家");

        waitingList.Add(model1);
        waitingList.Add(model2);
        waitingDict.Add(model1.roomId, model1);
        waitingDict.Add(model2.roomId, model2);
    }