/// <summary>
        ///   Synchronize/Update the terrain.
        /// </summary>
        public void Synchronize(BridgeSettings settings)
        {
            if (!settings.IsBridgeFileValid())
            {
                return;
            }

            // First copy the contents of the World Creator project folder over to the Unity folder and import them
            UnityTerrainUtility.CreateTerrainFromFile(settings);
        }
        /// <summary>
        ///   Draws this windows' GUI.
        /// </summary>
        public void OnGUI()
        {
            // for some reason OnGUI is called earlier than Awake() or Awake() isn't called at all => lazy initialization to make sure we have settings
            if (settings == null)
            {
                LoadSettings();
            }

            EditorGUILayout.BeginVertical("box");
            {
                this.selectedToolbarItemIndex = GUILayout.Toolbar(this.selectedToolbarItemIndex, this.toolbarItems,
                                                                  GUILayout.Height(32));
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical("box");
            {
                scrollPositionGeneralTab = GUILayout.BeginScrollView(scrollPositionGeneralTab);
                {
                    switch (this.selectedToolbarItemIndex)
                    {
                    case 0:
                        this.DrawTabGeneral();
                        break;

                    case 1:
                        this.DrawTabAbout();
                        break;
                    }
                }
                GUILayout.EndScrollView();

                GUILayout.FlexibleSpace();
            }
            EditorGUILayout.EndVertical();

            // Only show the synchronize button when a project folder has been selected
            if (settings.IsBridgeFileValid())
            {
                if (GUILayout.Button("SYNCHRONIZE", GUILayout.Height(50)))
                {
                    if (!File.Exists(settings.bridgeFilePath))
                    {
                        Debug.LogError("Selected file does not exist.");
                        return;
                    }

                    // Copy the sync folder ...
                    var           terrainFolder = Application.dataPath + @"/" + settings.terrainsFolderName + "/" + settings.terrainAssetName;
                    DirectoryInfo target        = new DirectoryInfo(terrainFolder + "/Assets");
                    DirectoryInfo source        = new DirectoryInfo(settings.bridgeFilePath).Parent;

                    if (source != null && source.Parent != null)
                    {
                        source = new DirectoryInfo(source.FullName + "/Assets/");
                    }

                    ModelPostprocessor.WorldCreatorImportActive = true;
                    AssetDatabase.StartAssetEditing();
                    this.CopyAll(source, target);
                    AssetDatabase.StopAssetEditing();
                    AssetDatabase.Refresh();
                    ModelPostprocessor.WorldCreatorImportActive = false;


                    if (settings.deleteUnusedAssets)
                    {
                        // Build a list of all terrain asset files
                        foreach (string num in Directory.GetFiles(@"Assets/" + settings.terrainsFolderName + "/" + settings.terrainAssetName))
                        {
                            if (num.Contains(settings.terrainAssetName + "_") || num.EndsWith(".mat"))
                            {
                                AssetDatabase.DeleteAsset(num);
                            }
                        }
                    }

                    // Copy colormap
                    try
                    {
                        if (File.Exists(source.Parent.FullName + "/colormap.png"))
                        {
                            File.Copy(source.Parent.FullName + "/colormap.png", terrainFolder + "/colormap.png", true);
                        }
                        else
                        {
                            File.Delete(terrainFolder + "/colormap.png");
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.Log(e.Message);
                    }

                    AssetDatabase.Refresh();

                    // ... perform synchronization ...
                    logic.Synchronize(settings);

                    // save the settings for the next time the window is used
                    SaveSettings();
                }
            }
        }