Example #1
0
    static IEnumerator InvokeLoadbundle(WwwBundle bc, UnityAction <float> uaing, UnityAction <float> uaend, ThreadPriority threadPriority)
    {
        //注册回调事件
        WwwCallBack wle = new WwwCallBack();

        if (uaing != null)
        {
            wle.AddIngEvent(uaing);
        }
        if (uaend != null)
        {
            wle.AddEndEvent(uaend);
        }

        bc.LoadState = LoadState.LoadIng;

        bc.LoadStartTime = DateTime.Now;
        //开始下载资源
        WWW www = new WWW(bc.SourceUrl);

        www.threadPriority = threadPriority;

        while (!www.isDone)// || www.progress <= 1)
        {
            float o = www.progress;
            bc.Progress = www.progress;
            wle.ActiveIngEvent(false, o);
            yield return(null);
        }
        float o1 = www.progress;

        bc.Progress = www.progress;
        wle.ActiveIngEvent(true, o1);

        //加载错误
        bc.LoadError = www.error;
        if (www.error != null)
        {
            bc.LoadState = LoadState.LoadFail;
            Debug.Log("Load Error:" + bc.SourceUrl + ":" + www.error);

            //MessageBox.ShowInEditor(www.error);
        }
        else
        {
            bc.Size = www.size;

            bc.Bundle = www.assetBundle;

            bc.LoadState = LoadState.LoadComplete;
        }

        bc.LoadEndTime = DateTime.Now;
        wle.ActiveEndEvent(true);
    }
Example #2
0
    static IEnumerator InvokeLoadText(WwwText tc, UnityAction <float> uaing, UnityAction <float> uaend)
    {
        //注册回调事件
        WwwCallBack wle = new WwwCallBack();

        if (uaing != null)
        {
            wle.AddIngEvent(uaing);
        }
        if (uaend != null)
        {
            wle.AddEndEvent(uaend);
        }

        tc.LoadState = LoadState.LoadIng;

        //记录开始加载时间
        tc.LoadStartTime = DateTime.Now;
        //开始下载资源
        WWW www = new WWW(tc.SourceUrl);

        while (!www.isDone)// || www.progress <= 1)
        {
            float o = www.progress;
            tc.Progress = www.progress;
            wle.ActiveIngEvent(false, o);
            yield return(null);
        }
        float o1 = www.progress;

        wle.ActiveIngEvent(true, o1);
        tc.Progress = www.progress;

        //加载错误
        tc.LoadError = www.error;
        if (www.error != null)
        {
            tc.LoadState = LoadState.LoadFail;
            Debug.Log("Load Error:" + www.error);
        }
        else
        {
            tc.Size        = www.size;
            tc.Data        = www.bytes;
            tc.TextContent = www.text;

            tc.LoadState = LoadState.LoadComplete;
        }

        tc.LoadEndTime = DateTime.Now;
        wle.ActiveEndEvent(true);
    }
Example #3
0
    static IEnumerator InvokeLoadaudio(WwwAudio ac, UnityAction <float> uaing, UnityAction <float> uaend)
    {
        //注册回调事件
        WwwCallBack wle = new WwwCallBack();

        if (uaing != null)
        {
            wle.AddIngEvent(uaing);
        }
        if (uaend != null)
        {
            wle.AddEndEvent(uaend);
        }

        ac.LoadState     = LoadState.LoadIng;
        ac.LoadStartTime = DateTime.Now;
        //开始下载资源
        WWW www = new WWW(ac.SourceUrl);

        ac.AudioContent = www.GetAudioClip(ac.Three3D);

        while (!www.isDone)// || www.progress <= 1)
        {
            float o = www.progress;
            ac.Progress = www.progress;
            wle.ActiveIngEvent(false, o);
            yield return(null);
        }
        float o1 = www.progress;

        ac.Progress = www.progress;
        wle.ActiveIngEvent(true, o1);

        ac.LoadError = www.error;
        if (www.error != null)
        {
            ac.LoadState = LoadState.LoadFail;
            Debug.Log("Load Error:" + www.error);

            //MessageBox.ShowInEditor(www.error);
        }
        else
        {
            ac.Size = www.size;

            ac.LoadState = LoadState.LoadComplete;
        }

        ac.LoadEndTime = DateTime.Now;
        wle.ActiveEndEvent(true);
    }
