示例#1
0
        void OnDied(Player playerWhoKilledYou)
        {
            if (!this.isServer)
            {
                return;
            }

            Player playerWhoDied = GetComponent <Player> ();

            string killer = "";

            if (playerWhoKilledYou != null)
            {
                killer = playerWhoKilledYou.playerName;
            }
            string dier = playerWhoDied.playerName;

            // send rpc to all players
            foreach (var p in PlayerManager.GetLoggedInNonBotPlayers())
            {
                var sync = p.GetComponent <KillEventSync> ();
                if (sync != null)
                {
                    sync.TargetKillEvent(p.connectionToClient, killer, dier);
                }
            }

            if (!NetworkStatus.IsHost())
            {
                // running as dedicated server
                // invoke event here, because there is no local player to invoke it
                onKillEvent(new KillEvent(killer, dier));
            }
        }
示例#2
0
        /// <summary> Use only on server. </summary>
        public static void    SendChatMessageToAllPlayers(string msg, string sender)
        {
            if (!NetworkStatus.IsServerStarted())
            {
                return;
            }

            foreach (var player in PlayerManager.GetLoggedInNonBotPlayers())
            {
                SendChatMessageToPlayer(player, msg, sender);
            }

            if (!NetworkStatus.IsHost())
            {
                // running as dedicated server
                // we should invoke the event here, because there is no local player to receive the chat message
                onChatMessage(new ChatMessage(msg, sender));
            }
        }
示例#3
0
        static void    DrawConsole()
        {
            int consoleWidth  = Screen.width;
            int consoleHeight = Screen.height / 2;

            // Draw rectangle in background.
            GUI.Box(new Rect(0, 0, consoleWidth, consoleHeight), "");


            // Draw some statistics above console

            GUILayout.BeginArea(new Rect(0, 0, Screen.width, 30));
            GUILayout.BeginHorizontal();

            // display fps
            GUILayout.Label("FPS: " + GameManager.GetAverageFps());

            // display uptime
            if (NetworkStatus.IsServerStarted())
            {
                GUILayout.Label(" uptime: " + Utilities.Utilities.FormatElapsedTime(Time.realtimeSinceStartup));
            }

            // let anybody else display their own stats
            try {
                onDrawStats();
            } catch (System.Exception ex) {
                Debug.LogException(ex);
            }

            // Display network statistics for client
            if (NetworkStatus.IsClientConnected() && !NetworkStatus.IsHost())
            {
                NetworkConnection conn = NetManager.GetClient().connection;
                byte error             = 0;
                GUILayout.Label(" ping: " + NetworkTransport.GetCurrentRtt(conn.hostId, conn.connectionId, out error) + " ms");
                GUILayout.Label(" lost_packets: " + NetworkTransport.GetNetworkLostPacketNum(conn.hostId, conn.connectionId, out error));
                GUILayout.Label(" received_rate: " + NetworkTransport.GetPacketReceivedRate(conn.hostId, conn.connectionId, out error));
                GUILayout.Label(" sent_rate: " + NetworkTransport.GetPacketSentRate(conn.hostId, conn.connectionId, out error));
            }

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


            m_consoleScrollPosition = GUILayout.BeginScrollView(
                m_consoleScrollPosition, GUILayout.Width(consoleWidth), GUILayout.Height(consoleHeight));


            /*
             * // Display player information
             * if( networkManager.IsServer() ) {
             *
             *      GUILayout.Label("Players");
             *      GUILayout.Label("name\t\t | health\t | kills\t | deaths\t | ping");
             *      foreach ( Player player in networkManager.players ) {
             *
             *              string s = "";
             *              s += player.playerName + "\t ";
             *              if (player.mainNetworkScript != null) {
             *                      s += player.mainNetworkScript.health + "\t " + player.mainNetworkScript.numKills + "\t " + player.mainNetworkScript.numDeaths ;
             *              }
             *              s += "\t 0 ms";
             *
             *              GUILayout.Label( s );
             *      }
             * }
             */

            // Draw log string
            //	if( logString != "" ) {
            {
                /*
                 * GUIStyle style = new GUIStyle( GUI.skin.textArea );
                 * //	style.wordWrap = true;
                 * style.richText = true ;
                 * GUILayout.Space(25);
                 * GUILayout.TextArea( logString, style, GUILayout.MinHeight (consoleHeight - 30) );
                 */

                GUILayout.Space(30);
                GUILayout.Label(m_logString);
            }

            GUILayout.EndScrollView();


            GUILayout.BeginHorizontal();

            string textToProcess = "";

            // Edit box for commands input.
            GUI.SetNextControlName("commands_input");
            m_consoleCommandText = GUILayout.TextField(m_consoleCommandText, 1000, GUILayout.Width(Screen.width / 4), GUILayout.Height(40));
            if (Event.current.isKey && GUI.GetNameOfFocusedControl() == "commands_input")
            {
                if (Event.current.keyCode == KeyCode.UpArrow)
                {
                    // up arrow pressed and edit box is in focus
                    BrowseHistoryBackwards();
                }
                else if (Event.current.keyCode == KeyCode.DownArrow)
                {
                    // down arrow pressed and edit box is in focus
                    BrowseHistoryForwards();
                }
                else if (Event.current.keyCode == KeyCode.Return)
                {
                    // enter pressed
                    textToProcess = m_consoleCommandText;
                }
            }

            // submit button
            //	bool submited = GUILayout.Button( "Submit", GUILayout.Width(60), GUILayout.Height(40) );
            bool submited = GameManager.DrawButtonWithCalculatedSize("Submit");

            if (submited)
            {
                textToProcess = m_consoleCommandText;
            }

            GUILayout.EndHorizontal();


            if (textToProcess != "")
            {
                SubmittedText(textToProcess);

                // clear input text box
                SetInputBoxText("");
            }
        }