Exemplo n.º 1
0
        /// <summary>
        /// 等待某消息到达
        /// </summary>
        /// <param name="msg">等待的消息名称</param>
        /// <param name="waitTime">超时时间</param>
        /// <param name="success">成功的回调</param>
        /// <param name="fail">失败的回调</param>
        /// <returns>操作成功则返回true</returns>
        public static bool WaitMsgArrival(int MsgID, float waitTime, taskFunc success, taskFunc fail)
        {
            if (msgWainList.ContainsKey(MsgID))
            {
                RemoveWaitMsg(MsgID);
            }
            // 记录起来
            WaitMsgNode node = new WaitMsgNode(waitTime, success, fail);

            msgWainList.Add(MsgID, node);

            return(true);
        }
Exemplo n.º 2
0
        public static void Update(float deltaTime)
        {
            int i = 0;

            // 处理已经到达的消息
            for (i = 0; i < arrivalList.Count; i++)
            {
                int msg = arrivalList[i];

                if (!msgWainList.ContainsKey(msg))
                {
                    // 无人等待,直接忽略掉
                    continue;
                }

                WaitMsgNode node = msgWainList[msg];
                node.OnSuccess();
                msgWainList.Remove(msg);
            }
            arrivalList.Clear();

            // 处理超时时间
            expireList.Clear();

            Dictionary <int, WaitMsgNode> .Enumerator iter = msgWainList.GetEnumerator();
            while (iter.MoveNext())
            {
                WaitMsgNode node = iter.Current.Value;
                if (node.IsExpired())
                {
                    expireList.Add(iter.Current.Key);
                }
            }
            iter.Dispose();


            for (i = 0; i < expireList.Count; i++)
            {
                WaitMsgNode node = msgWainList[expireList[i]];
                node.OnFail();
                msgWainList.Remove(expireList[i]);
            }
        }