Esempio n. 1
0
    // 游戏主菜单
    void MenuBlock()
    {
        GUI.BeginGroup(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 200, 250));
        GUILayout.Label("MAIN MENU", GUILayout.MaxWidth(200));

        if (GUILayout.Button("Create Room", GUILayout.MaxWidth(200)))
        {
            menuState = "hostgame";
        }
        if (GUILayout.Button("Enter Room", GUILayout.MaxWidth(200)))
        {
            menuState = "findgame";
        }
//			if(GUILayout.Button ("Play Offline",GUILayout.MaxWidth(200)))
//				menuState = "offlinegame";
        if (GUILayout.Button("Change Name", GUILayout.MaxWidth(200)))
        {
            menuState = "setname";
        }
        if (!UtilsC.IsWebPlayer())
        {
            if (GUILayout.Button("Exit", GUILayout.MaxWidth(200)))
            {
                Application.Quit();
            }
        }
        GUI.EndGroup();
    }
Esempio n. 2
0
 // Update is called once per frame
 void Update()
 {
     if (UtilsC.CheckPeerType(NetworkPeerType.Disconnected) && UtilsC.IsHostsExists())
     {
         hostData = MasterServer.PollHostList();
     }
 }
Esempio n. 3
0
    /*
     * void LoadingPopup(){
     *      if(UtilsC.IsWebPlayer(){
     *              GUI.Box(new Rect(Screen.width/4+0,Screen.height/2-30,450,50), "");
     *              if(Application.CanStreamedLevelBeLoaded (levelIndex)){
     *                      GUI.Label(new Rect(Screen.width/4+10,Screen.height/2-25,285,150), "Starting the game!");
     *                      //Application.LoadLevel((Application.loadedLevel+1));
     *              }else{
     *                      GUI.Label(new Rect(Screen.width/4+10,Screen.height/2-25,285,150), "Loading the game: "+Mathf.Floor(Application.GetStreamProgressForLevel(levelIndex)*100)+" %");
     *              }
     *      }
     * }
     */

    // 设置玩家名称
    void SetPlayerName()
    {
        GUILayout.BeginArea(new Rect(Screen.width / 2 - 85, Screen.height / 2 - 50, 200, 200));
        GUI.Box(new Rect(0, 40, 200, 80), "", GUI.skin.FindStyle("Box"));
        GUILayout.Label("Player Name", GUI.skin.FindStyle("Lable"));
        GUILayout.BeginHorizontal();
        GUILayout.Space(10);
        networkConnection.playerName = GUILayout.TextField(networkConnection.playerName, 20, GUILayout.MinWidth(180), GUILayout.MaxWidth(250));
        GUILayout.Space(15);
        GUILayout.EndHorizontal();

        if (UtilsC.IsStringCorrect(networkConnection.playerName))
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(50);
            if (GUILayout.Button("Exit", GUI.skin.FindStyle("Button"), GUILayout.MaxWidth(100)))
            {
                Application.Quit();
            }
            if (GUILayout.Button("OK", GUI.skin.FindStyle("Button"), GUILayout.MaxWidth(100)))
            {
                PlayerPrefs.SetString("playerName", networkConnection.playerName);
                menuState = "setavatarstyle";
            }
            GUILayout.Space(50);
            GUILayout.EndHorizontal();
        }
        else
        {
            GUI.Label(new Rect(12, 90, 185, 30), "Enter your player name!");
        }
        GUILayout.EndArea();
    }
Esempio n. 4
0
 void Update()
 {
     // 当本客户端没有连接并且有主机地址存在的时候,拉取服务器列表
     if (UtilsC.CheckPeerType(NetworkPeerType.Disconnected) && UtilsC.IsHostsExists())
     {
         hostData = MasterServer.PollHostList();
     }
 }
Esempio n. 5
0
 void Start()
 {
     playerName = "OldWheels-" + UtilsC.CreateRandomString(5); //Default Random Player Name
     DontDestroyOnLoad(this);
     m_NetwordView       = GetComponent <NetworkView>();
     m_NetwordView.group = 1;
     Application.LoadLevel(sceneOnDisconnect);
 }
Esempio n. 6
0
 void LocalPlayerTriggerEnterC2S(NetworkPlayer player, int checkPointIndex)
 {
     // 在服务器端执行
     if (UtilsC.CheckPeerType(NetworkPeerType.Server))
     {
         OnCarEnterCheckPoint(player, checkPointIndex);
     }
 }
