コード例 #1
0
 private void ApplyChanges()
 {
     if (Event.current.isKey)
     {
         switch (Event.current.keyCode)
         {
         case KeyCode.Return:
         case KeyCode.KeypadEnter:
             Event.current.Use();
             MeshAnimationExporter.ResizeDataLists(ref exportSettings.boneTransforms, ref exportSettings.boneNames, guiNumberOfBones);
             MeshAnimationExporter.ResizeDataLists(ref exportSettings.animationClips, ref exportSettings.animationNames, guiNumberOfClips);
             break;
         }
     }
 }
コード例 #2
0
    void OnGUI()
    {
        if (outputFilePath == null)
        {
            outputFolderPath = Application.streamingAssetsPath;
        }

        if (exportSettings == null)
        {
            exportSettings = new MeshAnimationExporter.ExportParameters();
        }
        windowWidth = position.width;

        mainScrollPosition = EditorGUILayout.BeginScrollView(mainScrollPosition);

        //烘培定义角度转向
        eulerAngle = EditorGUILayout.Vector3Field("Bake model after apply Rotation Offset XYZ(除了特殊需求,一般按默认值导出)", eulerAngle);

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Default Folder:" + exportSettings.outputFolderPath);

        EditorGUILayout.Space();

        #region Output File Selection
        EditorGUILayout.LabelField("Output File:");
        EditorGUILayout.BeginHorizontal();
        {
            string projectRelativeFilePath = GetAssetPath(outputFilePath);

            EditorGUILayout.SelectableLabel(projectRelativeFilePath,
                                            EditorStyles.textField,
                                            GUILayout.Height(EditorGUIUtility.singleLineHeight));

            GUI.SetNextControlName("BrowseButton");
            if (GUILayout.Button("Browse"))
            {
                BrowseSaveFile();
            }
        }
        EditorGUILayout.EndHorizontal();
        #endregion

        EditorGUILayout.Space();

        #region Base FBX File Setting
        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayout.LabelField("Base FBX:", GUILayout.Width(EditorGUIUtility.labelWidth - 4));
            GameObject newFbx = EditorGUILayout.ObjectField(fbx, typeof(GameObject), true) as GameObject;

            if (newFbx != null && newFbx != fbx)
            {
                // error if they drag the prefab itself, since it won't have any transform data
                if (PrefabUtility.GetCorrespondingObjectFromSource(newFbx) != null)
                {
                    fbx              = newFbx;
                    exportSettings   = MeshAnimationExporter.GenerateDefaultSettings(newFbx, DEFAULT_OUTPUT_FOLDER);
                    outputFolderPath = exportSettings.outputFolderPath;
                    outputFilePath   = exportSettings.outputFilePath;
                    guiNumberOfClips = exportSettings.animationClips.Length;
                    guiNumberOfBones = exportSettings.boneTransforms.Length;
                }
            }
        }

        EditorGUILayout.EndHorizontal();
        #endregion

        EditorGUILayout.Space();

        #region Framerate Setting
        exportSettings.framerate = EditorGUILayout.FloatField("Capture Framerate:", exportSettings.framerate);
        exportSettings.framerate = Mathf.Max(exportSettings.framerate, 1.0f);
        #endregion

        EditorGUILayout.Space();
        exportSettings.isLoadAllInMainScene = EditorGUILayout.Toggle("是否在主场景中加载全部动画", exportSettings.isLoadAllInMainScene);

        EditorGUILayout.Space();

        #region Clip Count Setting
        guiNumberOfClips = EditorGUILayout.IntField("Number of Clips:", guiNumberOfClips);
        ApplyChanges();
        #endregion

        EditorGUILayout.Space();

        labelWidth = GUILayout.Width(windowWidth * 0.3f);

        #region Animation Clip Setting
        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayout.LabelField("Animation Name:", labelWidth);
            EditorGUILayout.LabelField("Animation File:", labelWidth);
            EditorGUILayout.LabelField("Frames:", GUILayout.Width(windowWidth * 0.2f));
        }
        EditorGUILayout.EndHorizontal();

        DrawAnimationArrayGui();
        #endregion

        EditorGUILayout.Space();

        #region Bone Count Setting
        guiNumberOfBones = EditorGUILayout.IntField("Number of Bones:", guiNumberOfBones);
        ApplyChanges();
        #endregion

        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayout.LabelField("Bone Name:", labelWidth);
            EditorGUILayout.LabelField("Bone Transform:", labelWidth);
        }
        EditorGUILayout.EndHorizontal();

        DrawBoneArrayGui();

        #region Clear and Save Buttons
        EditorGUILayout.BeginHorizontal();
        {
            GUI.SetNextControlName("ClearButton");
            if (GUILayout.Button("Clear"))
            {
                ResetSettings();
                GUI.FocusControl("ClearButton");
            }

            if (GUILayout.Button("Export"))
            {
                //Save
                if (eulerAngle != Vector3.zero)
                {
                    exportSettings.quaternionOffset = Quaternion.Euler(eulerAngle);
                }

                //MeshAnimationExporter.Export(fbx, exportSettings);
                MeshAnimationExporter.ExportCombinedTexture(fbx, exportSettings);
            }
        }

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        {
            if (GUILayout.Button("Export All"))
            {
                if (EditorUtility.DisplayDialog("", "确定导出所有小兵动画?", "是", "否"))
                {
                    string   folder   = "Assets/Models/Units/Solider";
                    string[] dirs     = Directory.GetDirectories(folder);
                    int      progress = 0;
                    foreach (string dir in dirs)
                    {
                        string     name = Path.GetFileName(dir);
                        string     path = string.Format("{0}/{1}/{1}.fbx", folder, name);
                        GameObject fbx  = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                        if (fbx != null)
                        {
                            EditorUtility.DisplayProgressBar(folder, name, (progress++) / (float)dirs.Length);
                            exportSettings   = MeshAnimationExporter.GenerateDefaultSettings(fbx, DEFAULT_OUTPUT_FOLDER);
                            outputFolderPath = exportSettings.outputFolderPath;
                            outputFilePath   = exportSettings.outputFilePath;
                            guiNumberOfClips = exportSettings.animationClips.Length;
                            guiNumberOfBones = exportSettings.boneTransforms.Length;

                            //Save
                            if (eulerAngle != Vector3.zero)
                            {
                                exportSettings.quaternionOffset = Quaternion.Euler(eulerAngle);
                            }

                            MeshAnimationExporter.ExportCombinedTexture(fbx, exportSettings);
                        }
                        else
                        {
                            Debug.LogErrorFormat("没有找到小兵模型:{0}", path);
                        }
                    }
                    EditorUtility.ClearProgressBar();
                }
            }
        }
        EditorGUILayout.EndHorizontal();
        #endregion

        EditorGUILayout.EndScrollView();
    }