Пример #1
0
    public void _init()
    {
        _bgLoading = Resources.Load <Texture>("default/bg_loading");
        ResLog.Assert(_bgLoading != null, "找不到默认的图片信息");

        Resources.Load <Sprite>("default/default_sprite");
    }
Пример #2
0
        bool CollectPass(bool collectNow = false)
        {
            bool  collectAny = false;
            float now        = Time.unscaledTime;
            var   etor       = assets.GetEnumerator();

            while (etor.MoveNext())
            {
                var h = etor.Current.Value;
                if (!h.WaitForDispose)
                {
                    bool shouldDispose = (h.RefCount == 0) &&
                                         (collectNow || now - h.TimeWhenRefDropToZero > disposeDelay);

                    if (h.AleadyDisposed || shouldDispose)
                    {
                        waitToDispose.Add(h);
                        h.WaitForDispose = true;
                        collectAny       = true;
                        ResLog.Log("(AssetManager) collect " + h.Path);
                    }
                }
            }
            return(collectAny);
        }
Пример #3
0
        async void RunTests()
        {
            await ResourceSystem.Init();

            ResourceSystem.ResMode            = ResourceSystem.Mode.AssetBundle;
            AssetSystem.Instance.disposeDelay = 2f;
            ResLog.Log("=== ResourceSystem Initialized ===");

            foreach (Type type in testerTypes)
            {
                ResLog.LogFormat("=== Run {0} ===", type.Name);
                var go     = new GameObject();
                var tester = (Tester)go.AddComponent(type);
                try
                {
                    await tester.Test();
                }
                catch (Exception e)
                {
                    ResLog.LogException(e);
                }
                Destroy(go);
                await Awaiters.NextFrame;
                ResLog.Log("=== Done ===");
            }
        }
Пример #4
0
        void DisposePass(bool disposeAll = false)
        {
            int i = 0;

            for (int disposedCount = 0;
                 i < waitToDispose.Count && (disposeAll || disposedCount < disposePerFrame);
                 ++i)
            {
                var h = waitToDispose[i];
                if (h.WaitForDispose)
                {
                    try
                    {
                        h.Dispose();
                        assets.Remove(h.Path);
                        ResLog.Log("(AssetManager) dispose " + h.Path);
                    }
                    catch (Exception e)
                    {
                        ResLog.LogException(e);
                    }
                    ++disposedCount;
                }
            }
            waitToDispose.RemoveRange(0, i);
        }
Пример #5
0
        async Task SandboxTest()
        {
            string p = paths[0];

            byte[] bytes          = BytesLoader.Load(p);
            int    originalLength = bytes.Length;
            int    newLength      = originalLength * 2;

            string ppath = PathRouter.SandboxPath + p;

            Directory.CreateDirectory(Path.GetDirectoryName(ppath));
            File.WriteAllBytes(ppath, new byte[newLength]);
            ResLog.LogFormat("Write {0} bytes to {1}", newLength, ppath);

            bytes = BytesLoader.Load(p);
            Assert(bytes.Length > 0);
            ResLog.LogFormat("length:{0} original:{1}", bytes.Length, originalLength);
            Assert(bytes.Length == newLength);
            ResLog.Log("Sandbox: Load Finished");
            bytes = await BytesLoader.AsyncLoad(p);

            Assert(bytes.Length > 0);
            Assert(bytes.Length == newLength);
            ResLog.LogFormat("length:{0} original:{1}", bytes.Length, originalLength);
            ResLog.Log("Sandbox: AsyncLoad Finished");
        }
Пример #6
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;
            }
        }
Пример #7
0
        void SetMode()
        {
            string n = modeGroup.ActiveToggles().First().name;

            ResourceSystem.ResMode = (ResourceSystem.Mode)Enum.Parse(typeof(ResourceSystem.Mode), n);
            ResLog.Log("Current mode: " + n);
        }
