Пример #1
0
    void OnGUI()
    {
        if (!showGUI)
        {
            return;
        }

        int xpos    = 10 + offsetX;
        int ypos    = 40 + offsetY;
        int spacing = 24;

        if (!NetworkClient.active && !NetworkServer.active && manager.matchMaker == null)
        {
            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Start Host (H)"))
            {
                manager.StartHost();
            }
            ypos += spacing;

            if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Connect (C)"))
            {
                manager.StartClient();
            }
            manager.networkAddress = GUI.TextField(new Rect(xpos + 100, ypos, 100, 20), manager.networkAddress);
            ypos += spacing;

            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Start Server Only (S)"))
            {
                manager.StartServer();
            }
            ypos += spacing;

            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "To Main Menu (Esc)"))
            {
                ToMainMenu();
            }
            ypos += spacing;
        }
        else
        {
            if (NetworkServer.active)
            {
                GUI.Label(new Rect(xpos, ypos, 300, 20), "Server: port=" + manager.networkPort);
                ypos += spacing;
            }
            if (NetworkClient.active)
            {
                GUI.Label(new Rect(xpos, ypos, 300, 20), "Client: address=" + manager.networkAddress + " port=" + manager.networkPort);
                ypos += spacing;
            }
        }

        if (NetworkClient.active && !ClientScene.ready)
        {
            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Client Ready"))
            {
                ClientScene.Ready(manager.client.connection);

                if (ClientScene.localPlayers.Count == 0)
                {
                    ClientScene.AddPlayer(0);
                }
            }
            ypos += spacing;
        }

        if (NetworkServer.active || NetworkClient.active)
        {
            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Stop (X)"))
            {
                manager.StopHost();
            }
            ypos += spacing;
        }
    }
        void OnGUI()
        {
            if (!showGUI)
            {
                return;
            }

            int xpos    = 10 + offsetX;
            int ypos    = 40 + offsetY;
            int spacing = 24;

            if (!NetworkClient.active && !NetworkServer.active && manager.matchMaker == null)
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "LAN Host(H)"))
                {
                    manager.StartHost();
                }
                ypos += spacing;

                if (GUI.Button(new Rect(xpos, ypos, 105, 20), "LAN Client(C)"))
                {
                    manager.StartClient();
                }
                manager.networkAddress = GUI.TextField(new Rect(xpos + 100, ypos, 95, 20), manager.networkAddress);
                ypos += spacing;

                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "LAN Server Only(S)"))
                {
                    manager.StartServer();
                }
                ypos += spacing;
            }
            else
            {
                if (NetworkServer.active)
                {
                    GUI.Label(new Rect(xpos, ypos, 300, 20), "Server: port=" + manager.networkPort);
                    ypos += spacing;
                }
                if (NetworkClient.active)
                {
                    GUI.Label(new Rect(xpos, ypos, 300, 20), "Client: address=" + manager.networkAddress + " port=" + manager.networkPort);
                    ypos += spacing;
                }
            }

            if (NetworkClient.active && !ClientScene.ready)
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Client Ready"))
                {
                    ClientScene.Ready(manager.client.connection);

                    if (ClientScene.localPlayers.Count == 0)
                    {
                        ClientScene.AddPlayer(0);
                    }
                }
                ypos += spacing;
            }

            if (NetworkServer.active || NetworkClient.active)
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Stop (X)"))
                {
                    manager.StopHost();
                }
                ypos += spacing;
            }

            if (!NetworkServer.active && !NetworkClient.active)
            {
                ypos += 10;

                if (manager.matchMaker == null)
                {
                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Enable Match Maker (M)"))
                    {
                        manager.StartMatchMaker();
                    }
                    ypos += spacing;
                }
                else
                {
                    if (manager.matchInfo == null)
                    {
                        if (manager.matches == null)
                        {
                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Create Internet Match"))
                            {
                                manager.matchMaker.CreateMatch(manager.matchName, manager.matchSize, true, "", manager.OnMatchCreate);
                            }
                            ypos += spacing;

                            GUI.Label(new Rect(xpos, ypos, 100, 20), "Room Name:");
                            manager.matchName = GUI.TextField(new Rect(xpos + 100, ypos, 100, 20), manager.matchName);
                            ypos += spacing;

                            ypos += 10;

                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Find Internet Match"))
                            {
                                manager.matchMaker.ListMatches(0, 20, "", manager.OnMatchList);
                            }
                            ypos += spacing;
                        }
                        else
                        {
                            foreach (var match in manager.matches)
                            {
                                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Join Match:" + match.name))
                                {
                                    manager.matchName = match.name;
                                    manager.matchSize = (uint)match.currentSize;
                                    manager.matchMaker.JoinMatch(match.networkId, "", manager.OnMatchJoined);
                                }
                                ypos += spacing;
                            }
                        }
                    }

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Change MM server"))
                    {
                        showServer = !showServer;
                    }
                    if (showServer)
                    {
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Local"))
                        {
                            manager.SetMatchHost("localhost", 1337, false);
                            showServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Internet"))
                        {
                            manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
                            showServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Staging"))
                        {
                            manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, true);
                            showServer = false;
                        }
                    }

                    ypos += spacing;

                    GUI.Label(new Rect(xpos, ypos, 300, 20), "MM Uri: " + manager.matchMaker.baseUri);
                    ypos += spacing;

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Disable Match Maker"))
                    {
                        manager.StopMatchMaker();
                    }
                    ypos += spacing;
                }
            }
        }
