Exemplo n.º 1
0
    void OnGUI()
    {
        /*
        if (PhotonNetwork.connectionStateDetailed.ToString() != lastText) {
            text += PhotonNetwork.connectionStateDetailed.ToString() + ", ";
            lastText = PhotonNetwork.connectionStateDetailed.ToString();
        }

        GUILayout.Label(text);
        */

        if (!PhotonNetwork.connected) {
        } else {
            PhotonNetwork.GetRoomList();

            GUILayout.BeginArea(new Rect (Screen.width/2 - 200, Screen.height/2 - 200, 400, 400));

            if (networkState == NetworkingState.SelectRole) {
                GUILayout.Label("This is a cooperative multiplayer game that is meant to be played with 2 or more people, talking over Skype or similar technology. But you can still play solo for a few levels if that's your thing!", descriptionTextStyle, GUILayout.MinHeight(100));

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Start a game", GUILayout.MinWidth(100), GUILayout.MinHeight(50))) {
                    serverName = GenerateRandomName();
                    PhotonNetwork.CreateRoom(serverName);
                }

                if (GUILayout.Button("Join another game", GUILayout.MinWidth(150), GUILayout.MinHeight(50))) {
                    networkState = NetworkingState.InputServerName;
                }
                GUILayout.EndHorizontal();
            }

            if (networkState == NetworkingState.InputServerName) {
                GUILayout.BeginVertical();
                GUI.SetNextControlName("ServerNameBox");
                serverToJoin = GUILayout.TextField(serverToJoin, serverNameStyle, GUILayout.MinWidth(300), GUILayout.MinHeight(50));
                GUI.FocusControl("ServerNameBox");

                GUILayout.BeginHorizontal();
                if (serverToJoin.Length > 0) {
                    if (GUILayout.Button("Join", GUILayout.MinWidth(100), GUILayout.MinHeight(50))) {
                        PhotonNetwork.JoinRoom(serverToJoin);
                        serverName = serverToJoin;
                        networkState = NetworkingState.ConnectingToServer;
                    }
                }

                if (GUILayout.Button("Back", GUILayout.MinWidth(100), GUILayout.MinHeight(50))) {
                    networkState = NetworkingState.SelectRole;
                }
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();
            }

            if (networkState == NetworkingState.ConnectingToServer) {
                GUILayout.Label("Connecting to game...", serverNameStyle);
            }

            if (networkState == NetworkingState.ConnectionError || networkState == NetworkingState.NewServerError) {
                GUILayout.Label("Error: " + errorMessage, serverNameStyle);
                GUILayout.Space(10);
                if (GUILayout.Button("Try again", GUILayout.MinWidth(100), GUILayout.MinHeight(50))) {
                    if (networkState == NetworkingState.NewServerError) {
                        networkState = NetworkingState.SelectRole;
                    } else {
                        networkState = NetworkingState.InputServerName;
                    }
                }
            }

            GUILayout.EndArea ();

            if (networkState == NetworkingState.Connected) {
                GUILayout.Label("Other players can use this name to connect:");
                GUILayout.BeginHorizontal();
                GUILayout.Space(30);
                GUILayout.Label(serverName, serverNameStyle);
                GUILayout.EndHorizontal();
            }
        }
    }
Exemplo n.º 2
0
    void RecieveWorldState(string stateCollectionSerialized)
    {
        settings.stateCollection = StateCollection.Deserialize(stateCollectionSerialized);

        if (settings.stateCollection.version == StateCollection.gameVersion) {
            settings.GenerateLevel();
            settings.Resume();
            networkState = NetworkingState.Connected;
        } else {
            errorMessage = "Incorrect game version!";
            networkState = NetworkingState.ConnectionError;
            PhotonNetwork.LeaveRoom();
        }
    }
Exemplo n.º 3
0
 void OnPhotonCreateRoomFailed()
 {
     errorMessage = "Something went wrong, please try again.";
     networkState = NetworkingState.NewServerError;
 }
Exemplo n.º 4
0
 void OnPhotonJoinRoomFailed()
 {
     errorMessage = "Something went wrong...";
     networkState = NetworkingState.ConnectionError;
 }
Exemplo n.º 5
0
 void OnJoinedRoom()
 {
     if (PhotonNetwork.isMasterClient) {
         settings.GenerateState();
         settings.GenerateLevel();
         settings.Resume();
         networkState = NetworkingState.Connected;
     }
 }