Example #1
0
        protected override async Task AsyncRun()
        {
            string fullurl;
            var    loc = PathRouter.GetFullPath(Url, true, out fullurl);

            if (loc == PathLocation.NotFound)
            {
                throw new FileNotFoundException("BytesLoader", Url);
            }

            ResLog.VerboseFormat("BytesLoader.Load, loc:{0}, fullpath:{1}", loc, fullurl);

            byte[] bytes = null;
            try
            {
                bytes = await WWWLoader.AsyncLoad(fullurl, v => Progress = v);

                Finish(bytes);
            }
            catch (Exception e)
            {
                Finish(null, true);
                throw e;
            }
        }
Example #2
0
 protected override async Task AsyncInit()
 {
     #if UNITY_EDITOR
     ResourceModuleDebugger.Init();
     #endif
     PathRouter.Init();
 }
Example #3
0
        public static PrefabResource Load(string path)
        {
            if (!IsPlaying)
            {
                return(LoadInEditor(path));
            }

            using (var timer = LoadTimer.Start <PrefabLoader>(path))
            {
                var res = AssetSystem.Instance.FindAsset <PrefabResource>(path);
                if (null == res)
                {
                    res = new PrefabResource(path);
                    try
                    {
                        if (IsDev)
                        {
                            res = LoadInEditor(path, res);
                        }
                        else
                        {
                            string bundleName = string.Format(
                                "{0}/{1}.prefab{2}",
                                PathRouter.NoPrefix(PathRouter.Res),
                                path,
                                PathRouter.AssetBundleSuffix);
                            var assetBundleHandle = AssetBundleLoader.Load(bundleName);

                            res.prefabObject = assetBundleHandle.Bundle.LoadAsset(
                                Path.GetFileNameWithoutExtension(path));
                            if (null == res.prefabObject)
                            {
                                throw new ApplicationException(string.Format(
                                                                   "AssetBundle.LoadAsset({0}) => null, Bundle:{1}",
                                                                   Path.GetFileNameWithoutExtension(path),
                                                                   assetBundleHandle.Path));
                            }
                            res.AddDependency(assetBundleHandle);
                        }
                        AssetSystem.Instance.AddAsset(res);
                    }
                    catch (Exception e)
                    {
                        res.Dispose();
                        throw new ApplicationException("Error when loading Prefab:" + path, e);
                    }
                }
                return(res);
            }
        }
Example #4
0
 public static bool Exists(string path)
 {
     if (IsDev)
     {
         #if UNITY_EDITOR
         path = string.Format("{0}/{1}", PathRouter.Res, path);
         return(null != UnityEditor.AssetDatabase.LoadAssetAtPath <TextAsset>(path));
         #else
         throw new ApplicationException("IsDev is not allowed unless in Editor");
         #endif
     }
     else
     {
         return(PathLocation.NotFound != PathRouter.Exists(path));
     }
 }
Example #5
0
        static string GetLoadUrl(string url)
        {
            url = PathRouter.ABFolder + '/' + url;
            string fullurl;
            var    loc = PathRouter.GetFullPath(url, true, out fullurl);

            if (loc == PathLocation.NotFound)
            {
                throw new FileNotFoundException("AssetBundleLoader", url);
            }

            if (fullurl.StartsWith(PathRouter.FileProtocol))
            {
                fullurl = fullurl.Substring(PathRouter.FileProtocol.Length);
            }
            return(fullurl);
        }
Example #6
0
        public static byte[] Load(string path)
        {
            using (var timer = LoadTimer.Start <BytesLoader>(path))
            {
                string fullpath;
                var    loc = PathRouter.GetFullPath(path, false, out fullpath);
                if (loc == PathLocation.NotFound)
                {
                    throw new FileNotFoundException("BytesLoader", path);
                }

                ResLog.VerboseFormat("BytesLoader.Load, loc:{0}, fullpath:{1}", loc, fullpath);

                if (loc == PathLocation.InApp && Application.platform == RuntimePlatform.Android)
                {
                    return(AndroidPlugin.GetAssetBytes(path));
                }
                else
                {
                    return(File.ReadAllBytes(fullpath));
                }
            }
        }