Пример #3
0
    /// <summary>
    /// 開始時の処理
    /// </summary>
    void Start()
    {
        // もしクライアントとして実行中じゃなかったら何もしない
        if (!Global.Instance.IsClient)
        {
            return;
        }

        // 物理演算があるので常時処理しておきたい
        Application.runInBackground = true;

        // ネットワーク越しに座標など同期する必要があるプレハブを登録する
        foreach (var kvp in Global.Instance.NetPrefabs)
        {
            ClientScene.RegisterSpawnHandler(
                kvp.Key,
                (position, assetId) => {
                return(GameObject.Instantiate <GameObject>(kvp.Value));
            },
                (spawned) => GameObject.Destroy(spawned)
                );
        }

        // サーバーアドレスの取得
        string address;

        if (string.IsNullOrEmpty(Application.absoluteURL))
        {
            address = "localhost";
        }
        else
        {
            address = new Uri(Application.absoluteURL).GetComponents(UriComponents.Host, UriFormat.Unescaped);
        }

        // サーバーへ接続する
        _Client = new NetworkClient();
        _Client.Connect(address, this.Port);
        _Client.RegisterHandler(
            MsgType.Connect,
            (netMsg) => {
            ClientScene.Ready(netMsg.conn);
            ClientScene.AddPlayer(0);
        }
            );

        // ギミック無効化要求ハンドラ登録
        _Client.RegisterHandler(
            MyMsgType.DisableGimmick,
            (netMsg) => {
            var gimmicks = Server.Instance.GetComponentsInChildren <Gimmick>(true);
            for (int i = 0; i < gimmicks.Length; i++)
            {
                var gimmick = gimmicks[i];
                var c       = gimmick.GetComponent <Collider2D>();
                if (c != null)
                {
                    c.enabled = false;                             // 一旦衝突判定を無効化しておかないとクライアント側で正しい初期位置に戻ってくれない
                }
                gimmick.gameObject.SetActive(false);
                //gimmick.Initialize();
            }
        }
            );

        // ギミック有効化要求ハンドラ登録
        _Client.RegisterHandler(
            MyMsgType.EnableGimmick,
            (netMsg) => {
            var gimmicks = Server.Instance.GetComponentsInChildren <Gimmick>(true);
            for (int i = 0; i < gimmicks.Length; i++)
            {
                gimmicks[i].gameObject.SetActive(true);
            }
        }
            );

        // ギミック衝突判定有効化要求ハンドラ登録
        _Client.RegisterHandler(
            MyMsgType.EnableGimmickCollision,
            (netMsg) => {
            var gimmicks = Server.Instance.GetComponentsInChildren <Gimmick>(true);
            for (int i = 0; i < gimmicks.Length; i++)
            {
                var gimmick = gimmicks[i];
                var c       = gimmick.GetComponent <Collider2D>();
                if (c != null)
                {
                    c.enabled = true;
                }
            }
        }
            );
    }
 public void OnClient1Connected(NetworkMessage netMsg)
 {
     numClientConnects += 1;
     ClientScene.Ready(netMsg.conn);
 }
Пример #5
0
 // called when connected to a server
 public override void OnClientConnect(NetworkConnection conn)
 {
     ClientScene.Ready(conn);
     GameObject.Find("QRCodeReader").GetComponent <QRCodeReader>().webCam.Stop();
 }
Пример #6
0
 public void OnConnected(NetworkMessage netMsg)
 {
     Debug.Log("Connected?");
     ClientScene.Ready(netMsg.conn);
     ClientScene.AddPlayer(1);
 }
Пример #7
0
 public override void OnClientConnect(NetworkConnection conn)
 {
     ClientScene.Ready(conn);
     ClientScene.AddPlayer(conn, 0);
 }
