Exemple #1
0
        /// <summary>
        /// Sets the ping text and sprite color for a given <see cref="PingIndicator"/>
        /// </summary>
        /// <param name="pingIndicator">Target <see cref="PingIndicator"/></param>
        private void SetPingIndicatorColor(RoR2.UI.PingIndicator pingIndicator)
        {
            SpriteRenderer sprRenderer;
            Color          textColor = new Color(0, 0, 0, 0);

            RoR2.UI.PingIndicator.PingType pingType =
                pingIndicator.GetObjectValue <RoR2.UI.PingIndicator.PingType>("pingType");

            switch (pingType)
            {
            case RoR2.UI.PingIndicator.PingType.Default:
                textColor         = _colors["DefaultPingColor"];
                sprRenderer       = pingIndicator.defaultPingGameObjects[0].GetComponent <SpriteRenderer>();
                sprRenderer.color = _colors["DefaultPingSpriteColor"];
                break;

            case RoR2.UI.PingIndicator.PingType.Enemy:
                textColor         = _colors["EnemyPingColor"];
                sprRenderer       = pingIndicator.enemyPingGameObjects[0].GetComponent <SpriteRenderer>();
                sprRenderer.color = _colors["EnemyPingSpriteColor"];
                break;

            case RoR2.UI.PingIndicator.PingType.Interactable:
                textColor         = _colors["InteractiblePingColor"];
                sprRenderer       = pingIndicator.interactablePingGameObjects[0].GetComponent <SpriteRenderer>();
                sprRenderer.color = _colors["InteractiblePingSpriteColor"];
                break;
            }

            pingIndicator.pingText.color = textColor;
        }
Exemple #2
0
        /// <summary>
        /// Override method for RoR2.PingerController.SetCurrentPing
        /// </summary>
        public void SetCurrentPing(On.RoR2.PingerController.orig_SetCurrentPing orig,
                                   RoR2.PingerController self, RoR2.PingerController.PingInfo newPingInfo)
        {
            // For some reason, if you ping somewhere that is not pingable, it will create a
            // Ping at 0,0,0. If that happens, we just leave, since that isn't possible in the
            // regular game either, or if so, not at exactly those coordinates
            if (newPingInfo.origin == Vector3.zero)
            {
                return;
            }

            // If the targeted game object already has a ping, don't do anything
            // This is here to avoid stacking of different player pings on interactables
            if (newPingInfo.targetGameObject != null &&
                _pingIndicators.Any(indicator => indicator && indicator.pingTarget == newPingInfo.targetGameObject))
            {
                return;
            }

            self.NetworkcurrentPing = newPingInfo;

            // Here we create an instance of PingIndicator
            // since we're not jumping into PingerController.RebuildPing() to create one.
            GameObject go = (GameObject)Object.Instantiate(Resources.Load("Prefabs/PingIndicator"));

            RoR2.UI.PingIndicator pingIndicator = go.GetComponent <RoR2.UI.PingIndicator>();

            pingIndicator.pingOwner  = self.gameObject;
            pingIndicator.pingOrigin = newPingInfo.origin;
            pingIndicator.pingNormal = newPingInfo.normal;
            pingIndicator.pingTarget = newPingInfo.targetGameObject;

            pingIndicator.RebuildPing();

            RoR2.UI.PingIndicator.PingType pingType =
                pingIndicator.GetObjectValue <RoR2.UI.PingIndicator.PingType>("pingType");

            _painter.SetPingIndicatorColor(pingIndicator, pingType);
            _textBuilder.SetPingText(pingIndicator, pingType);
            SetPingTimer(pingIndicator, pingType);

            if (pingType == RoR2.UI.PingIndicator.PingType.Interactable)
            {
                _notificationBuilder.SetUnlockedItemNotification(pingIndicator);
            }

            // We add the ping indicator to our own local list
            _pingIndicators.Add(pingIndicator);

            if (self.hasAuthority)
            {
                self.CallCmdPing(self.currentPing);
            }
        }