/// <summary>
        /// Called by the server when any of the seats in the lobby have changed. (Including ours!)
        /// </summary>
        private void OnLobbyPlayerStateChanged(NetworkListEvent <CharSelectData.LobbyPlayerState> lobbyArray)
        {
            UpdateSeats();

            // now let's find our local player in the list and update the character/info box appropriately
            int localPlayerIdx = -1;

            for (int i = 0; i < CharSelectData.LobbyPlayers.Count; ++i)
            {
                if (CharSelectData.LobbyPlayers[i].ClientId == NetworkManager.Singleton.LocalClientId)
                {
                    localPlayerIdx = i;
                    break;
                }
            }

            if (localPlayerIdx == -1)
            {
                // we aren't currently participating in the lobby!
                // this can happen for various reasons, such as the lobby being full and us not getting a seat.
                UpdateCharacterSelection(CharSelectData.SeatState.Inactive);
            }
            else if (CharSelectData.LobbyPlayers[localPlayerIdx].SeatState == CharSelectData.SeatState.Inactive)
            {
                // we haven't chosen a seat yet (or were kicked out of our seat by someone else)
                UpdateCharacterSelection(CharSelectData.SeatState.Inactive);
            }
            else
            {
                // we have a seat! Note that if our seat is LockedIn, this function will also switch the lobby mode
                UpdateCharacterSelection(CharSelectData.LobbyPlayers[localPlayerIdx].SeatState, CharSelectData.LobbyPlayers[localPlayerIdx].SeatIdx);
            }
        }
Exemplo n.º 2
0
 private void ListChanged(NetworkListEvent <string> listEvent)
 {
     if (!IsOwner && !m_GotNetworkList)
     {
         Debug.Log("Received: " + listEvent.Value);
         m_GotNetworkList = true;
     }
 }
Exemplo n.º 3
0
 private void ListChanged(NetworkListEvent <int> listEvent)
 {
     if (!IsServer)
     {
         Debug.Log(m_Ids.Count);
         if (m_Ids.Count == m_IdCount)
         {
             Debug.Log("Passed");
         }
     }
 }