Пример #8
0
    void OnGUI()
    {
        if (!showGUI)
        {
            return;
        }

        int xpos            = 10 + offsetX;
        int ypos            = 10 + offsetY;
        int buttonWidth     = Screen.width - 20;
        int buttonHeight    = Screen.height / 5;
        int squareButtonDim = Screen.width / 12;
        int spacing         = buttonHeight;

        // Setup Button style
        GUIStyle aButton = new GUIStyle(GUI.skin.button);

        aButton.fontSize = fontSize;
        // Setup TextField style
        GUIStyle someText = new GUIStyle(GUI.skin.textField);

        someText.fontSize  = fontSize;
        someText.alignment = TextAnchor.MiddleCenter;
        // Set Text font size
        GUIStyle someLabel = new GUIStyle(GUI.skin.label);

        someLabel.fontSize = fontSize;

        if (NetworkServer.active || NetworkClient.active)
        {
            if (GUI.Button(new Rect(xpos, ypos, squareButtonDim, squareButtonDim), "X"))
            {
                manager.StopHost();
            }
            ypos += spacing;
        }

        // Initial connection menu
        if (!NetworkClient.active && !NetworkServer.active && manager.matchMaker == null)
        {
            /*
             * if (GUI.Button(new Rect(xpos, ypos, 200, 20), "LAN Host(H)"))
             * {
             *  manager.StartHost();
             * }
             * ypos += spacing;
             */

            // Lan client button
            if (GUI.Button(new Rect(xpos, ypos, buttonWidth / 2, buttonHeight), "LAN Client (C)", aButton))
            {
                manager.StartClient();
            }
            // IP input
            manager.networkAddress = GUI.TextField(new Rect(xpos + buttonWidth / 2, ypos, buttonWidth / 2, buttonHeight), manager.networkAddress, someText);
            ypos += spacing;

            // Start Server
            if (GUI.Button(new Rect(xpos, ypos, buttonWidth, buttonHeight), "LAN Server Only (S)", aButton))
            {
                manager.StartServer();
            }
            ypos += spacing;
        }
        else
        {
            if (NetworkServer.active)
            {
                GUI.Label(new Rect(xpos, ypos, buttonWidth, buttonHeight), "Server: port=" + manager.networkPort, someLabel);
                ypos += spacing;
            }
            if (NetworkClient.active)
            {
                GUI.Label(new Rect(xpos, ypos, buttonWidth, buttonHeight), "Client: address=" + manager.networkAddress + " port=" + manager.networkPort, someLabel);
                ypos += spacing;
            }
        }

        if (NetworkClient.active && !ClientScene.ready)
        {
            if (GUI.Button(new Rect(xpos, ypos, buttonWidth, buttonHeight), "Client Ready"))
            {
                ClientScene.Ready(manager.client.connection);

                if (ClientScene.localPlayers.Count == 0)
                {
                    ClientScene.AddPlayer(0);
                }
            }
            ypos += spacing;
        }
    }
 // client function
 public void OnConnected(NetworkMessage netMsg)
 {
     ClientScene.Ready(netMsg.conn);
     Debug.Log("Connected to server");
 }
 private void ShowControls()
 {
     this.m_ShowControls = EditorGUILayout.Foldout(this.m_ShowControls, this.m_ShowControlsLabel);
     if (this.m_ShowControls)
     {
         if (!string.IsNullOrEmpty(NetworkManager.networkSceneName))
         {
             EditorGUILayout.ObjectField("Current Scene:", GetSceneObject(NetworkManager.networkSceneName), typeof(UnityEngine.Object), true, new GUILayoutOption[0]);
         }
         EditorGUILayout.Separator();
         if ((!NetworkClient.active && !NetworkServer.active) && (this.m_Manager.matchMaker == null))
         {
             EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
             if (GUILayout.Toggle(false, "LAN Host", EditorStyles.miniButton, new GUILayoutOption[0]))
             {
                 this.m_Manager.StartHost();
             }
             if (GUILayout.Toggle(false, "LAN Server", EditorStyles.miniButton, new GUILayoutOption[0]))
             {
                 this.m_Manager.StartServer();
             }
             if (GUILayout.Toggle(false, "LAN Client", EditorStyles.miniButton, new GUILayoutOption[0]))
             {
                 this.m_Manager.StartClient();
             }
             if (GUILayout.Toggle(false, "Start Matchmaker", EditorStyles.miniButton, new GUILayoutOption[0]))
             {
                 this.m_Manager.StartMatchMaker();
                 this.m_ShowMatchMaker = true;
             }
             EditorGUILayout.EndHorizontal();
         }
         if ((NetworkClient.active && !ClientScene.ready) && GUI.Button(GetButtonRect(), "Client Ready"))
         {
             ClientScene.Ready(this.m_Manager.client.connection);
             if (ClientScene.localPlayers.Count == 0)
             {
                 ClientScene.AddPlayer(0);
             }
         }
         if ((NetworkServer.active || NetworkClient.active) && GUI.Button(GetButtonRect(), "Stop"))
         {
             this.m_Manager.StopServer();
             this.m_Manager.StopClient();
         }
         if (!NetworkServer.active && !NetworkClient.active)
         {
             EditorGUILayout.Separator();
             if ((this.m_Manager.matchMaker != null) && (this.m_Manager.matchInfo == null))
             {
                 if (this.m_Manager.matches == null)
                 {
                     EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
                     if (GUILayout.Toggle(false, "Create Internet Match", EditorStyles.miniButton, new GUILayoutOption[0]))
                     {
                         this.m_Manager.matchMaker.CreateMatch(this.m_Manager.matchName, this.m_Manager.matchSize, true, "", "", "", 0, 0, new NetworkMatch.DataResponseDelegate <MatchInfo>(this.m_Manager.OnMatchCreate));
                     }
                     if (GUILayout.Toggle(false, "Find Internet Match", EditorStyles.miniButton, new GUILayoutOption[0]))
                     {
                         this.m_Manager.matchMaker.ListMatches(0, 20, "", false, 0, 0, new NetworkMatch.DataResponseDelegate <List <MatchInfoSnapshot> >(this.m_Manager.OnMatchList));
                     }
                     if (GUILayout.Toggle(false, "Stop MatchMaker", EditorStyles.miniButton, new GUILayoutOption[0]))
                     {
                         this.m_Manager.StopMatchMaker();
                     }
                     EditorGUILayout.EndHorizontal();
                     this.m_Manager.matchName = EditorGUILayout.TextField("Room Name:", this.m_Manager.matchName, new GUILayoutOption[0]);
                     this.m_Manager.matchSize = (uint)EditorGUILayout.IntField("Room Size:", (int)this.m_Manager.matchSize, new GUILayoutOption[0]);
                     EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
                     if (GUILayout.Toggle(false, "Use Local Relay", EditorStyles.miniButton, new GUILayoutOption[0]))
                     {
                         this.m_Manager.SetMatchHost("localhost", 0x539, false);
                     }
                     if (GUILayout.Toggle(false, "Use Internet Relay", EditorStyles.miniButton, new GUILayoutOption[0]))
                     {
                         this.m_Manager.SetMatchHost("mm.unet.unity3d.com", 0x1bb, true);
                     }
                     EditorGUILayout.EndHorizontal();
                     EditorGUILayout.Separator();
                 }
                 else
                 {
                     foreach (MatchInfoSnapshot snapshot in this.m_Manager.matches)
                     {
                         if (GUI.Button(GetButtonRect(), "Join Match:" + snapshot.name))
                         {
                             this.m_Manager.matchName = snapshot.name;
                             this.m_Manager.matchSize = (uint)snapshot.currentSize;
                             this.m_Manager.matchMaker.JoinMatch(snapshot.networkId, "", "", "", 0, 0, new NetworkMatch.DataResponseDelegate <MatchInfo>(this.m_Manager.OnMatchJoined));
                         }
                     }
                     if (GUI.Button(GetButtonRect(), "Stop MatchMaker"))
                     {
                         this.m_Manager.StopMatchMaker();
                     }
                 }
             }
         }
         EditorGUILayout.Separator();
     }
 }
