예제 #1
0
 void Yes()
 {
     click?.Invoke();
     click_int?.Invoke(arg_int);
     click_string?.Invoke(arg_string);
     Destroy(gameObject);
 }
예제 #2
0
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="url"></param>
        /// <param name="param"></param>
        /// <param name="cookies"></param>
        /// <param name="method"></param>
        /// <param name="timeout_second"></param>
        /// <param name="handler"></param>
        public static void HttpRequestHandler(
            string url,
            Dictionary <string, string> param,
            List <Cookie> cookies,
            RequestMethodEnum method,
            int timeout_second,
            VoidFunc <HttpWebResponse, HttpStatusCode> handler)
        {
            HttpWebRequest  req = null;
            HttpWebResponse res = null;

            try
            {
                //连接到目标网页
                req             = (HttpWebRequest)WebRequest.Create(url);
                req.Timeout     = timeout_second * 1000;//10s请求超时
                req.Method      = GetMethod(method);
                req.ContentType = "application/x-www-form-urlencoded";
                //添加cookie
                if (ValidateHelper.IsPlumpList(cookies))
                {
                    req.CookieContainer = new CookieContainer();
                    foreach (var c in cookies)
                    {
                        req.CookieContainer.Add(c);
                    }
                }
                //如果是post并且有参数
                if (method == RequestMethodEnum.POST && ValidateHelper.IsPlumpDict(param))
                {
                    param = param.NotNull();
                    var post_data = param.ToUrlParam();
                    var data      = Encoding.UTF8.GetBytes(post_data);
                    using (var stream = req.GetRequestStream())
                    {
                        stream.Write(data, 0, data.Length);
                    }
                }
                res = (HttpWebResponse)req.GetResponse();
                handler.Invoke(res, res.StatusCode);
            }
            catch (Exception e)
            {
                e.AddErrorLog();
                throw e;
            }
            finally
            {
                try
                {
                    req?.Abort();
                }
                catch (Exception e)
                {
                    e.AddLog(typeof(HttpClientHelper));
                }
                res?.Dispose();
            }
        }
예제 #3
0
 public void OnMouseUpBut()
 {
     if (!locked)
     {
         gameObject.GetComponent <SpriteRenderer>().sprite = spriteUp;
         if (!haveConfirm)
         {
             click?.Invoke();
             click_int?.Invoke(arg_int);
         }
         else
         {
             GameObject confirm = Instantiate(Resources.Load <GameObject>("confirm"));
             confirm.GetComponent <Confirm>().click     = click;
             confirm.GetComponent <Confirm>().click_int = click_int;
             confirm.GetComponent <Confirm>().arg_int   = arg_int;
         }
     }
 }
예제 #4
0
파일: Com.cs 프로젝트: lulzzz/WCloud
        /// <summary>
        /// 使用递归找文件目录
        /// </summary>
        public static void FindFilesBad(DirectoryInfo dir, VoidFunc <FileInfo> func)
        {
            if (dir == null || !dir.Exists)
            {
                return;
            }
            var files = dir.GetFiles();

            if (ValidateHelper.IsNotEmpty(files))
            {
                files.ToList().ForEach(x => { func.Invoke(x); });
            }

            var dirs = dir.GetDirectories();

            if (ValidateHelper.IsNotEmpty(dirs))
            {
                dirs.ToList().ForEach(x => { FindFilesBad(x, func); });
            }
        }
    /*
     * UpdateFreeMovement
     *
     * sub-update that gets called when the camera is in TARGET mode
     *
     * @returns void
     */
    public void UpdateTargetMovement()
    {
        m_movementTimer += Time.deltaTime;

        //the timer cannot tick over the maximum
        if (m_movementTimer >= transitionTime)
        {
            //set the timer above the limit
            m_movementTimer = transitionTime + 0.01f;

            //snap to the target
            transform.position    = m_target;
            transform.eulerAngles = m_eulerEnd;
        }
        else
        {
            //evaluate the time curve
            float x = m_movementTimer / transitionTime;
            float y = transitionCurve.Evaluate(x);

            //apply a simple lerp to the position
            transform.position = Vector3.Lerp(m_start, m_target, y);
            //transform.eulerAngles = Vector3.Lerp(m_eulerStart, m_eulerEnd, y);
        }

        //check if the movement has finished
        if (m_movementTimer >= transitionTime)
        {
            //set the camera state back to free movement
            m_cameraState = eCameraState.FREE;

            //only invoke the call-back if one was specified
            if (m_targetCallback != null)
            {
                m_targetCallback.Invoke();
            }
        }
    }
