Exemplo n.º 1
0
 public void SetData(string networkAddress, NetworkDiscoveryData data)
 {
     _networkAddress = networkAddress;
     _data           = data;
     if (textRoomName != null)
     {
         textRoomName.text = data.roomName;
     }
     if (textPlayerName != null)
     {
         textPlayerName.text = data.playerName;
     }
     if (textSceneName != null)
     {
         textSceneName.text = data.sceneName;
     }
     if (textNetworkAddress != null)
     {
         textNetworkAddress.text = networkAddress + ":" + data.networkPort;
     }
     if (textPlayerCount != null)
     {
         textPlayerCount.text = data.numPlayers + "/" + data.maxPlayers;
     }
 }
Exemplo n.º 2
0
    protected virtual bool CanAddRoom(RoomInfo room, out NetworkDiscoveryData discoveryData)
    {
        discoveryData = new NetworkDiscoveryData();
        var customProperties = room.CustomProperties;

        if (customProperties.Count == 0)
        {
            return(false);
        }
        var isMatchMaking = (bool)customProperties[CUSTOM_ROOM_MATCH_MAKE];

        if (isMatchMaking)
        {
            return(false);
        }
        discoveryData.name           = room.Name;
        discoveryData.roomName       = (string)customProperties[CUSTOM_ROOM_ROOM_NAME];
        discoveryData.roomPassword   = (string)customProperties[CUSTOM_ROOM_ROOM_PASSWORD];
        discoveryData.playerId       = (string)customProperties[CUSTOM_ROOM_PLAYER_ID];
        discoveryData.playerName     = (string)customProperties[CUSTOM_ROOM_PLAYER_NAME];
        discoveryData.sceneName      = (string)customProperties[CUSTOM_ROOM_SCENE_NAME];
        discoveryData.state          = (byte)customProperties[CUSTOM_ROOM_STATE];
        discoveryData.numPlayers     = room.PlayerCount;
        discoveryData.maxPlayers     = room.MaxPlayers;
        discoveryData.fullProperties = customProperties;
        return(true);
    }
Exemplo n.º 3
0
    public override void OnReceivedRoomListUpdate()
    {
        var rooms      = PhotonNetwork.GetRoomList();
        var foundRooms = new List <NetworkDiscoveryData>();

        foreach (var room in rooms)
        {
            var customProperties = room.CustomProperties;
            if (customProperties.Count == 0)
            {
                continue;
            }
            var isMatchMaking = (bool)customProperties[CUSTOM_ROOM_MATCH_MAKE];
            if (!isMatchMaking)
            {
                var discoveryData = new NetworkDiscoveryData();
                discoveryData.name         = room.Name;
                discoveryData.roomName     = (string)customProperties[CUSTOM_ROOM_ROOM_NAME];
                discoveryData.roomPassword = (string)customProperties[CUSTOM_ROOM_ROOM_PASSWORD];
                discoveryData.playerId     = (string)customProperties[CUSTOM_ROOM_PLAYER_ID];
                discoveryData.playerName   = (string)customProperties[CUSTOM_ROOM_PLAYER_NAME];
                discoveryData.sceneName    = (string)customProperties[CUSTOM_ROOM_SCENE_NAME];
                discoveryData.state        = (byte)customProperties[CUSTOM_ROOM_STATE];
                discoveryData.numPlayers   = room.PlayerCount;
                discoveryData.maxPlayers   = room.MaxPlayers;
                foundRooms.Add(discoveryData);
            }
        }
        if (onReceivedRoomListUpdate != null)
        {
            onReceivedRoomListUpdate.Invoke(foundRooms);
        }
    }
    protected override bool CanAddRoom(RoomInfo room, out NetworkDiscoveryData discoveryData)
    {
        discoveryData = new NetworkDiscoveryData();
        var customProperties = room.CustomProperties;

        if (customProperties.Count == 0)
        {
            return(false);
        }
        var isMatchMaking = (bool)customProperties[CUSTOM_ROOM_MATCH_MAKE];

        if (isMatchMaking)
        {
            return(false);
        }
        discoveryData.name           = room.Name;
        discoveryData.roomName       = (string)customProperties[CUSTOM_ROOM_ROOM_NAME];
        discoveryData.roomPassword   = (string)customProperties[CUSTOM_ROOM_ROOM_PASSWORD];
        discoveryData.playerId       = (string)customProperties[CUSTOM_ROOM_PLAYER_ID];
        discoveryData.playerName     = (string)customProperties[CUSTOM_ROOM_PLAYER_NAME];
        discoveryData.sceneName      = (string)customProperties[CUSTOM_ROOM_SCENE_NAME];
        discoveryData.state          = (byte)customProperties[CUSTOM_ROOM_STATE];
        discoveryData.numPlayers     = room.PlayerCount;
        discoveryData.maxPlayers     = room.MaxPlayers;
        discoveryData.gameRule       = (string)customProperties[CUSTOM_ROOM_GAME_RULE];
        discoveryData.botCount       = (int)customProperties[CUSTOM_ROOM_GAME_RULE_BOT_COUNT];
        discoveryData.matchTime      = (int)customProperties[CUSTOM_ROOM_GAME_RULE_MATCH_TIME];
        discoveryData.matchKill      = (int)customProperties[CUSTOM_ROOM_GAME_RULE_MATCH_KILL];
        discoveryData.matchScore     = (int)customProperties[CUSTOM_ROOM_GAME_RULE_MATCH_SCORE];
        discoveryData.fullProperties = customProperties;
        return(true);
    }
