protected override IResourceLocation[] SetupLocations(KeyValuePair <string, string>[] assets) { Random.InitState(0); virtualBundleData = new VirtualAssetBundleRuntimeData(); sharedBundleLocations = new List <IResourceLocation>(); bundleMap = new Dictionary <string, VirtualAssetBundle>(); for (int i = 0; i < kBundleCount; i++) { var bundleName = "shared" + i; var b = new VirtualAssetBundle("shared" + i, i % 2 == 0, 0, ""); virtualBundleData.AssetBundles.Add(b); bundleMap.Add(b.Name, b); sharedBundleLocations.Add(new ResourceLocationBase(bundleName, bundleName, typeof(AssetBundleProvider).FullName, typeof(IAssetBundleResource))); } IResourceLocation[] locs = new IResourceLocation[assets.Length]; for (int i = 0; i < locs.Length; i++) { locs[i] = CreateLocationForAsset(assets[i].Key, assets[i].Value); } foreach (var b in virtualBundleData.AssetBundles) { b.SetSize(2048, 1024); b.OnAfterDeserialize(); } m_ResourceManager.ResourceProviders.Insert(0, new VirtualAssetBundleProvider(virtualBundleData)); m_ResourceManager.ResourceProviders.Insert(0, new VirtualBundledAssetProvider()); return(locs); }
protected override void CreateLocations(List<IResourceLocation> locations) { ResourceManager.InstanceProvider = new InstanceProvider(); ResourceManager.SceneProvider = new SceneProvider(); var virtualBundleData = new VirtualAssetBundleRuntimeData(); var sharedBundles = new List<VirtualAssetBundle>(); var sharedBundleLocations = new List<IResourceLocation>(); for (int i = 0; i < 10; i++) { var bundleName = "shared" + i; sharedBundles.Add(new VirtualAssetBundle("shared" + i, i % 2 == 0)); sharedBundleLocations.Add(new ResourceLocationBase(bundleName, bundleName, typeof(AssetBundleProvider).FullName)); } virtualBundleData.AssetBundles.AddRange(sharedBundles); for (int i = 0; i < 5; i++) { var isLocal = i % 2 == 0; var b = new VirtualAssetBundle("bundle" + i, isLocal); var bundleLocation = new ResourceLocationBase(b.Name, b.Name, typeof(AssetBundleProvider).FullName); for (int a = 0; a < 10; a++) { var name = b.Name + "_asset" + a; var path = RootFolder + "/" + name + ".prefab"; GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); go.name = name; #if UNITY_2018_3_OR_NEWER PrefabUtility.SaveAsPrefabAsset(go, path); #else PrefabUtility.CreatePrefab(path, go); #endif Object.DestroyImmediate(go, false); var asset = new VirtualAssetBundleEntry(path, Random.Range(1024, 1024 * 1024)); b.Assets.Add(asset); locations.Add(new ResourceLocationBase(name, path, typeof(BundledAssetProvider).FullName, bundleLocation, sharedBundleLocations[Random.Range(0, sharedBundleLocations.Count)], sharedBundleLocations[Random.Range(0, sharedBundleLocations.Count)])); } b.OnAfterDeserialize(); virtualBundleData.AssetBundles.Add(b); } var abManager = new GameObject("AssetBundleSimulator", typeof(VirtualAssetBundleManager)).GetComponent<VirtualAssetBundleManager>(); abManager.Initialize(virtualBundleData, s => s); ResourceManager.ResourceProviders.Insert(0, new CachedProvider(new VirtualAssetBundleProvider(abManager, typeof(AssetBundleProvider).FullName))); ResourceManager.ResourceProviders.Insert(0, new CachedProvider(new VirtualBundledAssetProvider())); }