コード例 #1
0
        private AssetResource _getResource(string url, string uri = null, LoaderXDataType autoCreateType = LoaderXDataType.BYTES)
        {
            if (uri == null)
            {
                uri = url;
            }

            AssetResource res = findResource(uri);

            if (res == null)
            {
                Type cls = null;

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

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

                string key = uri.ToLower();
                _resourceMap[key] = res;
            }
            return(res);
        }
コード例 #2
0
        public static void regist <T>(LoaderXDataType type) where T : AssetResource
        {
            Type clz = typeof(T);

            if (resourceTypeMapping.ContainsKey(type))
            {
                resourceTypeMapping.Remove(type);
            }

            resourceTypeMapping.Add(type, clz);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="uri"></param>
        /// <param name="type"></param>
        /// <param name="resultHandle">同url只返回一次回调</param>
        /// <returns></returns>
        public AssetResource add(string url, string uri, LoaderXDataType type, Action <EventX> resultHandle = null)
        {
            AssetResource resource = null;

            if (urlMapping.TryGetValue(uri, out resource))
            {
                return(resource);
            }
            resource = AssetsManager.getResource(url, uri, type);
            if (resource == null)
            {
                return(null);
            }
            innerAdd(uri, resource, resultHandle);
            return(resource);
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="uri"></param>
        /// <param name="type"></param>
        /// <param name="resultHandle">同url只返回一次回调</param>
        /// <returns></returns>
        public AssetResource add(string url, LoaderXDataType type, Action <EventX> resultHandle = null)
        {
            if (isStart)
            {
                DebugX.LogError("Qu不能在运行时加入:" + url);
            }

            AssetResource resource = null;

            if (string.IsNullOrEmpty(url))
            {
                return(resource);
            }

            string key = url.ToLower();

            if (urlMapping.TryGetValue(key, out resource))
            {
                return(resource);
            }
            resource = AssetsManager.getResource(url, type);
            if (resource == null)
            {
                return(null);
            }

            if (isUseRef)
            {
                resource.retain();
            }

            urlMapping.Add(key, resource);
            queue.Enqueue(resource);
            if (resultHandle != null && resultActions.ContainsKey(key) == false)
            {
                resultActions.Add(key, resultHandle);
            }

            return(resource);
        }
コード例 #6
0
 public abstract object parser(LoaderXDataType parserType);
コード例 #7
0
 public StreamingAssetsLoader(string fullLocalURL, string url, LoaderXDataType parserType) : base(url, parserType)
 {
     this.fullLocalURL = fullLocalURL;
 }
コード例 #8
0
 public RFLoader(string url, LoaderXDataType parserType)
 {
     _url        = url;
     _parserType = parserType;
 }
コード例 #9
0
 public WebRequestLoader(string url, LoaderXDataType parserType) : base(url, parserType)
 {
 }
コード例 #10
0
 public static AssetResource getResource(string url, string uri = null, LoaderXDataType autoCreateType = LoaderXDataType.BYTES)
 {
     return(instance()._getResource(url, uri, autoCreateType));
 }
コード例 #11
0
        public override object parser(LoaderXDataType parserType)
        {
            switch (parserType)
            {
            case LoaderXDataType.BYTES:
                _data = www.bytes;
                break;

            case LoaderXDataType.MANIFEST:
                if (assetBundle == null)
                {
                    assetBundle = www.assetBundle;
                }
                if (assetBundle != null)
                {
                    _data = assetBundle.LoadAsset("AssetBundleManifest");
                }
                else
                {
                    _data = null;
                    Debug.Log("No this Manisfest");
                }
                break;

            case LoaderXDataType.TEXTURE:
                texture2D = www.texture;
                if (www.assetBundle != null)
                {
                    www.assetBundle.Unload(false);
                }
                _data = texture2D;
                break;

            case LoaderXDataType.SOUND:
                _data = www.audioClip;
                break;

            case LoaderXDataType.ASSETBUNDLE:
                if (assetBundle == null)
                {
                    assetBundle = www.assetBundle;
                }
                _data = assetBundle;
                break;

            case LoaderXDataType.SPRITE:
                if (assetBundle == null)
                {
                    assetBundle = www.assetBundle;
                }
                if (assetBundle != null)
                {
                    _data = assetBundle.LoadAllAssets <Sprite>();    //assetBundle.LoadAll(typeof (Sprite));
                }
                break;

            case LoaderXDataType.AMF:
                ByteArray bytes = new ByteArray(www.bytes);
                if (bytes.BytesAvailable > 0)
                {
                    try
                    {
                        bytes.Inflate();
                    }
                    catch (Exception)
                    {
                        bytes.Position = 0;
                    }
                    _data = bytes.ReadObject();
                }
                else
                {
                    _data = null;
                }
                break;
            }

            return(_data);
        }
コード例 #12
0
 public FileStreamLoader(string fullLocalUrl, string url, LoaderXDataType parserType) : base(url, parserType)
 {
     this.fullLocalURL = fullLocalUrl;
 }
コード例 #13
0
ファイル: RFLoader.cs プロジェクト: ly774508966/foundation
 public RFLoader(string url, LoaderXDataType parserType)
 {
     this._url        = url;
     this._parserType = parserType;
 }