protected void Save(string key) { //_MainAssetBundleManifest = C_Singleton<GameResMgr>.Instance.GetAssetBundleManifest(key); if (!_Dic.ContainsKey(key)) { MessageBoxEditor.ShowErrorBox("加载资源信息收集出错", key + "不在设置中,让黄志龙检查", "好的"); return; } SaveLoadingRes(key, false); string content = ""; string result = Load(key); string[] data = result.Split('\n'); //string md5 = ""; for (int i = 0; i < data.Length; i++) { //string path = LocalPath.LocalPackagingResources + data[i]; string path = data[i]; EditorUtility.DisplayProgressBar("创建md5值: ", path, (float)i / (float)data.Length); //if (File.Exists(path)) //{ // md5 = getFileHash(path); // content += data[i] + "|" + md5 + "\n"; //} //else //{ // Debug.LogError(path+"没有打包,请检查打包资源"); // continue; //} if (string.IsNullOrEmpty(path)) { continue; } //资源对象 //if (_MainAssetBundleManifest == null || Hash128.Parse("0") == _MainAssetBundleManifest.GetAssetBundleHash(path)) //{ // Debug.LogError("path :"+path+ "没有打入总表,或者_MainAssetBundleManifest 总表不存在"); // continue; //} // content += setFileMd5(content, path); //查找依赖项 List <string> dpsList = C_Singleton <GameResMgr> .Instance.GetAllDependencies(path); for (int j = 0; j < dpsList.Count; j++) { content += setFileMd5(content, dpsList[j]); } } EditorUtility.ClearProgressBar(); string configPath = LocalPath.LocalHotUpdateConfigPath + key + ".txt"; FileTools.CreateDir(LocalPath.LocalHotUpdateConfigPath); FileTools.CreateFile(configPath, content); MessageBoxEditor.ShowErrorBox("assetbundle资源版本创建", "资源版本创建完成", "好的"); }
protected virtual void AutoSave() { string Result = ""; foreach (string key in _Dic.Keys) { Result += Load(key); string path = Application.dataPath + "/Resources/PackagingResources/Config/Loading/"; FileTools.CreateDir(path); //更新当前角色的动画设置 FileTools.CreateFile(path + key + ".txt", Result); } MessageBoxEditor.ShowErrorBox("收集结束", "加载文件创建完成", "好的"); }
////按照单集的每个分割点进行收集数据 protected void SaveSplitLoadingRes(string key, bool msg = true) { string Result = ""; int sum = 0; foreach (string k in _DicSplitRes[key].Keys)///每一个key对应一个保存信息的文本 { Result = ""; EditorUtility.DisplayProgressBar("加载资源信息收集: ", k, (float)sum++ / (float)_DicSplitRes[key].Keys.Count); //对每个资源进行加载 //k表示每个资源的文件名字,每个资源_DicSplitRes[key][k][i] if (!string.IsNullOrEmpty(_DicSplitRes[key][k][0]) && !string.IsNullOrEmpty(_DicSplitRes[key][k][_DicSplitRes[key][k].Count - 1])) { //打开对应的场景,并做相应的移动,只支持一个场景 _ActiveDestionScene = EditorSceneManager.OpenScene(_Dic[key][0], OpenSceneMode.Additive); EditorSceneManager.SetActiveScene(_ActiveDestionScene); //找到cutsceneplayer ,获取所有对象 GameObject player = GameObject.Find("CutsceneSequencePlayer"); if (player != null) { CutsceneSequencePlayer cutPlayer = player.GetComponent <CutsceneSequencePlayer>(); if (cutPlayer == null) { MessageBoxEditor.ShowErrorBox("加载资源信息收集出错", key + "没有CutsceneSequencePlayer对象,加载文件创建失败,请检查后重试", "好的"); return; } Result += cutPlayer.ReadLoadingMsg(_DicSplitRes[key][k][0], _DicSplitRes[key][k][_DicSplitRes[key][k].Count - 1], Result); } EditorSceneManager.CloseScene(_ActiveDestionScene, true); //更新当前角色的动画设置 FileTools.CreateDir(savePath); FileTools.CreateFile(savePath + k + ".txt", Result); } EditorUtility.ClearProgressBar(); } if (msg) { MessageBoxEditor.ShowErrorBox("收集结束", key + "加载文件创建完成", "好的"); } }
protected virtual void SaveLoadingRes(string key, bool msg = true) { if (!_Dic.ContainsKey(key)) { MessageBoxEditor.ShowErrorBox("加载资源信息收集出错", key + "不在设置中,让黄志龙检查", "好的"); return; } string Result = Load(key); string path = Application.dataPath + "/Resources/PackagingResources/Config/Loading/"; //更新当前角色的动画设置 FileTools.CreateDir(path); FileTools.CreateFile(path + key + ".txt", Result); if (msg) { MessageBoxEditor.ShowErrorBox("收集结束", key + "加载文件创建完成", "好的"); } }
protected virtual string Load(string key) { bool mark = false; string Result = ""; for (int i = 0; i < _Dic[key].Count; i++) { if (!string.IsNullOrEmpty(_Dic[key][i])) { mark = true; EditorUtility.DisplayProgressBar("加载资源信息收集: ", _Dic[key][i], (float)i / (float)_Dic[key].Count); //打开对应的场景,并做相应的移动 _ActiveDestionScene = EditorSceneManager.OpenScene(_Dic[key][i], OpenSceneMode.Additive); EditorSceneManager.SetActiveScene(_ActiveDestionScene); //找到cutsceneplayer ,获取所有对象 GameObject player = GameObject.Find("CutsceneSequencePlayer"); if (player != null) { CutsceneSequencePlayer cutPlayer = player.GetComponent <CutsceneSequencePlayer>(); if (cutPlayer == null) { MessageBoxEditor.ShowErrorBox("加载资源信息收集出错", key + "没有CutsceneSequencePlayer对象,加载文件创建失败,请检查后重试", "好的"); return(""); } Result += cutPlayer.NewReadLoadingMsg(key, Result); } EditorSceneManager.CloseScene(_ActiveDestionScene, true); } } if (mark) { EditorUtility.ClearProgressBar(); } return(Result); }
public static void CreatAnimatorController() { Transform[] transforms = Selection.GetTransforms(SelectionMode.TopLevel | SelectionMode.ExcludePrefab); for (int i = 0; i < transforms.Length; i++) { AnimatorController animatorController = null; string path = Application.dataPath + "/FBX/" + transforms[i].name + ".controller"; if (transforms[i].GetComponent <Animator>() == null) { transforms[i].gameObject.AddComponent <Animator>(); } string directory = "Assets/FBX/AnimatorController/"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string fileName = directory + transforms[i].name + "_AnimatorController.controller"; if (FileTools.IsFileExited(fileName)) { _LoadAnimatorCtrlPath = Application.dataPath + "/FBX/AnimatorController/" + transforms[i].name + "_AnimatorController.controller"; MessageBoxEditor.ShowSaveFileBoxComplex("创建动画控制器", fileName + "存在,是否覆盖", "不覆盖,直接使用", "新建", "连线", () => { animatorController = (AnimatorController)transforms[i].GetComponent <Animator>().runtimeAnimatorController; transforms[i].GetComponent <Animator>().runtimeAnimatorController = animatorController; }, () => { DirectoryInfo dir = new DirectoryInfo(Application.dataPath + "/FBX/AnimatorController/"); FileInfo[] fileInfo = dir.GetFiles(); string filePath = directory + transforms[i].name; int num = 0; string fileMark = fileName.Substring(fileName.LastIndexOf("/") + 1); int index = fileMark.LastIndexOf("_AnimatorController") + 1; string fileSubMark = fileMark.Substring(0, index); for (int k = 0; k < fileInfo.Length; k++) { if (fileInfo[k].Name.Contains(".meta") && fileInfo[k].Name.Contains(fileSubMark)) { num++; } } fileName = directory + transforms[i].name + "_" + num.ToString() + "_AnimatorController.controller"; animatorController = AnimatorController.CreateAnimatorControllerAtPath(fileName); transforms[i].GetComponent <Animator>().runtimeAnimatorController = animatorController; }, () => { animatorController = (AnimatorController)transforms[i].GetComponent <Animator>().runtimeAnimatorController; if (animatorController == null) { MessageBoxEditor.ShowErrorBox("创建出错", fileName + "没有动画控制器,需要先创建", "确认", () => { }); } }); } else { animatorController = AnimatorController.CreateAnimatorControllerAtPath(fileName); transforms[i].GetComponent <Animator>().runtimeAnimatorController = animatorController; } if (animatorController == null) { return; } AnimatorControllerLayer acl = animatorController.layers[0]; AnimatorStateMachine sm = acl.stateMachine; //创建一个空的状态,并且设置为默认 //int index = Array.FindIndex(sm.states, e => e.state.name.Equals("Empty")); for (int id = 0; id < sm.states.Length;) { if (sm.states[id].state.name.Equals("Empty") || sm.states[id].state.name.Contains("Empty")) { sm.RemoveState(sm.states[id].state); id--; } id++; } sm.defaultState = sm.AddState("Empty"); //删除所有的参数和参数连线 AnimatorControllerParameter[] animatorParameters = animatorController.parameters; if (animatorParameters != null && animatorParameters.Length > 0) { for (int p = 0; p < animatorParameters.Length; p++) { animatorController.RemoveParameter(animatorParameters[p]); } } animatorParameters = null; //新增所有的参数和参数连线 int length = sm.states.Length; for (int j = 0; j < length; j++) { string parameterTmp = ""; if (sm.states[j].state != null && sm.states[j].state.motion != null) { parameterTmp = sm.states[j].state.motion.name; } //如果是第一个对象,则第一个对象与最后一个对象形成切换条件 if (j == 0) { //空状态到第一个状态 SetConditionAndParameter(animatorController, sm, parameterTmp, 0, sm.states.Length - 1); } else if (j < sm.states.Length - 1)//其余的对象,当前的切换条件设置在前一个对象 { SetConditionAndParameter(animatorController, sm, parameterTmp, j, j - 1); } } } }
public override void Move(int i, bool single = false) { //if (i < 0) //{ // Debug.LogError("没有指定平台..."); // return; //} try { for (int j = 0; j < StoryName.Length; j++) { if (!_StoryDic[StoryName[j]]) { continue; } //查找资源 string config = _ConfigPath + StoryName[j] + ".txt"; if (!FileTools.IsFileExited(config)) { MessageBoxEditor.ShowErrorBox("移动内置资源", config + "不存在,移动内置资源失败", "好的"); continue; } string data = getContent(config); string[] result = data.Split('\n'); for (int k = 0; k < result.Length; k++) { //找到这个文件的资源 result[k] = result[k].Split('\r')[0]; result[k] = Assets.Scripts.C_Framework.C_String.DeleteExpandedName(result[k]);//去掉后缀 if (string.IsNullOrEmpty(result[k])) { continue; } if (!_ResPathList.Contains(result[k])) { _ResPathList.Add(result[k]); } } } //删除没有用到的资源 int deleteSum = 0; string PackResPath = Application.dataPath + "/Resources/PackagingResources"; List <string> ResDirectoryPaths = new List <string>(); ResDirectoryPaths = GetFile(PackResPath, ResDirectoryPaths); for (int resId = 0; resId < ResDirectoryPaths.Count; resId++) { if (Path.GetExtension(ResDirectoryPaths[resId]).Equals(".meta")) { continue; } ResDirectoryPaths[resId] = ResDirectoryPaths[resId].Replace("\\", "/"); //删除不存在表格的资源 if (!DeleteRes(ResDirectoryPaths[resId]) && FileTools.IsFileExited(ResDirectoryPaths[resId])) { File.Delete(ResDirectoryPaths[resId]); File.Delete(ResDirectoryPaths[resId] + ".meta"); Debug.Log("删除资源:" + ResDirectoryPaths[resId]); Debug.Log("删除资源:" + ResDirectoryPaths[resId] + ".meta"); deleteSum++; } } Debug.Log("cleanup res over....删除资源个数:" + deleteSum); } catch (Exception e) { Debug.LogError(e); } }
public void MoveTest(int i, bool single = false) { if (i < 0) { Debug.LogError("没有指定平台..."); return; } for (int j = 0; j < StoryName.Length; j++) { if (!_StoryDic[StoryName[j]]) { continue; } string AssetDestionResPath = ""; if (single) { //每一集单独一个资源文件夹 _DestionResPath = LocalPath.HotUpdatePath + "builtin/" + _Plamtform[i] + StoryName[j] + "Internal"; AssetDestionResPath = "Assets/builtin/" + _Plamtform[i] + StoryName[j] + "Internal"; } else { _DestionResPath = LocalPath.HotUpdatePath + "builtin/" + _Plamtform[i] + _Plamtform[i] + "Internal"; AssetDestionResPath = "Assets/builtin/" + _Plamtform[i] + _Plamtform[i] + "Internal"; } // _DestionResPath = Application.dataPath + "/builtin/" + _Plamtform[i] + _Plamtform[i] + "Internal"; //目标文件夹路径 FileTools.CreateDir(_DestionResPath); //查找资源 string config = _ConfigPath + StoryName[j] + ".txt"; if (!FileTools.IsFileExited(config)) { MessageBoxEditor.ShowErrorBox("移动内置资源", config + "不存在,移动内置资源失败", "好的"); continue; } string data = getContent(config); string[] result = data.Split('\n'); for (int k = 0; k < result.Length; k++) { //找到这个文件的资源 result[k] = result[k].Split('\r')[0]; result[k] = Assets.Scripts.C_Framework.C_String.DeleteExpandedName(result[k]);//去掉后缀 if (string.IsNullOrEmpty(result[k])) { continue; } string resDir = Assets.Scripts.C_Framework.C_String.GetSavePath(result[k]); //保存资源的子目录 string resFileName = Assets.Scripts.C_Framework.C_String.GetFileName(result[k]); //获取资源的名字 string res = _ResPath + resDir; if (!Directory.Exists(res)) //在资源项目结构中的位置 { // Debug.LogError("工程中不存在资源文件夹:"+res); continue; } string[] DirectoryPaths = Directory.GetFiles(res); //获取该资源结构文件夹中的所有文件 //foreach (string dirpath in DirectoryPaths) for (int pathId = 0; pathId < DirectoryPaths.Length; pathId++) { string dirpath = DirectoryPaths[pathId]; if (string.IsNullOrEmpty(dirpath)) { continue; } if (Path.GetExtension(dirpath).Equals(".meta")) { continue; } string dirpathTemp = dirpath.ToLower(); string mark = "PackagingResources/"; int id = dirpath.LastIndexOf(mark) + mark.Length; string filePath = ""; if (id == -1) { filePath = dirpath; } else if (id + 1 >= dirpath.Length) { continue; } else { filePath = dirpath.Substring(id); } if (string.IsNullOrEmpty(filePath)) { continue; } string filePathNoEx = Assets.Scripts.C_Framework.C_String.DeleteExpandedName(filePath);//去掉后缀 string desFileName = (resDir + resFileName).ToLower(); if (!filePathNoEx.ToLower().Equals(desFileName)) { continue; } Debug.Log("移动资源:" + dirpath); try { //创建资源移动的目标资源子目录 FileTools.CreateDir(_DestionResPath + "/" + resDir); //将资源从项目工程文件夹移动到目标文件夹中,覆盖方式拷贝 string destionPathFile = _DestionResPath + "/" + filePath; string destionPathFileMeta = _DestionResPath + "/" + filePath + ".meta"; if (FileTools.IsFileExited(destionPathFile)) { File.Delete(destionPathFile); } if (FileTools.IsFileExited(destionPathFileMeta)) { File.Delete(destionPathFileMeta); } // string tmp =Application.dataPath+ "/Resources/PackagingResources/" + filePath; string tmp = DirectoryPaths[pathId]; string tmpMeta = tmp + ".meta"; // AssetDatabase.CopyAsset(tmp, destionPathFile); // AssetDatabase.CopyAsset(tmpMeta, destionPathFileMeta); // File.Copy(tmp, destionPathFile,true); // File.Copy(tmpMeta, destionPathFileMeta, true); FileInfo fileInfo = new FileInfo(tmp); if (!fileInfo.Exists) { Debug.LogError(fileInfo.FullName + "is not exited.."); } fileInfo.CopyTo(destionPathFile, true); FileInfo fileInfoMeta = new FileInfo(tmp); fileInfoMeta.CopyTo(destionPathFileMeta, true); if (!fileInfoMeta.Exists) { Debug.LogError(fileInfoMeta.FullName + "is not exited.."); } } catch (Exception e) { Debug.LogError(e); continue; } } } } }
public virtual void Move(int i, bool single = false) { Debug.Log("开始移动"); for (int j = 0; j < StoryName.Length; j++) { if (!_StoryDic[StoryName[j]]) { continue; } if (single) { //每一集单独一个资源文件夹 _DestionResPath = LocalPath.HotUpdatePath + "builtin/" + _Plamtform[i] + StoryName[j] + "/"; } else { _DestionResPath = LocalPath.HotUpdatePath + "builtin/" + _Plamtform[i] + _Plamtform[i]; } //目标文件夹路径 FileTools.CreateDir(_DestionResPath); //查找资源 string config = _ConfigPath + StoryName[j] + ".txt"; if (!FileTools.IsFileExited(config)) { MessageBoxEditor.ShowErrorBox("移动内置资源", config + "不存在,移动内置资源失败", "好的"); continue; } string data = getContent(config); data.Replace("\r", ""); string[] result = data.Split('\n'); for (int k = 0; k < result.Length; k++) { if (string.IsNullOrEmpty(result[k])) { continue; } result[k] = result[k].Split('\r')[0]; string res = _ResPath + result[k]; if (string.IsNullOrEmpty(res))//资源名字 { continue; } if (!Directory.Exists(_ResPath)) { Debug.LogError("不存在资源目录:" + _ResPath); continue; } //移动到目标文件夹,如果文件夹不存在,先创建 if (!File.Exists(res)) { Debug.LogError("不存在资源:" + res); continue; } string subFloder = Assets.Scripts.C_Framework.C_String.GetSavePath(result[k]);//= result[k].Substring(0, result[k].LastIndexOf('/') > -1 ? result[k].LastIndexOf('/') : result[k].Length); if (FileTools.CreateDir(_DestionResPath + subFloder)) { // Debug.Log(_DestionResPath + subFloder+"is exited.."); } try { File.Copy(_ResPath + result[k], _DestionResPath + result[k], true); } catch (Exception e) { Debug.LogError(e); continue; } string mainfest = _ResPath + result[k] + ".manifest"; if (!File.Exists(mainfest)) { Debug.LogError(res + "不存在资源manifest文件:" + mainfest); continue; } try { Debug.Log("存在资源manifest文件:" + mainfest); if (File.Exists(_DestionResPath + result[k] + ".manifest")) { Debug.Log("存在destion资源manifest文件:" + _DestionResPath + result[k] + ".manifest"); } File.Copy(mainfest, _DestionResPath + result[k] + ".manifest", true); } catch (Exception e) { Debug.LogError(e); continue; } } //移动主mainfe文件 if (single) { MoveMainfest(i); } } //移动主mainfe文件 if (!single) { MoveMainfest(i); } Debug.Log("移动完成"); }