/// <summary>
        /// Display GUI for updating the preview shown in the editor
        /// </summary>
        public void PreviewUpdate()
        {
            EditorGUILayout.Space();
            EditorGUILayout.Separator();
            EditorGUILayout.Space();

            if (GUILayout.Button("Generate"))
            {
                if (_config.Generator.GenerationRadius > 4)
                {
                    int amt = TilePool.GetTilePositionsFromRadius(
                        _config.Generator.GenerationRadius, new Vector2(0, 0), _config.Generator.Length)
                              .Count;
                    string msg = "You are about to generate " + amt + " Tiles synchronously which " +
                                 "may take a while. Are you sure you want to continue?";
                    if (EditorUtility.DisplayDialog("Warning", msg, "Continue"))
                    {
                        _config.GenerateEditor();
                    }
                }
                else
                {
                    _config.GenerateEditor();
                }
            }
            if (GUILayout.Button("Clear Tiles"))
            {
                if (_config.Generator != null && _config.Generator.Pool != null)
                {
                    _config.Generator.Pool.RemoveAll();
                }
            }
        }
        /// <summary>
        /// Gets the biome at the passed x and z world coordinates.
        /// </summary>
        /// <param name="x">world space x coordinate</param>
        /// <param name="z">world space z coordinate</param>
        /// <returns>Found <see cref="BiomeData"/> instance, null if nothing was found.</returns> //todo remove
