private void GenerateLODs()
 {
     try
     {
         EditorUtility.DisplayProgressBar("Generating LODs", "Generating LODs...", 0f);
         var lodGroup = LODGenerator.GenerateLODs(lodGeneratorHelper);
         if (lodGroup != null)
         {
             using (var serializedObject = new SerializedObject(lodGeneratorHelper))
             {
                 var isGeneratedProperty = serializedObject.FindProperty(IsGeneratedFieldName);
                 serializedObject.UpdateIfRequiredOrScript();
                 isGeneratedProperty.boolValue = true;
                 serializedObject.ApplyModifiedPropertiesWithoutUndo();
             }
         }
     }
     catch (System.Exception ex)
     {
         Debug.LogException(ex);
         DisplayError("Failed to generate LODs!", ex.Message, "OK", lodGeneratorHelper);
     }
     finally
     {
         EditorUtility.ClearProgressBar();
     }
 }
    void BatchGenerateLOD()
    {
        Debug.Log("Begin Generating.");
        GameObject         SubMeshHolder = Selection.gameObjects[0];
        LODGeneratorHelper myHelper      = null;
        List <LODLevel>    myLODLevels   = new List <LODLevel>();

        //SerializedProperty levelsProperty = null;
        //SerializedProperty LevelProperty = null;
        for (int i = 0; i < myQualities.Count; i++)
        {
            myLODLevels.Add(new LODLevel(myScreenRelativeTransitionHeights[i], myQualities[i]));
        }
        for (int index = 0; index < SubMeshHolder.transform.childCount; index++)
        {
            if (!EditorUtility.DisplayCancelableProgressBar("Generating LODs", "Child index: " + index, (float)index / SubMeshHolder.transform.childCount))
            {
                myHelper                       = SubMeshHolder.transform.GetChild(index).gameObject.AddComponent <LODGeneratorHelper>();
                myHelper.FadeMode              = myFadeMode;
                myHelper.AnimateCrossFading    = myAnimateCrossFading;
                myHelper.AutoCollectRenderers  = myAutoCollectRenderers;
                myHelper.SimplificationOptions = new SimplificationOptions()
                {
                    PreserveBorderEdges     = myPreserveBorderEdges,
                    PreserveUVSeamEdges     = myPreserveUVSeamEdges,
                    PreserveUVFoldoverEdges = myPreserveUVFoldoverEdges,
                    EnableSmartLink         = myEnableSmartLink,
                    VertexLinkDistance      = myVertexLinkDistance,
                    MaxIterationCount       = myMaxIterationCount,
                    Agressiveness           = myAgressiveness
                };
                myHelper.SaveAssetsPath = mySaveAssetsPath;
                myHelper.Levels         = myLODLevels.ToArray();
                //levelsProperty = new SerializedObject(myHelper).FindProperty(LevelsFieldName);
                //LevelProperty = levelsProperty.GetArrayElementAtIndex(index);
                try
                {
                    var lodGroup = LODGenerator.GenerateLODs(myHelper);
                    if (lodGroup != null)
                    {
                        using (var serializedObject = new SerializedObject(myHelper))
                        {
                            var isGeneratedProperty = serializedObject.FindProperty(IsGeneratedFieldName);
                            serializedObject.UpdateIfRequiredOrScript();
                            isGeneratedProperty.boolValue = true;
                            serializedObject.ApplyModifiedPropertiesWithoutUndo();
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    Debug.LogException(ex);
                    EditorUtility.DisplayDialog("Failed to generate LODs!", ex.Message, "OK");
                    break;
                }
                finally
                {
                    //EditorUtility.ClearProgressBar();
                }
            }
            else
            {
                Debug.LogWarning("Generate cancle.");
                break;
            }
        }
        EditorUtility.ClearProgressBar();
        Debug.Log("End Generating.");
    }