예제 #6
0
파일: Com.cs 프로젝트: lulzzz/WCloud
        /// <summary>
        /// 使用栈找文件
        /// </summary>
        public static void FindFiles(string path, VoidFunc <FileInfo> func, VoidFunc <int> stack_count_func = null)
        {
            var root = new DirectoryInfo(path);

            if (!root.Exists)
            {
                throw new NotExistException("目录不存在");
            }

            var stack = new Stack <DirectoryInfo>();

            stack.Push(root);
            DirectoryInfo cur_node = null;

            while (stack.Count > 0)
            {
                stack_count_func?.Invoke(stack.Count);

                cur_node = stack.Pop();
                if (cur_node == null || !cur_node.Exists)
                {
                    break;
                }

                var files = cur_node.GetFiles();
                if (ValidateHelper.IsNotEmpty(files))
                {
                    files.ToList().ForEach(x => { func.Invoke(x); });
                }

                var dirs = cur_node.GetDirectories();
                if (ValidateHelper.IsNotEmpty(dirs))
                {
                    dirs.ToList().ForEach(x => { stack.Push(x); });
                }
            }
        }
예제 #7
0
        public static async Task SendHttpRequestAsync(
            string url,
            Dictionary <string, string> param,
            Dictionary <string, FileModel> files,
            List <Cookie> cookies,
            RequestMethodEnum method,
            int timeout_second,
            VoidFunc <HttpResponseMessage> handler)
        {
            var u = new Uri(url);

            using (var httpHandler = new HttpClientHandler()
            {
                UseCookies = false
            })
            {
                //创建cookie
                if (ValidateHelper.IsPlumpList(cookies))
                {
                    var cookieContainer = new System.Net.CookieContainer();
                    cookies.ForEach(x =>
                    {
                        cookieContainer.Add(u, x);
                    });
                    httpHandler.UseCookies      = true;
                    httpHandler.CookieContainer = cookieContainer;
                }
                using (var client = new HttpClient(httpHandler))
                {
                    client.DefaultRequestHeaders.Add("UserAgent",
                                                     "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
                    //发送X_FORWARDED_FOR头(若是用取源IP的方式,可以用这个来造假IP,对日志的记录无效)
                    client.DefaultRequestHeaders.Add("X_FORWARDED_FOR", "101.0.0.11");
                    client.Timeout = TimeSpan.FromSeconds(timeout_second);

                    HttpResponseMessage response = null;
                    if (method == RequestMethodEnum.POST)
                    {
                        //使用MultipartFormDataContent请参考邮件里的记录
                        //拼url传参
                        //using (var urlContent = new FormUrlEncodedContent(param)) { }
                        //form提交
                        using (var formContent = new MultipartFormDataContent())
                        {
                            if (ValidateHelper.IsPlumpDict(param))
                            {
                                param = param.NotNull();
                                foreach (var key in param.Keys)
                                {
                                    formContent.Add(new StringContent(param[key]), key);
                                }
                            }
                            if (ValidateHelper.IsPlumpDict(files))
                            {
                                foreach (var key in files.Keys)
                                {
                                    formContent.Add(CreateFileContent(files[key], key), key);
                                }
                            }
                            response = await client.PostAsync(u, formContent);
                        }
                    }
                    if (method == RequestMethodEnum.GET)
                    {
                        response = await client.GetAsync(u);
                    }
                    if (method == RequestMethodEnum.PUT)
                    {
                        throw new NotImplementedException();
                        //response = await client.PutAsync(u, null);
                    }
                    if (method == RequestMethodEnum.DELETE)
                    {
                        response = await client.DeleteAsync(u);
                    }

                    if (response == null)
                    {
                        throw new Exception("返回空");
                    }
                    using (response)
                    {
                        handler.Invoke(response);
                    }
                }
            }
        }