Пример #11
0
 // called when connected to a server
 public override void OnClientConnect(NetworkConnection conn)
 {
     ClientScene.Ready(conn);
 }
Пример #12
0
        void ShowControls()
        {
            m_ShowControls = EditorGUILayout.Foldout(m_ShowControls, m_ShowControlsLabel);
            if (!m_ShowControls)
            {
                return;
            }

            if (!string.IsNullOrEmpty(NetworkManager.networkSceneName))
            {
                EditorGUILayout.ObjectField("Current Scene:", GetSceneObject(NetworkManager.networkSceneName), typeof(UnityObject), true);
            }
            EditorGUILayout.Separator();

            if (!NetworkClient.active && !NetworkServer.active && m_Manager.matchMaker == null)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Toggle(false, "LAN Host", EditorStyles.miniButton))
                {
                    m_Manager.StartHost();
                }
                if (GUILayout.Toggle(false, "LAN Server", EditorStyles.miniButton))
                {
                    m_Manager.StartServer();
                }
                if (GUILayout.Toggle(false, "LAN Client", EditorStyles.miniButton))
                {
                    m_Manager.StartClient();
                }
                if (GUILayout.Toggle(false, "Start Matchmaker", EditorStyles.miniButton))
                {
                    m_Manager.StartMatchMaker();
                    m_ShowMatchMaker = true;
                }
                EditorGUILayout.EndHorizontal();
            }

            if (NetworkClient.active && !ClientScene.ready)
            {
                if (GUI.Button(GetButtonRect(), "Client Ready"))
                {
                    ClientScene.Ready(m_Manager.client.connection);

                    if (ClientScene.localPlayers.Count == 0)
                    {
                        ClientScene.AddPlayer(0);
                    }
                }
            }

            if (NetworkServer.active || NetworkClient.active)
            {
                if (GUI.Button(GetButtonRect(), "Stop"))
                {
                    m_Manager.StopServer();
                    m_Manager.StopClient();
                }
            }
            if (!NetworkServer.active && !NetworkClient.active)
            {
                EditorGUILayout.Separator();
                if (m_Manager.matchMaker != null)
                {
                    if (m_Manager.matchInfo == null)
                    {
                        if (m_Manager.matches == null)
                        {
                            EditorGUILayout.BeginHorizontal();
                            if (GUILayout.Toggle(false, "Create Internet Match", EditorStyles.miniButton))
                            {
                                m_Manager.matchMaker.CreateMatch(m_Manager.matchName, m_Manager.matchSize, true, "", m_Manager.OnMatchCreate);
                            }
                            if (GUILayout.Toggle(false, "Find Internet Match", EditorStyles.miniButton))
                            {
                                m_Manager.matchMaker.ListMatches(0, 20, "", m_Manager.OnMatchList);
                            }
                            if (GUILayout.Toggle(false, "Stop MatchMaker", EditorStyles.miniButton))
                            {
                                m_Manager.StopMatchMaker();
                            }
                            EditorGUILayout.EndHorizontal();
                            m_Manager.matchName = EditorGUILayout.TextField("Room Name:", m_Manager.matchName);
                            m_Manager.matchSize = (uint)EditorGUILayout.IntField("Room Size:", (int)m_Manager.matchSize);

                            EditorGUILayout.BeginHorizontal();
                            if (GUILayout.Toggle(false, "Use Local Relay", EditorStyles.miniButton))
                            {
                                m_Manager.SetMatchHost("localhost", 1337, false);
                            }
                            if (GUILayout.Toggle(false, "Use Internet Relay", EditorStyles.miniButton))
                            {
                                m_Manager.SetMatchHost("mm.unet.unity3d.com", 80, false);
                            }
                            EditorGUILayout.EndHorizontal();

                            EditorGUILayout.Separator();
                        }
                        else
                        {
                            foreach (var match in m_Manager.matches)
                            {
                                if (GUI.Button(GetButtonRect(), "Join Match:" + match.name))
                                {
                                    m_Manager.matchName = match.name;
                                    m_Manager.matchSize = (uint)match.currentSize;
                                    m_Manager.matchMaker.JoinMatch(match.networkId, "", m_Manager.OnMatchJoined);
                                }
                            }
                            if (GUI.Button(GetButtonRect(), "Stop MatchMaker"))
                            {
                                m_Manager.StopMatchMaker();
                            }
                        }
                    }
                }
            }

            EditorGUILayout.Separator();
        }