Esempio n. 7
0
 public void OnBtnOKClicked()
 {
     networkConnection.playerName = playerName.text;
     if (UtilsC.IsStringCorrect(networkConnection.playerName))
     {
         PlayerPrefs.SetString("playerName", networkConnection.playerName);
         PlayerPrefs.Save();
         UIManager.GetInst().SetPanelShow("setavatarstyle");
     }
 }
Esempio n. 8
0
    // 断掉连接
    public void Disconnect(int timeout)
    {
        if (playerObjMap.ContainsKey(Network.player))
        {
            playerObjMap.Remove(Network.player);
        }
        bool isServer = UtilsC.CheckPeerType(NetworkPeerType.Server);

        Network.Disconnect(timeout);
        if (isServer)
        {
            MasterServer.UnregisterHost();
        }
    }
Esempio n. 9
0
    void OnGUI()
    {
        if (UIManager.C_USE_NEW_UI == false)
        {
            GUI.skin = guiskin;
            GUILayout.Label("Connection status: " + Network.peerType.ToString());
            if (UtilsC.CheckPeerType(NetworkPeerType.Disconnected))
            {
                switch (menuState)
                {
                // 选择赛车
                case "setavatarstyle": SetAvatarStyle();
                    break;

                // 显示主菜单
                case "menublock": MenuBlock();
                    break;

                // 建立比赛房间
                case "hostgame": HostGame();
                    break;

                // 进入比赛房间
                case "findgame": FindGame();
                    break;

                //				case "offlinegame":OfflineGameSettings();
                //		            break;
                // 设置玩家名称
                case "setname": SetPlayerName();
                    break;

                // 消息出错
                case "networkerror": MSG_Error();
                    break;

                // 尝试重连
                case "tryingtoconnect": MSG_TryingToConnect();
                    break;

                // 设置玩家名称
                default: SetPlayerName();
                    break;
                }
            }
            DrawCursor();
        }
    }
Esempio n. 10
0
        public void TestModInterop()
        {
            typeof(UtilsC).ModInterop();
            typeof(UtilsD).ModInterop();

            typeof(UtilsA).ModInterop();
            Assert.AreEqual(UtilsA.Something(2, 3), UtilsC.Something(2, 3));
            Assert.AreEqual(UtilsA.AnotherThing(2, 3), UtilsC.AnotherThing(2, 3));

            typeof(UtilsB).ModInterop();
            Assert.AreEqual(UtilsA.Something(2, 3), UtilsC.Something(2, 3));
            Assert.AreEqual(UtilsB.AnotherThing(2, 3), UtilsC.AnotherThing(2, 3));

            Assert.AreEqual(UtilsB.Something(2, 3), UtilsD.Something(2, 3));
            Assert.AreEqual(UtilsB.AnotherThing(2, 3), UtilsD.AnotherThing(2, 3));
        }
Esempio n. 11
0
    void InGameMenu()
    {
        if (UtilsC.CheckPeerType(NetworkPeerType.Client))
        {
            if (GUILayout.Button("Disconnect"))
            {
                networkConnection.Disconnect(200);
            }
            GUILayout.Label("Ping to server: " + Network.GetAveragePing(Network.connections[0]));
        }

        if (UtilsC.CheckPeerType(NetworkPeerType.Server))
        {
            if (GUILayout.Button("Stop Server", GUILayout.MaxWidth(115)))
            {
                networkConnection.Disconnect(200);
            }

            if (Network.connections.Length > 0)
            {
                GUILayout.Label("Connections: " + Network.connections.Length);

                scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(170), GUILayout.Height(100));
                for (int i = 0; i < Network.connections.Length; i++)
                {
                    GUILayout.Label("Ping to " + i.ToString() + " player: " + Network.GetAveragePing(Network.connections[i]));
                    if (GUILayout.Button("Kick " + i.ToString() + " player", GUILayout.MaxWidth(150)))
                    {
                        networkConnection.Kick(Network.connections[i], true);
                    }
                }
                GUILayout.EndScrollView();
            }
            else
            {
                GUILayout.Label("No Player Connected");
            }
        }

        GUILayout.Label("You Name: " + networkConnection.playerName);

        if (networkConnection.usePassword && UtilsC.IsStringCorrect(networkConnection.password))
        {
            GUILayout.Label("Server Password: " + networkConnection.password);
        }
    }
