Beispiel #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);
                }
            }
        }
Beispiel #2
0
        private AssetResource _getResource(string url, LoaderXDataType autoCreateType = LoaderXDataType.BYTES)
        {
            AssetResource res = findResource(url);

            if (res == null)
            {
                Type cls = null;
                if (resourceTypeMapping.TryGetValue(autoCreateType, out cls) == false)
                {
                    res = new AssetResource();
                }
                else
                {
                    res = (AssetResource)Activator.CreateInstance(cls, url);
                }

                res.parserType = autoCreateType;
                res.addEventListener(SAEventX.DISPOSE, resourceDisposeHandle);

                string key = url.ToLower();
                _resourceMap[key] = res;
            }

            return(res);
        }
Beispiel #3
0
        private void resourceDisposeHandle(SAEventX e)
        {
            AssetResource res = e.target as AssetResource;

            res.removeEventListener(SAEventX.DISPOSE, resourceDisposeHandle);

            string uri = res.url.ToLower();

            if (_resourceMap.ContainsKey(uri))
            {
                _resourceMap.Remove(uri);
            }
        }
Beispiel #4
0
        public AssetResource findResource(string url)
        {
            if (url == null)
            {
                return(null);
            }
            AssetResource res = null;
            string        key = url.ToLower();

            if (_resourceMap.TryGetValue(key, out res))
            {
                return(res);
            }
            return(null);
        }
        public RFLoader getLoader(AssetResource resource)
        {
            RFLoader        loader     = null;
            string          url        = resource.url;
            LoaderXDataType parserType = resource.parserType;

            if (_loadingPool.TryGetValue(resource.url, out loader))
            {
                return(loader);
            }

            string localPath = versionLoaderFactory.getLocalPathByURL(url, true);

            if (resource.isForceRemote == false)
            {
                string fullLocalPath = PathDefine.getPersistentLocal(localPath);
                if (File.Exists(fullLocalPath))
                {
                    loader = new FileStreamLoader(fullLocalPath, url, parserType);
                }
                else
                {
                    fullLocalPath = PathDefine.getStreamingAssetsLocal(localPath, true);
                    if (Application.platform == RuntimePlatform.IPhonePlayer)
                    {
                        loader = new WebRequestLoader(fullLocalPath, parserType);
                    }
                    else
                    {
                        loader = new StreamingAssetsLoader(fullLocalPath, url, parserType);
                    }
                }
            }

            if (loader == null)
            {
                loader             = new WebRequestLoader(url, parserType);
                loader.isLocalFile = false;
                if (resource.isForceRemote)
                {
                    loader.postData = resource.postData;
                    loader.timeout  = resource.timeout;
                }
            }

            _loadingPool[resource.url] = loader;
            return(loader);
        }
Beispiel #6
0
        public void load(string url)
        {
            isLoaded = false;

            AssetResource resource = null;

            if (AssetsManager.routerResourceDelegate != null)
            {
                resource = AssetsManager.routerResourceDelegate(url, name, "sound");
            }

            if (resource == null)
            {
                resource = AssetsManager.getResource(url, LoaderXDataType.PREFAB);
            }
            AssetsManager.bindEventHandle(resource, completeHandle);
            resource.load();
        }