Example #4
0
    static IEnumerator SubmitToServer(WwwText wt, WWWForm wf, UnityAction <float> uaing, UnityAction <float> uaend)
    {
        yield return(new WaitForFixedUpdate());

        //注册回调事件
        WwwCallBack wle = new WwwCallBack();

        if (uaing != null)
        {
            wle.AddIngEvent(uaing);
        }
        if (uaend != null)
        {
            wle.AddEndEvent(uaend);
        }
        wt.LoadState = LoadState.LoadIng;

        //开始提交资源
        WWW www;

        if (wf == null)
        {
            www = new WWW(wt.SourceUrl);
        }
        else
        {
            www = new WWW(wt.SourceUrl, wf);
        }

        wt.LoadStartTime = DateTime.Now;

        bool chaoshi = false;

        while (!www.isDone)// || www.progress <= 1)
        {
            float o = www.progress;
            wt.Progress = www.progress;
            wle.ActiveIngEvent(false, o);

            DateTime temptime = DateTime.Now;
            TimeSpan ts       = new TimeSpan(temptime.Ticks);
            TimeSpan ts1      = new TimeSpan(wt.LoadStartTime.Ticks);
            TimeSpan cha      = ts.Subtract(ts1).Duration();
            if (cha.TotalSeconds > TimeOut)
            {
                chaoshi = true;
                break;
            }
            yield return(null);
        }
        if (!chaoshi)
        {
            float o1 = www.progress;
            wt.Progress = www.progress;
            wle.ActiveIngEvent(true, o1);

            wt.LoadError = www.error;
            if (www.error != null)
            {
                wt.LoadState = LoadState.LoadFail;
                Debug.Log("UpLoad Error:" + www.error);
                //MessageBox.ShowInEditor(www.error);
            }
            else
            {
                wt.Size = www.size;

                wt.TextContent = www.text;

                wt.LoadState = LoadState.LoadComplete;
            }
        }
        else
        {
            //wt.Dispose();
            wt.LoadState = LoadState.LoadFail;
            wt.LoadError = "out time";
            //MessageBox.Show("超时");
        }

        wt.LoadEndTime = DateTime.Now;
        wle.ActiveEndEvent(true);
    }
Example #5
0
    static IEnumerator InvokeLoadImage(WwwImage ic, UnityAction <float> uaing, UnityAction <float> uaend)
    {
        //注册回调事件
        WwwCallBack wle = new WwwCallBack();

        if (uaing != null)
        {
            wle.AddIngEvent(uaing);
        }
        if (uaend != null)
        {
            wle.AddEndEvent(uaend);
        }

        ic.LoadState = LoadState.LoadIng;

        ic.LoadStartTime = DateTime.Now;
        //开始下载资源
        WWW www = new WWW(ic.SourceUrl);

        while (!www.isDone)// || www.progress <= 1)
        {
            float o = www.progress;
            ic.Progress = www.progress;
            wle.ActiveIngEvent(false, o);
            yield return(null);
        }
        float o1 = www.progress;

        ic.Progress = www.progress;
        wle.ActiveIngEvent(true, o1);

        //加载错误
        ic.LoadError = www.error;
        if (www.error != null)
        {
            ic.LoadState = LoadState.LoadFail;
            Debug.Log("Load Error:" + ic.SourceUrl + ":" + www.error);

            //MessageBox.ShowInEditor(www.error);
        }
        else
        {
            ic.Size = www.size;


            if (ic.SourceUrl.Contains(".gif"))
            {
                ic.ImageContent = AnalysisPage.GetGifImage(www.bytes, 0);
            }
            else
            {
                ic.ImageContent = www.texture;
            }

            ic.LoadState = LoadState.LoadComplete;
        }

        ic.LoadEndTime = DateTime.Now;
        wle.ActiveEndEvent(true);
    }
