示例#1
0
        public static IEnumerator Dispose()
        {
            IsInitialising = true;
            ProgressManager.RemoveProgressBars("Unload Asset Bundles");

            int progressID = Progress.Start("Unload Asset Bundles", null, Progress.Options.Sticky);
            int bundleID   = Progress.Start("Bundles", null, Progress.Options.Sticky, progressID);
            int prefabID   = Progress.Start("Prefabs", null, Progress.Options.Sticky, progressID);

            Progress.Report(bundleID, 0f);
            Progress.Report(prefabID, 0f);
            PrefabManager.ReplaceWithDefault(PrefabManager.CurrentMapPrefabs, prefabID);

            while (PrefabManager.IsChangingPrefabs)
            {
                yield return(null);
            }

            for (int i = 0; i < BundleCache.Count; i++)
            {
                Progress.Report(bundleID, (float)i / BundleCache.Count, "Unloading: " + BundleCache.ElementAt(i).Key);
                BundleCache.ElementAt(i).Value.Unload(true);
                yield return(null);
            }

            int bundleCount = BundleCache.Count;

            BundleLookup.Clear();
            BundleCache.Clear();
            AssetCache.Clear();

            Progress.Report(bundleID, 0.99f, "Unloaded: " + bundleCount + " bundles.");
            Progress.Finish(bundleID, Progress.Status.Succeeded);
            IsInitialised = false; IsInitialising = false;
        }
示例#2
0
    private static T GetAsset <T>(string filePath) where T : Object
    {
        if (!BundleLookup.TryGetValue(filePath, out AssetBundle bundle))
        {
            return(null);
        }

        return(bundle.LoadAsset <T>(filePath));
    }
示例#3
0
        public void TryGetBundle_ReturnsFalse_WhenBundleIsNotRegistered(string bundleName)
        {
            var bundleLookup = new BundleLookup(_testBundles);

            var result = bundleLookup.TryGetBundle(bundleName, out Bundle bundle);

            Assert.False(result);
            Assert.Null(bundle);
        }
示例#4
0
        public void TryGetBundle_ReturnsValidBundle_WhenBundleIsRegistered(string bundleName)
        {
            var bundleLookup = new BundleLookup(_testBundles);

            var result = bundleLookup.TryGetBundle(bundleName, out Bundle bundle);

            Assert.True(result);
            Assert.NotNull(bundle);
            Assert.Equal(bundleName, bundle.Name);
        }
示例#5
0
        public void TryGetBundle_ThrowsException_WhenNameIsNull()
        {
            var bundleLookup = new BundleLookup(_testBundles);

            Assert.Throws <ArgumentNullException>(() => bundleLookup.TryGetBundle(null, out Bundle bundle));
        }