Пример #13
0
    public void SetClientReady()
    {
        if (!ClientScene.ready)
        {
            if (ClientScene.Ready(this.networkManager.client.connection))
            {
                Camera       cam      = Camera.main.GetComponent <Camera>();
                PostRenderer renderer = cam.GetComponent <PostRenderer>();
                if (renderer != null)
                {
                    renderer.enabled = true;
                }
                MinimapStuffs stuffs = GameObject.FindObjectOfType <MinimapStuffs>();
                if (stuffs != null)
                {
                    Camera minimapCamera = stuffs.GetComponent <Camera>();
                    minimapCamera.enabled      = true;
                    stuffs.playerCameraPanning = Camera.main.GetComponent <CameraPanning>();
                }
                this.LANClientReady.SetActive(false);
                this.LANClientNotReady.SetActive(false);

                GameMetricLogger.EnableLoggerHotkey();

                NewSpawner[] spawners = GameObject.FindObjectsOfType <NewSpawner>();
                foreach (NewSpawner spawn in spawners)
                {
                    if (spawn != null && spawn.hasAuthority)
                    {
                        NewSpawner.Instance.CmdSetReadyFlag(ClientScene.ready && !NetworkServer.active);
                    }
                }

                GameMetricLogger.SetGameLogger(GameLoggerOptions.StartGameMetrics);
            }
            else
            {
                this.LANClientReady.SetActive(false);
                this.LANClientNotReady.SetActive(true);
            }
            if (ClientScene.localPlayers.Count == 0)
            {
                ClientScene.AddPlayer(0);
            }
        }
        else
        {
            this.LANClientReady.SetActive(false);
            this.LANClientNotReady.SetActive(false);

            Camera       cam      = Camera.main.GetComponent <Camera>();
            PostRenderer renderer = cam.GetComponent <PostRenderer>();
            if (renderer != null)
            {
                renderer.enabled = true;
            }
            MinimapStuffs stuffs = GameObject.FindObjectOfType <MinimapStuffs>();
            if (stuffs != null)
            {
                Camera minimapCamera = stuffs.GetComponent <Camera>();
                minimapCamera.enabled      = true;
                stuffs.playerCameraPanning = Camera.main.GetComponent <CameraPanning>();
            }

            this.LANClientReady.SetActive(false);
            this.LANClientNotReady.SetActive(false);

            string name = this.playerNameField.text;
            if (name.Length > 0)
            {
                GameMetricLogger.instance.playerName = name;
            }
            else
            {
                GameMetricLogger.instance.playerName = "Player";
            }
            GameMetricLogger.instance.difficultyEquations = this.difficultyDropdown.options[this.difficultyDropdown.value].text;
            GameMetricLogger.EnableLoggerHotkey();

            NewSpawner[] spawners = GameObject.FindObjectsOfType <NewSpawner>();
            foreach (NewSpawner spawn in spawners)
            {
                if (spawn != null && spawn.hasAuthority)
                {
                    NewSpawner.Instance.CmdSetReadyFlag(ClientScene.ready && !NetworkServer.active);
                }
            }

            GameMetricLogger.SetGameLogger(GameLoggerOptions.StartGameMetrics);
        }

        Canvas         canvas = GameObject.FindObjectOfType <Canvas>();
        TooltipLocator loc    = canvas.GetComponent <TooltipLocator>();

        if (loc != null)
        {
            loc.tooltip.SetToolTipHidden(true);
        }
    }
