private string GetAssemblyFullPath(IAssemblyMetadata metadata) { BundleData member = this.FrameworkAdaptor.InstalledBundles.Find(a => a.SymbolicName == metadata.Owner.SymbolicName); AssertUtility.NotNull(member); return(BundleUtility.FindAssemblyFullPath(member.Path, metadata.Path, true)); }
private void ResolveAndValidateAssembly(string bundlePath, List <IAssemblyMetadata> assemblyMetadata) { assemblyMetadata.RemoveAll(delegate(IAssemblyMetadata item) { try { AssemblyName name3; string assemblyFile = BundleUtility.FindAssemblyFullPath(bundlePath, item.Path, true); AssemblyName assemblyName = AssemblyName.GetAssemblyName(assemblyFile); if (assemblyName == null) { assemblyName = new AssemblyName { Name = Path.GetFileNameWithoutExtension(assemblyFile), Version = FrameworkConstants.DEFAULT_VERSION, CultureInfo = FrameworkConstants.DEFAULT_CULTURE }; } item.Path = assemblyFile; item.Version = assemblyName.Version; item.AssemblyName = assemblyName; if (this.TryToReplaceWithGlobalAssembly(item, out name3)) { FileLogUtility.Warn(string.Format(Messages.LocalAssemblyReplacedByGlobal, new object[] { item.AssemblyName, item.Owner.SymbolicName, item.Owner.Version, name3 })); item.IsDuplicatedWithGlobalAssembly = true; item.AssemblyName = name3; } return(false); } catch (Exception exception) { item.Owner.AssembliesFailedToLoad.Add(item); FileLogUtility.Error(string.Format(Messages.BundleAssemblyLoadFailed, new object[] { item.Path, item.Owner.SymbolicName, item.Owner.Version, exception.Message })); return(true); } }); }
public IBundle InstallBundle(string location, Stream stream) { IBundle bundle = Framework.Bundles.GetBundle(location); if (bundle == null) { BundleData bundleData = Framework.ServiceContainer.GetFirstOrDefaultService <IBundleInstallerService>().CreateBundleData(location, stream); if (bundleData == null) { Framework.EventManager.DispatchFrameworkEvent(this, new FrameworkEventArgs(FrameworkEventType.Error, new Exception($"Install bundle in '{location}' failed."))); return(null); } Tuple <IBundle, IBundleMetadata> tuple = Framework.AddBundleData(bundleData); bundle = tuple.Item1; IBundleMetadata metadata = tuple.Item2; if (string.IsNullOrEmpty(bundleData.HostBundleSymbolicName)) { Interface1 host = metadata as Interface1; AssertUtility.IsTrue(host != null); List <IFragmentBundleMetadata> metadatas = BundleUtility.GetMetadatas <IFragmentBundleMetadata>(Framework.FrameworkAdaptor.State.Bundles); BundleUtility.BindFragmentMetadatas(host, metadatas); } else { IFragmentBundleMetadata metadata2 = metadata as IFragmentBundleMetadata; AssertUtility.IsTrue(metadata2 != null); BundleUtility.GetMetadatas <Interface1>(Framework.FrameworkAdaptor.State.Bundles); } Framework.ServiceContainer.GetFirstOrDefaultService <IBundlePersistent>().SaveInstallLocation(location); } return(bundle); }
public HostBundleMetadataNode(IResolver resolver, Interface1 metadata) : base(resolver, metadata) { this._referencableProxy = new Referencable(); AssertUtility.ArgumentNotNull(resolver, "resolver"); this.FragmentNodes = new List <IFragmentBundleMetadataNode>(); BundleUtility.BuildFragments(this); }
private void _UnnamedAllResource(string rootpath) { List <string> reslist = BundleUtility.GetAllFilePath(rootpath, BundleConfig.metaExtension); foreach (string path in reslist) { BundleUtility.NamedMetaFile(path, ""); } }
private void _ListAllBundle(string rootPath, string fileEnd, Dictionary <string, List <string> > cList) { if (string.IsNullOrEmpty(fileEnd) || string.IsNullOrEmpty(rootPath)) { return; } List <string> allPerfab = BundleUtility.GetAllFilePath(rootPath, fileEnd); _ListAllAssets(allPerfab, cList); }
private void _ListAllAssets(List <string> allAssets, Dictionary <string, List <string> > cList) { string[] strArray = new string[1]; foreach (string path in allAssets) { strArray[0] = path.Replace("\\", "/").Replace(Application.dataPath, "Assets"); string[] deparry = AssetDatabase.GetDependencies(strArray); List <string> deps = BundleUtility.RemoveTargetAndScript(deparry, strArray[0]); if (strArray[0].IndexOf(BundleConfig.prefabBundlePath) >= 0) { m_BundleList.AddResourceAndDependencies(strArray[0], deps, false); } else { m_BundleList.AddResourceAndDependencies(strArray[0], deps, true); } } }
public List <Tuple <IFragmentBundleMetadataNode, List <IAssemblyMetadataNode> > > AttachAllFragments() { List <IFragmentBundleMetadata> metadatas = BundleUtility.GetMetadatas <IFragmentBundleMetadata>(base.ConstraintResolver.State.Bundles); BundleUtility.BindFragmentMetadatas((Interface1)base.Metadata, metadatas); List <Interface2> unResolverNodes = base.ConstraintResolver.State.Resolver.UnResolverNodes; BundleUtility.BuildFragments(this); List <Tuple <IFragmentBundleMetadataNode, List <IAssemblyMetadataNode> > > rt = new List <Tuple <IFragmentBundleMetadataNode, List <IAssemblyMetadataNode> > >(this.FragmentNodes.Count); this.FragmentNodes.ForEach(delegate(IFragmentBundleMetadataNode a) { base.ConstraintResolver.ResolvedAssemblyMetadataNodes.AddRange(a.SharedAssemblyNodes); base.ConstraintResolver.ResolvedAssemblyMetadataNodes.AddRange(a.PrivateAssemblyNodes); }); this.FragmentNodes.ForEach(delegate(IFragmentBundleMetadataNode fragementNode) { rt.Add(TupleUtility.CreateTuple <IFragmentBundleMetadataNode, List <IAssemblyMetadataNode> >(fragementNode, new List <IAssemblyMetadataNode>(fragementNode.SharedAssemblyNodes))); }); return(rt); }
public static void BuildAssetBundles(BuildTarget?target = null) { var buildTarget = target ?? EditorUserBuildSettings.activeBuildTarget; // Choose the output path according to the build target. string outputPath = Path.Combine(BundleUtility.AssetBundlesOutputPath, BundleUtility.GetPlatformName(target)); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } //@TODO: use append hash... (Make sure pipeline works correctly with it.) BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle | BuildAssetBundleOptions.StrictMode, buildTarget); CopyAssetBundlesTo(outputPath, Path.Combine(Application.streamingAssetsPath, BundleUtility.AssetBundlesOutputPath)); AssetDatabase.Refresh(); }
public static void BuildPlayer() { var outputPath = EditorUtility.SaveFolderPanel("Choose Location of the Built Game", "", ""); if (outputPath.Length == 0) { return; } string[] levels = GetLevelsFromBuildSettings(); if (levels.Length == 0) { Log.Info("Nothing to build."); return; } var target = EditorUserBuildSettings.activeBuildTarget; string targetName = GetBuildTargetName(target); if (targetName == null) { return; } // Build and copy AssetBundles. BuildAssetBundles(); CopyAssetBundlesTo(Path.Combine(BundleUtility.AssetBundlesOutputPath, BundleUtility.GetPlatformName(target)), Path.Combine(Application.streamingAssetsPath, BundleUtility.AssetBundlesOutputPath)); AssetDatabase.Refresh(); BuildOptions option = EditorUserBuildSettings.development ? BuildOptions.Development : BuildOptions.None; BuildPipeline.BuildPlayer(levels, outputPath + targetName, EditorUserBuildSettings.activeBuildTarget, option); if (Directory.Exists(outputPath)) { foreach (var file in Directory.GetFiles(outputPath, "*.manifest", SearchOption.AllDirectories)) { File.Delete(file); } } }
public AssetBundleBuild[] ListAllAssets(string rootPath, bool buildScene) { Dictionary <string, List <string> > containterList = new Dictionary <string, List <string> >(); _ListAllBundle(rootPath, "All", containterList); List <AssetBundleBuild> result = new List <AssetBundleBuild>(); DirectoryInfo DirInfo = new DirectoryInfo(rootPath); foreach (DirectoryInfo di in DirInfo.GetDirectories()) { if (di.FullName.EndsWith(BundleConfig.allinone_suffix)) { AssetBundleBuild abb = new AssetBundleBuild(); string fileName = di.FullName.Replace("\\", "/").Replace(Application.dataPath, "Assets"); m_BundleList.RemoveRepeatBundleAndDep(fileName); List <string> allPerfab = BundleUtility.GetAllFilePath(di.FullName, "All"); for (int i = 0; i < allPerfab.Count; i++) { allPerfab[i] = allPerfab[i].Replace("\\", "/").Replace(Application.dataPath, "Assets"); } abb.assetNames = allPerfab.ToArray(); abb.assetBundleName = ProcessBundleName(fileName); result.Add(abb); } } foreach (string asset in m_BundleList) { AssetBundleBuild abb = new AssetBundleBuild(); abb.assetNames = new string[] { asset }; abb.assetBundleName = ProcessBundleName(asset); result.Add(abb); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); return(result.ToArray()); }
//命名全部的perfab和perfab依赖的公共的资源,非公共资源不单独打包,最大限度降低碎片度 public AssetBundleBuild[] ListedAllAndPublicAsset(string rootPath, bool buildScene) { _UnnamedAllResource(rootPath); Dictionary <string, List <string> > containterList = new Dictionary <string, List <string> >(); _ListAllBundle(rootPath, "All", containterList); foreach (string fileEnd in BundleConfig.assetPrefab) { m_BundleList.RemoveRepeatBundleAndDep("Assets" + fileEnd); _ListAllBundle(Application.dataPath + fileEnd, ".prefab", new Dictionary <string, List <string> >()); } AssetBundleBuild[] ConfigBundleArray = new AssetBundleBuild[BundleConfig.tableAssetsPathRoot.Length]; int j = 0; foreach (BundlePathConfigPair pair in BundleConfig.tableAssetsPathRoot) { m_BundleList.RemoveRepeatBundleAndDep("Assets" + pair.mAssetPath); List <string> allPerfab = BundleUtility.GetAllFilePath(Application.dataPath + pair.mAssetPath, "All"); for (int i = 0; i < allPerfab.Count; i++) { allPerfab[i] = allPerfab[i].Replace("\\", "/").Replace(Application.dataPath, "Assets"); } ConfigBundleArray[j].assetNames = allPerfab.ToArray(); ConfigBundleArray[j].assetBundleName = pair.mBundleName + ".data"; ++j; } j = 0; AssetBundleBuild[] abbArray = new AssetBundleBuild[m_BundleList.Count]; foreach (string asset in m_BundleList) { abbArray[j].assetNames = new string[] { asset }; abbArray[j].assetBundleName = ProcessBundleName(asset); //abbArray[i].assetBundleVariant = ProcessBundleName(asset); ++j; } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); List <AssetBundleBuild> resultList = new List <AssetBundleBuild>(); resultList.AddRange(abbArray); resultList.AddRange(ConfigBundleArray); // resultList.AddRange(resourceBundleArray); //List<AssetBundleBuild> LastResultList = new List<AssetBundleBuild>(resultList); //List<string> bundleList = new List<string>();//<AssetBundleBuild>(); //for(int i = LastResultList.Count -1; i >=0; i--) //{ // if (bundleList.Contains(LastResultList[i].assetBundleName)) // { // resultList.RemoveAt(i); // } // else // { // bundleList.Add(LastResultList[i].assetBundleName); // } //} return(resultList.ToArray()); }