Esempio n. 12
0
    public void OnQuit()
    {
        if (UtilsC.CheckPeerType(NetworkPeerType.Client))
        {
            networkConnection.Disconnect(200);
        }

        if (UtilsC.CheckPeerType(NetworkPeerType.Server))
        {
            networkConnection.Disconnect(200);

            if (Network.connections.Length > 0)
            {
                for (int i = 0; i < Network.connections.Length; i++)
                {
                    networkConnection.Kick(Network.connections[i], true);
                }
            }
        }
    }
Esempio n. 13
0
    void Start()
    {
        if (sInst != null)
        {
            throw new System.Exception("there is NetworkConnection exist!!!!");
        }

        sInst = this;
        //playerName = UtilsC.CreateRandomString(5);
        if (PlayerPrefs.HasKey("playerName"))
        {
            playerName = PlayerPrefs.GetString("playerName");
        }
        else
        {
            playerName = UtilsC.CreateRandomString(5);
        }
        DontDestroyOnLoad(this);
        networkView.group = 1;
        Application.LoadLevel(sceneOnDisconnect);
    }
Esempio n. 14
0
 void SetGameID()
 {
     gameType = UtilsC.CreateRandomString(30);
 }
Esempio n. 15
0
    // 建立比赛房间
    void HostGame()
    {
        GUILayout.BeginArea(new Rect(Screen.width / 2 - 325, Screen.height / 2 - 180, 700, 400));

        GUI.Box(new Rect(0, 20, 650, 300), "");

        GUILayout.Label("CREATE ROOM");
        GUILayout.BeginArea(new Rect(5, 100, 400, 180));
        GUILayout.Label("MAIN");
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();
        GUILayout.Label("Server Port: ");
        GUILayout.Label("Server Name: ");
        GUILayout.Label("Server Info: ");
        GUILayout.Label("Max connections: ");
        GUILayout.EndVertical();
        GUILayout.BeginVertical();
        networkConnection.connectPort       = int.Parse(GUILayout.TextField(networkConnection.connectPort.ToString()));
        networkConnection.serverName        = GUILayout.TextField(networkConnection.serverName, GUILayout.MinWidth(140));
        networkConnection.serverDescription = GUILayout.TextField(networkConnection.serverDescription, GUILayout.MinWidth(140));
        networkConnection.maxConnections    = int.Parse(GUILayout.TextField(networkConnection.maxConnections.ToString(), GUILayout.MinWidth(140)));
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();
        GUILayout.EndArea();

        GUILayout.BeginArea(new Rect(10, 240, 190, 250));
        networkConnection.usePassword = GUILayout.Toggle(networkConnection.usePassword, "Use Password");
        if (networkConnection.usePassword)
        {
            networkConnection.password = GUILayout.PasswordField(networkConnection.password, "*"[0], 15, GUILayout.Width(150));
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Generate", GUI.skin.FindStyle("Button"), GUILayout.MaxWidth(70)))
            {
                networkConnection.password = UtilsC.CreateRandomString(15);
            }
            if (GUILayout.Button("Clear", GUI.skin.FindStyle("Button"), GUILayout.MaxWidth(70)))
            {
                networkConnection.password = "";
            }
            GUILayout.EndHorizontal();
        }

        GUILayout.EndArea();

        GUILayout.BeginArea(new Rect(180, 350, 500, 30));
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Start Server", GUILayout.MaxWidth(130)))
        {
            text_ = GameObject.Find("Loading text");
            text_.renderer.enabled = true;
            networkConnection.StartServer(loadLevelInfo[levelIndex].sceneName);
        }
        if (GUILayout.Button("Back To Menu", GUILayout.MaxWidth(130)))
        {
            menuState = "menublock";
        }

        GUILayout.EndHorizontal();
        GUILayout.EndArea();

        GUILayout.BeginArea(new Rect(450, 50, 190, 250));
        GUILayout.Label("ACCESS POINT");
        GUILayout.BeginVertical();
        GUILayout.Label("Point: " + loadLevelInfo[levelIndex].mapName);
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Prev", GUILayout.MinWidth(70)))
        {
            if (levelIndex == 0)
            {
                levelIndex = loadLevelInfo.Length - 1;
            }
            else
            {
                levelIndex--;
            }
        }

        if (GUILayout.Button("Next", GUILayout.MinWidth(70)))
        {
            if (levelIndex == loadLevelInfo.Length - 1)
            {
                levelIndex = 0;
            }
            else
            {
                levelIndex++;
            }
        }

        GUILayout.EndHorizontal();
        if (loadLevelInfo[levelIndex].mapPreview)
        {
            GUILayout.Box(loadLevelInfo[levelIndex].mapPreview, GUI.skin.FindStyle("Box"));
        }
        else
        {
            GUILayout.Box("No Image");
        }
        GUILayout.EndVertical();
        GUILayout.EndArea();
        GUILayout.EndArea();
    }
