public detailPrototype_class() { this.minWidth = (float)1; this.maxWidth = (float)2; this.minHeight = (float)1; this.maxHeight = (float)2; this.noiseSpread = 0.1f; this.healthyColor = Color.white; this.dryColor = new Color(0.8f, 0.76f, 0.53f); this.renderMode = DetailRenderMode.Grass; }
public void SetFromPrototype(DetailPrototype prototype) { BendFactor = prototype.bendFactor; DryColor = prototype.dryColor; HealthyColor = prototype.healthyColor; MaxHeight = prototype.maxHeight; MinHeight = prototype.minHeight; MaxWidth = prototype.maxWidth; MinWidth = prototype.minWidth; NoiseSpread = prototype.noiseSpread; Prototype = prototype.prototype; PrototypeTexture = prototype.prototypeTexture; RenderMode = prototype.renderMode; }
private void BeginRecordDetailProperties() { m_initialDetailTexture = DetailTexture; m_initialDetail = Detail; m_initialRenderMode = RenderMode; m_initialBendFactor = BendFactor; m_initialDryColor = DryColor; m_initialHealthyColor = HealthyColor; m_initialMaxHeight = MaxHeight; m_initialMaxWidth = MaxWidth; m_initialMinHeight = MinHeight; m_initialMinWidth = MinWidth; m_initialNoiseSpread = NoiseSpread; }
/// <summary> /// Constructor to create clone copy /// </summary> /// <param name="lbGrassConfig"></param> public LBGrassConfig(LBGrassConfig lbGrassConfig) { grassTextureName = lbGrassConfig.grassTextureName; grassTexturePath = lbGrassConfig.grassTexturePath; grassTextureAlternativePath = lbGrassConfig.grassTextureAlternativePath; sourceName = lbGrassConfig.sourceName; grassPatchFadingMode = lbGrassConfig.grassPatchFadingMode; detailRenderMode = lbGrassConfig.detailRenderMode; dryColour = lbGrassConfig.dryColour; healthyColour = lbGrassConfig.healthyColour; minHeight = lbGrassConfig.minHeight; maxHeight = lbGrassConfig.maxHeight; minWidth = lbGrassConfig.minWidth; maxWidth = lbGrassConfig.maxWidth; }
internal void InitializeDefaults(Terrain terrain, int index) { this.m_Terrain = terrain; this.m_PrototypeIndex = index; DetailPrototype detailPrototype; if (this.m_PrototypeIndex == -1) { detailPrototype = new DetailPrototype(); } else { detailPrototype = this.m_Terrain.terrainData.detailPrototypes[this.m_PrototypeIndex]; } this.m_Detail = detailPrototype.prototype; this.m_NoiseSpread = detailPrototype.noiseSpread; this.m_MinWidth = detailPrototype.minWidth; this.m_MaxWidth = detailPrototype.maxWidth; this.m_MinHeight = detailPrototype.minHeight; this.m_MaxHeight = detailPrototype.maxHeight; this.m_HealthyColor = detailPrototype.healthyColor; this.m_DryColor = detailPrototype.dryColor; DetailRenderMode renderMode = detailPrototype.renderMode; if (renderMode != DetailRenderMode.GrassBillboard) { if (renderMode != DetailRenderMode.Grass) { if (renderMode == DetailRenderMode.VertexLit) { this.m_RenderMode = DetailMeshRenderMode.VertexLit; } } else { this.m_RenderMode = DetailMeshRenderMode.Grass; } } else { Debug.LogError("Detail meshes can't be rendered as billboards"); this.m_RenderMode = DetailMeshRenderMode.Grass; } this.OnWizardUpdate(); }
protected override void ReadFromImpl(object obj) { base.ReadFromImpl(obj); DetailPrototype uo = (DetailPrototype)obj; prototype = ToID(uo.prototype); prototypeTexture = ToID(uo.prototypeTexture); minWidth = uo.minWidth; maxWidth = uo.maxWidth; minHeight = uo.minHeight; maxHeight = uo.maxHeight; noiseSpread = uo.noiseSpread; bendFactor = uo.bendFactor; healthyColor = uo.healthyColor; dryColor = uo.dryColor; renderMode = uo.renderMode; usePrototypeMesh = uo.usePrototypeMesh; }
internal static bool IsModeSupportedByRenderPipeline(DetailRenderMode renderMode, bool useInstancing, out string errorMessage) { if (GraphicsSettings.currentRenderPipeline != null) { if (renderMode == DetailRenderMode.GrassBillboard && GraphicsSettings.currentRenderPipeline.terrainDetailGrassBillboardShader == null) { errorMessage = "The current render pipeline does not support Billboard details. Details will not be rendered."; return(false); } else if (renderMode == DetailRenderMode.VertexLit && !useInstancing && GraphicsSettings.currentRenderPipeline.terrainDetailLitShader == null) { errorMessage = "The current render pipeline does not support VertexLit details. Details will be rendered using the default shader."; return(false); } else if (renderMode == DetailRenderMode.Grass && GraphicsSettings.currentRenderPipeline.terrainDetailGrassShader == null) { errorMessage = "The current render pipeline does not support Grass details. Details will be rendered using the default shader without alpha test and animation."; return(false); } } errorMessage = string.Empty; return(true); }
public static void AddToDetail(DetailRenderMode mode, bool isMesh) { var terrain = (Terrain)FindObjectOfType(typeof(Terrain)); var listOfDetails = new List <DetailPrototype>(); listOfDetails.AddRange(terrain.terrainData.detailPrototypes); var detailPrefabs = new List <GameObject>(); var grassTex = new List <Texture2D>(); foreach (var obj in listOfDetails) { detailPrefabs.Add(obj.prototype); if (!isMesh) { grassTex.Add(obj.prototypeTexture); } } var selection = Selection.objects; foreach (var obj in selection) { var thisObject = obj as GameObject; var thisTexture = obj as Texture2D; if ((thisObject == null && isMesh) || (thisTexture == null && !isMesh)) { if (EditorUtility.DisplayDialog(obj.name + " not added.", obj.name + " skipped because it is not a valid target", "Continue", "Cancel")) { continue; } else { return; } } if (isMesh) { foreach (var rend in thisObject.GetComponentsInChildren <Renderer>()) { if (rend.sharedMaterials.Length >= 1) { continue; } if (EditorUtility.DisplayDialog(obj.name + " may cause issue", obj.name + " has multiple materials and will not display on terrain. Would you like to add to terrain anyway?", "Add Anyway", "Camcel")) { Debug.Log(obj.name + " added to terrain anyway"); } else { Debug.Log(obj.name + " not added to terrain"); return; } } } if ((detailPrefabs.Contains(thisObject) && isMesh) || (grassTex.Contains(thisTexture) && !isMesh)) { var choice = EditorUtility.DisplayDialogComplex("Detail Object already Exists!", "What would you like to do?", "Replace Prefab", "Cancel", "Make Copy"); switch (choice) { case (0): Debug.Log("Replacing Prefab"); if (isMesh) { detailPrefabs[detailPrefabs.IndexOf(obj as GameObject)] = obj as GameObject; } else { grassTex[grassTex.IndexOf(obj as Texture2D)] = obj as Texture2D; } break; case (1): Debug.Log("Cancelling Process"); continue; case (2): Debug.Log("Duplicating Prefab"); break; } } var prototype = new DetailPrototype(); prototype.renderMode = mode; prototype.usePrototypeMesh = isMesh; if (isMesh) { prototype.prototype = obj as GameObject; //if (fileExists) // prototype.prototype.name = GetUniqueName(prototype.prototype.name, protoNames); } else { prototype.prototypeTexture = obj as Texture2D; //if (fileExists) // prototype.prototypeTexture.name = GetUniqueName(prototype.prototype.name, protoNames); } listOfDetails.Add(prototype); Undo.RegisterCompleteObjectUndo(terrain, "AddDetailToTerrain"); terrain.terrainData.detailPrototypes = listOfDetails.ToArray(); terrain.Flush(); terrain.terrainData.RefreshPrototypes(); EditorUtility.DisplayDialog("Success", obj.name + " successfully added to terrain as " + mode + ". The change may take a moment to take effect.", "Continue"); } terrain.Flush(); terrain.terrainData.RefreshPrototypes(); }
/// <summary> /// Constructor to create a clone of a LBTerrainGrass instance /// </summary> /// <param name="lbTerrainGrass"></param> public LBTerrainGrass(LBTerrainGrass lbTerrainGrass) { this.texture = lbTerrainGrass.texture; if (lbTerrainGrass.textureName == null) { this.textureName = string.Empty; } else { this.textureName = lbTerrainGrass.textureName; } this.minHeight = lbTerrainGrass.minHeight; this.maxHeight = lbTerrainGrass.maxHeight; this.minWidth = lbTerrainGrass.minWidth; this.maxWidth = lbTerrainGrass.maxWidth; this.healthyColour = lbTerrainGrass.healthyColour; this.dryColour = lbTerrainGrass.dryColour; this.noiseSpread = lbTerrainGrass.noiseSpread; this.minPopulatedHeight = lbTerrainGrass.minPopulatedHeight; this.maxPopulatedHeight = lbTerrainGrass.maxPopulatedHeight; this.minInclination = lbTerrainGrass.minInclination; this.maxInclination = lbTerrainGrass.maxInclination; this.influence = lbTerrainGrass.influence; this.minDensity = lbTerrainGrass.minDensity; this.density = lbTerrainGrass.density; this.detailRenderMode = lbTerrainGrass.detailRenderMode; this.isCurvatureConcave = lbTerrainGrass.isCurvatureConcave; this.curvatureDistance = lbTerrainGrass.curvatureDistance; this.curvatureMinHeightDiff = lbTerrainGrass.curvatureMinHeightDiff; this.grassPlacingMode = lbTerrainGrass.grassPlacingMode; this.grassPatchFadingMode = lbTerrainGrass.grassPatchFadingMode; this.map = lbTerrainGrass.map; this.mapColour = lbTerrainGrass.mapColour; this.mapTolerance = lbTerrainGrass.mapTolerance; this.mapInverse = lbTerrainGrass.mapInverse; this.mapToleranceBlendCurve = lbTerrainGrass.mapToleranceBlendCurve; this.mapIsPath = lbTerrainGrass.mapIsPath; this.isDisabled = lbTerrainGrass.isDisabled; if (lbTerrainGrass.filterList != null) { this.filterList = LBFilter.CopyList(lbTerrainGrass.filterList); } else { this.filterList = new List <LBFilter>(); } this.showGrass = lbTerrainGrass.showGrass; this.useNoise = lbTerrainGrass.useNoise; this.noiseTileSize = lbTerrainGrass.noiseTileSize; this.noiseOctaves = lbTerrainGrass.noiseOctaves; this.grassPlacementCutoff = lbTerrainGrass.grassPlacementCutoff; if (lbTerrainGrass.lbTerrainDataList == null) { this.lbTerrainDataList = null; } else { this.lbTerrainDataList = new List <LBTerrainData>(lbTerrainGrass.lbTerrainDataList); } this.useMeshPrefab = lbTerrainGrass.useMeshPrefab; this.meshPrefab = lbTerrainGrass.meshPrefab; if (lbTerrainGrass.meshPrefabName == null) { this.meshPrefabName = string.Empty; } else { this.meshPrefabName = lbTerrainGrass.meshPrefabName; } this.showPrefabPreview = lbTerrainGrass.showPrefabPreview; this.GUID = lbTerrainGrass.GUID; }
// Class constructors public LBTerrainGrass() { this.texture = null; // Added v1.4.2 Beta 5b this.textureName = string.Empty; this.minHeight = 0.5f; this.maxHeight = 1f; this.minWidth = 0.5f; this.maxWidth = 1f; this.healthyColour = new Color(67f / 255f, 249 / 255f, 42 / 255f, 1f); this.dryColour = new Color(205f / 255f, 188f / 255f, 26f / 255f, 1f); this.noiseSpread = 0.1f; this.minPopulatedHeight = 0.5f; this.maxPopulatedHeight = 1f; this.minInclination = 0f; this.maxInclination = 30f; this.influence = 0.5f; this.minDensity = 0; // So to a low default (2) max density to cater for mesh grasses. this.density = 2; this.detailRenderMode = DetailRenderMode.Grass; this.grassPlacingMode = GrassPlacingMode.Height; this.grassPatchFadingMode = GrassPatchFadingMode.DontFade; // Added v2.0.7 Beta 6 this.isCurvatureConcave = false; this.curvatureMinHeightDiff = 1f; this.curvatureDistance = 5f; // Added v1.1 Beta 7 this.map = null; this.mapColour = UnityEngine.Color.green; this.mapTolerance = 1; this.mapInverse = false; // Added v1.3.2 Beta 7b this.mapToleranceBlendCurve = LBMap.GetDefaultToleranceBlendCurve; this.mapIsPath = false; // Added v1.2.1 this.isDisabled = false; // Added v1.3.0 Beta 3a this.showGrass = true; // Added v1.3.1 Beta 6a this.useNoise = false; this.noiseTileSize = 10f; this.noiseOctaves = 5; this.grassPlacementCutoff = 0.5f; // Added v1.4.2 Beta 3f this.lbTerrainDataList = null; // Added v1.4.2 Beta 5c this.useMeshPrefab = false; this.meshPrefab = null; this.meshPrefabName = string.Empty; // Added v2.0.7 Beta 4a this.showPrefabPreview = false; // Added v2.0.0 // Assign a unique identifier GUID = System.Guid.NewGuid().ToString(); }
void FillDetailMap(Terrain terrain, int tileX, int tileZ) { int[,] detailMap0 = new int[m_detailMapSize, m_detailMapSize]; int[,] detailMap1 = new int[m_detailMapSize, m_detailMapSize]; int[,] detailMap2 = new int[m_detailMapSize, m_detailMapSize]; int[,] detailMap3 = new int[m_detailMapSize, m_detailMapSize]; int[,] detailMap4 = new int[m_detailMapSize, m_detailMapSize]; int[,] detailMap5 = new int[m_detailMapSize, m_detailMapSize]; // gameObject.AddComponent<UsPgEraser>(); float ratio = (float)m_terrainSize / (float)m_detailMapSize; Random.seed = 481516234; ///////////////Генерация травы//////////////////////////////////////// for (int x = 0; x < m_detailMapSize; x++) { for (int z = 0; z < m_detailMapSize; z++) { ///////////////////////////////////////////////////////////////////// /////////Переменные размерности от угла земли///////// float unit = 1f / (m_detailMapSize - 1); float normX = x * unit; float normZ = z * unit; float angle = terrain.terrainData.GetSteepness(normX, normZ); float height = terrain.terrainData.GetInterpolatedHeight(normX, normZ); float frac = angle / 65.0f; ///////////////////Плейсить траву если угол меньше 90 градусов c учётом высоты водной поверхности и водной поверхности/////// if (frac < 0.6f && height > 1.1f * m_waterHeight) { float worldPosX = (x + tileX * (m_detailMapSize - 1)) * ratio; float worldPosZ = (z + tileZ * (m_detailMapSize - 1)) * ratio; float noise = m_detailNoise.FractalNoise2D(worldPosX, worldPosZ, 3, m_detailFrq, 1.0f); ///////////////Распределение шума//////////////// if (noise > 0.0f) { float rnd = Random.value; if (rnd < 0.33f) { detailMap0[z, x] = 3; } else if (rnd < 0.46f) { detailMap1[z, x] = 3; } else if (rnd < 0.56f) { detailMap2[z, x] = 3; } else if (rnd < 0.66f) { detailMap3[z, x] = 3; } else if (rnd < 0.76f) { detailMap4[z, x] = 3; } else { detailMap5[z, x] = 3; } } if (height > m_cliffHeight) { detailMap0[z, x] = 0; detailMap1[z, x] = 0; detailMap2[z, x] = 0; detailMap3[z, x] = 0; detailMap4[z, x] = 0; detailMap5[z, x] = 0; } } ///////////////////////////////////////////////////////////////////// } } ///////////////////////////////////////////////////////////////////////////// terrain.terrainData.wavingGrassStrength = m_wavingGrassSize; terrain.terrainData.wavingGrassAmount = m_wavingGrassBending; terrain.terrainData.wavingGrassSpeed = m_wavingGrassSpeed; terrain.terrainData.wavingGrassTint = GeneralGrassTint; terrain.detailObjectDensity = m_detailObjectDensity; detailMode = DetailRenderMode.Grass; terrain.detailObjectDistance = m_detailObjectDistance; terrain.terrainData.SetDetailResolution(m_detailMapSize, m_detailResolutionPerPatch); terrain.terrainData.SetDetailLayer(0, 0, 0, detailMap0); terrain.terrainData.SetDetailLayer(0, 0, 1, detailMap1); terrain.terrainData.SetDetailLayer(0, 0, 2, detailMap2); terrain.terrainData.SetDetailLayer(0, 0, 3, detailMap3); terrain.terrainData.SetDetailLayer(0, 0, 4, detailMap4); terrain.terrainData.SetDetailLayer(0, 0, 5, detailMap5); terrain.terrainData.RefreshPrototypes(); terrain.Flush(); }
private void EndRecordDetailProperties() { IRTE editor = IOC.Resolve <IRTE>(); Terrain terrain = Terrain; int index = m_detailsList.SelectedIndex; Texture2D detailTexture = DetailTexture; GameObject detail = Detail; DetailRenderMode renderMode = RenderMode; float bendFactor = BendFactor; Color dryColor = DryColor; Color healthyColor = HealthyColor; float maxHeight = MaxHeight; float maxWidth = MaxWidth; float minHeight = MinHeight; float minWidth = MinWidth; float noiseSpread = NoiseSpread; m_detailsList.DataBindVisible(); editor.Undo.CreateRecord(record => { DetailPrototype selectedDetail = terrain.terrainData.detailPrototypes[index]; if (selectedDetail != null) { selectedDetail.prototypeTexture = detailTexture; selectedDetail.prototype = detail; selectedDetail.renderMode = renderMode; selectedDetail.bendFactor = bendFactor; selectedDetail.dryColor = dryColor; selectedDetail.healthyColor = healthyColor; selectedDetail.maxHeight = maxHeight; selectedDetail.maxWidth = maxWidth; selectedDetail.minHeight = minHeight; selectedDetail.minWidth = minWidth; selectedDetail.noiseSpread = noiseSpread; Refresh(terrain, index, selectedDetail); if (m_detailsList != null) { m_detailsList.Items = terrain.terrainData.detailPrototypes.Select(p => new DetailPrototypeWrapper(p)); m_detailsList.SelectedIndex = index; } } return(true); }, record => { DetailPrototype selectedDetail = terrain.terrainData.detailPrototypes[index]; if (selectedDetail != null) { selectedDetail.prototypeTexture = m_initialDetailTexture; selectedDetail.prototype = m_initialDetail; selectedDetail.renderMode = m_initialRenderMode; selectedDetail.bendFactor = m_initialBendFactor; selectedDetail.dryColor = m_initialDryColor; selectedDetail.healthyColor = m_initialHealthyColor; selectedDetail.maxHeight = m_initialMaxHeight; selectedDetail.maxWidth = m_initialMaxWidth; selectedDetail.minHeight = m_initialMinHeight; selectedDetail.minWidth = m_initialMinWidth; selectedDetail.noiseSpread = m_initialNoiseSpread; Refresh(terrain, index, selectedDetail); if (m_detailsList != null) { m_detailsList.Items = terrain.terrainData.detailPrototypes.Select(p => new DetailPrototypeWrapper(p)); m_detailsList.SelectedIndex = index; } } return(true); }); }