Пример #14
0
        private void OnGUI()
        {
            if (!this.showGUI)
            {
                return;
            }
            int  num1         = 10 + this.offsetX;
            int  num2         = 40 + this.offsetY;
            bool notConnected = this.manager.client == null || this.manager.client.connection == null ||
                                this.manager.client.connection.connectionId == -1;

            if (!this.manager.IsClientConnected() && !NetworkServer.active &&
                this.manager.matchMaker == null)
            {
                if (notConnected)
                {
                    if (GUI.Button(new Rect((float)num1, (float)num2, 105f, 20f), "LAN Client(C)"))
                    {
                        this.manager.StartClient();
                    }
                    this.manager.networkAddress = GUI.TextField(new Rect((float)(num1 + 100), (float)num2, 95f, 20f),
                                                                this.manager.networkAddress);
                    int num3 = num2 + 24;
                }
                else
                {
                    GUI.Label(new Rect((float)num1, (float)num2, 200f, 20f),
                              "Connecting to " + this.manager.networkAddress + ":" + (object)this.manager.networkPort +
                              "..");
                    num2 += 24;
                    if (GUI.Button(new Rect((float)num1, (float)num2, 200f, 20f), "Cancel Connection Attempt"))
                    {
                        this.manager.StopClient();
                    }
                }
            }
            else
            {
                if (NetworkServer.active)
                {
                    string text = "Server: port=" + (object)this.manager.networkPort;
                    if (this.manager.useWebSockets)
                    {
                        text += " (Using WebSockets)";
                    }
                    GUI.Label(new Rect((float)num1, (float)num2, 300f, 20f), text);
                    num2 += 24;
                }

                if (this.manager.IsClientConnected())
                {
                    GUI.Label(new Rect((float)num1, (float)num2, 300f, 20f),
                              "Client: address=" + this.manager.networkAddress + " port=" +
                              (object)this.manager.networkPort);
                    num2 += 24;
                }
            }

            if (this.manager.IsClientConnected() && !ClientScene.ready)
            {
                if (GUI.Button(new Rect((float)num1, (float)num2, 200f, 20f), "Client Ready"))
                {
                    ClientScene.Ready(this.manager.client.connection);
                    if (ClientScene.localPlayers.Count == 0)
                    {
                        ClientScene.AddPlayer((short)0);
                    }
                }

                num2 += 24;
            }

            if (NetworkServer.active || this.manager.IsClientConnected())
            {
                if (GUI.Button(new Rect((float)num1, (float)num2, 200f, 20f), "Stop (X)"))
                {
                    this.manager.StopHost();
                }
                num2 += 24;
            }
        }
