//アセットバンドルのリストを取得 List <MainAssetInfo> GetAssetBudleList(AssetFileManagerSettings settings) { List <MainAssetInfo> assets = new List <MainAssetInfo>(); //指定ディレクトリ以下のアセットを全て取得 MainAssetInfo inputDirAsset = new MainAssetInfo(AssetBundleDirectory); foreach (MainAssetInfo asset in inputDirAsset.GetAllChidren()) { if (asset.IsDirectory) { continue; } if (IsIgnoreAssetBundle(asset)) { continue; } AssetFileSetting assetFileSetting = settings.FindSettingFromPath(asset.AssetPath); AssetFileEncodeType encodeType = assetFileSetting.EncodeType; switch (encodeType) { case AssetFileEncodeType.AssetBundle: assets.Add(asset); break; default: break; } } return(assets); }
//アセットバンドルのリストを取得 List <MainAssetInfo> GetAssetBudleList(MainAssetInfo inputDirAsset) { List <MainAssetInfo> assets = new List <MainAssetInfo>(); //シナリオ用のアセットを取得 assets.AddRange(MakeScenarioAssetBudleList()); //指定ディレクトリ以下のアセットを全て取得 assets.AddRange(MakeAssetBudleList(inputDirAsset)); return(assets); }
//アセットバンドルのビルド void BuildAssetBundles(FileIOManager fileIOManager) { if (buildMode == AssetBundleBuildMode.None) { return; } //アセットバンドルをプラットフォーム別にビルド List <BuildTarget> buildTargets = new List <BuildTarget>(); switch (buildMode) { case AssetBundleBuildMode.OnlyEditor: //エディタ上のみ buildTargets.Add(AssetBundleHelper.BuildTargetFlagToBuildTarget(AssetBundleHelper.EditorAssetBundleTarget())); break; case AssetBundleBuildMode.AllPlatform: //全プラットフォーム { buildTargets = AssetBundleHelper.BuildTargetFlagsToBuildTargetList(buildTargetFlags); } break; default: break; } MainAssetInfo inputDirAsset = new MainAssetInfo(this.ResourcesDirectory); List <MainAssetInfo> assets = GetAssetBudleList(inputDirAsset); RenameAssetBundles(inputDirAsset.AssetPath, assets); AssetBundleBuild[] builds = ToAssetBundleBuilds(assets); if (builds.Length <= 0) { return; } foreach (BuildTarget buildTarget in buildTargets) { string outputPath = FilePathUtil.Combine(OutputPath, AssetBundleHelper.BuildTargetToBuildTargetFlag(buildTarget).ToString()); //出力先のディレクトリを作成 if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } //アセットバンドルを作成 AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(outputPath, builds, buildOptions, buildTarget); Debug.Log("BuildAssetBundles to " + buildTarget.ToString()); if (isOutputLog) { WriteManifestLog(manifest, outputPath); } } }
//アセットバンドル化しないアセットを取得 bool IsIgnoreAssetBundle(MainAssetInfo asset) { string path = asset.AssetPath; if (path.EndsWith("keep.keep")) { return(true); } return(false); }
void EditDirectroy(MainAssetInfo directory) { if (!directory.IsDirectory) { return; } foreach (MainAssetInfo asset in directory.GetAllChidren()) { if (asset.Asset as MonoScript != null) { EditScript(asset); } } }
void EditDirectory(MainAssetInfo directory) { if (!directory.IsDirectory) { return; } foreach (MainAssetInfo asset in directory.GetAllChildren()) { if (asset.Asset is MonoScript || asset.Asset is Shader || asset.Asset is TextAsset) { EditScript(asset); } } }
//フォルダの場合に、フォルダ以下にあるアセットを取得します internal List <MainAssetInfo> GetAllChidren() { List <MainAssetInfo> list = new List <MainAssetInfo>(); if (IsDirectory) { //重複を避けるためにHashSetを使う HashSet <string> guids = new HashSet <string>(AssetDatabase.FindAssets("", new[] { AssetPath })); foreach (string guid in guids) { list.Add(MainAssetInfo.CreateFromGUID(guid)); } } return(list); }
//再ビルドが必要かタイムスタンプをチェック static bool RebuildCheckTimeStamp(DicingTextures target, bool rebuild, out AssetBuildTimeStamp timeStamp) { MainAssetInfo dir = new MainAssetInfo(target.InputDir); timeStamp = dir.MakeBuildTimeStampAllChildren <Texture2D>(); if (rebuild) { return(true); } else { //タイムスタンプが一致するなら、再ビルド必要ない return(!target.BuildTimeStamp.Compare(timeStamp)); } }
void EditScript(MainAssetInfo asset) { try { string text = File.ReadAllText(asset.FullPath); if (text.Contains("\r\n")) { File.WriteAllText(asset.FullPath, text.Replace("\r\n", "\n"), System.Text.Encoding.Unicode); Debug.Log(asset.FullPath); } } catch (System.Exception e) { Debug.LogError(e.Message); } }
//ファイルの読み込み void ImportSub(AdvScenarioDataProject project) { Project = project; if (project.ChapterDataList.Count <= 0) { Debug.LogError("ChapterDataList is zeo"); return; } AssetFileManager.ClearCheckErrorInEditor(); AssetFileManager.IsEditorErrorCheck = true; AdvCommand.IsEditorErrorCheck = true; AdvCommand.IsEditorErrorCheckWaitType = project.CheckWaitType; UnityEngine.Profiling.Profiler.BeginSample("Import Scenarios"); AdvEngine engine = UtageEditorToolKit.FindComponentAllInTheScene <AdvEngine>(); if (engine != null) { engine.BootInitCustomCommand(); } this.scenarioDataTbl = new Dictionary <string, AdvScenarioData>(); this.macroManager = new AdvMacroManager(); AdvScenarioDataBuilderWindow.ProjectData.CreateScenariosIfMissing(); this.scenariosAsset = project.Scenarios; this.scenariosAsset.ClearOnImport(); //チャプターデータのインポート project.ChapterDataList.ForEach(x => ImportChapter(x.chapterName, x.ExcelPathList)); //ファイルが存在しているかチェック if (project.RecourceDir != null) { string path = new MainAssetInfo(project.RecourceDir).FullPath; AssetFileManager.CheckErrorInEditor(path, project.CheckExt); } UnityEngine.Profiling.Profiler.EndSample(); EditorUtility.SetDirty(this.scenariosAsset); AssetDatabase.Refresh(); AdvCommand.IsEditorErrorCheck = false; AdvCommand.IsEditorErrorCheckWaitType = false; AssetFileManager.IsEditorErrorCheck = false; }
void Build(MainAssetInfo textureDir, MainAssetInfo output1, MainAssetInfo output2, bool isRebuild) { //スクリプタブルオブジェクトの取得(なければ作成) string name = textureDir.Asset.name; DicingTextures dicingAsset = UtageEditorToolKit.GetImportedAssetCreateIfMissing <DicingTextures>(FilePathUtil.Combine(output1.AssetPath, name + ".asset")); Object outPutDir = UtageEditorToolKit.GetFolderAssetCreateIfMissing(output2.AssetPath, name); //情報を設定 dicingAsset.InputDir = textureDir.Asset; dicingAsset.OutputDir = outPutDir; if (dicingAsset.InputDir == null || dicingAsset.OutputDir == null) { Debug.LogError("Folder is not found"); return; } //パッキング処理 DicingTexturePacker.Pack(dicingAsset, isRebuild); }
//まとめる対象のテクスチャをロード static List <TextureInfo> LoadTextures(DicingTextures target) { List <TextureInfo> textures = new List <TextureInfo>(); MainAssetInfo dir = new MainAssetInfo(target.InputDir); int count = 0; List <MainAssetInfo> assets = dir.GetAllChildren(); foreach (var asset in assets) { if (asset.Asset is Texture2D) { textures.Add(new TextureInfo(asset.Asset as Texture2D, target)); } ++count; DisplayProgressBar(target, 0.3f * count / assets.Count, "Load Textures"); } return(textures); }
//リソースファイルをバージョンアップ public void VersionUpResouces(string keyFiles, Object resourcesDir, bool isOnlyNew) { //指定ディレクトリ以下のアセットを全て取得 MainAssetInfo inputDirAsset = new MainAssetInfo(resourcesDir); List <MainAssetInfo> assets = inputDirAsset.GetAllChidren(); string inputDir = inputDirAsset.AssetPath; List <ConvertFileList.CusomFileVersionUpInfo> customFileVersionUpInfoList = new List <ConvertFileList.CusomFileVersionUpInfo>(); int convertFileCount = 0; int versionUpCount = 0; foreach (MainAssetInfo asset in assets) { if (asset.IsDirectory) { continue; } AssetFileSetting assetFileSetting = Settings.FindSettingFromPath(asset.AssetPath); AssetFileEncodeType encodeType = assetFileSetting.EncodeType; switch (encodeType) { case AssetFileEncodeType.AlreadyEncoded: { ++convertFileCount; bool isVersionUp = TryConvertToUtageFile(asset, inputDir, isOnlyNew); if (isVersionUp) { ++versionUpCount; } string fileKey = FilePathUtil.RemoveDirectory(asset.AssetPath, inputDir); customFileVersionUpInfoList.Add(new ConvertFileList.CusomFileVersionUpInfo(fileKey, isVersionUp)); } break; default: break; } } ConvertFileList.EditorVersionUp(keyFiles, customFileVersionUpInfoList); Debug.Log(string.Format("{0}/{1}files version up", versionUpCount, convertFileCount)); }
//アセットバンドルのリストを取得 List <MainAssetInfo> MakeAssetBudleList(MainAssetInfo inputDirAsset) { List <MainAssetInfo> assets = new List <MainAssetInfo>(); //指定ディレクトリ以下のアセットを全て取得 foreach (MainAssetInfo asset in inputDirAsset.GetAllChildren()) { if (asset.IsDirectory) { continue; } if (IsIgnoreAssetBundle(asset)) { continue; } assets.Add(asset); } return(assets); }
//宴独自形式へのコンバート bool TryConvertToUtageFile(MainAssetInfo asset, string inputDir, bool isOnlyNew) { string outputFileName = ToOutPutFilePath(asset.AssetPath, inputDir); AssetFileSetting setting = Settings.FindSettingFromPath(outputFileName); if (setting.EncodeType == AssetFileEncodeType.AlreadyEncoded) { outputFileName += ExtensionUtil.UtageFile; } //新しいファイルのみコピー if (isOnlyNew) { if (File.Exists(outputFileName) && File.GetLastWriteTime(asset.FullPath) <= File.GetLastWriteTime(outputFileName)) { return(false); } } return(TryConvertFileFromMem(outputFileName, File.ReadAllBytes(asset.FullPath))); }
//シナリオのアセットバンドルのリストを取得 List <MainAssetInfo> MakeScenarioAssetBudleList() { List <MainAssetInfo> assets = new List <MainAssetInfo>(); //章別に分割するかどうか if (separateChapter) { string[] pathList = AssetDatabase.GetDependencies(AssetDatabase.GetAssetPath(ProjectSetting.Scenarios)); foreach (string path in pathList) { MainAssetInfo assetInfo = new MainAssetInfo(path); if (assetInfo.Asset is AdvChapterData) { assets.Add(assetInfo); } } } else { assets.Add(new MainAssetInfo(ProjectSetting.Scenarios)); } return(assets); }
//ファイルのコンバート void Build(bool isRebuild, DicingFolderData folderData) { MainAssetInfo inut = new MainAssetInfo(folderData.InputFolder); MainAssetInfo output1 = new MainAssetInfo(folderData.OuputFolder1); MainAssetInfo output2 = new MainAssetInfo(folderData.OuputFolder2); foreach (var child in inut.GetAllChildren()) { //ディレクトリのみ検索 if (!child.IsDirectory) { continue; } //子以下のフォルダは対象にしない if (FilePathUtil.GetDirectoryPath(child.AssetPath) != inut.AssetPath) { continue; } Build(child, output1, output2, isRebuild); } AssetDatabase.Refresh(); }
public SubAssetInfo(Object asset, MainAssetInfo mainAsset) : base(asset) { this.MainAsset = mainAsset; }
//ファイルのコンバート void Convert() { try { AssetFileManager assetFileManager = FindObjectOfType <AssetFileManager>(); if (assetFileManager == null) { Debug.LogError("FileManager is not found in current scene"); return; } //ファイルの入出力に使う FileIOManager fileIOManager = assetFileManager.FileIOManger; AssetFileManagerSettings settings = assetFileManager.Settings; if (outputType == OutputType.Default) { AssetFileManagerSettings.LoadType loadType = settings.LoadTypeSetting; if (isOutputLocal && LocalDirectory != null) { //ローカルの場合は、LoadTypeをLocalCompressedに settings.LoadTypeSetting = AssetFileManagerSettings.LoadType.LocalCompressed; string output = new MainAssetInfo(LocalDirectory).FullPath; //リソースをバージョンアップ AdvFileListConverter converter = new AdvFileListConverter(output, fileIOManager, settings); converter.VersionUp(VersionUpLocalFiles); if (isOutputLocalLog) { converter.WriteLog(false); } } if (isOutputServer && !string.IsNullOrEmpty(OutputServerResourcePath)) { //サーバーの場合は、LoadTypeをServerに settings.LoadTypeSetting = AssetFileManagerSettings.LoadType.Server; //シナリオやリソースをバージョンアップ AdvFileListConverter converter = new AdvFileListConverter(OutputServerResourcePath, fileIOManager, settings); converter.VersionUp(VersionUpServerFiles); if (isOutputServerLog) { converter.WriteLog(false); } //アセットバンドルをビルド BuildAssetBundles(OutputServerResourcePath, fileIOManager, settings, isOutputServerLog); } settings.LoadTypeSetting = loadType; } else { //シナリオやリソースをバージョンアップ AdvFileListConverter converter = new AdvFileListConverter(AdvancedOutputPath, fileIOManager, settings); converter.VersionUp(VersionUpAdvanceFiles); if (isOutputAdvancedLog) { converter.WriteLog(false); } //アセットバンドルをビルド BuildAssetBundles(AdvancedOutputPath, fileIOManager, settings, isOutputAdvancedLog); } AssetDatabase.Refresh(); } catch (System.Exception e) { Debug.LogException(e); } }