public override void OnInspectorGUI() { serializedObject.Update(); CustomTerrain terrain = (CustomTerrain)target; EditorGUILayout.PropertyField(_resetHeightMap); _showRandom = EditorGUILayout.Foldout(_showRandom, "Random"); if (_showRandom) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set Heights Between Random Values", EditorStyles.boldLabel); EditorGUILayout.PropertyField(_randomHeightRange); if (GUILayout.Button("Random Heights")) { terrain.RandomTerrain(); } } _showLoadHeights = EditorGUILayout.Foldout(_showLoadHeights, "Load Heights"); if (_showLoadHeights) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Load Heights From Texture", EditorStyles.boldLabel); EditorGUILayout.PropertyField(_heightMapImage); EditorGUILayout.PropertyField(_heightMapScale); if (GUILayout.Button("Load Texture")) { terrain.LoadTexture(); } } _showPerlinNoise = EditorGUILayout.Foldout(_showPerlinNoise, "Perlin Noise"); if (_showPerlinNoise) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Generate Heights From Perlin Noise", EditorStyles.boldLabel); EditorGUILayout.Slider(_perlinXScale, 0, 0.01f, new GUIContent("X Scale")); EditorGUILayout.Slider(_perlinYScale, 0, 0.01f, new GUIContent("Y Scale")); EditorGUILayout.IntSlider(_perlinXOffset, 0, 10000, new GUIContent("X Offset")); EditorGUILayout.IntSlider(_perlinYOffset, 0, 10000, new GUIContent("Y Offset")); EditorGUILayout.IntSlider(_perlinOctaves, 0, 10, new GUIContent("Octaves")); EditorGUILayout.Slider(_perlinPersistance, 0.1f, 10, new GUIContent("Persistance")); EditorGUILayout.Slider(_perlinHeightScale, 0, 1, new GUIContent("Height Scale")); if (GUILayout.Button("Generate")) { terrain.Perlin(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); if (GUILayout.Button("Reset")) { terrain.ResetTerrain(); } serializedObject.ApplyModifiedProperties(); }
private void RandomTerrainGUI(CustomTerrain terrain) { showRandom = EditorGUILayout.Foldout(showRandom, "Random"); if (showRandom) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set heights between values", EditorStyles.boldLabel); EditorGUILayout.PropertyField(randomHeightRange); if (GUILayout.Button("Random Heights")) { terrain.RandomTerrain(); } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Generate landshaft using Perlin Noise", EditorStyles.boldLabel); EditorGUILayout.Slider(perlinXScale, 0, 1, new GUIContent("XScale")); EditorGUILayout.Slider(perlinYScale, 0, 1, new GUIContent("YScale")); EditorGUILayout.IntSlider(perlinXOffset, 0, 10000, new GUIContent("XOffset")); EditorGUILayout.IntSlider(perlinYOffset, 0, 10000, new GUIContent("YOffset")); EditorGUILayout.IntSlider(pelinOctaves, 1, 10, new GUIContent("pelinOctaves")); EditorGUILayout.Slider(perlinPersistance, 0.1f, 10, new GUIContent("perlinPersistance")); EditorGUILayout.Slider(perlinHeightScale, 0, 1, new GUIContent("perlinHeightScale")); if (GUILayout.Button("Perlin Noise")) { terrain.Perlin(); } } }
private void SplatMapsGUI(CustomTerrain terrain) { showSplatMaps = EditorGUILayout.Foldout(showSplatMaps, "Splat Maps"); if (showSplatMaps) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Splat Maps", EditorStyles.boldLabel); EditorGUILayout.Slider(blendingNoiseMultiplier, 0.1f, 1f, new GUIContent("Noise Multiplier")); EditorGUILayout.Slider(blendingNoiseParams, 0.001f, 0.1f, new GUIContent("Noise Parameters")); EditorGUILayout.Slider(blendingOffset, 0.001f, 0.1f, new GUIContent("Noise Offset")); splatMapTable = GUITableLayout.DrawTable(splatMapTable, serializedObject.FindProperty(nameof(terrain.splatHeights))); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewSplatHeight(); } if (GUILayout.Button("-")) { terrain.RemoveSplatHeight(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Apply")) { terrain.SplatMaps(); } } }
public bool Contains(MPos uv) { // The first check ensure that the cell is within the valid map region,avoiding potential crashes in deeper code. //第一次检查确保单元格在有效的地图区域内,避免在更深的代码中潜在的崩溃。 // All CellLayers have the same geometry,and CustomTerrain is convenient. return(CustomTerrain.Contains(uv) && ContainsAllProjectedCellsCovering(uv)); }
private void MultiplePerlinGUI(CustomTerrain terrain) { showMultiplePerlin = EditorGUILayout.Foldout(showMultiplePerlin, "Multiple Perline Noises"); if (showMultiplePerlin) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Multiple Perline Noises", EditorStyles.boldLabel); perlinParametrsTable = GUITableLayout.DrawTable(perlinParametrsTable, serializedObject.FindProperty(nameof(terrain.perlinParamentrs))); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { terrain.AddNewPerlin(); } if (GUILayout.Button("-")) { terrain.RemovePerlin(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Multiple Perlin Terrain")) { terrain.MultiplePerlinTerrain(); } if (GUILayout.Button("Generate")) { terrain.MultiplePerlinTerrain(); } } }
private void GenerateTexture(CustomTerrain terrain) { showHeights = EditorGUILayout.Foldout(showHeights, "Height Map"); if (showHeights) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); int hmtSize = (int)(EditorGUIUtility.currentViewWidth - 100); GUILayout.Label(heightmapTexture, GUILayout.Width(hmtSize), GUILayout.Height(hmtSize)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Refresh", GUILayout.Width(hmtSize))) { float[,] heightMap = terrain.terrainData.GetHeights(0, 0, terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight); for (int y = 0; y < terrain.terrainData.heightmapHeight; y++) { for (int x = 0; x < terrain.terrainData.heightmapWidth; x++) { heightmapTexture.SetPixel(x, y, new Color(heightMap[x, y], heightMap[x, y], heightMap[x, y], 1)); } } heightmapTexture.Apply(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } }
/// <summary> /// 在地图上放随机地形 /// </summary> public void FillingMapWithTerrain() { List <CustomTerrain> keys = new List <CustomTerrain>(terrianDic.Keys); //前几个找随机空地放地形 for (int i = 0; i < keys.Count - 1; i++) { CustomTerrain curTerrain = keys[i]; for (int j = 0; j < terrianDic[curTerrain]; j++) { int[] emptyGridXY = GetEmptyGird(1); int x = emptyGridXY[0]; int y = emptyGridXY[1]; Map[x, y].SetTerrianInfo(curTerrain); terrianMap.SetTile(Map[x, y].CoordinateInMap, curTerrain.tile); } } //地图上空的地方放最后一个地形 CustomTerrain lastTerrain = keys[keys.Count - 1]; for (int i = 0; i < Map.GetLength(0); i++) { for (int j = 0; j < Map.GetLength(1); j++) { if (!Map[i, j].isTerriannOccupied) { Map[i, j].SetTerrianInfo(lastTerrain); terrianMap.SetTile(Map[i, j].CoordinateInMap, lastTerrain.tile); } } } }
public bool Contains(MPos uv) { // The first check ensures that the cell is within the valid map region, avoiding // potential crashes in deeper code. All CellLayers have the same geometry, and // CustomTerrain is convenient. return(CustomTerrain.Contains(uv) && ContainsAllProjectedCellsCovering(uv)); }
public bool placeTree(ref TreeTextures t, ref CustomTerrain terrain, ref Vector3 p) { //Check steepness TextureConstraints cons = treescontrainst[t]; return(terrain.getSteepness(p.x, p.z) <= cons.max_steepness && p.y >= cons.min_altitude * highest_altitude && p.y <= cons.max_altitude * highest_altitude); }
public override void OnInspectorGUI() { serializedObject.Update(); CustomTerrain terrain = (CustomTerrain)target; showRandom = EditorGUILayout.Foldout(showRandom, "Random"); if (showRandom) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set Heights Between Random Values", EditorStyles.boldLabel); EditorGUILayout.PropertyField(randomHeightRange); if (GUILayout.Button("Random Heights")) { terrain.RandomTerrain(); } if (GUILayout.Button("Add Other Layer of Random Heights")) { terrain.AddOtherLayerRandomTerrain(); } if (GUILayout.Button("Reset Heights")) { terrain.ResetTerrain(); } } serializedObject.ApplyModifiedProperties(); }
void Initialize(string mapFile) { stream.Seek(400, SeekOrigin.Begin); var x = stream.ReadInt32(); var y = stream.ReadInt32(); mapSize = new Size(x * 2, y * 2); if (!Game.ModData.DefaultTerrainInfo.TryGetValue(tileset, out var terrainInfo)) { throw new InvalidDataException("Unknown tileset {0}".F(tileset)); } this.terrainInfo = terrainInfo as CustomTerrain; map = new Map(Game.ModData, terrainInfo, mapSize.Width + 2 * MapCordonWidth, mapSize.Height + 2 * MapCordonWidth) { Title = Path.GetFileNameWithoutExtension(mapFile), Author = "Gate 5 Creations" }; var tl = new PPos(MapCordonWidth, MapCordonWidth); var br = new PPos(MapCordonWidth + mapSize.Width - 1, MapCordonWidth + mapSize.Height - 1); map.SetBounds(tl, br); stream.Seek(424, SeekOrigin.Begin); numberOfActors = stream.ReadInt32(); mapPlayers = new MapPlayers(map.Rules, 0); }
void Start() { terrain = Terrain.activeTerrain; cterrain = terrain.GetComponent <CustomTerrain>(); width = terrain.terrainData.size.x; height = terrain.terrainData.size.z; }
// Update is called once per frame void Update() { if (randomWeights && layers.Length > 0) { layers_weights = CustomTerrain.randomWeights(layers.Length); } updateAll(); }
void Start() { terrain = Terrain.activeTerrain; cterrain = terrain.GetComponent <CustomTerrain>(); width = terrain.terrainData.size.x; height = terrain.terrainData.size.z; anim = gameObject.GetComponent <Animal>(); }
// Start is called before the first frame update void Start() { anim = GetComponent <Animator>(); cam = Camera.main; terrain = FindObjectOfType <CustomTerrain>(); lastpos = transform.localPosition; ikcomp = anim.gameObject.GetComponent <PlayerControllerIKFeetPlacementTask>(); }
void Start() { anim = GetComponent <Animator>(); network_struct = new int[] { input, input *2, input *4, input *2, input, 3 }; energy = max_energy; terrain = Terrain.activeTerrain; cterrain = terrain.GetComponent <CustomTerrain>(); previous_location = transform.position; }
public override void OnInspectorGUI() { bool changed = DrawDefaultInspector(); autoUpdate = EditorGUILayout.Toggle("Auto Update", autoUpdate); if ((changed && autoUpdate) || GUILayout.Button("Generate")) { CustomTerrain terrain = (CustomTerrain)target; terrain.GenerateAndApplyMesh(); } }
public void setup(CustomTerrain ct, GeneticAlgo ga) { terrain = ct; genetic_algo = ga; updateSetup(); zone = new VegetationConstraint[livesIn.Length]; for (int i = 0; i < livesIn.Length; i++) { zone[i] = terrain.getVegetationFromZone(livesIn[i]);//Added } }
public int getDet(int x, int y, ref Vector2 detail_sz, ref CustomTerrain cterrain) { Vector2 prop = cterrain.getPropDetAlpha();//Added Layers l = cterrain.getOccupance(y / (int)prop.y, x / (int)prop.x); Layers l2 = cterrain.getOccupance((int)Mathf.Min(y + grassOffset, detail_sz.y - 1) / (int)prop.y, (int)Mathf.Min(x + grassOffset, detail_sz.x - 1) / (int)prop.x); Layers l3 = cterrain.getOccupance((int)Mathf.Max(y - grassOffset, 0) / (int)prop.y, (int)Mathf.Max(x - grassOffset, 0) / (int)prop.x); if (place(y, x, ref cterrain) && Array.Exists(terrain_of_growth, el => el == l && el == l2 && el == l3)) { return(1); } return(0); }
private void RefreshHeightMapDisplay(CustomTerrain terrain) { float[,] heightMap = terrain.HeightMap; for (int y = 0; y < terrain.terrainData.heightmapHeight; y++) { for (int x = 0; x < terrain.terrainData.heightmapWidth; x++) { heightMapTexture.SetPixel(x, y, new Color(heightMap[x, y], heightMap[x, y], heightMap[x, y], 1.0f)); } } heightMapTexture.Apply(); }
public bool place(float x, float z, ref CustomTerrain terrain, bool det = false) { float y = terrain.get(x, z); bool check = terrain.getSteepness(x, z) <= max_steepness && y >= min_altitude * terrain.max_height && y <= max_altitude * terrain.max_height; if (check && det) { Vector2 prop = terrain.textureSize();//Added Layers l = terrain.getOccupance((int)z, (int)x); Layers l2 = terrain.getOccupance((int)Mathf.Min(z + grassOffset, prop.y - 1), (int)Mathf.Min(x + grassOffset, prop.x - 1)); Layers l3 = terrain.getOccupance((int)Mathf.Max(z - grassOffset, 0), (int)Mathf.Max(x - grassOffset, 0)); return(Array.Exists(terrain_of_growth, el => el == l && el == l2 && el == l3)); } return(check); }
public void ReloadTextures() { customTerrains.Clear(); foreach (Terrain terrain in terrains) { CustomTerrain terrainTracks = terrain.GetComponent <CustomTerrain>(); if (terrainTracks == null) { terrainTracks = terrain.gameObject.AddComponent <CustomTerrain>(); } customTerrains.Add(terrainTracks); terrainTracks.Reload(terrainShader, customTextures, new Vector3(tesselation, MinTesDist, MaxTesDist));; } }
private void LoadingHeightGUI(CustomTerrain terrain) { showLoadHeights = EditorGUILayout.Foldout(showLoadHeights, "Load heights"); if (showLoadHeights) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Load heights from texture", EditorStyles.boldLabel); EditorGUILayout.PropertyField(heighMapImage); EditorGUILayout.PropertyField(heighMapScale); if (GUILayout.Button("Load Texture")) { terrain.LoadTexture(); } } }
private void MidpointDisplacementGUI(CustomTerrain terrain) { midpointDisplacement = EditorGUILayout.Foldout(midpointDisplacement, "MidpointDisplacement"); if (midpointDisplacement) { GUILayout.Label("Midpoint Displacement", EditorStyles.boldLabel); EditorGUILayout.Slider(mpRoughtness, 0f, 5f, new GUIContent("roughtness")); EditorGUILayout.PropertyField(mpMinHeight, new GUIContent("MP Min Height")); EditorGUILayout.PropertyField(mpMaxHeight, new GUIContent("MP Max Height")); EditorGUILayout.PropertyField(mpDampererPower, new GUIContent("MP Damperer Power")); if (GUILayout.Button("Midpoint Displacement")) { terrain.MidpointDisplacement(); } } }
void Start() { terrain = GetComponent <CustomTerrain>(); // Retrieve once public variables from CustomTerrain.cs LeftFootCollider = terrain.leftFootCollider; RightFootCollider = terrain.rightFootCollider; // Retrieve once though methods of CustomTerrain.cs HeightmapSize = terrain.GridSize(); TerrainSize = terrain.TerrainSize(); //mass = terrain.mass; //force = mass * 10f; IsPreviousLeftFootGrounded = false; IsPreviousRightFootGrounded = false; }
public override void OnInspectorGUI() { DrawDefaultInspector(); CustomTerrain nt = (CustomTerrain)target; if (GUILayout.Button("Regenerate")) { nt.Regenerate(); } if (GUILayout.Button("Save")) { nt.SaveMesh(); } if (GUILayout.Button("Load")) { nt.LoadMesh(); } }
public override void OnUpdateFunc() { base.OnUpdateFunc(); GlobalUImanager.Instance.ShowTip(_showTip && !_lockUpdateMouse); //显示每个地块的信息 if (_showTip && !_lockUpdateMouse) { mousePosition = Input.mousePosition; if (RectTransformUtility.ScreenPointToLocalPointInRectangle( tip.canvasTransform as RectTransform, mousePosition, null, out UIpos)) { mapCoordinate = BattleManager.Instance.BattleMap.MousePos2MapCoordinate(mousePosition); tip.SetPosition(UIpos, mapCoordinate); CustomTerrain curTerrain = BattleManager.Instance.BattleMap.GetCurMouseLand(mousePosition).CurTerrian; tip.SetText(string.Format("当前地形:{0}\n人口:{1},金币:{2},粮食:{3}", curTerrain.name, curTerrain.population, curTerrain.gold, curTerrain.food)); } } }
public override void OnInspectorGUI() { serializedObject.Update(); CustomTerrain terrain = (CustomTerrain)target; showRandom = EditorGUILayout.Foldout(showRandom, "Random"); if (showRandom) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Set heights between random values", EditorStyles.boldLabel); EditorGUILayout.PropertyField(randomHeightRange); if (GUILayout.Button("Random Heights")) { terrain.RandomTerrain(); } } showLoadHeights = EditorGUILayout.Foldout(showLoadHeights, "Load Heights"); if (showLoadHeights) { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Label("Load Heights From Texture", EditorStyles.boldLabel); EditorGUILayout.PropertyField(heightMapImage); EditorGUILayout.PropertyField(heightMapScale); if (GUILayout.Button("Load Texture")) { terrain.LoadTexture(); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); if (GUILayout.Button("Reset Terrain")) { terrain.ResetTerrain(); } serializedObject.ApplyModifiedProperties(); }
private void OnDrawGizmos() { if (!_terrain) { _terrain = GetComponent <CustomTerrain>(); } float w = _terrain.width * _terrain.spacing.x; float h = _terrain.height * _terrain.spacing.z; Gizmos.color = Color.blue; Vector3 destination = transform.position + respawnOffset + (transform.TransformDirection(respawnOffsetDirection) * w); Gizmos.DrawLine(transform.position + respawnOffset, destination); Gizmos.color = Color.magenta; if (player) { Gizmos.DrawLine(new Vector3(player.position.x, destination.y, player.position.z), new Vector3(player.position.x, destination.y, destination.z)); } /* * float one = w / chunkCount; * for (int x = 0; x < chunkCount + 1; x++) { * Gizmos.color = Color.green; * Gizmos.DrawLine(transform.position + new Vector3(one * x, 0f, 0f), transform.position + new Vector3(one * x, 0f, h)); * * int xIndex = ((_terrain.width / chunkCount) * x) % _terrain.width; * * Gizmos.color = Color.cyan; * if (_terrain && _terrain.Vertices != null && _terrain.Vertices.Length > 0) * Gizmos.DrawSphere(_terrain.transform.TransformPoint(_terrain.Vertices[xIndex]), 5f); * } * Gizmos.color = Color.green; */ Gizmos.color = Color.blue; Vector3 mid = new Vector3(transform.position.x, transform.position.y + _terrain.mirrorPositionOffset.y / 2f, transform.position.z); Gizmos.DrawSphere(mid, 2f); }
void Start() { terrain = Terrain.activeTerrain; cterrain = GetComponent <CustomTerrain>(); curr_growth = 0.0f; animals = new List <GameObject>(); width = terrain.terrainData.size.x; height = terrain.terrainData.size.z; for (int i = 0; i < pop_size; i++) { GameObject animal = makeAnimal(); if (animal.GetComponent <Animal>().checkConstraint()) { animals.Add(animal); } else { removeAnimal(animal.GetComponent <Animal>()); } } }