Exemplo n.º 5
0
    public void SetData(NetworkDiscoveryData data)
    {
        Data = data;

        if (uiRoomData != null)
        {
            uiRoomData.SetData(data);
        }
    }
Exemplo n.º 6
0
 public void ShowEnterPasswordDialog(NetworkDiscoveryData data)
 {
     if (uiEnterPassword == null)
     {
         Debug.LogError("[UIPhotonNetworking] uiEnterPassword is empty");
         return;
     }
     uiEnterPassword.uiPhotonNetworking = this;
     uiEnterPassword.SetData(data);
     uiEnterPassword.Show();
 }
    public virtual void WriteBroadcastData()
    {
        var discoveryData = new NetworkDiscoveryData();

        discoveryData.roomName       = roomName;
        discoveryData.playerName     = PlayerSave.GetPlayerName();
        discoveryData.sceneName      = Assets.onlineScene.SceneName;
        discoveryData.networkAddress = networkAddress;
        discoveryData.networkPort    = networkPort;
        discoveryData.numPlayers     = PlayersCount;
        discoveryData.maxPlayers     = maxConnections;
        NetworkDiscovery.data        = JsonUtility.ToJson(discoveryData);
    }
Exemplo n.º 8
0
    public virtual void WriteBroadcastData()
    {
        var discoveryData = new NetworkDiscoveryData();

        discoveryData.roomName             = roomName;
        discoveryData.playerName           = PlayerSave.GetPlayerName();
        discoveryData.sceneName            = onlineScene;
        discoveryData.networkAddress       = networkAddress;
        discoveryData.networkPort          = networkPort;
        discoveryData.numPlayers           = numPlayers;
        discoveryData.maxPlayers           = maxConnections;
        NetworkDiscovery.useNetworkManager = false;
        NetworkDiscovery.broadcastData     = JsonUtility.ToJson(discoveryData);
    }
    public void SetData(NetworkDiscoveryData data)
    {
        Data = data;

        if (textRoomName != null)
        {
            textRoomName.text = string.IsNullOrEmpty(data.roomName) ? "Untitled" : data.roomName;
        }
        if (textPlayerName != null)
        {
            textPlayerName.text = data.playerName;
        }
        if (textSceneName != null)
        {
            textSceneName.text = BaseNetworkGameInstance.GetMapNameByScene(data.sceneName);
        }
        if (textPlayerCount != null)
        {
            textPlayerCount.text = data.numPlayers + "/" + data.maxPlayers;
        }
        if (textRoomState != null)
        {
            switch ((SimplePhotonNetworkManager.RoomState)data.state)
            {
            case SimplePhotonNetworkManager.RoomState.Waiting:
                textRoomState.text = roomStateWaiting;
                break;

            case SimplePhotonNetworkManager.RoomState.Playing:
                textRoomState.text = roomStatePlaying;
                break;
            }
        }

        BaseNetworkGameRule gameRule = null;

        if (textGameRule != null &&
            BaseNetworkGameInstance.GameRules.TryGetValue(data.gameRule, out gameRule))
        {
            textGameRule.text = gameRule == null ? "" : gameRule.Title;
        }

        if (textBotCount != null)
        {
            textBotCount.text = data.botCount.ToString("N0");
            textBotCount.gameObject.SetActive(gameRule != null && gameRule.HasOptionBotCount);
        }

        if (textMatchTime != null)
        {
            textMatchTime.text = data.matchTime.ToString("N0");
            textMatchTime.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchTime);
        }

        if (textMatchKill != null)
        {
            textMatchKill.text = data.matchKill.ToString("N0");
            textMatchKill.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchKill);
        }

        if (textMatchScore != null)
        {
            textMatchScore.text = data.matchScore.ToString("N0");
            textMatchScore.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchScore);
        }

        if (hasPasswordObject != null)
        {
            hasPasswordObject.SetActive(!string.IsNullOrEmpty(data.roomPassword));
        }
    }