Exemplo n.º 4
0
        /// <inheritdoc />
        public void Clear()
        {
            if (NetworkManager.Singleton.IsServer)
            {
                m_List.Clear();
            }

            NetworkListEvent <T> listEvent = new NetworkListEvent <T>()
            {
                Type = NetworkListEvent <T> .EventType.Clear
            };

            HandleAddListEvent(listEvent);
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public void RemoveAt(int index)
        {
            if (NetworkManager.Singleton.IsServer)
            {
                m_List.RemoveAt(index);
            }

            NetworkListEvent <T> listEvent = new NetworkListEvent <T>()
            {
                Type  = NetworkListEvent <T> .EventType.RemoveAt,
                Index = index
            };

            HandleAddListEvent(listEvent);
        }
Exemplo n.º 6
0
        /// <inheritdoc />
        public void Insert(int index, T item)
        {
            if (NetworkManager.Singleton.IsServer)
            {
                m_List.Insert(index, item);
            }

            NetworkListEvent <T> listEvent = new NetworkListEvent <T>()
            {
                Type  = NetworkListEvent <T> .EventType.Insert,
                Index = index,
                Value = item
            };

            HandleAddListEvent(listEvent);
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        public bool Remove(T item)
        {
            if (NetworkManager.Singleton.IsServer)
            {
                m_List.Remove(item);
            }

            NetworkListEvent <T> listEvent = new NetworkListEvent <T>()
            {
                Type  = NetworkListEvent <T> .EventType.Remove,
                Value = item
            };

            HandleAddListEvent(listEvent);
            return(true);
        }
Exemplo n.º 8
0
        /// <inheritdoc />
        public void Add(T item)
        {
            if (NetworkManager.Singleton.IsServer)
            {
                m_List.Add(item);
            }

            NetworkListEvent <T> listEvent = new NetworkListEvent <T>()
            {
                Type  = NetworkListEvent <T> .EventType.Add,
                Value = item,
                Index = m_List.Count - 1
            };

            HandleAddListEvent(listEvent);
        }
Exemplo n.º 9
0
        /// <inheritdoc />
        public void Clear()
        {
            EnsureInitialized();

            if (m_NetworkBehaviour.NetworkManager.IsServer)
            {
                m_List.Clear();
            }

            var listEvent = new NetworkListEvent <T>()
            {
                Type = NetworkListEvent <T> .EventType.Clear
            };

            HandleAddListEvent(listEvent);
        }
Exemplo n.º 10
0
        /// <inheritdoc />
        public void RemoveAt(int index)
        {
            EnsureInitialized();

            if (m_NetworkBehaviour.NetworkManager.IsServer)
            {
                m_List.RemoveAt(index);
            }

            var listEvent = new NetworkListEvent <T>()
            {
                Type  = NetworkListEvent <T> .EventType.RemoveAt,
                Index = index
            };

            HandleAddListEvent(listEvent);
        }
Exemplo n.º 11
0
        /// <inheritdoc />
        public void Insert(int index, T item)
        {
            EnsureInitialized();

            if (m_NetworkBehaviour.NetworkManager.IsServer)
            {
                m_List.Insert(index, item);
            }

            var listEvent = new NetworkListEvent <T>()
            {
                Type  = NetworkListEvent <T> .EventType.Insert,
                Index = index,
                Value = item
            };

            HandleAddListEvent(listEvent);
        }
Exemplo n.º 12
0
        /// <inheritdoc />
        public bool Remove(T item)
        {
            EnsureInitialized();

            if (m_NetworkBehaviour.NetworkManager.IsServer)
            {
                m_List.Remove(item);
            }

            var listEvent = new NetworkListEvent <T>()
            {
                Type  = NetworkListEvent <T> .EventType.Remove,
                Value = item
            };

            HandleAddListEvent(listEvent);
            return(true);
        }
Exemplo n.º 13
0
        /// <inheritdoc />
        public void Add(T item)
        {
            EnsureInitialized();

            if (m_NetworkBehaviour.NetworkManager.IsServer)
            {
                m_List.Add(item);
            }

            var listEvent = new NetworkListEvent <T>()
            {
                Type  = NetworkListEvent <T> .EventType.Add,
                Value = item,
                Index = m_List.Count - 1
            };

            HandleAddListEvent(listEvent);
        }
Exemplo n.º 14
0
        private void HandleLobbyPlayersStateChanged(NetworkListEvent <LobbyPlayerState> lobbyState)
        {
            for (int i = 0; i < lobbyPlayerCards.Length; i++)
            {
                if (lobbyPlayers.Count > i)
                {
                    lobbyPlayerCards[i].UpdateDisplay(lobbyPlayers[i]);
                }
                else
                {
                    lobbyPlayerCards[i].DisableDisplay();
                }
            }

            if (IsHost)
            {
                startGameButton.interactable = IsEveryoneReady();
            }
        }
Exemplo n.º 15
0
        /// <inheritdoc />
        public void ReadDelta(Stream stream, bool keepDirtyDelta, ushort localTick, ushort remoteTick)
        {
            using (var reader = PooledNetworkReader.Get(stream))
            {
                ushort deltaCount = reader.ReadUInt16Packed();
                for (int i = 0; i < deltaCount; i++)
                {
                    NetworkListEvent <T> .EventType eventType = (NetworkListEvent <T> .EventType)reader.ReadBits(3);
                    switch (eventType)
                    {
                    case NetworkListEvent <T> .EventType.Add:
                    {
                        m_List.Add((T)reader.ReadObjectPacked(typeof(T)));     //BOX

                        if (OnListChanged != null)
                        {
                            OnListChanged(new NetworkListEvent <T>
                                {
                                    Type  = eventType,
                                    Index = m_List.Count - 1,
                                    Value = m_List[m_List.Count - 1]
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            m_DirtyEvents.Add(new NetworkListEvent <T>()
                                {
                                    Type  = eventType,
                                    Index = m_List.Count - 1,
                                    Value = m_List[m_List.Count - 1]
                                });
                        }
                    }
                    break;

                    case NetworkListEvent <T> .EventType.Insert:
                    {
                        int index = reader.ReadInt32Packed();
                        m_List.Insert(index, (T)reader.ReadObjectPacked(typeof(T)));     //BOX

                        if (OnListChanged != null)
                        {
                            OnListChanged(new NetworkListEvent <T>
                                {
                                    Type  = eventType,
                                    Index = index,
                                    Value = m_List[index]
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            m_DirtyEvents.Add(new NetworkListEvent <T>()
                                {
                                    Type  = eventType,
                                    Index = index,
                                    Value = m_List[index]
                                });
                        }
                    }
                    break;

                    case NetworkListEvent <T> .EventType.Remove:
                    {
                        T   value = (T)reader.ReadObjectPacked(typeof(T));   //BOX
                        int index = m_List.IndexOf(value);
                        m_List.RemoveAt(index);

                        if (OnListChanged != null)
                        {
                            OnListChanged(new NetworkListEvent <T>
                                {
                                    Type  = eventType,
                                    Index = index,
                                    Value = value
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            m_DirtyEvents.Add(new NetworkListEvent <T>()
                                {
                                    Type  = eventType,
                                    Index = index,
                                    Value = value
                                });
                        }
                    }
                    break;

                    case NetworkListEvent <T> .EventType.RemoveAt:
                    {
                        int index = reader.ReadInt32Packed();
                        T   value = m_List[index];
                        m_List.RemoveAt(index);

                        if (OnListChanged != null)
                        {
                            OnListChanged(new NetworkListEvent <T>
                                {
                                    Type  = eventType,
                                    Index = index,
                                    Value = value
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            m_DirtyEvents.Add(new NetworkListEvent <T>()
                                {
                                    Type  = eventType,
                                    Index = index,
                                    Value = value
                                });
                        }
                    }
                    break;

                    case NetworkListEvent <T> .EventType.Value:
                    {
                        int index = reader.ReadInt32Packed();
                        T   value = (T)reader.ReadObjectPacked(typeof(T));   //BOX
                        if (index < m_List.Count)
                        {
                            m_List[index] = value;
                        }

                        if (OnListChanged != null)
                        {
                            OnListChanged(new NetworkListEvent <T>
                                {
                                    Type  = eventType,
                                    Index = index,
                                    Value = value
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            m_DirtyEvents.Add(new NetworkListEvent <T>()
                                {
                                    Type  = eventType,
                                    Index = index,
                                    Value = value
                                });
                        }
                    }
                    break;

                    case NetworkListEvent <T> .EventType.Clear:
                    {
                        //Read nothing
                        m_List.Clear();

                        if (OnListChanged != null)
                        {
                            OnListChanged(new NetworkListEvent <T>
                                {
                                    Type = eventType,
                                });
                        }

                        if (keepDirtyDelta)
                        {
                            m_DirtyEvents.Add(new NetworkListEvent <T>()
                                {
                                    Type = eventType
                                });
                        }
                    }
                    break;
                    }
                }
            }
        }