Exemplo n.º 1
0
    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);
            }
        }
    }
Exemplo n.º 2
0
    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();
        //}
    }