//		public BiomeData GetBiomeAt(float x, float z) { //TODO moev to biomedata?
//			BiomeData chosen = null;
//			var settings = Instance;
//
//			foreach (BiomeData b in BiomesData) {
//				var hm = settings.HeightMapData;
//				var tm = settings.TemperatureMapData;
//				var mm = settings.MoistureMapData;
//
//				if (b.IsHeightConstrained && !hm.HasGenerator()) continue;
//				if (b.IsTemperatureConstrained && !tm.HasGenerator()) continue;
//				if (b.IsMoistureConstrained && !mm.HasGenerator()) continue;
//
//				bool passHeight = b.IsHeightConstrained && b.HeightConstraint.Fits(hm.GetValue(x, z)) || !b.IsHeightConstrained;
//				bool passTemp = b.IsTemperatureConstrained && b.TemperatureConstraint.Fits(tm.GetValue(x, z)) || !b.IsTemperatureConstrained;
//				bool passMoisture = b.IsMoistureConstrained && b.MoistureConstraint.Fits(mm.GetValue(x, z)) || !b.IsMoistureConstrained;
//
//				if (passHeight && passTemp && passMoisture) {
//					chosen = b;
//				}
//			}
//
//			return chosen;
//		}

        void OnDrawGizmosSelected()
        {
            if (!IsInitialized)
            {
                return;
            }

            //Grid center
            Vector3 worldXYZ   = Generator.TrackedObject != null ? Generator.TrackedObject.transform.position : Vector3.zero;
            Vector2 gridCenter = new Vector2(worldXYZ.x, worldXYZ.z);


            //On general tab selected: display mesh radius squares and collider radius
            List <GridPosition> positions = TilePool.GetTilePositionsFromRadius(Generator.GenerationRadius, gridCenter, Generator.Length);

            //Mesh radius squares
            foreach (GridPosition pos in positions)
            {
                Vector3 pos3D = new Vector3(pos.X * Generator.Length, 0, pos.Z * Generator.Length);

                //Draw LOD squares
                Gizmos.color = GetLodPreviewColor(pos);
                //bool isPreviewTile = Previewer.GetPreviewingPositions().Contains(pos);
                if (Gizmos.color != Color.white)
                {
                    Gizmos.DrawCube(pos3D, new Vector3(Generator.Length, 0, Generator.Length));
                }

                //Draw overlayed grid
                Gizmos.color = Color.white;
                pos3D.y     += 0.1f;
                Gizmos.DrawWireCube(pos3D, new Vector3(Generator.Length, 0, Generator.Length));
            }

            //Generation radius
            if (Generator.TrackedObject != null)
            {
                var     pos    = Generator.TrackedObject.transform.position;
                Vector3 extPos = new Vector3(pos.x, 0, pos.z);

                Gizmos.color = Color.blue;
                Gizmos.DrawWireCube(extPos, new Vector3(Generator.ColliderGenerationExtent, 0, Generator.ColliderGenerationExtent));
            }
        }
        /// <summary>
        /// Display GUI for updating the preview shown in the editor
        /// </summary>
        public void PreviewUpdate()
        {
            EditorGUILayout.Space();
            EditorGUILayout.Separator();
            EditorGUILayout.Space();

            if (GUILayout.Button("Generate"))
            {
                if (_config.Generator.GenerationRadius > 4)
                {
                    int amt = TilePool.GetTilePositionsFromRadius(
                        _config.Generator.GenerationRadius, new Vector2(0, 0), _config.Generator.Length)
                              .Count;
                    string msg = "You are about to generate " + amt + " Tiles synchronously which " +
                                 "may take a while. Are you sure you want to continue?";
                    if (EditorUtility.DisplayDialog("Warning", msg, "Continue"))
                    {
                        _config.GenerateEditor();
                    }
                }
                else
                {
                    _config.GenerateEditor();
                }
            }
            if (GUILayout.Button("Clear Tiles"))
            {
                if (_config.Generator != null && _config.Generator.Pool != null)
                {
                    _config.Generator.Pool.RemoveAll();

                    //Remove any trailing Tile components
                    foreach (Tile t in _config.GetComponents <Tile>())
                    {
#if UNITY_EDITOR
                        Object.DestroyImmediate(t.gameObject);
#else
                        Object.Destroy(t.gameObject);
#endif
                    }
                }
            }
        }
        void OnDrawGizmosSelected()
        {
            if (!IsInitialized)
            {
                return;
            }

            //Grid center
            Vector3 worldXYZ   = Generator.TrackedObject != null ? Generator.TrackedObject.transform.position : Vector3.zero;
            Vector2 gridCenter = new Vector2(worldXYZ.x, worldXYZ.z);


            //On general tab selected: display mesh radius squares and collider radius
            List <GridPosition> positions = TilePool.GetTilePositionsFromRadius(Generator.GenerationRadius, gridCenter, Generator.Length);

            //Mesh radius squares
            foreach (GridPosition pos in positions)
            {
                if (!EditorState.ShowLodGrid && !EditorState.ShowLodCubes)
                {
                    break;
                }

                Vector3 pos3D     = new Vector3(pos.X * Generator.Length, 0, pos.Z * Generator.Length);
                Color   prevColor = GetLodPreviewColor(pos);

                //Draw LOD squares and cubes
                if (EditorState.ShowLodGrid)
                {
                    Gizmos.color = prevColor;
                    if (Gizmos.color != Color.white)
                    {
                        Gizmos.DrawCube(pos3D, new Vector3(Generator.Length, 0, Generator.Length));
                    }

                    //Draw overlayed grid
                    Gizmos.color = Color.white;
                    pos3D.y     += 0.1f;
                    Gizmos.DrawWireCube(pos3D, new Vector3(Generator.Length, 0, Generator.Length));
                }

                //Draw cube wireframes
                if (EditorState.ShowLodCubes)
                {
                    float height = Generator.Amplitude;
                    Gizmos.color = prevColor;
                    pos3D.y     += height / 2;
                    Gizmos.DrawWireCube(pos3D, new Vector3(Generator.Length - 1f, height, Generator.Length - 1f));
                }
            }

            //LOD change radius
            if (Generator.TrackedObject != null && EditorState.ShowLodChangeRadius)
            {
                Gizmos.color  = Color.blue;
                Handles.color = Gizmos.color;

                Vector3 pos = Generator.TrackedObject.transform.position;
                DrawCylinder(pos, Generator.LodChangeRadius);
            }

            //Generation radius
            if (Generator.TrackedObject != null)
            {
                var pos = Generator.TrackedObject.transform.position;

                Gizmos.color = Color.blue;
                //DrawCylinder(pos);
            }
        }