コード例 #1
0
    public void OnGUI()
    {
        if (ScreenSpaceDebug.Instance.ShouldDraw)
        {
            OnDrawDebugStuff();
        }

        // Draw player names
        if (networkView.isMine && Possession != null && Camera.current != null)
        {
            GUI.skin = Relay.Instance.BaseSkin;
            GUIStyle boxStyle = new GUIStyle(Relay.Instance.BaseSkin.customStyles[2])
            {
                fixedWidth  = 0,
                fixedHeight = 18,
                alignment   = TextAnchor.MiddleCenter,
                padding     = new RectOffset(5, 5, 3, 3),
            };
            foreach (var character in PlayerScript.UnsafeAllEnabledPlayerScripts)
            {
                if (character == null)
                {
                    continue;
                }
                if (character == Possession)
                {
                    continue;
                }
                if (!Possession.ShootingScript.CharacterIsInTargets(character))
                {
                    continue;
                }
                Vector3 screenPosition = Camera.current.WorldToScreenPoint(InfoPointForPlayerScript(character));
                screenPosition.y = Screen.height - screenPosition.y;
                if (screenPosition.z < 0)
                {
                    continue;
                }
                bool isVisible = Possession.CanSeeOtherPlayer(character);
                if (!isVisible)
                {
                    continue;
                }
                string otherPlayerName;
                if (character.Possessor == null)
                {
                    otherPlayerName = "?";
                }
                else
                {
                    otherPlayerName = character.Possessor.Name;
                }
                Vector2 baseNameSize  = boxStyle.CalcSize(new GUIContent(otherPlayerName));
                float   baseNameWidth = baseNameSize.x + 10;
                var     rect          = new Rect(screenPosition.x - baseNameWidth / 2, screenPosition.y, baseNameWidth,
                                                 boxStyle.fixedHeight);
                GUI.Box(rect, otherPlayerName, boxStyle);
            }
        }

        if (networkView.isMine)
        {
            if (ShouldDisplayJoinPanel)
            {
                GUI.skin = Relay.Instance.BaseSkin;
                GUILayout.Window(Definitions.PlayerGameChoicesWindowID, new Rect(0, Screen.height - 110, Screen.width, 110), DrawGameChoices, string.Empty);
            }
        }
    }
コード例 #2
0
    public void Update()
    {
        if (networkView.isMine)
        {
            WeaponIndicatorScript.Instance.ShouldRender = Possession != null;
            UpdateShouldCameraSpin();

            Relay.Instance.OptionsMenu.ShouldDisplaySpectateButton = !IsSpectating;

            if (Possession == null)
            {
                if (Input.GetButtonDown("Fire") && !IsSpectating)
                {
                    IndicateRespawn();
                }
            }

            // Update player labels
            if (Camera.current != null)
            {
                foreach (var playerScript in PlayerScript.UnsafeAllEnabledPlayerScripts)
                {
                    if (playerScript == null)
                    {
                        continue;
                    }
                    Vector3 position = Camera.current.WorldToScreenPoint(InfoPointForPlayerScript(playerScript));
                    Vector2 prevScreenPosition;
                    if (!LastGUIDebugPositions.TryGetValue(playerScript, out prevScreenPosition))
                    {
                        prevScreenPosition = (Vector2)position;
                    }
                    Vector2 newScreenPosition = Vector2.Lerp(prevScreenPosition, (Vector2)position,
                                                             1f - Mathf.Pow(0.0000000001f, Time.deltaTime));
                    LastGUIDebugPositions[playerScript] = newScreenPosition;
                }
            }

            IsDoingMenuStuff = Relay.Instance.MessageLog.HasInputOpen;

            // Debug visibility info for other playerscripts
            if (Possession != null)
            {
                foreach (var character in PlayerScript.UnsafeAllEnabledPlayerScripts)
                {
                    if (character != Possession)
                    {
                        bool canSee = Possession.CanSeeOtherPlayer(character);
                        if (canSee)
                        {
                            ScreenSpaceDebug.AddMessageOnce("VISIBLE", character.transform.position);
                        }
                    }
                }
            }

            // Leaderboard show/hide
            // Always show when not possessing anything
            // Never show when already showing options screen
            if (Possession == null || TimeToHoldLeaderboardFor >= 0f)
            {
                Server.Leaderboard.Show = true;
            }
            // Otherwise, show when holding tab
            else
            {
                Server.Leaderboard.Show = Input.GetKey("tab") && !Relay.Instance.ShowOptions;
            }

            TimeToHoldLeaderboardFor -= Time.deltaTime;

            // TODO test this in a multiplayer environment
            // if game is no longer active, i.e., round end or host forced end, then
            if (!this.Server.IsGameActive)
            {
                // force mouse state to be unlocked
                //playerScript.lockMouse = false;
                Cursor.visible   = true;
                Cursor.lockState = CursorLockMode.None;
            }

            //if (!Relay.Instance.ShowOptions && Possession != null && !ShouldDisplayJoinPanel)
            //     playerScript.lockMouse = true;

            // if (ShouldDisplayJoinPanel || Relay.Instance.ShowOptions || !Server.IsGameActive)
            //    playerScript.lockMouse = false;

            // Update ping
            Ping = uLink.Network.GetAveragePing(Server.networkView.owner);
        }

        if (Possession != null)
        {
            // toggle bubble
            Possession.TextBubbleVisible = IsDoingMenuStuff;
        }

        if (Input.GetKeyDown("f11"))
        {
            ScreenSpaceDebug.LogMessageSizes();
        }

        TimeSinceLastRespawnRequest += Time.deltaTime;
    }