Esempio n. 16
0
    // 进入比赛房间
    void FindGame()
    {
        GUILayout.BeginArea(new Rect(Screen.width / 2 - 300, Screen.height / 2 - 200, 600, 400));
        GUI.Box(new Rect(0, 20, 600, 400), "");
        GUILayout.Label("Find Game Servers");

        GUILayout.BeginArea(new Rect(0, 30, 595, 200));
        GUI.Box(new Rect(5, 0, 590, 200), "", GUI.skin.FindStyle("Box"));
        scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(575), GUILayout.Height(200));
        if (UtilsC.IsHostsExists())
        {
            foreach (HostData element in networkConnection.hostData)
            {
                string name        = " [" + element.gameName + " " + element.connectedPlayers + " / " + element.playerLimit + "] ";
                string hostInfo    = "";
                string gameComment = " [" + element.comment + "] ";

                foreach (string host in element.ip)
                {
                    hostInfo = hostInfo + host + ":" + element.port + " ";
                }
                hostInfo = " [" + hostInfo + "] ";

                GUILayout.BeginHorizontal();
                GUILayout.Label(name + gameComment + hostInfo + (element.passwordProtected ? "Private " : "Public ").ToString(), GUI.skin.FindStyle("Lable1"));
                GUILayout.Space(100);
                if (GUILayout.Button("Connect", GUI.skin.FindStyle("Button"), GUILayout.MaxWidth(55)))
                {
                    string TEMP_IP = "";
                    foreach (string part in element.ip)
                    {
                        TEMP_IP = TEMP_IP + part;
                    }
                    networkConnection.connectToIP = TEMP_IP;
                    networkConnection.connectPort = int.Parse(element.port.ToString());
                    networkConnection.Connect();
                }
                GUILayout.Space(10);
                GUILayout.EndHorizontal();
            }
        }
        else
        {
            GUILayout.Label(" There are no hosts registered");
        }
        GUILayout.EndScrollView();
        GUILayout.EndArea();

        GUILayout.BeginArea(new Rect(0, 233, 480, 127));
        GUI.Box(new Rect(5, 0, 450, 127), "", GUI.skin.FindStyle("Box"));
        GUILayout.BeginArea(new Rect(15, 5, 350, 250));
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();
        GUILayout.Label("IP: ");
        GUILayout.Label("Port: ");
        GUILayout.EndVertical();
        GUILayout.BeginVertical();
        networkConnection.connectToIP = GUILayout.TextField(networkConnection.connectToIP, GUILayout.MaxWidth(200));
        networkConnection.connectPort = int.Parse(GUILayout.TextField(networkConnection.connectPort.ToString(), GUILayout.MaxWidth(200)));
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        networkConnection.usePassword = GUILayout.Toggle(networkConnection.usePassword, "Use Password");
        if (networkConnection.usePassword)
        {
            networkConnection.password = GUILayout.PasswordField(networkConnection.password, "*"[0], 15, GUILayout.Width(100));
        }
        GUILayout.EndHorizontal();
        GUILayout.EndArea();
        GUILayout.EndArea();

        GUILayout.BeginArea(new Rect(15, 340, 250, 30));
        if (GUILayout.Button("Connect", GUI.skin.FindStyle("Button"), GUILayout.MaxWidth(130)))
        {
            networkConnection.Connect();
        }
        GUILayout.EndArea();

        GUILayout.BeginArea(new Rect(5, 365, 500, 30));
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Refresh List", GUILayout.MaxWidth(130)))
        {
            networkConnection.RefreshServerList();
        }
        if (GUILayout.Button("Back To Menu", GUILayout.MaxWidth(130)))
        {
            menuState = "menublock";
        }
        GUILayout.EndHorizontal();
        GUILayout.EndArea();
        GUILayout.EndArea();
    }