Пример #8
0
        public override async Task Test()
        {
            foreach (string ab in AssetBundleLoader.Manifest.GetAllAssetBundles())
            {
                paths.Add(ab);
            }

            var handle = await AssetBundleLoader.AsyncLoad("Prefabs/CompleteLevelArt.prefab.ab");

            ++handle.RefCount;
            await Awaiters.Seconds(5f);

            --handle.RefCount;
            AssetSystem.Instance.GarbageCollect();
            ResLog.Log("Async Load Finished");

            handle = AssetBundleLoader.Load("Prefabs/CompleteLevelArt.prefab.ab");
            ++handle.RefCount;
            await Awaiters.Seconds(5f);

            --handle.RefCount;
            AssetSystem.Instance.GarbageCollect();
            ResLog.Log("Load Finished");

            List <AssetHandle> handles = new List <AssetHandle>();

            foreach (string ab in AssetBundleLoader.Manifest.GetAllAssetBundles())
            {
                var h = await AssetBundleLoader.AsyncLoad(ab);

                ++h.RefCount;
                handles.Add(h);
            }
            ResLog.Log("Async Load All");
            await Awaiters.Seconds(5f);

            ResLog.Log("Disposing");
            handles.ForEach(h => -- h.RefCount);
            handles.Clear();
            AssetSystem.Instance.GarbageCollect();
            ResLog.Log("Async Load All Finished");

            foreach (string ab in AssetBundleLoader.Manifest.GetAllAssetBundles())
            {
                var h = AssetBundleLoader.Load(ab);
                ++h.RefCount;
                handles.Add(h);
            }
            ResLog.Log("Load All");
            await Awaiters.Seconds(5f);

            ResLog.Log("Disposing");
            handles.ForEach(h => -- h.RefCount);
            handles.Clear();
            AssetSystem.Instance.GarbageCollect();
            ResLog.Log("Load All Finished");
        }
Пример #9
0
 public void Start()
 {
     if (null == stopwatch)
     {
         stopwatch = Stopwatch.StartNew();
     }
     stopwatch.Restart();
     ResLog.LogFormat("Load start ({0}) {1}", typeName, url);
 }
Пример #10
0
 public void Release()
 {
     if (handleRefCount == 0)
     {
         ResLog.LogErrorFormat("{0} handleRefCount < 0 !", this);
         return;
     }
     --handleRefCount;
     --RefCount;
 }
Пример #11
0
 public void Stop()
 {
     if (null != stopwatch)
     {
         stopwatch.Stop();
         ResLog.LogFormat(
             "Load finish {0} ms ({1}) {2}",
             stopwatch.ElapsedMilliseconds, typeName, url);
         stopwatch.Reset();
     }
 }
Пример #12
0
        public void Release()
        {
            if (--RefCount <= 0)
            {
                if (RefCount < 0)
                {
                    ResLog.LogWarningFormat("{0} RefCount({1}) < 0", ToString(), RefCount);
                }

                var typeDict = GetTypeDict(GetType());
                typeDict.Remove(Url);
            }
        }
Пример #13
0
        public override I_ObjectInfo GetAsset <T>(string resPath)
        {
            T obj = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(RequestResPath);

            if (obj == null)
            {
                ResLog.Error("本地加载资源出错,Path:[{0}]", RequestResPath);
                ForceExit(string.Format("本地加载资源出错,Path:[{0}]", RequestResPath));
                return(null);
            }
            I_ObjectInfo objectInfo = new ResInfo(obj, RequestResPath);

            return(objectInfo);
        }
Пример #14
0
        public override async Task Test()
        {
            string folder = Application.dataPath + "/Resources/Prefabs";

            foreach (string file in Directory.EnumerateFiles(folder, "*.prefab", SearchOption.AllDirectories))
            {
                string path = PathRouter.NormalizePath(file)
                              .Replace(folder, "Prefabs")
                              .Replace(".prefab", "");
                ResLog.Log(path);
            }

            await TestAsyncLoad();
            await TestLoad();
        }
Пример #15
0
        public void AddAsset(AssetHandle h)
        {
            if (assets.ContainsKey(h.Path))
            {
                throw new ArgumentException(string.Format(
                                                "Asset of path {0} already exists in AssetManager",
                                                h.Path));
            }

            assets.Add(h.Path, h);
            if (h.RequireTick)
            {
                tickAssets.Add(h);
            }
            ResLog.Log("(AssetManager) add asset " + h.Path);
        }
Пример #16
0
        async Task InAppTest()
        {
            foreach (string p in paths)
            {
                byte[] bytes = BytesLoader.Load(p);
                Assert(bytes.Length > 0);
            }
            ResLog.Log("InApp: Load Finished");

            foreach (string p in paths)
            {
                byte[] bytes = await BytesLoader.AsyncLoad(p);

                Assert(bytes.Length > 0);
            }
            ResLog.Log("InApp: AsyncLoad Finished");
        }
Пример #17
0
        async void AsyncLoad()
        {
            loading = true;
            try
            {
                await SceneLoader.AsyncLoad(
                    dropdown.captionText.text,
                    v => progress.text = string.Format("Loading {0:P2}", v));

                current.text = SceneResource.Current.Path;
            }
            catch (Exception e)
            {
                ResLog.LogException(e);
            }
            loading = false;
        }
