Esempio n. 1
0
        private void completeHandle(SAEventX e)
        {
            isLoaded = true;
            AssetResource resource = e.target as AssetResource;

            AssetsManager.bindEventHandle(resource, completeHandle, false);
            if (e.type == SAEventX.FAILED)
            {
                return;
            }

            if (gameObject.activeSelf == false)
            {
                recycle();
                return;
            }

            AudioClip clip = resource.data as AudioClip;

            if (clip != null)
            {
                _source.clip   = clip;
                _source.loop   = loop;
                _source.volume = _soundValue;
                _source.Play();
                if (loop == false)
                {
                    CallLater.Add(recycle, _source.clip.length);
                }
            }
        }
Esempio n. 2
0
        public void Play()
        {
            if (_source.clip == null && isLoaded)
            {
                CallLater.Add(recycle, 0.1f);
                return;
            }

            if (_source.clip == null)
            {
                return;
            }

            if (gameObject.activeSelf == false)
            {
                gameObject.SetActive(true);
            }

            if (_source.isPlaying == false)
            {
                _source.loop = loop;
                _source.time = _delay;
                _source.Play();
            }

            if (loop == false)
            {
                if (_source.clip != null)
                {
                    CallLater.Add(recycle, _source.clip.length);
                }
                else
                {
                    recycle();
                }
            }
        }
Esempio n. 3
0
        private IEnumerator doLoad(string url)
        {
            UnityWebRequest request;

            switch (_parserType)
            {
            case LoaderXDataType.BYTES:
            case LoaderXDataType.AMF:
            case LoaderXDataType.TEXTURE:
            case LoaderXDataType.MANIFEST:
            case LoaderXDataType.ASSETBUNDLE:
                request = UnityWebRequest.Get(url);
                break;

            case LoaderXDataType.POST:
                request = UnityWebRequest.Post(url, postData);
                break;

            case LoaderXDataType.GET:
                string fullPath = url;
                if (string.IsNullOrEmpty(postData) == false)
                {
                    fullPath = url + "?" + postData;
                }
                request = UnityWebRequest.Get(fullPath);
                break;

            default:
                request = UnityWebRequest.Get(url);
                break;
            }

            float startTime = Time.realtimeSinceStartup;
            bool  isTimeout = false;

            if (timeout > 0)
            {
                request.timeout = timeout;
            }

            while (!request.isDone)
            {
                if (timeout > 0 && Time.realtimeSinceStartup - startTime > timeout * 2)
                {
                    isTimeout = true;
                    break;
                }

                if (checkProgress)
                {
                    update(request.downloadProgress);
                }

                yield return(request.SendWebRequest());
            }

            long responseCode = request.responseCode;

            if (request.isHttpError || (responseCode != 200 && responseCode != 204))
            {
                string error = "code=" + responseCode;
                if (isTimeout)
                {
                    error += ",error=isTimeout:" + timeout;
                }
                else if (request.isHttpError)
                {
                    error += "error=" + request.error;
                }
                else
                {
                    if (responseCode == 404)
                    {
                        mapping404[_url] = true;
                    }
                }

                _status = LoadState.ERROR;
                string message = string.Format("下载文件失败:{0} reson:{1}", _url, error);
                DebugX.LogWarning(message);

                request.Dispose();
                request = null;

                if (retryCount > _retriedCount)
                {
                    _retriedCount++;
                    CallLater.Add(retryLoad, 1.0f);
                    yield break;
                }

                this.simpleDispatch(SAEventX.FAILED, message);
            }
            else
            {
                _status = LoadState.COMPLETE;
                switch (_parserType)
                {
                case LoaderXDataType.BYTES:
                case LoaderXDataType.AMF:
                    _data = request.downloadHandler.data;
                    break;

                case LoaderXDataType.ASSETBUNDLE:
                case LoaderXDataType.MANIFEST:
                    onAssetBundleHandle(AssetBundle.LoadFromMemory(request.downloadHandler.data));
                    break;

                case LoaderXDataType.TEXTURE:
                    Texture2D tex = new Texture2D(2, 2, TextureFormat.ARGB32, false, false);
                    tex.LoadImage(request.downloadHandler.data);
                    _data = tex;
                    break;

                default:
                    _data = request.downloadHandler.data;
                    break;
                }
                request.Dispose();
                request = null;
                this.simpleDispatch(SAEventX.COMPLETE, _data);
            }
//            selfComplete();
        }