Example #6
0
    static IEnumerator SubmitToServer(WwwText wt, WWWForm wf, UnityAction<float> uaing, UnityAction<float> uaend)
    {
        yield return new WaitForFixedUpdate();
        //注册回调事件
        WwwCallBack wle = new WwwCallBack();
        if (uaing != null)
            wle.AddIngEvent(uaing);
        if (uaend != null)
            wle.AddEndEvent(uaend);
        wt.LoadState = LoadState.LoadIng;

        //开始提交资源
        WWW www;

        if (wf == null)
            www = new WWW(wt.SourceUrl);
        else
            www = new WWW(wt.SourceUrl, wf);

        wt.LoadStartTime = DateTime.Now;

        bool chaoshi = false;
        while (!www.isDone)// || www.progress <= 1)
        {
            float o = www.progress;
            wt.Progress = www.progress;
            wle.ActiveIngEvent(false, o);

            DateTime temptime = DateTime.Now;
            TimeSpan ts = new TimeSpan(temptime.Ticks);
            TimeSpan ts1 = new TimeSpan(wt.LoadStartTime.Ticks);
            TimeSpan cha = ts.Subtract(ts1).Duration();
            if (cha.TotalSeconds > TimeOut)
            {
                chaoshi = true;
                break;
            }
            yield return null;
        }
        if (!chaoshi)
        {
            float o1 = www.progress;
            wt.Progress = www.progress;
            wle.ActiveIngEvent(true, o1);

            wt.LoadError = www.error;
            if (www.error != null)
            {
                wt.LoadState = LoadState.LoadFail;
                Debug.Log("UpLoad Error:" + www.error);
                //MessageBox.ShowInEditor(www.error);
            }
            else
            {
                wt.Size = www.size;

                wt.TextContent = www.text;

                wt.LoadState = LoadState.LoadComplete;

            }
        }
        else
        {
            //wt.Dispose();
            wt.LoadState = LoadState.LoadFail;
            wt.LoadError = "out time";
            //MessageBox.Show("超时");
        }

        wt.LoadEndTime = DateTime.Now;
        wle.ActiveEndEvent(true);
    }
Example #7
0
    static IEnumerator InvokeLoadText(WwwText tc, UnityAction<float> uaing, UnityAction<float> uaend)
    {
        //注册回调事件
        WwwCallBack wle = new WwwCallBack();
        if (uaing != null)
            wle.AddIngEvent(uaing);
        if (uaend != null)
            wle.AddEndEvent(uaend);

        tc.LoadState = LoadState.LoadIng;

        //记录开始加载时间
        tc.LoadStartTime = DateTime.Now;
        //开始下载资源
        WWW www = new WWW(tc.SourceUrl);

        while (!www.isDone)// || www.progress <= 1)
        {
            float o = www.progress;
            tc.Progress = www.progress;
            wle.ActiveIngEvent(false, o);
            yield return null;
        }
        float o1 = www.progress;
        wle.ActiveIngEvent(true, o1);
        tc.Progress = www.progress;

        //加载错误
        tc.LoadError = www.error;
        if (www.error != null)
        {
            tc.LoadState = LoadState.LoadFail;
            Debug.Log("Load Error:" + www.error);
        }
        else
        {
            tc.Size = www.size;
            tc.Data = www.bytes;
            tc.TextContent = www.text;

            tc.LoadState = LoadState.LoadComplete;
        }

        tc.LoadEndTime = DateTime.Now;
        wle.ActiveEndEvent(true);
    }