Пример #18
0
        public override async Task Test()
        {
            foreach (string ab in AssetBundleLoader.Manifest.GetAllAssetBundles())
            {
                string relpath = PathRouter.ABFolder + '/' + ab;
                string fullpath;
                Assert(PathLocation.NotFound != PathRouter.GetFullPath(relpath, true, out fullpath));
                urls.Add(fullpath);
            }

            ResLog.Log("ResourceSystem.Init");
            await TestLoadOne(urls[0]);

            ResLog.Log("TestLoadOne finished");
            await TestLoadMutiple();

            ResLog.Log("TestLoadMutiple finished");
        }
Пример #19
0
        public static void Init()
        {
            PersistentPath             = Application.persistentDataPath + '/';
            PersistentPathWithProtocol = FileProtocol + PersistentPath;

            SandboxPath             = PersistentPath + Sandbox + '/';
            SandboxPathWithProtocol = FileProtocol + SandboxPath;

            switch (Application.platform)
            {
            case RuntimePlatform.WindowsEditor:
            case RuntimePlatform.OSXEditor:
            {
                StreamingPath             = Application.streamingAssetsPath + '/';
                StreamingPathWithProtocol = FileProtocol + StreamingPath;
            }
            break;

            case RuntimePlatform.Android:
            {
                StreamingPath             = Application.dataPath + "!/assets/";
                StreamingPathWithProtocol = Application.streamingAssetsPath + '/';
            }
            break;

            case RuntimePlatform.IPhonePlayer:
            {
                StreamingPath             = Application.streamingAssetsPath + '/';
                StreamingPathWithProtocol = Uri.EscapeUriString(FileProtocol + StreamingPath);
            }
            break;

            default:
                throw new ApplicationException("Unsupported platform: " + Application.platform);
            }

            ResLog.Log("DataPath: " + Application.dataPath);
            ResLog.Log("PersistentPath: " + PersistentPath);
            ResLog.Log("PersistentPathWithProtocol: " + PersistentPathWithProtocol);
            ResLog.Log("SandboxPath: " + SandboxPath);
            ResLog.Log("SandboxPathWithProtocol: " + SandboxPathWithProtocol);
            ResLog.Log("StreamingPath: " + StreamingPath);
            ResLog.Log("StreamingPathWithProtocol: " + StreamingPathWithProtocol);
        }
Пример #20
0
        /// <summary>
        /// use www to load stuff
        /// never let exception out of this function
        /// </summary>
        protected async void AsyncStartLoading()
        {
            ++_runningCount;
            ResLog.VerboseFormat(
                "({0}) Dispatch {1} for loading, current running {2}",
                GetType().Name, Url, _runningCount);
            try
            {
                using (WWW www = new WWW(Url))
                {
                    www.threadPriority = Application.backgroundLoadingPriority;
                    while (!www.isDone)
                    {
                        Progress = www.progress;
                        await Awaiters.NextFrame;
                    }
                    Progress = www.progress;

                    if (!string.IsNullOrEmpty(www.error))
                    {
                        throw new ApplicationException(string.Format(
                                                           "WWW error, url={0}, error={1}",
                                                           Url, www.error));
                    }
                    else
                    {
                        Finish(www.bytes);
                    }
                }
            }
            catch (Exception e)
            {
                Finish(null, true);
                exception = e;
            }
            finally
            {
                --_runningCount;
            }
        }
Пример #21
0
        async Task TestLoad()
        {
            List <GameObject> instances = new List <GameObject>();
            var prefabResource          = PrefabLoader.Load("Prefabs/CompleteLevelArt");

            instances.Add(prefabResource.Instantiate <GameObject>());
            instances.Add(prefabResource.Instantiate <GameObject>());
            AssetSystem.Instance.GarbageCollect();
            ResLog.Log("Instantiate Finish");
            await Awaiters.Seconds(5f);

            instances.ForEach(go => GameObject.Destroy(go));
            instances.Clear();
            ResLog.Log("Destroy Instances");
            await Awaiters.Seconds(3f);

            AssetSystem.Instance.GarbageCollect();
            ResLog.Log("Garbage Collect");
            await Awaiters.Seconds(5f);

            ResLog.Log("TestLoad Finish");
        }
Пример #22
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));
                }
            }
        }
Пример #23
0
 void SetSyncMode()
 {
     syncMode = syncGroup.ActiveToggles().First().name;
     ResLog.Log("Current sync mode: " + syncMode);
 }