public void StopBehavior()
 {
     if (task != null)
     {
         task.Stop();
     }
 }
Exemple #2
0
        /// <summary>
        /// 服务器断开连接
        /// </summary>
        public void Disconnect()
        {
            tcpReciverTask.Stop();
            udpReciverTask.Stop();

            isConnect = false;
            tcpSocket.Disconnect();
            udpSocket.Stop();

            tcpReciver.Reset();
            udpReciver.Reset();
        }
        /// <summary>
        /// 请求异步事件
        /// </summary>
        /// <param name="requestType"></param>
        /// <param name="requestArgs"></param>
        /// <param name="responseType"></param>
        /// <param name="handler"></param>
        /// <param name="timeOut"></param>
        public static void Request(string requestType, ArrayList requestArgs, string responseType, Action <ArrayList> handler, float timeOut = 2)
        {
            string responseString = responseType + "Request";
            //处理返回动作
            Action <ArrayList> responseHandler = null;

            CoroutineTaskManager.CoroutineTask task = null;
            responseHandler = (array) => {
                handler(array);
                EventDispatcher.RemoveEventListener <ArrayList>(responseString, responseHandler);
                task.Stop();
            };
            //监听返回行为
            EventDispatcher.AddEventListener <ArrayList>(responseString, responseHandler);
            //出发请求事件
            EventDispatcher.TriggerEvent <ArrayList>(requestType, requestArgs);
            //处理超时情况
            task = CoroutineTaskManager.Instance.WaitSecondTodo(() =>
            {
                Debug.logger.LogError("Request", requestType + "request Timeout!");
                EventDispatcher.RemoveEventListener <ArrayList>(responseString, responseHandler);
            }, timeOut);
        }