Пример #15
0
    void OnGUI()
    {
        if (!showGUI)
        {
            return;
        }

        int xpos    = 10 + offsetX;
        int ypos    = 10 + offsetY;
        int spacing = 24;

        if (NetworkClient.active && !ClientScene.ready)
        {
            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Client Ready"))
            {
                ClientScene.Ready(manager.client.connection);

                if (ClientScene.localPlayers.Count == 0)
                {
                    ClientScene.AddPlayer(0);
                }
            }
            ypos += spacing;
        }

        if (NetworkServer.active || NetworkClient.active)
        {
            if (!clientSetup)
            {
                myClient = manager.client; SetupClient(); clientSetup = true;
            }

            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Disconnect"))
            {
                manager.StopHost();
                gm.leaveGame();
            }
            ypos += spacing;
        }

        if (!NetworkServer.active && !NetworkClient.active)
        {
            clientSetup = false;
            if (manager.matchInfo == null)
            {
                if (manager.matches == null)
                {
                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Create Match"))
                    {
                        manager.matchMaker.CreateMatch(manager.matchName, manager.matchSize, true, "", "", "", 0, 0, manager.OnMatchCreate);
                        gm.begin(1);
                    }
                    ypos += spacing;

                    GUI.Label(new Rect(xpos, ypos, 100, 20), "Room Name:");
                    manager.matchName = GUI.TextField(new Rect(xpos + 100, ypos, 100, 20), manager.matchName);
                    ypos += spacing;

                    ypos += 10;

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Find Match"))
                    {
                        manager.matchMaker.ListMatches(0, 20, "", true, 0, 0, manager.OnMatchList);
                    }
                    ypos += spacing;
                }
                else
                {
                    foreach (var match in manager.matches)
                    {
                        if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Join Match:" + match.name))
                        {
                            manager.matchName = match.name;
                            manager.matchSize = (uint)match.currentSize;
                            manager.matchMaker.JoinMatch(match.networkId, "", "", "", 0, 0, manager.OnMatchJoined);
                            gm.begin(2);
                        }
                        ypos += spacing;
                    }

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Back"))
                    {
                        manager.matches = null;
                    }
                    ypos += spacing;
                }
            }

            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Change MM server"))
            {
                showServer = !showServer;
            }
            if (showServer)
            {
                ypos += spacing;
                if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Local"))
                {
                    manager.SetMatchHost("localhost", 1337, false);
                    showServer = false;
                }
                ypos += spacing;
                if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Internet"))
                {
                    manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
                    showServer = false;
                }
                ypos += spacing;
                if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Staging"))
                {
                    manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, true);
                    showServer = false;
                }
            }

            ypos += spacing;

            try { GUI.Label(new Rect(xpos, ypos, 300, 20), "MM Uri: " + manager.matchMaker.baseUri); }
            catch { }
            ypos += spacing;
        }
    }
Пример #16
0
 private void OnClientConnected(NetworkMessage netMsg)
 {
     ClientScene.Ready(netMsg.conn);
     ClientScene.AddPlayer(0);
 }