Example #8
0
    static IEnumerator InvokeLoadmovie(WwwMovie mc, UnityAction<float> uaing, UnityAction<float> uaend)
    {
        //注册回调事件
        WwwCallBack wle = new WwwCallBack();
        if (uaing != null)
            wle.AddIngEvent(uaing);
        if (uaend != null)
            wle.AddEndEvent(uaend);

        mc.LoadState = LoadState.LoadIng;
        mc.LoadStartTime = DateTime.Now;
        //开始下载资源
        WWW www = new WWW(mc.SourceUrl);

        mc.MovieContent = www.movie;
        while (!www.isDone)// || www.progress <= 1)
        {
            float o = www.progress;
            mc.Progress = www.progress;
            wle.ActiveIngEvent(false, o);
            yield return null;
        }
        float o1 = www.progress;
        mc.Progress = www.progress;
        wle.ActiveIngEvent(true, o1);
        mc.LoadState = LoadState.LoadComplete;

        mc.LoadError = www.error;
        if (www.error != null)
        {
            mc.LoadState = LoadState.LoadFail;
            Debug.Log("Load Error:" + www.error);
            //MessageBox.ShowInEditor(www.error);
        }
        else
        {
            mc.Size = www.size;
        }

        mc.LoadEndTime = DateTime.Now;
        wle.ActiveEndEvent(true);
    }
Example #9
0
    static IEnumerator InvokeLoadImage(WwwImage ic, UnityAction<float> uaing, UnityAction<float> uaend)
    {
        //注册回调事件
        WwwCallBack wle = new WwwCallBack();
        if (uaing != null)
            wle.AddIngEvent(uaing);
        if (uaend != null)
            wle.AddEndEvent(uaend);

        ic.LoadState = LoadState.LoadIng;

        ic.LoadStartTime = DateTime.Now;
        //开始下载资源
        WWW www = new WWW(ic.SourceUrl);

        while (!www.isDone)// || www.progress <= 1)
        {
            float o = www.progress;
            ic.Progress = www.progress;
            wle.ActiveIngEvent(false, o);
            yield return null;
        }
        float o1 = www.progress;
        ic.Progress = www.progress;
        wle.ActiveIngEvent(true, o1);

        //加载错误
        ic.LoadError = www.error;
        if (www.error != null)
        {
            ic.LoadState = LoadState.LoadFail;
            Debug.Log("Load Error:" + ic.SourceUrl + ":" + www.error);

            //MessageBox.ShowInEditor(www.error);
        }
        else
        {
            ic.Size = www.size;

            if (ic.SourceUrl.Contains(".gif"))
            {
                ic.ImageContent = AnalysisPage.GetGifImage(www.bytes, 0);
            }
            else
            {
                ic.ImageContent = www.texture;
            }

            ic.LoadState = LoadState.LoadComplete;
        }

        ic.LoadEndTime = DateTime.Now;
        wle.ActiveEndEvent(true);
    }
Example #10
0
    static IEnumerator InvokeLoadbundle(WwwBundle bc, UnityAction<float> uaing, UnityAction<float> uaend, ThreadPriority threadPriority)
    {
        //注册回调事件
        WwwCallBack wle = new WwwCallBack();
        if (uaing != null)
            wle.AddIngEvent(uaing);
        if (uaend != null)
            wle.AddEndEvent(uaend);

        bc.LoadState = LoadState.LoadIng;

        bc.LoadStartTime = DateTime.Now;
        //开始下载资源
        WWW www = new WWW(bc.SourceUrl);
        www.threadPriority = threadPriority;

        while (!www.isDone)// || www.progress <= 1)
        {
            float o = www.progress;
            bc.Progress = www.progress;
            wle.ActiveIngEvent(false, o);
            yield return null;
        }
        float o1 = www.progress;
        bc.Progress = www.progress;
        wle.ActiveIngEvent(true, o1);

        //加载错误
        bc.LoadError = www.error;
        if (www.error != null)
        {
            bc.LoadState = LoadState.LoadFail;
            Debug.Log("Load Error:" + bc.SourceUrl + ":" + www.error);

            //MessageBox.ShowInEditor(www.error);
        }
        else
        {
            bc.Size = www.size;

            bc.Bundle = www.assetBundle;

            bc.LoadState = LoadState.LoadComplete;
        }

        bc.LoadEndTime = DateTime.Now;
        wle.ActiveEndEvent(true);
    }