Beispiel #1
0
        void RefreshRoomUI(RoomState state)
        {
            //delete
            foreach (GameObject room in roomStateUIs)
            {
                Destroy(room);
            }
            roomStateUIs.Clear();

            //UI
            int blue = 0;
            int red  = 0;

            for (int i = 0; i < state.players.Count; i++)
            {
                GameObject player = GameObject.Instantiate(Resources.Load("PlayerState"), room.transform) as GameObject;
                if (state.players[i].faction == 0)
                {
                    player.GetComponent <RectTransform>().anchoredPosition = new Vector2(-160, 142 + -34 * blue++);
                }
                else
                {
                    player.GetComponent <RectTransform>().anchoredPosition = new Vector2(160, 142 + -34 * red++);
                }
                player.GetComponent <PlayerStateScript>().Init(state.players[i]);
                roomStateUIs.Add(player);
            }
        }
Beispiel #2
0
        public void SendRoomStateToAll()
        {
            RoomState state = new RoomState();

            state.roomid = roomid;
            foreach (Player player in players.Values)
            {
                state.players.Add(new PlayerState {
                    userid = player.userid, username = player.username, faction = player.faction, ready = player.ready
                });
            }

            foreach (Player player in players.Values)
            {
                GSrv.Send(MessageType.ReplyRoomState, GSrv.Serialize <RoomState>(state), player.connection, NetDeliveryMethod.ReliableOrdered);
            }
        }
Beispiel #3
0
        public void ReplyRoomStateHandler(NetConnection connection, object data)
        {
            RoomState state = GCli.Deserialize <RoomState>((byte[])data);

            RefreshRoomUI(state);
        }