public void InitResMgr() { if (AssetBundlePathHelper.SimulationMode) { AssetBundleSettings.AssetBundleConfigFile = ConfigFileUtility.BuildEditorDataTable(); } else { AssetBundleSettings.AssetBundleConfigFile.Reset(); var outResult = new List <string>(); // 未进行过热更 if (AssetBundleSettings.LoadAssetResFromStreamingAssetsPath) { ResKit.Architecture.Interface.GetUtility <IZipFileHelper>() .GetFileInInner(ResDatas.FileName, outResult); } // 进行过热更 else { AssetBundlePathHelper.GetFileInFolder(AssetBundlePathHelper.PersistentDataPath, ResDatas.FileName, outResult); } foreach (var outRes in outResult) { AssetBundleSettings.AssetBundleConfigFile.LoadFromFile(outRes); } } }
public static void BuildDataTable(string[] abNames = null, string outputPath = null) { Log.I("Start Default BuildAssetDataTable!"); var table = new ResDatas(); ConfigFileUtility.AddABInfo2ResDatas(table, abNames); var filePath = (outputPath ?? (AssetBundlePathHelper.StreamingAssetsPath + AssetBundleSettings.RELATIVE_AB_ROOT_FOLDER)).CreateDirIfNotExists() + ResDatas.FileName; table.Save(filePath); AssetDatabase.Refresh(); }
public IEnumerator InitResMgrAsync() { if (AssetBundlePathHelper.SimulationMode) { AssetBundleSettings.AssetBundleConfigFile = ConfigFileUtility.BuildEditorDataTable(); yield return(null); } else { AssetBundleSettings.AssetBundleConfigFile.Reset(); var outResult = new List <string>(); var pathPrefix = AssetBundlePathHelper.PathPrefix; // 未进行过热更 if (AssetBundleSettings.LoadAssetResFromStreamingAssetsPath) { var streamingPath = Application.streamingAssetsPath + "/AssetBundles/" + AssetBundlePathHelper.GetPlatformName() + "/" + ResDatas.FileName; outResult.Add(pathPrefix + streamingPath); } // 进行过热更 else { var persistentPath = Application.persistentDataPath + "/AssetBundles/" + AssetBundlePathHelper.GetPlatformName() + "/" + ResDatas.FileName; outResult.Add(pathPrefix + persistentPath); } foreach (var outRes in outResult) { Log.I(outRes); yield return(AssetBundleSettings.AssetBundleConfigFile.LoadFromFileAsync(outRes)); } yield return(null); } }
public static void WriteClass(TextWriter writer, string ns) { var buildDataTable = ConfigFileUtility.BuildEditorDataTable(); var allAssetDataGroups = buildDataTable.AllAssetDataGroups; var assetBundleInfos = new List <AssetBundleInfo>(); allAssetDataGroups.ForEach(assetDataGroup => { var assetDatas = assetDataGroup.AssetBundleDatas; assetDatas.ForEach(abUnit => { assetBundleInfos.Add(new AssetBundleInfo(abUnit.abName) { assets = assetDataGroup.AssetDatas .Where(assetData => assetData.OwnerBundleName == abUnit.abName) .Select(assetData => assetData.AssetName) .ToArray() }); }); }); var compileUnit = new CodeCompileUnit(); var codeNamespace = new CodeNamespace(ns); compileUnit.Namespaces.Add(codeNamespace); foreach (var assetBundleInfo in assetBundleInfos) { var className = assetBundleInfo.Name; var bundleName = className.Substring(0, 1).ToLower() + className.Substring(1); int firstNumber; if (int.TryParse(bundleName[0].ToString(), out firstNumber)) { continue; } className = className.Substring(0, 1).ToUpper() + className.Substring(1).Replace("/", "_").Replace("@", "_").Replace("!", "_"); var codeType = new CodeTypeDeclaration(className); codeNamespace.Types.Add(codeType); var bundleNameField = new CodeMemberField { Attributes = MemberAttributes.Public | MemberAttributes.Const, Name = "BundleName", Type = new CodeTypeReference(typeof(System.String)) }; codeType.Members.Add(bundleNameField); bundleNameField.InitExpression = new CodePrimitiveExpression(bundleName.ToLowerInvariant()); var checkRepeatDict = new Dictionary <string, string>(); foreach (var asset in assetBundleInfo.assets) { var assetField = new CodeMemberField { Attributes = MemberAttributes.Public | MemberAttributes.Const }; var content = Path.GetFileNameWithoutExtension(asset); assetField.Name = content.ToUpperInvariant().Replace("@", "_").Replace("!", "_"); assetField.Type = new CodeTypeReference(typeof(System.String)); if (!assetField.Name.StartsWith("[") && !assetField.Name.StartsWith(" [") && !checkRepeatDict.ContainsKey(assetField.Name)) { checkRepeatDict.Add(assetField.Name, asset); codeType.Members.Add(assetField); } assetField.InitExpression = new CodePrimitiveExpression(content); } checkRepeatDict.Clear(); } var provider = new CSharpCodeProvider(); var options = new CodeGeneratorOptions { BlankLinesBetweenMembers = false, BracingStyle = "C" }; provider.GenerateCodeFromCompileUnit(compileUnit, writer, options); }