protected void exportSkinsFile_OneSubMeshOneFile() { foreach (Mesh mesh in m_meshList) { foreach (SubMesh subMesh in mesh.m_subMeshList) { string xmlStr = "<?xml version='1.0' encoding='utf-8' ?>\n<Root>\n"; xmlStr += string.Format(" <Mesh name=\"{0}\" >\n", UtilPath.getFileNameNoExt(mesh.skelMeshParam.m_name)); subMesh.exportSubMeshBoneFile(mesh.skelMeshParam, ref xmlStr); xmlStr += " </Mesh>\n"; xmlStr += "</Root>"; string xmlName = string.Format("{0}.xml", UtilPath.getFileNameNoExt(subMesh.m_part)); //string xmlPath = string.Format("{0}/{1}/{2}", m_outPath, m_modelTypes.modelTypeDic[mesh.skelMeshParam.m_modelType].subPath, xmlName); string xmlPath = string.Format("{0}/{1}", m_outPath, xmlName); xmlPath = ExportUtil.getDataPath(xmlPath); UtilPath.deleteFile(xmlPath); FileStream fileStream = new FileStream(xmlPath, FileMode.CreateNew); byte[] data = new UTF8Encoding().GetBytes(xmlStr); //开始写入 fileStream.Write(data, 0, data.Length); //清空缓冲区、关闭流 fileStream.Flush(); fileStream.Close(); fileStream.Dispose(); } } }
protected void packOneLevelPack() { string resPath = ""; List <string> nameList = new List <string>(); List <string> pathList = new List <string>(); List <string> filesList = UtilPath.GetAll(ExportUtil.getDataPath(m_packParam.m_inPath)); string ext = ""; string nameNoExt = ""; string tmpStr = ""; StreamedSceneAssetBundleParam bundleParam = new StreamedSceneAssetBundleParam(); foreach (string filePath in filesList) { ext = UtilPath.getFileExt(filePath); nameNoExt = UtilPath.getFileNameNoExt(filePath); if (ExportUtil.isArrContainElem(ext, m_packParam.m_extArr)) { resPath = ExportUtil.convFullPath2AssetsPath(filePath); nameList.Add(resPath); bundleParam.m_levels = nameList.ToArray(); pathList.Clear(); pathList.Add(m_packParam.m_outPath); tmpStr = string.Format("{0}{1}", nameNoExt, UtilApi.DOTUNITY3D); pathList.Add(tmpStr); bundleParam.m_locationPath = ExportUtil.getStreamingDataPath(UtilPath.combine(pathList.ToArray())); ExportUtil.BuildStreamedSceneAssetBundle(bundleParam); } } }
protected void packOneBundlePack() { string resPath = ""; List <string> assetNamesList = new List <string>(); List <Object> objList = new List <Object>(); UnityEngine.Object go; List <string> pathList = new List <string>(); List <string> filesList = UtilPath.GetAll(ExportUtil.getDataPath(m_packParam.m_inPath)); string ext = ""; string nameNoExt = ""; #if UNITY_4_6 string tmpStr = ""; #endif AssetBundleParam bundleParam = new AssetBundleParam(); foreach (string filePath in filesList) { objList.Clear(); assetNamesList.Clear(); ext = UtilPath.getFileExt(filePath); nameNoExt = UtilPath.getFileNameNoExt(filePath); if (ExportUtil.isArrContainElem(ext, m_packParam.m_extArr)) { resPath = ExportUtil.convFullPath2AssetsPath(filePath); assetNamesList.Add(resPath); go = AssetDatabase.LoadAssetAtPath(resPath, ExportUtil.convResStr2Type(ExportUtil.convExt2ResStr(ext))); if (go) { objList.Add(go); #if UNITY_5 bundleParam.m_buildList = new AssetBundleBuild[1]; bundleParam.m_buildList[0].assetBundleName = nameNoExt; bundleParam.m_buildList[0].assetBundleVariant = UtilApi.UNITY3D; bundleParam.m_buildList[0].assetNames = assetNamesList.ToArray(); pathList.Clear(); pathList.Add(m_packParam.m_outPath); bundleParam.m_pathName = ExportUtil.getStreamingDataPath(UtilPath.combine(pathList.ToArray())); #elif UNITY_4_6 || UNITY_4_5 bundleParam.m_assets = objList.ToArray(); pathList.Clear(); pathList.Add(m_packParam.m_outPath); tmpStr = string.Format("{0}{1}", nameNoExt, ExportUtil.DOTUNITY3D); pathList.Add(tmpStr); bundleParam.m_pathName = ExportUtil.getStreamingDataPath(ExportUtil.combine(pathList.ToArray())); #endif ExportUtil.BuildAssetBundle(bundleParam); } else { LoggerTool.error(string.Format("AssetDatabase.LoadAssetAtPath 不能加载资源 {0}", filePath)); } } } }
public void exportMeshBone(XmlDocument xmlDocSave, XmlElement root) { XmlElement meshXml = xmlDocSave.CreateElement("Mesh"); root.AppendChild(meshXml); meshXml.SetAttribute("name", UtilPath.getFileNameNoExt(m_skelMeshParam.m_name)); foreach (SubMesh subMesh in m_subMeshList) { subMesh.exportSubMeshBone(m_skelMeshParam, xmlDocSave, meshXml); } }
public void exportMeshBoneFile(ref string xmlStr) { if (m_subMeshList.Count == 0) // 说明没有定义 SubMesh,就说明导出 GameObject 中有 Skinned Mesh Renderer 组件的 GameObject { addSubMesh(); } xmlStr += string.Format(" <Mesh name=\"{0}\" >\n", UtilPath.getFileNameNoExt(m_skelMeshParam.m_name)); foreach (SubMesh subMesh in m_subMeshList) { subMesh.exportSubMeshBoneFile(m_skelMeshParam, ref xmlStr); } xmlStr += " </Mesh>\n"; }
protected void onFindOneFile(string fullPath, string name) { string ext = UtilPath.getFileExt(fullPath); string nameNoExt = UtilPath.getFileNameNoExt(fullPath); XmlAnimatorController controller = null; if (ExportUtil.FBX == ext) { if (!nameNoExt.Contains(ExportUtil.AT)) // 如果包含 @ ,就说明是一个动画 { m_xmlTmp.SetAttribute("outname", nameNoExt); controller = new XmlAnimatorController(); ExportAnimatorControllerSys.m_instance.controllerList.Add(controller); controller.parseXml(m_xmlTmp); // 调整完整的文件名字 controller.adjustFileName(nameNoExt); } } }
// 遍历一个文件的时候处理 public void handleFile(string fullFileName, string name) { fullFileName = UtilPath.normalPath(fullFileName); if (m_ignoreExtList.IndexOf(UtilPath.getFileExt(fullFileName)) == -1) { string fineNameNoExt = UtilPath.getFileNameNoExt(fullFileName); string assetPath = fullFileName.Substring(fullFileName.IndexOf(ExportUtil.ASSETS)); string destPath = ""; if (m_unity3dExtNameList.IndexOf(UtilPath.getFileExt(fullFileName)) != -1) { if (fullFileName.LastIndexOf('/') != m_srcFullPath.Length) { destPath = fullFileName.Substring(m_srcFullPath.Length + 1, fullFileName.LastIndexOf('/') - (m_srcFullPath.Length + 1)); } if (!string.IsNullOrEmpty(m_destRoot)) { destPath = Path.Combine(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath, m_destRoot); destPath = Path.Combine(destPath, destPath); } else { destPath = Path.Combine(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath, destPath); } AssetBundleParam bundleParam = new AssetBundleParam(); #if UNITY_5 bundleParam.m_buildList = new AssetBundleBuild[1]; bundleParam.m_buildList[0].assetBundleName = fineNameNoExt; bundleParam.m_buildList[0].assetBundleVariant = UtilApi.UNITY3D; bundleParam.m_buildList[0].assetNames = new string[1]; bundleParam.m_buildList[0].assetNames[0] = assetPath; bundleParam.m_targetPlatform = ResExportSys.m_instance.m_targetPlatform; bundleParam.m_pathName = destPath; #elif UNITY_4_6 || UNITY_4_5 bundleParam.m_assets = objList.ToArray(); pathList.Clear(); pathList.Add(m_skelMeshParam.m_outPath); pathList.Add(skelNoExt + ".unity3d"); bundleParam.m_pathName = ExportUtil.getStreamingDataPath(ExportUtil.combine(pathList.ToArray())); #endif ExportUtil.BuildAssetBundle(bundleParam); // 打包成 unity3d 后文件名字会变成小写,这里修改一下 UtilPath.modifyFileNameToCapital(destPath, fineNameNoExt); } else // 直接拷贝过去 { if (fullFileName.LastIndexOf('/') != m_srcFullPath.Length) { destPath = fullFileName.Substring(m_srcFullPath.Length + 1, fullFileName.Length - (m_srcFullPath.Length + 1)); } if (!string.IsNullOrEmpty(m_destRoot)) { destPath = Path.Combine(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath, m_destRoot); destPath = Path.Combine(destPath, destPath); } else { destPath = Path.Combine(ResExportSys.m_instance.m_pResourcesCfgPackData.m_destFullPath, destPath); File.Copy(fullFileName, destPath); } } addResListItem(fullFileName, destPath); } }
public void packSkel() { List <string> pathList = new List <string>(); pathList.Add(m_skelMeshParam.m_inPath); pathList.Add(m_skelMeshParam.m_name); string resPath = ExportUtil.getRelDataPath(UtilPath.combine(pathList.ToArray())); GameObject go = AssetDatabase.LoadAssetAtPath(resPath, ExportUtil.convResStr2Type("prefab")) as GameObject; GameObject subMeshGo = null; string skelNoExt = UtilPath.getFileNameNoExt(m_skelMeshParam.m_name); string outPrefabPath = ""; List <Object> objList = new List <Object>(); List <string> assetNamesList = new List <string>(); GameObject instanceGo; pathList.Clear(); if (string.IsNullOrEmpty(m_skelMeshParam.m_outPath)) { pathList.Add(SkinAnimSys.m_instance.m_xmlSubMeshRoot.m_outPath); } else { pathList.Add(m_skelMeshParam.m_outPath); } //pathList.Add(SkinAnimSys.m_instance.m_xmlSkeletonRoot.m_modelTypes.modelTypeDic[m_skelMeshParam.m_modelType].subPath); pathList.Add(skelNoExt + ".prefab"); outPrefabPath = ExportUtil.getRelDataPath(UtilPath.combine(pathList.ToArray())); assetNamesList.Add(outPrefabPath); // 原始的资源是不能修改的,必须要 Instantiate 后才能修改,因此这里 Instantiate 一个 GameObject instanceGo = UtilApi.Instantiate(go) as GameObject; //PrefabUtility.CreatePrefab(outPrefabPath, go); //go = AssetDatabase.LoadAssetAtPath(outPrefabPath, ExportUtil.convResStr2Type("prefab")) as GameObject; Animator animator = null; if (instanceGo != null) { // 单位化转换 UtilApi.normalRST(instanceGo.transform); // 释放子模型 foreach (SubMesh subMesh in m_subMeshList) { subMeshGo = instanceGo.transform.Find(subMesh.m_name).gameObject; if (subMeshGo != null) { //GameObject.DestroyImmediate(subMeshGo); //GameObject.Destroy(subMeshGo); //GameObject.DestroyImmediate(subMeshGo, true); UtilApi.DestroyImmediate(subMeshGo, false); } } // 添加控制器 string controlPath = string.Format("{0}/{1}.controller", m_skelMeshParam.m_controllerPath, skelNoExt); controlPath = ExportUtil.getRelDataPath(controlPath); animator = instanceGo.GetComponent <Animator>(); UnityEngine.Object assetObj = AssetDatabase.LoadAssetAtPath(controlPath, typeof(AnimatorController)); animator.runtimeAnimatorController = assetObj as RuntimeAnimatorController; // 保存资源 PrefabUtility.CreatePrefab(outPrefabPath, instanceGo); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); UtilApi.DestroyImmediate(instanceGo, false); // 现在不直接打包,需要最后发布的时候才打包 //go = AssetDatabase.LoadAssetAtPath(outPrefabPath, ExportUtil.convResStr2Type("prefab")) as GameObject; //objList.Add(go); // AssetBundleParam bundleParam = new AssetBundleParam(); //#if UNITY_5 // bundleParam.m_buildList = new AssetBundleBuild[1]; // bundleParam.m_buildList[0].assetBundleName = skelNoExt; // bundleParam.m_buildList[0].assetBundleVariant = ExportUtil.UNITY3D; // bundleParam.m_buildList[0].assetNames = assetNamesList.ToArray(); // pathList.Clear(); // pathList.Add(m_skelMeshParam.m_outPath); // bundleParam.m_pathName = ExportUtil.getStreamingDataPath(ExportUtil.combine(pathList.ToArray())); //#elif UNITY_4_6 || UNITY_4_5 // bundleParam.m_assets = objList.ToArray(); // pathList.Clear(); // pathList.Add(m_skelMeshParam.m_outPath); // pathList.Add(skelNoExt + ".unity3d"); // bundleParam.m_pathName = ExportUtil.getStreamingDataPath(ExportUtil.combine(pathList.ToArray())); //#endif // ExportUtil.BuildAssetBundle(bundleParam); } }