Exemplo n.º 1
0
    public void LoopMessage()
    {
        if (Input.GetKeyDown(KeyCode.T))
        {
            Message tt = new Message((int)MessageType.VersionCallBack);
            //message.SetObject("updateinfo", oTGContent.mUpgradeInfo);
            tt.SetBool("newversion", true);
            tt.SetBool("isforceupgrade", true);
            tt.SetString("desc", "这是更新信息");
            tt.SetString("version", "100006");
            otgMessageQueue.Enqueue(tt);
        }

        if (otgMessageQueue.Count == 0)
        {
            return;
        }
        Message message = otgMessageQueue.Peek();

        switch ((MessageType)message.messageType)
        {
        case MessageType.VersionCallBack:
            if (OnVersionCallback != null)
            {
                VersionCallStruct callStruct = new VersionCallStruct()
                {
                    newversion     = message.GetBool("newversion"),
                    version        = message.GetString("version"),
                    desc           = message.GetString("desc"),
                    isforceupgrade = message.GetBool("isforceupgrade")
                };
                OnVersionCallback(callStruct);
                otgMessageQueue.Dequeue();
            }
            break;

        case MessageType.ErrorCallBack:
            DownLoadError downLoadError = (DownLoadError)message.GetInt("error");
            if (OnDownLoadError != null)
            {
                OnDownLoadError(downLoadError);
                otgMessageQueue.Dequeue();
            }

            break;

        case MessageType.FinishCallBack:
            if (OnDownLoadCompleted != null)
            {
                OnDownLoadCompleted();
                otgMessageQueue.Dequeue();
            }
            break;

        default:
            break;
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// 初始化数据
    /// </summary>
    public virtual void Init()
    {
        this.beginDownload    = null;
        this.downloadProgress = null;
        this.downloadFinish   = null;
        this.downloadText     = null;
        this.downloadData     = null;
        this.downloadError    = null;

        this.isFinish = false;
        this.url      = string.Empty;
    }
    public static void GetByteRequest(this WebRequest wwwUtil, string url, DownLoadData data, DownLoadError error = null)
    {
        GetWWWItem item = WWWItemPool.GetWWWItem <GetWWWItem>();

        if (item == null)
        {
            item = new GetWWWItem();
            WWWItemPool.AddWWWItem(item);
        }

        item.SetValue(url);
        item.downloadData  = data;
        item.downloadError = error;

        wwwUtil.AddTask(item);
    }
    public static void GetStringRequest(this WebRequest wwwUtil, string url, BeginDownLoad begin, DownLoadProgress progress, DownLoadText text, DownLoadError error = null)
    {
        GetWWWItem item = WWWItemPool.GetWWWItem <GetWWWItem>();

        if (item == null)
        {
            item = new GetWWWItem();
            WWWItemPool.AddWWWItem(item);
        }

        item.SetValue(url);
        item.beginDownload    = begin;
        item.downloadProgress = progress;
        item.downloadText     = text;
        item.downloadError    = error;

        wwwUtil.AddTask(item);
    }
    public static void WWWFormWWWRequest(this WebRequest wwwUtil, string url, WWWForm form, BeginDownLoad begin, DownLoadProgress progress, DownLoadFinish finish, DownLoadError error = null)
    {
        FormWWWItem item = WWWItemPool.GetWWWItem <FormWWWItem>();

        if (item == null)
        {
            item = new FormWWWItem();
            WWWItemPool.AddWWWItem(item);
        }

        item.SetValue(url, form);
        item.beginDownload    = begin;
        item.downloadProgress = progress;
        item.downloadFinish   = finish;
        item.downloadError    = error;

        wwwUtil.AddTask(item);
    }
    public static void WWWFormByteRequest(this WebRequest wwwUtil, string url, WWWForm form, DownLoadProgress progress, DownLoadData data, DownLoadError error = null)
    {
        FormWWWItem item = WWWItemPool.GetWWWItem <FormWWWItem>();

        if (item == null)
        {
            item = new FormWWWItem();
            WWWItemPool.AddWWWItem(item);
        }

        item.SetValue(url, form);
        item.downloadProgress = progress;
        item.downloadData     = data;
        item.downloadError    = error;

        wwwUtil.AddTask(item);
    }
    public static void WWWFormStringRequest(this WebRequest wwwUtil, string url, WWWForm form, BeginDownLoad begin, DownLoadText text, DownLoadError error = null)
    {
        FormWWWItem item = WWWItemPool.GetWWWItem <FormWWWItem>();

        if (item == null)
        {
            item = new FormWWWItem();
            WWWItemPool.AddWWWItem(item);
        }

        item.SetValue(url, form);
        item.beginDownload = begin;
        item.downloadText  = text;
        item.downloadError = error;

        wwwUtil.AddTask(item);
    }
    public static void PostWWWRequest(this WebRequest wwwUtil, string url, byte[] postData, BeginDownLoad begin, DownLoadProgress progress, DownLoadFinish finish, DownLoadError error = null)
    {
        PostWWWItem item = WWWItemPool.GetWWWItem <PostWWWItem>();

        if (item == null)
        {
            item = new PostWWWItem();
            WWWItemPool.AddWWWItem(item);
        }

        item.SetValue(url, postData);
        item.beginDownload    = begin;
        item.downloadProgress = progress;
        item.downloadFinish   = finish;
        item.downloadError    = error;

        wwwUtil.AddTask(item);
    }
    public static void PostByteRequest(this WebRequest wwwUtil, string url, byte[] postData, DownLoadProgress progress, DownLoadData data, DownLoadError error = null)
    {
        PostWWWItem item = WWWItemPool.GetWWWItem <PostWWWItem>();

        if (item == null)
        {
            item = new PostWWWItem();
            WWWItemPool.AddWWWItem(item);
        }

        item.SetValue(url, postData);
        item.downloadProgress = progress;
        item.downloadData     = data;
        item.downloadError    = error;

        wwwUtil.AddTask(item);
    }
    public static void PostStringRequest(this WebRequest wwwUtil, string url, byte[] postData, BeginDownLoad begin, DownLoadText text, DownLoadError error = null)
    {
        PostWWWItem item = WWWItemPool.GetWWWItem <PostWWWItem>();

        if (item == null)
        {
            item = new PostWWWItem();
            WWWItemPool.AddWWWItem(item);
        }

        item.SetValue(url, postData);
        item.beginDownload = begin;
        item.downloadText  = text;
        item.downloadError = error;

        wwwUtil.AddTask(item);
    }
    public static void GetWWWRequest(this WebRequest wwwUtil, string url, DownLoadProgress progress, DownLoadFinish finish, DownLoadError error = null)
    {
        GetWWWItem item = WWWItemPool.GetWWWItem <GetWWWItem>();

        if (item == null)
        {
            item = new GetWWWItem();
            WWWItemPool.AddWWWItem(item);
        }

        item.SetValue(url);
        item.downloadProgress = progress;
        item.downloadFinish   = finish;
        item.downloadError    = error;

        wwwUtil.AddTask(item);
    }