public virtual void Build() { Clear(); var buildList = GetBuildList(); if (buildList != null && buildList.Count > 0) { BuildAssetBundleOptions bundleOptions;//打包设置: bundleOptions = BuildAssetBundleOptions.None; bundleOptions |= BuildAssetBundleOptions.ChunkBasedCompression; bundleOptions |= BuildAssetBundleOptions.DeterministicAssetBundle; bundleOptions |= BuildAssetBundleOptions.DisableLoadAssetByFileName; bundleOptions |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; var buildExportPath = AssetBuildConfiger.GetInstance().GetExportFolderPath(); var buildPlatform = AssetBuildConfiger.GetInstance().GetBuildType(); if (!XFolderTools.Exists(buildExportPath)) { XFolderTools.CreateDirectory(buildExportPath); } BuildPipeline.BuildAssetBundles(buildExportPath, buildList.ToArray(), bundleOptions, buildPlatform); } }
public static void TryCreateFolder(string path) { if (!XFolderTools.Exists(path)) { XFolderTools.CreateDirectory(path); } }
//拆成10个 public static void SaveAllLevelPrefabs(GameObject srcGO, string savePath) { if (srcGO) { string effectId = XStringTools.SplitPathKey(srcGO.name); string finalPath = Path.Combine(savePath, effectId); if (!XFolderTools.Exists(finalPath)) { XFolderTools.CreateDirectory(finalPath); } for (int i = 1; i <= EffectLevelUtil.MAX_LEVEL; i++) { string saveName = Path.Combine(finalPath, string.Format("{0}_{1:D2}.prefab", effectId, i)); SavePrefabByLevel(srcGO, saveName, i); } } }
static T GetOrCreateAsset() { T asset = null; if (XFileTools.Exists(_configAssetsPath)) { asset = AssetDatabase.LoadAssetAtPath <T>(_configAssetsPath); } else { asset = ScriptableObject.CreateInstance <T>(); if (!XFolderTools.Exists(_saveFolder)) { XFolderTools.CreateDirectory(_saveFolder); } AssetDatabase.CreateAsset(asset, _configAssetsPath); AssetDatabase.Refresh(); } return(asset); }
private void DoStart() { _assetMap.Clear(); _checkfilePath2srcAssetPath.Clear(); _processPath2srcAssetPath.Clear(); string processFolderPath = AssetProcesserConfiger.GetInstance().GetProcessFloderPath(); if (!XFolderTools.Exists(processFolderPath)) { XFolderTools.CreateDirectory(processFolderPath); } string outputPath = AssetProcesserConfiger.GetInstance().GetProcessSaveFolderPath(_progresersName); if (!XFolderTools.Exists(outputPath)) { XFolderTools.CreateDirectory(outputPath); } OnStart(); }
protected bool SaveCheckfile(string srcPath, AssetProcessCheckfile checkfile) { if (checkfile == null) { return(false); } string checkfileSavePath = GetCheckfilePath(srcPath); if (!XFileTools.Exists(checkfileSavePath)) { string checkfileParentPath = Path.GetDirectoryName(checkfileSavePath); if (!XFolderTools.Exists(checkfileParentPath)) { XFolderTools.CreateDirectory(checkfileParentPath); } } AssetDatabase.DeleteAsset(checkfileSavePath); AssetDatabase.CreateAsset(checkfile, checkfileSavePath); return(true); }
private void BuildAll() { Build4Common(); Build4Custom(); Build4Share(); BuildAssetBundleOptions bundleOptions;//打包设置: bundleOptions = BuildAssetBundleOptions.None; bundleOptions |= BuildAssetBundleOptions.ChunkBasedCompression; bundleOptions |= BuildAssetBundleOptions.DeterministicAssetBundle; bundleOptions |= BuildAssetBundleOptions.DisableLoadAssetByFileName; bundleOptions |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; var buildExportPath = AssetBuildConfiger.GetInstance().GetExportFolderPath(); var buildPlatform = AssetBuildConfiger.GetInstance().GetBuildType(); if (!XFolderTools.Exists(buildExportPath)) { XFolderTools.CreateDirectory(buildExportPath); } BuildPipeline.BuildAssetBundles(buildExportPath, GetBuildsArray(), bundleOptions, buildPlatform); }
/// <summary> /// 生成动画及控制器 /// sprite子项命名规则:组_动作名_编号,没有编号的一律不生成Anima /// </summary> /// <param name="assetPath"></param> public static Dictionary <string, Dictionary <string, AnimationClip> > GenerateAnimationClipFromTextureFile(string assetPath, string saveRootPath = "", System.Action <AnimationClip> callback = null) { string assetFileNonExtName = Path.GetFileNameWithoutExtension(assetPath); string assetRootPath = Path.GetDirectoryName(assetPath); TextureImporter importer = LoadImporterFromTextureFile(assetPath); if (importer) { //判断是否是精灵图集 if (!(importer.textureType == TextureImporterType.Sprite && importer.spriteImportMode == SpriteImportMode.Multiple)) { return(null); } //获取所有精灵帧 Object[] sheetObjs = AssetDatabase.LoadAllAssetsAtPath(assetPath); var sheetDict = new Dictionary <string, Dictionary <string, SortedList <string, SpriteSheetFrameData> > >(); foreach (var obj in sheetObjs) { SpriteSheetFrameData metadata = SpriteSheetFrameData.TryCreate(obj as Sprite); if (metadata != null) { string groupName = metadata.groupName; Dictionary <string, SortedList <string, SpriteSheetFrameData> > actionMaps; if (sheetDict.ContainsKey(groupName)) { actionMaps = sheetDict[groupName]; } else { actionMaps = new Dictionary <string, SortedList <string, SpriteSheetFrameData> >(); sheetDict.Add(groupName, actionMaps); } // string actionName = metadata.actionName; SortedList <string, SpriteSheetFrameData> frameList; if (actionMaps.ContainsKey(actionName)) { frameList = actionMaps[actionName]; } else { frameList = new SortedList <string, SpriteSheetFrameData>(); actionMaps.Add(actionName, frameList); } string idName = metadata.idName; if (frameList.ContainsKey(idName)) { Debug.LogWarning(string.Format("{0}_{1}重复ID:{2}", groupName, actionName, idName)); metadata.idName = string.Format("{0}_{1}", metadata.idName, frameList.Count); idName = metadata.idName; } frameList.Add(idName, metadata); } } if (saveRootPath == "") { saveRootPath = assetRootPath; } Dictionary <string, Dictionary <string, AnimationClip> > outMap = new Dictionary <string, Dictionary <string, AnimationClip> >(); foreach (var groupPair in sheetDict) { //保存资源 string groupName = groupPair.Key; string[] subFolders = groupName.Split(new char[] { '@' }); string saveOutRootPath = saveRootPath; for (int i = 0; i < subFolders.Length; i++) { saveOutRootPath = XPathTools.Combine(saveOutRootPath, subFolders[i]); if (!XFolderTools.Exists(saveOutRootPath)) { XFolderTools.CreateDirectory(saveOutRootPath); } } Dictionary <string, AnimationClip> outActionMap; if (outMap.ContainsKey(groupName)) { outActionMap = outMap[groupName]; } else { outActionMap = new Dictionary <string, AnimationClip>(); outMap.Add(groupName, outActionMap); } foreach (var actionPair in groupPair.Value) { //保存动画Clip string outName = actionPair.Key; string saveName = string.Format("{0}.anim", outName); string savePath = Path.Combine(saveOutRootPath, saveName); List <Sprite> spriteList = new List <Sprite>(); foreach (var listPair in actionPair.Value) { spriteList.Add(listPair.Value.sprite); } AnimationClip clip = MakeAnimationClip(spriteList.ToArray(), SpriteToolsConfig.GetInstance().defaultFrameRate, savePath); outActionMap.Add(actionPair.Key, clip); if (callback != null) { callback(clip); } } } return(outMap); } return(null); }
static void BuildAssembly(bool wait) { for (int i = 0; i < AssembliesToolsConfig.GetInstance().buildPathList.Count; i++) { var buildInfo = AssembliesToolsConfig.GetInstance().buildPathList[i]; if (!string.IsNullOrEmpty(buildInfo.srcPath) && !string.IsNullOrEmpty(buildInfo.buildPath) && !string.IsNullOrEmpty(buildInfo.projectPath)) { bool[] editorFlags = { true, true, true, true }; List <string> csFilePaths = new List <string>(); XFolderTools.TraverseFiles(buildInfo.srcPath, (string fullPath) => { if (Path.GetExtension(fullPath) == ".cs") { csFilePaths.Add(fullPath); } }, true); string srcPathName = Path.GetFileNameWithoutExtension(buildInfo.srcPath); string outputAssembly = XPathTools.Combine(buildInfo.buildPath, string.Format("{0}.dll", srcPathName)); string assemblyProjectPath = XPathTools.Combine(buildInfo.projectPath, string.Format("{0}.dll", srcPathName)); if (csFilePaths.Count > 0) { if (!XFolderTools.Exists(buildInfo.buildPath)) { XFolderTools.CreateDirectory(buildInfo.buildPath); } if (!XFolderTools.Exists(buildInfo.projectPath)) { XFolderTools.CreateDirectory(buildInfo.projectPath); } bool editorFlag = editorFlags[i]; var assemblyBuilder = new AssemblyBuilder(outputAssembly, csFilePaths.ToArray()); // Exclude a reference to the copy of the assembly in the Assets folder, if any. assemblyBuilder.excludeReferences = new string[] { assemblyProjectPath }; if (editorFlag) { assemblyBuilder.flags = AssemblyBuilderFlags.EditorAssembly; } // Called on main thread assemblyBuilder.buildStarted += delegate(string assemblyPath) { Debug.LogFormat("Assembly build started for {0}", assemblyPath); }; // Called on main thread assemblyBuilder.buildFinished += delegate(string assemblyPath, CompilerMessage[] compilerMessages) { foreach (var v in compilerMessages) { if (v.type == CompilerMessageType.Error) { Debug.LogError(v.message); } else { Debug.LogWarning(v.message); } } var errorCount = compilerMessages.Count(m => m.type == CompilerMessageType.Error); var warningCount = compilerMessages.Count(m => m.type == CompilerMessageType.Warning); Debug.LogFormat("Assembly build finished for {0}", assemblyPath); Debug.LogFormat("Warnings: {0} - Errors: {0}", errorCount, warningCount); if (errorCount == 0) { File.Copy(outputAssembly, assemblyProjectPath, true); AssetDatabase.ImportAsset(assemblyProjectPath); } }; // Start build of assembly if (!assemblyBuilder.Build()) { Debug.LogErrorFormat("Failed to start build of assembly {0}!", assemblyBuilder.assemblyPath); return; } if (wait) { while (assemblyBuilder.status != AssemblyBuilderStatus.Finished) { System.Threading.Thread.Sleep(10); } } } else { XFileTools.Delete(assemblyProjectPath); continue; } } } }