Example #1
0
        /// <summary>
        /// Send a message to default receiver of the target message
        /// </summary>
        /// <param name="messageIndex">index of message list</param>
        public virtual void SendToDefaultReceiver(int messageIndex)
        {
            vMessage _message = messageIndex > 0 && messageIndex < messages.Count ? messages[messageIndex] : null;

            if (_message != null)
            {
                for (int i = 0; i < _message.defaultReceivers.Count; i++)
                {
                    if (_message.defaultReceivers[i])
                    {
                        _message.defaultReceivers[i].Send(_message.name, _message.message);
                    }
                }
            }
        }
        /// <summary>
        /// Send a message to default receiver of the target message
        /// </summary>
        /// <param name="messageIndex">index of message list</param>
        public virtual void SendToParentReceiver(int messageIndex)
        {
            var receiver = GetComponentInParent <vMessageReceiver>();

            if (!receiver)
            {
                return;
            }

            vMessage _message = messages.Count > 0 && messageIndex < messages.Count ? messages[messageIndex] : null;

            if (_message != null)
            {
                receiver.Send(_message.name, _message.message);
            }
        }
Example #3
0
        /// <summary>
        /// Send a message to target receiver
        /// </summary>
        /// <param name="messageIndex">index of message list</param>
        /// <param name="target">target receiver</param>
        public virtual void Send(GameObject target, int messageIndex)
        {
            if (target)
            {
                return;
            }
            var _receiver = target.GetComponent <vMessageReceiver>();

            if (!_receiver)
            {
                return;
            }
            vMessage _message = messageIndex > 0 && messageIndex < messages.Count ? messages[messageIndex] : null;

            if (_message != null)
            {
                _receiver.Send(_message.name, _message.message);
            }
        }