private bool CheckPoint(Texture2D maskTexture, Vector3 position, float min, float max) { try { if (maskTexture == null) { return(false); } if (!maskTexture.isReadable) { Debug.LogError("Texture is not marked as readable. Please set is readable on the texture import settings on texture " + maskTexture.name); } Terrain terrain = TerrainHelper.GetTerrain(position); if (terrain != null) { float scalerX = (float)(position.x - terrain.transform.position.x) / (float)terrain.terrainData.size.x; float scalerZ = (float)(position.z - terrain.transform.position.z) / (float)terrain.terrainData.size.z; Color value = Color.white; value = maskTexture.GetPixel(Mathf.RoundToInt(scalerX * maskTexture.width), Mathf.RoundToInt(scalerZ * maskTexture.height)); switch (ReflectionMaskerData.m_channelSelection) { case ReflectionMaskerChannelSelection.R: if (value.r >= min && value.r <= max) { return(false); } break; case ReflectionMaskerChannelSelection.G: if (value.g >= min && value.g <= max) { return(false); } break; case ReflectionMaskerChannelSelection.B: if (value.b >= min && value.b <= max) { return(false); } break; case ReflectionMaskerChannelSelection.A: if (value.a >= min && value.a <= max) { return(false); } break; case ReflectionMaskerChannelSelection.RGBA: if (value.r >= min && value.r <= max) { return(false); } if (value.g >= min && value.g <= max) { return(false); } if (value.b >= min && value.b <= max) { return(false); } if (value.a >= min && value.a <= max) { return(false); } break; } } return(true); } catch (Exception e) { Debug.LogError("Issues happened when trying to check the point " + e.Message + " Happened here " + e.StackTrace); return(true); } }
/// <summary> /// Draw gizmos /// </summary> void OnDrawGizmos() { if (m_resources == null) { return; } if (m_spawner == null) { return; } if (m_terrainHeightMap == null) { return; } //Lets visualise fitness float x, y = transform.position.y, z; float xStart = transform.position.x - m_range; float xEnd = transform.position.x + m_range; float zStart = transform.position.z - m_range; float zEnd = transform.position.z + m_range; float ballsize = Mathf.Clamp(m_resolution * 0.25f, 0.5f, 5f); m_spawner.m_settings.m_spawnRange = m_range; m_spawner.m_spawnerBounds = new Bounds(transform.position, new Vector3(m_range * 2f, m_range * 20f, m_range * 2f)); SpawnInfo spawnInfo = new SpawnInfo(); Vector3 location = new Vector3(); float fitness = 0f; //Create caches if ((DateTime.Now - m_lastCacheUpdateDate).TotalSeconds > 5) { m_lastCacheUpdateDate = DateTime.Now; m_spawner.DeleteSpawnCaches(); m_spawner.CreateSpawnCaches(m_selectedResourceType, m_selectedResourceIdx); //Also update the location so make moving it easier Terrain terrain = TerrainHelper.GetTerrain(transform.position); if (terrain != null) { transform.position = new Vector3(transform.position.x, terrain.SampleHeight(transform.position) + 5f, transform.position.z); } } //Set up the texture layer array in spawn info spawnInfo.m_textureStrengths = new float[Terrain.activeTerrain.terrainData.alphamapLayers]; //Now visualise fitness for (x = xStart; x < xEnd; x += m_resolution) { for (z = zStart; z < zEnd; z += m_resolution) { location.Set(x, y, z); if (m_spawner.CheckLocation(location, ref spawnInfo)) { fitness = GetFitness(ref spawnInfo); if (fitness < m_minimumFitness) { continue; } Gizmos.color = Color.Lerp(m_unfitColour, m_fitColour, fitness); Gizmos.DrawSphere(spawnInfo.m_hitLocationWU, ballsize); } } } //Now draw water //Water if (m_resources != null) { BoundsDouble bounds = new BoundsDouble(); if (TerrainHelper.GetTerrainBounds(ref bounds) == true) { bounds.center = new Vector3Double(bounds.center.x, GaiaSessionManager.GetSessionManager().GetSeaLevel(), bounds.center.z); bounds.size = new Vector3Double(bounds.size.x, 0.05f, bounds.size.z); Gizmos.color = new Color(Color.blue.r, Color.blue.g, Color.blue.b, Color.blue.a / 4f); Gizmos.DrawCube(bounds.center, bounds.size); } } }