コード例 #1
0
        /// <summary>
        /// Handle the signal
        /// </summary>
        /// <param name="signal">Signal that is broadcast containing an advanced filter</param>
        /// <returns></returns>
        private bool OnSaySomething(SaySomething signal)
        {
            long[] appliedFilters;
            bool   match;

            // if the signal filter and the receivers filters are both null
            if (signal.filter == null || _longFilter == null)
            {
                // no filters applied
                appliedFilters = null;

                // check if there is a match
                // if the And type is used, the only match if both signal filter and receiver filter are null
                // if the Or type is used, then return a match
                match = (signal.filterType == FilterType.And ? signal.filter == _longFilter : true);
            }
            else
            {
                // set up the applied filters as the intersection of the long filter list and the signal filter
                appliedFilters = _longFilter.Intersect(signal.filter).ToArray();

                // check if there is a match
                // if the And type is used, then only match if the applied filter length is greater than the signal filter length and applied filters length is greater than zero. This means that all values matched
                // if the Or type is used, then only match if the applied filters length is greater than zero
                match = (signal.filterType == FilterType.And ? appliedFilters.Length >= signal.filter.Length : true) && appliedFilters.Length > 0;
            }

            if (match)
            {
                // if there was a match, then show the signal text, the filters that were used and start the countdown
                messageText.text  = FormatMessage(signal.text, appliedFilters);
                _messageCountdown = messageTime;

                // received signal
                return(true);
            }
            else
            {
                // signal was not received since the filters did not match
                return(false);
            }
        }
コード例 #2
0
 void Start()
 {
     // cache the signal to save on memory allocation and disposal
     _signal = new SaySomething();
 }