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); }
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 ==="); } }
void SetMode() { string n = modeGroup.ActiveToggles().First().name; ResourceSystem.ResMode = (ResourceSystem.Mode)Enum.Parse(typeof(ResourceSystem.Mode), n); ResLog.Log("Current mode: " + n); }
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); }
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"); }
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"); }
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(); }
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); }
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"); }
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"); }
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); }
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"); }
void SetSyncMode() { syncMode = syncGroup.ActiveToggles().First().name; ResLog.Log("Current sync mode: " + syncMode); }