Beispiel #1
0
        public void Public <T>(MessageVer2 multiType, T value, bool sync = true) where T : IMessage, new()
        {
            var query = mProvider.Provider(multiType);

            if (sync == true)
            {
                Broadcast(value, query);
            }
            else
            {
                Task.Run(() => Broadcast(value, query));
            }
            // throw new BnyxMessageException($"当前发送的消息类型组不存在{multiType}");
        }
Beispiel #2
0
        /// <summary>
        /// 订阅消息组,游戏初始化
        /// </summary>
        /// <param name="multiType">作用域</param>
        /// <param name="seek">种子数据,第一次有效</param>
        /// <typeparam name="T">种子数据类型</typeparam>
        /// todo 种子数据不能通过指定更新,只能通过publish来更新
        /// <returns>可观察的结果</returns>
        public IObservable <T> Receive <T> (MessageVer2 multiType, T seek) where T : IMessage, new()
        {
            var query = mProvider.Provider(multiType);

            IObservable <T>[] array = new IObservable <T> [query.Count];

            var value = default(T);

            for (byte i = 0; i < array.Length; i++)
            {
                var entity = query[i];
                if (entity.Valid == true)
                {
                    if (seek != null)
                    {
                        var vaild = seek.SEEK;
                        if (vaild == true)
                        {
                            value     = seek;
                            seek.SEEK = false;
                        }
                        else
                        {
                            throw new BnyxMessageException("Fatal:无效的种子数据或已经存在种子数据");
                        }
                    }
                    var receive = entity.Broker.Receive <T>(value);
                    array[i] = receive;
                }
            }

            var merge = Observable.Merge(array);

            if (mNeedDistinct)
            {
                return(merge.Distinct());
            }
            else
            {
                return(merge);
            }
            // throw new BnyxMessageException($"当前接受的消息类型组不存在{multiType}");
        }
Beispiel #3
0
        private List <FilterEntity> Query(MessageVer2 multiType)
        {
            var cache  = new List <FilterEntity>();
            var values = Enum.GetValues(typeof(MessageVer2));

            foreach (var value in values)
            {
                var type = (MessageVer2)value;
                if ((multiType & type) == type)
                {
                    var broker = mMessageDic[type];
                    var entity = new FilterEntity();
                    entity.Broker = broker;
                    entity.Valid  = true;
                    cache.Add(entity);
                    Debug.LogFormat($"---------------name:{value.ToString()}---value:{(uint) value}");
                }
            }

            return(cache);
        }
Beispiel #4
0
 /// <summary>
 /// 正常使用接口
 /// </summary>
 /// <param name="multiType"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public IObservable <T> Receive <T>(MessageVer2 multiType) where T : IMessage, new()
 {
     return(Receive <T>(multiType, null));
 }
Beispiel #5
0
        // 从池子里面取出需要的消息池子对象
        // 可以取出多个
        public List <FilterEntity> Provider(MessageVer2 multiType)
        {
            var result = Query(multiType);

            return(result);
        }