public static void excute() { //创建实例 GameModelDataHolder go = ScriptableObject.CreateInstance <GameModelDataHolder>(); ModelDataProcess.excute(); ModelDic dictModelData = ModelDataProcess._dicModelData; foreach (KeyValuePair <string, ModelData> kvp in dictModelData) { GameModelData pData = new GameModelData(); pData._strAssetName = kvp.Value._strAssetName; pData._strAnimationAssetName = kvp.Value._strAnimationAssetName; pData._strModelName = kvp.Value._strModelName; pData._listAnimEvents = kvp.Value._listAnimEvents; pData._listModelBps = kvp.Value._listModelBps; pData._listAnimations = kvp.Value._listAnimations; pData.nColliderType = kvp.Value._nColliderType; pData.nColliderParams = kvp.Value._nColliderParams; pData.colliderCenter = kvp.Value._nColliderCenter; Debug.Log(kvp.Key); go._listGameModel.Add(pData); } //生成asset string p = "Assets/Resources/GameModelData/GameModelData.asset"; AssetDatabase.CreateAsset(go, p); string assetbundle_path = GameDataAssetbundlePath + IPath.getPlatformName() + "/modelsassetbundles"; //创建路径 if (!Directory.Exists(assetbundle_path)) { Directory.CreateDirectory(assetbundle_path); } //打包 UnityEngine.Object o = AssetDatabase.LoadAssetAtPath(p, typeof(GameModelDataHolder)); BuildPipeline.BuildAssetBundle(o, null, assetbundle_path + "/gamemodeldata.assetbundle", EditorVariables.eBuildABOpt, EditorVariables.eBuildTarget); //删除临时的asset //AssetDatabase.DeleteAsset(p); }
public void OnPreprocessModel() { ModelImporter mi = (ModelImporter)assetImporter; //修正缩放比 // mi.globalScale = 0.01f; //动作类型 mi.animationType = ModelImporterAnimationType.Legacy; mi.generateAnimations = ModelImporterGenerateAnimations.GenerateAnimations; if (assetPath.Contains("/Models/")) { //不自动生成材质,有其他工具生成,统一生成管理 mi.importMaterials = false; mi.globalScale = 1.0f; } else if (assetPath.Contains("/Effects/zhuanshu")) { mi.globalScale = 1.0f; } else if (assetPath.Contains("/UIModel/")) { } else { return; } //关闭动作压缩,会导致动作占用空间增大,但是可以避免产生额外的压缩损伤 #if ANIMATION_COMPRESS mi.animationCompression = ModelImporterAnimationCompression.KeyframeReduction; #else mi.animationCompression = ModelImporterAnimationCompression.off; #endif #region modify (Author: @XB.Wu) if (ModelDataProcess._dicModelData.Count == 0) { ModelDataProcess.excute(); } #endregion //如果是纯动作文件则进行裁剪 //动作文件命名格式:modelName@anim if (assetPath.Contains("@")) { string[] tempAssetList = assetPath.Split(new char[] { '@' }); string strAssetModelName = tempAssetList[0].Substring(tempAssetList[0].LastIndexOf('/') + 1); if (assetPath.Contains("/Models/") && !_listModels.Contains(strAssetModelName)) { _listModels.Add(strAssetModelName); } ModelData pModelData = ModelDataProcess.getModelDataByIdx(strAssetModelName); if (pModelData == null) { //EditorUtility.DisplayDialog("Animation Clip", "No Clip config is found in the AnimationClipConfig.ini, and Check the config and make sure its available", "Ok"); Debug.LogWarning(strAssetModelName + " Clip config can't be found in the AnimationClipConfig.ini, and Check the config and make sure its available"); return; } #region modify (Author: @XB.Wu) //bool bInit = pModelData.InitFlag; //if (bInit) //{ // //EditorUtility.DisplayDialog("Animation Clip", "This animation's FBX has been imported already. Please delete the previous asset and try again.", "Ok"); // Debug.LogWarning("This animation's FBX has been imported already. Please delete the previous asset and try again."); // return; //} #endregion AnimClipInfo info = null; ModelImporterClipAnimation[] animations = new ModelImporterClipAnimation[pModelData._listAnimClips.ToArray().Length]; for (int i = 0; i < animations.Length; i++) { info = pModelData._listAnimClips[i]; animations[i] = SetClipAnimation(info.name, info.firstFrame, info.lastFrame, info.isloop); } mi.clipAnimations = animations; //pModelData.InitFlag = true; } else { string[] tempAssetList = assetPath.Split(new char[] { '.', 'F', 'B', 'X' }); int startIdx = assetPath.LastIndexOf('/'); int endIdx = assetPath.LastIndexOf(".FBX"); string strAssetModelName = assetPath.Substring(startIdx + 1, endIdx - startIdx - 1); if (assetPath.Contains("/Models/") && !_listModels.Contains(strAssetModelName)) { _listModels.Add(strAssetModelName); } } }
static void CheckModel(){ bCheckModel = true; //加载配置 ModelDataProcess.excute(); bCheckModel = false; //检测配置文件 checkConfig(); if (!Directory.Exists(modelPath)) { LogSys.LogError("无法检测模型,不存在文件夹 " + modelPath); return; } string[] files = Directory.GetFiles(modelPath); _listElementError.Clear(); //文件的数量 int fileNum = files.Length; if (fileNum == 0) { LogSys.LogError("文件夹下没有任何模型 " + modelPath); return; } foreach (var item in ModelDataProcess._dicModelData) { bool result = true; string modelId = item.Key; _curModelId = modelId; ModelData cfg = item.Value; //测试绑点 List<string> listBindError = new List<string>(); UnityEngine.Object obj = Resources.Load("Models/" + modelId); if (obj != null) { GameObject go = GameObject.Instantiate(obj) as GameObject; for (int i = 0; i < cfg._listModelBps.Count; i++) { string bp = cfg._listModelBps[i]; if (!getBp(go.transform, bp)) { listBindError.Add(bp); result = false; } } result = checkElement(go.transform); if (listBindError.Count > 0) { string bindError = ""; for (int i = 0; i < listBindError.Count; i++) { bindError += " [" + listBindError[i] + "] "; } Utils.LogSys.LogError(string.Format("绑点缺失 {0} {1}", modelId, bindError)); } GameObject.DestroyImmediate(go); Utils.LogSys.Log("正确 " + modelId); } } }
void OnGUI() { //分隔线 EditorGUILayout.Separator(); EditorGUILayout.Separator(); if (ModelPreProcess._listModels.Count > 0) { EditorGUILayout.BeginScrollView(Vector2.zero, GUILayout.Width(350), GUILayout.Height(140)); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("模型"); EditorGUILayout.EndHorizontal(); //分隔线 EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.BeginVertical(); for (int i = 0; i < ModelPreProcess._listModels.Count; i++) { string strAssetModelName = ModelPreProcess._listModels[i]; ModelData pModelData = ModelDataProcess.getModelDataByIdx(strAssetModelName); if (pModelData != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(strAssetModelName); EditorGUILayout.LabelField(pModelData._strModelName); EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); //分隔线 EditorGUILayout.Separator(); EditorGUILayout.Separator(); } if (bImportIni) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("ini配置"); EditorGUILayout.EndHorizontal(); } //分隔线 EditorGUILayout.Separator(); EditorGUILayout.Separator(); if (GUILayout.Button("打包", GUILayout.Width(100), GUILayout.ExpandWidth(true))) { //打包模型 for (int i = 0; i < ModelPreProcess._listModels.Count; i++) { Utils.LogSys.LogWarning(ModelPreProcess._listModels[i]); string name = ModelPreProcess._listModels[i]; UnityEngine.Object o = Resources.Load("Models/" + name); //CreateAssetBundle.excute_single_model(o); customer.collectModel(o); } if (bImportIni) { //ModelDataExport.ModelDataAssetAndCreateAssetBundle.excute(); customer.collectAllAssetbundles(); } ModelPreProcess._listModels.Clear(); ModelDataProcess._dicModelData.Clear(); Close(); AssetDatabase.Refresh(); } //分隔线 EditorGUILayout.Separator(); EditorGUILayout.Separator(); if (GUILayout.Button("取消", GUILayout.Width(100), GUILayout.ExpandWidth(true))) { //打包模型 if (EditorUtility.DisplayDialogComplex("警告", "确定不打包该资源?若要重新打包,请先删除模型再导入。", "确定", "取消", "") == 0) { ModelPreProcess._listModels.Clear(); ModelDataProcess._dicModelData.Clear(); Close(); } } //if (GUILayout.Button("取消", GUILayout.Width(100), GUILayout.ExpandWidth(true))) { // ModelPreProcess._listModels.Clear(); // ModelDataProcess._dicModelData.Clear(); //} }