Пример #17
0
        void OnGUI()
        {
            if (!showGUI)
            {
                return;
            }

            NetworkManager manager = (NetworkManager)this.manager;

            int       xpos    = 10 + offsetX;
            int       ypos    = 40 + offsetY;
            const int spacing = 24;

            bool noConnection = (manager.client == null || manager.client.connection == null ||
                                 manager.client.connection.connectionId == -1);

            if (!manager.IsClientConnected() && !NetworkServer.active && manager.matchMaker == null)
            {
                if (noConnection)
                {
                    if (UnityEngine.Application.platform != RuntimePlatform.WebGLPlayer)
                    {
                        if (GUI.Button(new Rect(xpos, ypos, 200, 20), "LAN Host(H)"))
                        {
                            manager.StartHost();
                        }
                        ypos += spacing;
                    }

                    if (GUI.Button(new Rect(xpos, ypos, 105, 20), "LAN Client(C)"))
                    {
                        manager.StartClient();
                    }

                    manager.networkAddress = GUI.TextField(new Rect(xpos + 100, ypos, 95, 20), manager.networkAddress);
                    ypos += spacing;

                    if (UnityEngine.Application.platform == RuntimePlatform.WebGLPlayer)
                    {
                        // cant be a server in webgl build
                        GUI.Box(new Rect(xpos, ypos, 200, 25), "(  WebGL cannot be server  )");
                        ypos += spacing;
                    }
                    else
                    {
                        if (GUI.Button(new Rect(xpos, ypos, 200, 20), "LAN Server Only(S)"))
                        {
                            manager.StartServer();
                        }
                        ypos += spacing;
                    }
                }
                else
                {
                    GUI.Label(new Rect(xpos, ypos, 200, 20), "Connecting to " + manager.networkAddress + ":" + manager.networkPort + "..");
                    ypos += spacing;


                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Cancel Connection Attempt"))
                    {
                        manager.StopClient();
                    }
                }
            }
            else
            {
                if (NetworkServer.active)
                {
                    string serverMsg = "Server: port=" + manager.networkPort;
                    if (manager.useWebSockets)
                    {
                        serverMsg += " (Using WebSockets)";
                    }
                    GUI.Label(new Rect(xpos, ypos, 300, 20), serverMsg);
                    ypos += spacing;
                }
                if (manager.IsClientConnected())
                {
                    GUI.Label(new Rect(xpos, ypos, 300, 20), "Client: address=" + manager.networkAddress + " port=" + manager.networkPort);
                    ypos += spacing;
                }
            }

            if (manager.IsClientConnected() && !ClientScene.ready)
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Client Ready"))
                {
                    ClientScene.Ready(manager.client.connection);

                    if (ClientScene.localPlayers.Count == 0)
                    {
                        ClientScene.AddPlayer(0);
                    }
                }
                ypos += spacing;
            }

            if (NetworkServer.active || manager.IsClientConnected())
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Stop (X)"))
                {
                    NetworkServer.SetAllClientsNotReady();
                    if (NetworkServer.active)
                    {
                        manager.StopHost();
                    }
                    else
                    {
                        manager.StopClient();
                    }
                }
                ypos += spacing;
            }

            if (!NetworkServer.active && !manager.IsClientConnected() && noConnection)
            {
                ypos += 10;

                if (UnityEngine.Application.platform == RuntimePlatform.WebGLPlayer)
                {
                    GUI.Box(new Rect(xpos - 5, ypos, 220, 25), "(WebGL cannot use Match Maker)");
                    return;
                }

                if (manager.matchMaker == null)
                {
                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Enable Match Maker (M)"))
                    {
                        manager.StartMatchMaker();
                    }
                    ypos += spacing;
                }
                else
                {
                    if (manager.matchInfo == null)
                    {
                        if (manager.matches == null)
                        {
                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Create Internet Match"))
                            {
                                manager.StartHostAll(manager.matchName, manager.matchSize);
                                //manager.matchMaker.CreateMatch(manager.matchName, manager.matchSize, true, "", "", "", 0, 0, manager.OnMatchCreate);
                            }
                            ypos += spacing;

                            GUI.Label(new Rect(xpos, ypos, 100, 20), "Room Name:");
                            manager.matchName = GUI.TextField(new Rect(xpos + 100, ypos, 100, 20), manager.matchName);
                            ypos += spacing;

                            ypos += 10;

                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Find Internet Match"))
                            {
                                manager.matchMaker.ListMatches(0, 20, "", false, 0, 0, manager.OnMatchList);
                            }
                            ypos += spacing;
                        }
                        else
                        {
                            for (int i = 0; i < manager.matches.Count; i++)
                            {
                                var match = manager.matches[i];
                                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Join Match:" + match.name))
                                {
                                    manager.StartClientAll(match);
                                    //manager.matchName = match.name;
                                    //manager.matchMaker.JoinMatch(match.networkId, "", "", "", 0, 0, manager.OnMatchJoined);
                                }
                                ypos += spacing;
                            }

                            if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Back to Match Menu"))
                            {
                                manager.matches = null;
                            }
                            ypos += spacing;
                        }
                    }

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Change MM server"))
                    {
                        showServer = !showServer;
                    }
                    if (showServer)
                    {
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Local"))
                        {
                            manager.SetMatchHost("localhost", 1337, false);
                            showServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Internet"))
                        {
                            manager.SetMatchHost("mm.unet.unity3d.com", 443, true);
                            showServer = false;
                        }
                        ypos += spacing;
                        if (GUI.Button(new Rect(xpos, ypos, 100, 20), "Staging"))
                        {
                            manager.SetMatchHost("staging-mm.unet.unity3d.com", 443, true);
                            showServer = false;
                        }
                    }

                    ypos += spacing;

                    GUI.Label(new Rect(xpos, ypos, 300, 20), "MM Uri: " + manager.matchMaker.baseUri);
                    ypos += spacing;

                    if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Disable Match Maker"))
                    {
                        manager.StopMatchMaker();
                    }
                    ypos += spacing;
                }
            }
        }
 public void OnCharacterCreated(NetworkConnection conn, CharacterCreatedMessage msg)
 {
     Debug.Log("Character created");
     ClientScene.Ready(conn);
     OnClientAuthenticated.Invoke(conn);
 }