private void AdjustGrassDensity()
 {
     GrassDensity = GUnityTerrainDataImporter.GetAdjustedGrassDensity(SrcData, GrassDensity);
     CalculateEstimatedGrassStorage();
 }
        private void DoBulkImport()
        {
            string[]           guid         = AssetDatabase.FindAssets("t:TerrainData", new string[] { Directory });
            List <TerrainData> terrainDatas = new List <TerrainData>();

            for (int i = 0; i < guid.Length; ++i)
            {
                string      path = AssetDatabase.GUIDToAssetPath(guid[i]);
                TerrainData data = AssetDatabase.LoadAssetAtPath <TerrainData>(path);
                terrainDatas.Add(data);
            }

            GCommon.ForEachTerrain(
                BulkImportGroupId,
                (t) =>
            {
                if (t == null || t.TerrainData == null)
                {
                    return;
                }
                TerrainData srcData = terrainDatas.Find(d => d.name.StartsWith("TerrainData") && d.name.EndsWith(t.TerrainData.Id));
                if (srcData == null)
                {
                    return;
                }

                GBackup.TryCreateInitialBackup(HISTORY_PREFIX, t, GCommon.AllResourceFlags);

                GUnityTerrainDataImporter importer = new GUnityTerrainDataImporter();
                importer.SrcTerrain          = null;
                importer.SrcData             = srcData;
                importer.DesData             = t.TerrainData;
                importer.DesTerrain          = t;
                importer.ImportGeometry      = ImportGeometry;
                importer.UseUnityTerrainSize = UseUnityTerrainSize;

                importer.ImportSplats         = ImportSplats;
                importer.ImportSplatsAsAlbedo = ImportSplatsAsAlbedo;
                bool createNewSplatGroup      = CreateNewSplatPrototypesGroup;
                if (t.TerrainData.Shading.Splats == null ||
                    t.TerrainData.Shading.Splats == GGriffinSettings.Instance.TerrainDataDefault.Shading.Splats)
                {
                    createNewSplatGroup = true;
                }
                importer.CreateNewSplatPrototypesGroup = createNewSplatGroup;

                importer.ImportTrees    = ImportTrees;
                bool createNewTreeGroup = CreateNewTreePrototypesGroup;
                if (t.TerrainData.Foliage.Trees == null ||
                    t.TerrainData.Foliage.Trees == GGriffinSettings.Instance.TerrainDataDefault.Foliage.Trees)
                {
                    createNewTreeGroup = true;
                }
                importer.CreateNewTreePrototypesGroup = createNewTreeGroup;

                importer.ImportGrasses   = ImportGrasses;
                bool createNewGrassGroup = CreateNewGrassPrototypesGroup;
                if (t.TerrainData.Foliage.Grasses == null ||
                    t.TerrainData.Foliage.Grasses == GGriffinSettings.Instance.TerrainDataDefault.Foliage.Grasses)
                {
                    createNewGrassGroup = true;
                }
                importer.CreateNewGrassPrototypesGroup = createNewGrassGroup;

                GrassDensity          = GUnityTerrainDataImporter.GetAdjustedGrassDensity(srcData);
                importer.GrassDensity = GrassDensity;
                importer.Import();

                GBackup.TryCreateBackup(HISTORY_PREFIX, t, GCommon.AllResourceFlags);
            });

            GStylizedTerrain.MatchEdges(BulkImportGroupId);
        }
        private void CreateTerrainAndImportData()
        {
            GameObject terrainRoot = new GameObject(string.Format("{0}-{1}", Root.name, ConversionName));

            terrainRoot.transform.parent   = Root.transform.parent;
            terrainRoot.transform.position = Root.transform.position;

            for (int i = 0; i < Terrains.Count; ++i)
            {
#if UNITY_EDITOR
                GCommonGUI.CancelableProgressBar("Converting", "Converting " + Terrains[i].name, 1f);
#endif
                GStylizedTerrain t = CreateTerrain();
                t.transform.parent   = terrainRoot.transform;
                t.transform.position = Terrains[i].transform.position;
                t.name = Terrains[i].name;

#if !UNITY_2018_1 && !UNITY_2018_2
                t.GroupId = Terrains[i].groupingID;
#endif
                if (ImportSplats)
                {
                    t.TerrainData.Shading.Splats = SplatGroups[SplatGroupIndices[i]];
                    GSplatsModel splatModel = t.TerrainData.Shading.Splats.Prototypes.Count <= 4 ?
                                              GSplatsModel.Splats4Normals4 :
                                              GSplatsModel.Splats8;
                    Material mat = GGriffinSettings.Instance.WizardSettings.GetClonedMaterial(GLightingModel.PBR, GTexturingModel.Splat, splatModel);
                    t.TerrainData.Shading.MaterialToRender.shader = mat.shader;
                    t.TerrainData.Shading.UpdateMaterials();
                    GUtilities.DestroyObject(mat);
                }
                if (ImportTrees)
                {
                    t.TerrainData.Foliage.Trees = TreeGroups[TreeGroupIndices[i]];
                }
                if (ImportGrasses)
                {
                    t.TerrainData.Foliage.Grasses = GrassGroups[GrassGroupIndices[i]];
                }

                GUnityTerrainDataImporter importer = new GUnityTerrainDataImporter();
                importer.SrcData                       = Terrains[i].terrainData;
                importer.SrcTerrain                    = Terrains[i];
                importer.DesData                       = t.TerrainData;
                importer.DesTerrain                    = t;
                importer.ImportGeometry                = ImportGeometry;
                importer.UseUnityTerrainSize           = true;
                importer.ImportSplats                  = ImportSplats;
                importer.ImportSplatsAsAlbedo          = ImportSplatsAsAlbedo;
                importer.CreateNewSplatPrototypesGroup = false;
                importer.ImportTrees                   = ImportTrees;
                importer.CreateNewTreePrototypesGroup  = false;
                importer.ImportGrasses                 = ImportGrasses;
                importer.CreateNewGrassPrototypesGroup = false;
                importer.GrassDensity                  = GUnityTerrainDataImporter.GetAdjustedGrassDensity(importer.SrcData, 1);
                importer.Import();

#if UNITY_EDITOR
                SaveAssets();
                GCommonGUI.ClearProgressBar();
#endif
            }
        }