コード例 #1
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();
                }
            }
        }
コード例 #2
0
        private void itemComplete(EventX e)
        {
            AssetResource resource = e.target as AssetResource;

            resource.removeEventListener(EventX.COMPLETE, itemComplete);
            resource.removeEventListener(EventX.FAILED, itemComplete);
            //resource.removeEventListener(AssetEvent.PROGRESS, itemProgress);
            int index = runningList.IndexOf(resource);

            if (index != -1)
            {
                runningList.RemoveAt(index);
            }

            if (isStart == false)
            {
                return;
            }
            running--;

            loaded = total - queue.Count;
            this.dispatchEvent(new EventX(EventX.PROGRESS, (float)loaded / total));

            Action <EventX> action = null;

            if (resultActions.TryGetValue(resource.id, out action))
            {
                action(e);
            }

            CallLater.Add(loadNext);
        }
コード例 #3
0
        private void completeHandle(EventX e)
        {
            isLoaded = true;
            AssetResource resource = e.target as AssetResource;

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

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

            AudioClip clip = resource.getMainAsset() 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);
                }
            }
        }
コード例 #4
0
ファイル: SkinBase.cs プロジェクト: ly774508966/foundation
 protected virtual void clickTween()
 {
     if (_skin == null)
     {
         return;
     }
     TweenScale.Play(_skin, 0.1f, Vector3.one * 0.95f);
     CallLater.Add(() => TweenScale.Play(_skin, 0.1f, Vector3.one), 0.1f);
 }
コード例 #5
0
        public void Pause()
        {
            _delay = _source.time;
            if (_source)
            {
                _source.Pause();
            }

            CallLater.Remove(recycle);
        }
コード例 #6
0
        private void loadHandle(EventX e)
        {
            _concurrence--;

            RFLoader target = e.target as RFLoader;

            //trace("loaderQueue",_concurrence,event.type,target.url);

            target.removeEventListener(EventX.COMPLETE, loadHandle);
            target.removeEventListener(EventX.FAILED, loadHandle);
            target.removeEventListener(EventX.DISPOSE, loadHandle);

            CallLater.Add(next);
        }
コード例 #7
0
 private static void CheckNetWork()
 {
     if (Application.internetReachability != NetworkReachability.NotReachable)
     {
         Action oldAction = ReachableAction;
         if (oldAction != null)
         {
             ReachableAction = null;
             oldAction();
         }
     }
     else
     {
         CallLater.Add(CheckNetWork, TIME);
     }
 }
コード例 #8
0
        private IEnumerator doLoad(string url)
        {
            UnityWebRequest request;

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

            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 stratTime = Time.realtimeSinceStartup;
            bool  isTimeout = false;

            if (timeout > 0)
            {
                request.timeout = Mathf.CeilToInt(timeout);
            }
            while (!request.isDone)
            {
                if (timeout > 0 && (Time.realtimeSinceStartup - stratTime) > (timeout * 1.2f))
                {
                    isTimeout = true;
                    break;
                }

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

                yield return(request.SendWebRequest());
            }

            long responseCode = request.responseCode;

            if (request.isNetworkError || (responseCode != 200 && responseCode != 204) || isTimeout)
            {
                string error = "code=" + responseCode;
                if (isTimeout)
                {
                    error += ",error=isTimeout:" + timeout;
                }
                else if (request.isNetworkError)
                {
                    error += ",error=" + request.error;
                }
                else
                {
                    if (responseCode == 404)
                    {
                        mapping404[_url] = true;
                    }
                }
                _status = LoadState.ERROR;
                string message = string.Format("下载文件失败:{0} reason:{1}", _url, error);
                DebugX.LogWarning(message);

                request.Dispose();
                request = null;

                if (retryCount > _retryedCount)
                {
                    _retryedCount++;
                    _status = LoadState.LOADING;
                    ///本身加载需要时间,所以不必later太长
                    CallLater.Add(retryLoad, 1.0f);
                    yield break;
                }

                this.simpleDispatch(EventX.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:
                    //linner;
                    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(EventX.COMPLETE, _data);
            }
            selfComplete();
        }
コード例 #9
0
 public static void Start(Action action)
 {
     ReachableAction = action;
     CallLater.Add(CheckNetWork, TIME);
 }