Example #1
0
        private IEnumerable <IMyBroadcastListener> UpdateBroadcast()
        {
            var broadcastTag = $"{Me.CubeGrid.EntityId}.NIN.NAME";

            if (_broadcastTag != broadcastTag)
            {
                IGC.UnregisterBroadcastListener(_broadcastTag);
                _broadcastTag = broadcastTag;
            }
            var broadcastListener = IGC.RegisterBroadcastListener(broadcastTag);

            yield return(null);

            IGC.SendBroadcastMessage(broadcastTag, _priority);

            yield return(null);

            while (broadcastListener.HasPendingMessage)
            {
                var message          = broadcastListener.AcceptMessage();
                var priorityReceived = -1;
                try
                {
                    priorityReceived = (int)message.Data;
                }
                catch
                {
                    EchoManager.Print($"Received an invalid message in broadcast channel: {message.Data}");
                }

                if (!_ignorePriority && priorityReceived > _priority)
                {
                    Disable();
                }

                yield return(null);
            }

            EnableIfReady();

            yield return(broadcastListener);
        }