Added new tile generation to the game
This commit is contained in:
@@ -225,10 +225,10 @@ MonoBehaviour:
|
||||
m_GameObject: {fileID: 154033017}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 21edae6d584d6527bbb87c3393c1274f, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: c37c1b94acdd7be698608e78ad857060, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
tilePrefab: {fileID: 7573435787306895624, guid: a3113b7ce76b2d5c1998c0dadca2acdd, type: 3}
|
||||
tile: {fileID: 7573435787306895624, guid: a3113b7ce76b2d5c1998c0dadca2acdd, type: 3}
|
||||
--- !u!1 &1664013424
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -22,19 +22,19 @@ public class ContentGenerator : MonoBehaviour
|
||||
|
||||
public GameObject generateContent(string tiletype)
|
||||
{
|
||||
switch (tiletype)
|
||||
switch (tiletype.ToLower())
|
||||
{
|
||||
case "Plane":
|
||||
case "plane":
|
||||
return generateTileContent();
|
||||
case "Mountain":
|
||||
case "mountains":
|
||||
return generateStoneTileContent();
|
||||
case "Forest":
|
||||
case "forest":
|
||||
return generateTreeTileContent();
|
||||
case "River":
|
||||
case "river":
|
||||
return generateRiverTileContent();
|
||||
case "Lake":
|
||||
case "lake":
|
||||
return generateLakeTileContent();
|
||||
case "City":
|
||||
case "city":
|
||||
return generateCityTileContent();
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -20,7 +20,7 @@ public class SteamWorksHandler : MonoBehaviour
|
||||
{
|
||||
if (counterForest != -1 && !isGodMode())
|
||||
{
|
||||
if (tiletype == "Forest")
|
||||
if (tiletype.ToLower() == "forest")
|
||||
{
|
||||
counterForest++;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Assets.Scripts
|
||||
{
|
||||
GameObject coordinates = GameObject.Find("txtCoordinates");
|
||||
Vector3 position = GameObject.Find("Player").transform.position;
|
||||
string tiletype = GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>().getCurrentTile().GetComponent<Tile>().getTileType();
|
||||
string tiletype = GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>().getCurrentTile().GetComponent<Tile>().getTileType().ToString();
|
||||
if (tiletype != null)
|
||||
{
|
||||
tiletype = tiletype.Replace("Tile", "");
|
||||
|
||||
@@ -9,44 +9,7 @@ using System.Linq;
|
||||
public class NoiseGenerator
|
||||
{
|
||||
System.Random rand = new System.Random();
|
||||
public void applyNoise(GameObject tile, string name, Dictionary<Vector3, GameObject> map)
|
||||
{
|
||||
/*if(name.Length > 0){
|
||||
applyCityNoise(tile);
|
||||
}
|
||||
else{
|
||||
applyNormalNoise(tile, map);
|
||||
}*/
|
||||
applyNewNoise(tile, map);
|
||||
|
||||
}
|
||||
|
||||
private void applyCityNoise(GameObject tile)
|
||||
{
|
||||
//resetMesh(tile);
|
||||
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
float[] samples;
|
||||
Color32[] colors;
|
||||
int chance = rand.Next(1, 101);
|
||||
samples = calculateSamplesCity(tile);
|
||||
string tiletype = "City";
|
||||
|
||||
colors = new Color32[samples.Length];
|
||||
for (int i = 0; i < samples.Length; i++)
|
||||
{
|
||||
colors[i] = new Color32(0, 185, 0, 255);
|
||||
}
|
||||
|
||||
for (int i = 0; i < samples.Length; i++)
|
||||
{
|
||||
vertices[i].y = samples[i] * 3;
|
||||
}
|
||||
applyMesh(tile, vertices, mesh, colors);
|
||||
tile.GetComponent<Tile>().setType(tiletype);
|
||||
}
|
||||
|
||||
private void applyNewNoise(GameObject tile, Dictionary<Vector3, GameObject> map)
|
||||
public void applyNoise(GameObject tile, Dictionary<Vector3, GameObject> map, Vector3 index)
|
||||
{
|
||||
//resetMesh(tile);
|
||||
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
|
||||
@@ -55,90 +18,44 @@ public class NoiseGenerator
|
||||
Color32[] colors;
|
||||
Color32 low;
|
||||
Color32 high;
|
||||
string tiletype = "";
|
||||
samples = calculateBasicSamples(tile);
|
||||
|
||||
low = new Color32(0, 150, 0, 255);
|
||||
high = new Color32(0, 110, 20, 255);
|
||||
|
||||
float lowestValue = 10;
|
||||
float highestValue = 0;
|
||||
|
||||
for (int i = 0; i < samples.Length; i++)
|
||||
{
|
||||
if (lowestValue > samples[i])
|
||||
{
|
||||
lowestValue = samples[i];
|
||||
}
|
||||
if (highestValue < samples[i])
|
||||
{
|
||||
highestValue = samples[i];
|
||||
}
|
||||
}
|
||||
|
||||
float modifier = highestValue - lowestValue;
|
||||
|
||||
colors = new Color32[samples.Length];
|
||||
for (int i = 0; i < samples.Length; i++)
|
||||
{
|
||||
colors[i] = Color32.Lerp(low, high, (1 / modifier) * (samples[i] - lowestValue));
|
||||
}
|
||||
|
||||
for (int i = 0; i < samples.Length; i++)
|
||||
{
|
||||
vertices[i].y = samples[i] * 3;
|
||||
}
|
||||
applyMesh(tile, vertices, mesh, colors);
|
||||
tile.GetComponent<Tile>().setType(tiletype);
|
||||
}
|
||||
|
||||
private void applyNormalNoise(GameObject tile, Dictionary<Vector3, GameObject> map)
|
||||
{
|
||||
//resetMesh(tile);
|
||||
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
float[] samples;
|
||||
Color32[] colors;
|
||||
Color32 low;
|
||||
Color32 high;
|
||||
int chance = rand.Next(1, 101);
|
||||
string tiletype = "";
|
||||
if (chance > 85 && chance <= 100)
|
||||
{
|
||||
samples = calculateSamplesForest(tile);
|
||||
low = new Color32(0, 150, 0, 255);
|
||||
high = new Color32(0, 110, 20, 255);
|
||||
tiletype = "Forest";
|
||||
}
|
||||
else if (chance > 70 && chance <= 85)
|
||||
{
|
||||
samples = calculateSamplesMountain(tile);
|
||||
low = new Color32(0, 150, 0, 255);
|
||||
high = new Color32(140, 140, 140, 255);
|
||||
tiletype = "Mountain";
|
||||
}
|
||||
else if (chance > 55 && chance <= 70)
|
||||
{
|
||||
samples = calculateSamplesLake(tile);
|
||||
low = new Color32(30, 110, 190, 255);
|
||||
high = new Color32(0, 150, 0, 255);
|
||||
tiletype = "Lake";
|
||||
}
|
||||
else if (chance > 40 && chance <= 55)
|
||||
{
|
||||
samples = calculateSamplesRiver(tile);
|
||||
low = new Color32(30, 160, 190, 255);
|
||||
high = new Color32(0, 150, 0, 255);
|
||||
tiletype = "River";
|
||||
List<TileType> availableTypes = checkAvailability(map, index);
|
||||
TileType tiletype = TileType.NULL;
|
||||
if (index == new Vector3(0, 0, 0))
|
||||
{ //IS SPAWN
|
||||
tiletype = (TileType)rand.Next(0, TileTypeMethods.getHighest() + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
samples = calculateSamplesPlane(tile);
|
||||
low = new Color32(0, 150, 0, 255);
|
||||
high = new Color32(0, 185, 0, 255);
|
||||
tiletype = "Plane";
|
||||
if (availableTypes.Count == 0)
|
||||
{
|
||||
Debug.Log("NO MATCH FOUND");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (availableTypes.Contains(TileType.CITY))
|
||||
{
|
||||
if (rand.Next(0, 101) < 10)
|
||||
{
|
||||
tiletype = TileType.CITY;
|
||||
SteamWorksHandler.getStandardAchievement("CityAchievement");
|
||||
}
|
||||
else
|
||||
{
|
||||
availableTypes.Remove(TileType.CITY);
|
||||
tiletype = availableTypes[rand.Next(0, availableTypes.Count)];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tiletype = availableTypes[rand.Next(0, availableTypes.Count)];
|
||||
}
|
||||
}
|
||||
}
|
||||
tile.name = tiletype.ToString() + "_" + map.Count;
|
||||
|
||||
low = TileTypeMethods.getLowestColor(tiletype);
|
||||
high = TileTypeMethods.getHighestColor(tiletype);
|
||||
samples = TileTypeMethods.generateSamples(tiletype, vertices, rand);
|
||||
|
||||
float lowestValue = 10;
|
||||
float highestValue = 0;
|
||||
@@ -163,14 +80,156 @@ public class NoiseGenerator
|
||||
colors[i] = Color32.Lerp(low, high, (1 / modifier) * (samples[i] - lowestValue));
|
||||
}
|
||||
|
||||
//Connect samples to neighbours
|
||||
samples = connectNeighbourSamples(samples, map, index);
|
||||
colors = connectNeighbourColors(colors, map, index);
|
||||
|
||||
for (int i = 0; i < samples.Length; i++)
|
||||
{
|
||||
vertices[i].y = samples[i] * 3;
|
||||
}
|
||||
applyMesh(tile, vertices, mesh, colors);
|
||||
tile.GetComponent<Tile>().setType(tiletype);
|
||||
|
||||
applyMesh(tile, mesh, vertices, colors);
|
||||
}
|
||||
|
||||
private List<TileType> checkAvailability(Dictionary<Vector3, GameObject> tiles, Vector3 index)
|
||||
{
|
||||
List<List<TileType>> toCheck = new List<List<TileType>>();
|
||||
List<TileType> result = new List<TileType>();
|
||||
for (int i = 0; i < TileTypeMethods.getHighest() + 1; i++)
|
||||
{
|
||||
result.Add((TileType)i);
|
||||
}
|
||||
|
||||
if (tiles.ContainsKey(index - new Vector3(1, 0, 0)))
|
||||
{
|
||||
toCheck.Add(tiles[index - new Vector3(1, 0, 0)].GetComponent<Tile>().getPossibleNeighbours());
|
||||
}
|
||||
if (tiles.ContainsKey(index - new Vector3(-1, 0, 0)))
|
||||
{
|
||||
toCheck.Add(tiles[index - new Vector3(-1, 0, 0)].GetComponent<Tile>().getPossibleNeighbours());
|
||||
}
|
||||
if (tiles.ContainsKey(index - new Vector3(0, 0, 1)))
|
||||
{
|
||||
toCheck.Add(tiles[index - new Vector3(0, 0, 1)].GetComponent<Tile>().getPossibleNeighbours());
|
||||
}
|
||||
if (tiles.ContainsKey(index - new Vector3(0, 0, -1)))
|
||||
{
|
||||
toCheck.Add(tiles[index - new Vector3(0, 0, -1)].GetComponent<Tile>().getPossibleNeighbours());
|
||||
}
|
||||
|
||||
for (int i = 0; i < toCheck.Count; i++)
|
||||
{
|
||||
result = result.Intersect(toCheck[i]).ToList();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private float[] connectNeighbourSamples(float[] basis, Dictionary<Vector3, GameObject> tiles, Vector3 index)
|
||||
{
|
||||
float[] result = basis;
|
||||
Mesh mesh;
|
||||
Vector3[] vertices;
|
||||
int sidelength = (int)Mathf.Sqrt(result.Length);
|
||||
|
||||
if (tiles.ContainsKey(index - new Vector3(1, 0, 0))) //Links
|
||||
{
|
||||
mesh = tiles[index - new Vector3(1, 0, 0)].GetComponent<MeshFilter>().mesh;
|
||||
vertices = mesh.vertices;
|
||||
for (int i = 0; i < sidelength; i++)
|
||||
{
|
||||
result[sidelength - 1 + i * sidelength] = vertices[0 + i * sidelength].y / 3;
|
||||
result[sidelength - 2 + i * sidelength] = (result[sidelength - 1 + i * sidelength] + result[sidelength - 3 + i * sidelength]) / 2;
|
||||
}
|
||||
}
|
||||
if (tiles.ContainsKey(index - new Vector3(-1, 0, 0))) //Rechts
|
||||
{
|
||||
mesh = tiles[index - new Vector3(-1, 0, 0)].GetComponent<MeshFilter>().mesh;
|
||||
vertices = mesh.vertices;
|
||||
for (int i = 0; i < sidelength; i++)
|
||||
{
|
||||
result[0 + i * sidelength] = vertices[sidelength - 1 + i * sidelength].y / 3;
|
||||
result[1 + i * sidelength] = (result[0 + i * sidelength] + result[2 + i * sidelength]) / 2;
|
||||
}
|
||||
|
||||
}
|
||||
if (tiles.ContainsKey(index - new Vector3(0, 0, 1))) //Unten
|
||||
{
|
||||
mesh = tiles[index - new Vector3(0, 0, 1)].GetComponent<MeshFilter>().mesh;
|
||||
vertices = mesh.vertices;
|
||||
for (int i = 0; i < sidelength; i++)
|
||||
{
|
||||
result[sidelength * sidelength - (sidelength - i)] = vertices[i].y / 3;
|
||||
result[sidelength * (sidelength - 1) - (sidelength - i)] = (result[sidelength * sidelength - (sidelength - i)] + result[sidelength * (sidelength - 2) - (sidelength - i)]) / 2;
|
||||
}
|
||||
|
||||
}
|
||||
if (tiles.ContainsKey(index - new Vector3(0, 0, -1))) //Oben
|
||||
{
|
||||
mesh = tiles[index - new Vector3(0, 0, -1)].GetComponent<MeshFilter>().mesh;
|
||||
vertices = mesh.vertices;
|
||||
for (int i = 0; i < sidelength; i++)
|
||||
{
|
||||
result[i] = vertices[sidelength * sidelength - (sidelength - i)].y / 3;
|
||||
result[i + sidelength] = (result[i] + result[i + sidelength * 2]) / 2;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Color32[] connectNeighbourColors(Color32[] basis, Dictionary<Vector3, GameObject> tiles, Vector3 index)
|
||||
{
|
||||
Color32[] result = basis;
|
||||
Mesh mesh;
|
||||
Color32[] colors;
|
||||
int sidelength = (int)Mathf.Sqrt(result.Length);
|
||||
|
||||
if (tiles.ContainsKey(index - new Vector3(1, 0, 0))) //Links
|
||||
{
|
||||
mesh = tiles[index - new Vector3(1, 0, 0)].GetComponent<MeshFilter>().mesh;
|
||||
colors = mesh.colors32;
|
||||
for (int i = 0; i < sidelength; i++)
|
||||
{
|
||||
result[sidelength - 1 + i * sidelength] = colors[0 + i * sidelength];
|
||||
result[sidelength - 2 + i * sidelength] = Color32.Lerp(result[sidelength - 1 + i * sidelength], result[sidelength - 3 + i * sidelength], 0.5f);
|
||||
}
|
||||
}
|
||||
if (tiles.ContainsKey(index - new Vector3(-1, 0, 0))) //Rechts
|
||||
{
|
||||
mesh = tiles[index - new Vector3(-1, 0, 0)].GetComponent<MeshFilter>().mesh;
|
||||
colors = mesh.colors32;
|
||||
for (int i = 0; i < sidelength; i++)
|
||||
{
|
||||
result[0 + i * sidelength] = colors[sidelength - 1 + i * sidelength];
|
||||
result[1 + i * sidelength] = Color32.Lerp(result[0 + i * sidelength], result[2 + i * sidelength], 0.5f);
|
||||
}
|
||||
|
||||
}
|
||||
if (tiles.ContainsKey(index - new Vector3(0, 0, 1))) //Unten
|
||||
{
|
||||
mesh = tiles[index - new Vector3(0, 0, 1)].GetComponent<MeshFilter>().mesh;
|
||||
colors = mesh.colors32;
|
||||
for (int i = 0; i < sidelength; i++)
|
||||
{
|
||||
result[sidelength * sidelength - (sidelength - i)] = colors[i];
|
||||
result[sidelength * (sidelength - 1) - (sidelength - i)] = Color32.Lerp(result[sidelength * sidelength - (sidelength - i)], result[sidelength * (sidelength - 2) - (sidelength - i)], 0.5f);
|
||||
}
|
||||
}
|
||||
if (tiles.ContainsKey(index - new Vector3(0, 0, -1))) //Oben
|
||||
{
|
||||
mesh = tiles[index - new Vector3(0, 0, -1)].GetComponent<MeshFilter>().mesh;
|
||||
colors = mesh.colors32;
|
||||
for (int i = 0; i < sidelength; i++)
|
||||
{
|
||||
result[i] = colors[sidelength * sidelength - (sidelength - i)];
|
||||
result[i + sidelength] = Color32.Lerp(result[i], result[i + sidelength * 2], 0.5f);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private void resetMesh(GameObject tile)
|
||||
{
|
||||
Mesh mesh = tile.GetComponent<MeshCollider>().sharedMesh;
|
||||
@@ -185,144 +244,15 @@ public class NoiseGenerator
|
||||
tile.GetComponent<MeshCollider>().sharedMesh = mesh;
|
||||
}
|
||||
|
||||
private float[] calculateBasicSamples(GameObject tile)
|
||||
{
|
||||
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
float[] samples = new float[vertices.Length];
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
float xCord = tile.GetComponent<Tile>().getPosition().x + vertices[i].x / (vertices.Length - 1) * 10;
|
||||
float yCord = tile.GetComponent<Tile>().getPosition().z + vertices[i].z / (vertices.Length - 1) * 10;
|
||||
float sample = Mathf.PerlinNoise(xCord, yCord) - 0.1f * rand.Next(0, 6);
|
||||
samples[i] = sample;
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
private float[] calculateSamplesCity(GameObject tile)
|
||||
{
|
||||
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
float[] samples = new float[vertices.Length];
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
samples[i] = 0;
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
private float[] calculateSamplesPlane(GameObject tile)
|
||||
{
|
||||
float[] samples = calculateBasicSamples(tile);
|
||||
return samples;
|
||||
}
|
||||
|
||||
private float[] calculateSamplesForest(GameObject tile)
|
||||
{
|
||||
float[] samples = calculateBasicSamples(tile);
|
||||
return samples;
|
||||
}
|
||||
|
||||
private float[] calculateSamplesMountain(GameObject tile)
|
||||
{
|
||||
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
float[] samples = calculateBasicSamples(tile);
|
||||
|
||||
int amount = rand.Next(1, 5);
|
||||
int index = 0;
|
||||
for (int i = 0; i < amount; i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
index = rand.Next(0, samples.Length);
|
||||
if (vertices[index].x != 5 && vertices[index].z != 5 && vertices[index].x != -5 && vertices[index].z != -5)
|
||||
{
|
||||
samples[index] = 3;
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
private float[] calculateSamplesRiver(GameObject tile)
|
||||
{
|
||||
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
float[] samples = calculateBasicSamples(tile);
|
||||
|
||||
bool isVertical = (rand.Next(0, 2) == 0 ? true : false);
|
||||
int startX = 0;
|
||||
int startZ = 0;
|
||||
|
||||
if (isVertical)
|
||||
{
|
||||
startZ = (rand.Next(0, 2) == 0 ? 4 : -4);
|
||||
startX = rand.Next(-4, 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
startZ = rand.Next(-4, 5);
|
||||
startX = (rand.Next(0, 2) == 0 ? 4 : -4);
|
||||
}
|
||||
|
||||
for (int k = 0; k < vertices.Length; k++)
|
||||
{
|
||||
if (isVertical)
|
||||
{
|
||||
if (Mathf.Round(vertices[k].x) == startX && Mathf.Round(vertices[k].z) != 5 && Mathf.Round(vertices[k].z) != -5)
|
||||
{
|
||||
samples[k] = samples[k] - rand.Next(2, 4) + 0.5f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Mathf.Round(vertices[k].x) != 5 && Mathf.Round(vertices[k].x) != -5 && Mathf.Round(vertices[k].z) == startZ)
|
||||
{
|
||||
samples[k] = samples[k] - rand.Next(2, 4) + 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
||||
private float[] calculateSamplesLake(GameObject tile)
|
||||
{
|
||||
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
float[] samples = calculateBasicSamples(tile);
|
||||
|
||||
int randX = rand.Next(-3, 4);
|
||||
int randZ = rand.Next(-3, 4);
|
||||
|
||||
for (int i = -1; i < 2; i++)
|
||||
{
|
||||
for (int j = -1; j < 2; j++)
|
||||
{
|
||||
for (int k = 0; k < vertices.Length; k++)
|
||||
{
|
||||
if (Mathf.Round(vertices[k].x) == randX + i && Mathf.Round(vertices[k].z) == randZ + j)
|
||||
{
|
||||
samples[k] = samples[k] - rand.Next(1, 3) - 0.25f * rand.Next(0, 4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
|
||||
private void applyMesh(GameObject tile, Vector3[] vertices, Mesh mesh, Color32[] colors)
|
||||
public void applyMesh(GameObject tile, Mesh mesh, Vector3[] vertices, Color32[] colors)
|
||||
{
|
||||
mesh.vertices = vertices;
|
||||
mesh.colors32 = colors;
|
||||
mesh.RecalculateBounds();
|
||||
mesh.RecalculateNormals();
|
||||
mesh.colors32 = colors;
|
||||
tile.GetComponent<MeshCollider>().sharedMesh = mesh;
|
||||
tile.GetComponent<MeshFilter>().sharedMesh = mesh;
|
||||
}
|
||||
|
||||
public void saveTile(GameObject tile, string path)
|
||||
@@ -374,6 +304,6 @@ public class NoiseGenerator
|
||||
parts = current.Value<string>().Split('/');
|
||||
vertices[i] = new Vector3(float.Parse(parts[0]), float.Parse(parts[1]), float.Parse(parts[2]));
|
||||
}
|
||||
applyMesh(tile, vertices, tile.GetComponent<MeshFilter>().mesh, colors);
|
||||
applyMesh(tile, tile.GetComponent<MeshFilter>().mesh, vertices, colors);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Assets.Scripts
|
||||
public void update(object obj, int amount)
|
||||
{
|
||||
GameObject tile = (GameObject)obj;
|
||||
string tilename = tile.GetComponent<Tile>().getTileType();
|
||||
string tilename = tile.GetComponent<Tile>().getTileType().ToString();
|
||||
if (keyword == "Forest" && tilename.ToLower().Contains("forest"))
|
||||
{
|
||||
current++;
|
||||
|
||||
@@ -1,204 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class NoiseTesting : MonoBehaviour
|
||||
{
|
||||
System.Random rand = new System.Random();
|
||||
Dictionary<Vector3, GameObject> mapGen;
|
||||
Vector3 current;
|
||||
Vector3 next;
|
||||
public GameObject tilePrefab;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
mapGen = new Dictionary<Vector3, GameObject>();
|
||||
current = new Vector3(0, 0, 0);
|
||||
mapGen.Add(current, Instantiate(tilePrefab, current, Quaternion.identity));
|
||||
applyNormalNoise(mapGen[current], mapGen);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
applyNormalNoise(mapGen[new Vector3(0, 0, 0)], mapGen);
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.A))
|
||||
{
|
||||
next = current - new Vector3(100, 0, 0);
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.W))
|
||||
{
|
||||
next = current - new Vector3(0, 0, -100);
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.D))
|
||||
{
|
||||
next = current - new Vector3(-100, 0, 0);
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.S))
|
||||
{
|
||||
next = current - new Vector3(0, 0, 100);
|
||||
}
|
||||
|
||||
if (next != current)
|
||||
{
|
||||
current = next;
|
||||
if (!mapGen.ContainsKey(current))
|
||||
{
|
||||
mapGen.Add(current, Instantiate(tilePrefab, current, Quaternion.identity));
|
||||
applyNormalNoise(mapGen[current], mapGen);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void applyNormalNoise(GameObject tile, Dictionary<Vector3, GameObject> map)
|
||||
{
|
||||
//resetMesh(tile);
|
||||
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
//float[] samples = calculateBasicSamples(tile);
|
||||
float[] samples = calculateConnectedSamples(tile);
|
||||
|
||||
Color32[] colors;
|
||||
Color32 low = new Color32(0, 150, 0, 255);
|
||||
Color32 high = new Color32(0, 110, 20, 255);
|
||||
string tiletype = "";
|
||||
|
||||
float lowestValue = 10;
|
||||
float highestValue = 0;
|
||||
|
||||
for (int i = 0; i < samples.Length; i++)
|
||||
{
|
||||
if (lowestValue > samples[i])
|
||||
{
|
||||
lowestValue = samples[i];
|
||||
}
|
||||
if (highestValue < samples[i])
|
||||
{
|
||||
highestValue = samples[i];
|
||||
}
|
||||
}
|
||||
|
||||
float modifier = highestValue - lowestValue;
|
||||
|
||||
colors = new Color32[samples.Length];
|
||||
for (int i = 0; i < samples.Length; i++)
|
||||
{
|
||||
colors[i] = Color32.Lerp(low, high, (1 / modifier) * (samples[i] - lowestValue));
|
||||
}
|
||||
|
||||
for (int i = 0; i < samples.Length; i++)
|
||||
{
|
||||
vertices[i].y = samples[i];// * 3;
|
||||
}
|
||||
applyMesh(tile, vertices, mesh, colors);
|
||||
//tile.GetComponent<Tile>().setType(tiletype);
|
||||
}
|
||||
|
||||
private void resetMesh(GameObject tile)
|
||||
{
|
||||
Mesh mesh = tile.GetComponent<MeshCollider>().sharedMesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
vertices[i].y = 0;
|
||||
}
|
||||
mesh.vertices = vertices;
|
||||
mesh.RecalculateBounds();
|
||||
mesh.RecalculateNormals();
|
||||
tile.GetComponent<MeshCollider>().sharedMesh = mesh;
|
||||
}
|
||||
|
||||
private float[] calculateBasicSamples(GameObject tile)
|
||||
{
|
||||
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
float[] samples = new float[vertices.Length];
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
float xCord = vertices[i].x / (vertices.Length - 1) * 10;
|
||||
float zCord = vertices[i].z / (vertices.Length - 1) * 10;
|
||||
float sample = Mathf.PerlinNoise(xCord, zCord) - 0.5f * rand.Next(0, 6);
|
||||
samples[i] = sample;
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
private float[] calculateConnectedSamples(GameObject tile)
|
||||
{
|
||||
//Working with "next" as index for tile to be generated
|
||||
//Working with "mapGen" as map Placeholder to check against neighbours
|
||||
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
|
||||
Vector3[] vertices = mesh.vertices;
|
||||
float[] samples = Enumerable.Repeat(-100f, vertices.Length).ToArray();
|
||||
int sideLength = Mathf.RoundToInt(Mathf.Sqrt(vertices.Length));
|
||||
samples = connectSamples(samples, sideLength);
|
||||
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
if (samples[i] == -100)
|
||||
{
|
||||
float xCord = vertices[i].x / (vertices.Length - 1) * 10;
|
||||
float zCord = vertices[i].z / (vertices.Length - 1) * 10;
|
||||
float sample = Mathf.PerlinNoise(xCord, zCord) - 1f * rand.Next(0, 6);
|
||||
samples[i] = sample;
|
||||
}
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
private void applyMesh(GameObject tile, Vector3[] vertices, Mesh mesh, Color32[] colors)
|
||||
{
|
||||
mesh.vertices = vertices;
|
||||
mesh.RecalculateBounds();
|
||||
mesh.RecalculateNormals();
|
||||
mesh.colors32 = colors;
|
||||
tile.GetComponent<MeshCollider>().sharedMesh = mesh;
|
||||
}
|
||||
|
||||
private float[] connectSamples(float[] samples, int sideLength)
|
||||
{
|
||||
Mesh mesh;
|
||||
Vector3[] vertices;
|
||||
|
||||
for (int i = 0; i < sideLength; i++)
|
||||
{
|
||||
if (mapGen.ContainsKey(next - new Vector3(100, 0, 0)))
|
||||
{ //LINKS
|
||||
mesh = mapGen[next - new Vector3(100, 0, 0)].GetComponent<MeshFilter>().mesh;
|
||||
vertices = mesh.vertices;
|
||||
samples[sideLength - 1 + sideLength * i] = vertices[sideLength * i].y;
|
||||
}
|
||||
|
||||
if (mapGen.ContainsKey(next - new Vector3(-100, 0, 0)))
|
||||
{ //RECHTS
|
||||
mesh = mapGen[next - new Vector3(-100, 0, 0)].GetComponent<MeshFilter>().mesh;
|
||||
vertices = mesh.vertices;
|
||||
samples[sideLength * i] = vertices[sideLength - 1 + sideLength * i].y;
|
||||
}
|
||||
|
||||
if (mapGen.ContainsKey(next - new Vector3(0, 0, -100)))
|
||||
{ //OBEN
|
||||
mesh = mapGen[next - new Vector3(0, 0, -100)].GetComponent<MeshFilter>().mesh;
|
||||
vertices = mesh.vertices;
|
||||
samples[i] = vertices[(sideLength * sideLength) - (sideLength-i)].y;
|
||||
}
|
||||
|
||||
if (mapGen.ContainsKey(next - new Vector3(0, 0, 100)))
|
||||
{ //UNTEN
|
||||
mesh = mapGen[next - new Vector3(0, 0, 100)].GetComponent<MeshFilter>().mesh;
|
||||
vertices = mesh.vertices;
|
||||
samples[(sideLength * sideLength) - (sideLength-i)] = vertices[i].y;
|
||||
}
|
||||
}
|
||||
|
||||
return samples;
|
||||
}
|
||||
}
|
||||
@@ -131,6 +131,7 @@ GameObject:
|
||||
- component: {fileID: 7573435787306895637}
|
||||
- component: {fileID: 7573435787306895626}
|
||||
- component: {fileID: 7602326841346784209}
|
||||
- component: {fileID: 6053739292490587254}
|
||||
m_Layer: 0
|
||||
m_Name: Tile
|
||||
m_TagString: Tile
|
||||
@@ -226,3 +227,15 @@ MeshCollider:
|
||||
m_Convex: 0
|
||||
m_CookingOptions: 30
|
||||
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!114 &6053739292490587254
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7573435787306895624}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 82f0b9ba1d91bf9148eb63b088e12979, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Assets.Scripts;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -13,18 +14,15 @@ public class Tile : MonoBehaviour
|
||||
float borderSouth;
|
||||
float borderWest;
|
||||
System.Random rand = new System.Random();
|
||||
string tiletype;
|
||||
TileType tiletype;
|
||||
GameObject contentGenerator;
|
||||
|
||||
List<GameObject> aliveEnemies = new List<GameObject>();
|
||||
|
||||
public void generateTile(Vector3 pos, string type)
|
||||
public void generateTile(Vector3 pos, TileType type)
|
||||
{
|
||||
if (tiletype == null)
|
||||
{
|
||||
tiletype = type;
|
||||
}
|
||||
SteamWorksHandler.getForestAchievement(type);
|
||||
tiletype = type;
|
||||
SteamWorksHandler.getForestAchievement(type.ToString());
|
||||
contentGenerator = GameObject.Find("ContentGenerator");
|
||||
setPosition(pos);
|
||||
setBorders();
|
||||
@@ -58,7 +56,7 @@ public class Tile : MonoBehaviour
|
||||
int xChange = 0;
|
||||
int zChange = 0;
|
||||
int sideLimiter = 0;
|
||||
if(tiletype == "City"){
|
||||
if(tiletype == TileType.CITY){
|
||||
sideLimiter = 20;
|
||||
}
|
||||
else{
|
||||
@@ -70,7 +68,7 @@ public class Tile : MonoBehaviour
|
||||
{
|
||||
xChange = rand.Next(-2, +2);
|
||||
zChange = rand.Next(-2, +2);
|
||||
if(tiletype == "City"){
|
||||
if(tiletype == TileType.CITY){
|
||||
list.Add(new Vector3(j + xChange, 0, i + zChange));
|
||||
}
|
||||
else{
|
||||
@@ -87,10 +85,10 @@ public class Tile : MonoBehaviour
|
||||
int chance = rand.Next(1, 101);
|
||||
if (chance >= 25)
|
||||
{
|
||||
GameObject content = contentGenerator.GetComponent<ContentGenerator>().generateContent(tiletype);
|
||||
GameObject content = contentGenerator.GetComponent<ContentGenerator>().generateContent(tiletype.ToString());
|
||||
if (content != null)
|
||||
{
|
||||
if(tiletype == "City" && (content.tag.ToLower().Contains("npc") || content.tag.ToLower().Contains("tree") || content.tag.ToLower().Contains("stone") || content.tag.ToLower().Contains("ore"))){
|
||||
if(tiletype == TileType.CITY && (content.tag.ToLower().Contains("npc") || content.tag.ToLower().Contains("tree") || content.tag.ToLower().Contains("stone") || content.tag.ToLower().Contains("ore"))){
|
||||
position.y = 5;
|
||||
}
|
||||
GameObject obj = Instantiate(content, position, Quaternion.identity);
|
||||
@@ -113,7 +111,7 @@ public class Tile : MonoBehaviour
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setType(string tiletype)
|
||||
public void setType(TileType tiletype)
|
||||
{
|
||||
this.tiletype = tiletype;
|
||||
}
|
||||
@@ -199,7 +197,7 @@ public class Tile : MonoBehaviour
|
||||
Destroy(enemy);
|
||||
}
|
||||
|
||||
public string getTileType()
|
||||
public TileType getTileType()
|
||||
{
|
||||
return tiletype;
|
||||
}
|
||||
@@ -291,8 +289,12 @@ public class Tile : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
tiletype = json["tiletype"].ToString();
|
||||
tiletype = (TileType)Enum.Parse(typeof(TileType), json["tiletype"].ToString());
|
||||
setPosition(pos);
|
||||
setBorders();
|
||||
}
|
||||
|
||||
public List<TileType> getPossibleNeighbours(){
|
||||
return TileTypeMethods.getPossibleNeighbours(tiletype);
|
||||
}
|
||||
}
|
||||
220
Assets/Scripts/TileType.cs
Normal file
220
Assets/Scripts/TileType.cs
Normal file
@@ -0,0 +1,220 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public enum TileType
|
||||
{
|
||||
PLAIN,
|
||||
HILLS,
|
||||
FOREST,
|
||||
MOUNTAINS,
|
||||
LAKE,
|
||||
CITY,
|
||||
DESERT,
|
||||
NULL
|
||||
}
|
||||
|
||||
static class TileTypeMethods
|
||||
{
|
||||
public static TileType getRandomType(int index)
|
||||
{
|
||||
return (TileType)index;
|
||||
}
|
||||
|
||||
public static int getHighest()
|
||||
{
|
||||
return (int)TileType.DESERT;
|
||||
}
|
||||
|
||||
public static List<TileType> getPossibleNeighbours(TileType toCheck)
|
||||
{
|
||||
List<TileType> result = new List<TileType>();
|
||||
switch (toCheck)
|
||||
{
|
||||
case TileType.PLAIN:
|
||||
result.Add(TileType.PLAIN);
|
||||
result.Add(TileType.FOREST);
|
||||
result.Add(TileType.LAKE);
|
||||
result.Add(TileType.MOUNTAINS);
|
||||
result.Add(TileType.DESERT);
|
||||
result.Add(TileType.HILLS);
|
||||
break;
|
||||
case TileType.FOREST:
|
||||
result.Add(TileType.PLAIN);
|
||||
result.Add(TileType.FOREST);
|
||||
break;
|
||||
case TileType.MOUNTAINS:
|
||||
result.Add(TileType.PLAIN);
|
||||
result.Add(TileType.MOUNTAINS);
|
||||
break;
|
||||
case TileType.LAKE:
|
||||
result.Add(TileType.PLAIN);
|
||||
result.Add(TileType.LAKE);
|
||||
result.Add(TileType.DESERT);
|
||||
result.Add(TileType.CITY);
|
||||
break;
|
||||
case TileType.DESERT:
|
||||
result.Add(TileType.PLAIN);
|
||||
result.Add(TileType.LAKE);
|
||||
result.Add(TileType.DESERT);
|
||||
break;
|
||||
case TileType.HILLS:
|
||||
result.Add(TileType.PLAIN);
|
||||
result.Add(TileType.HILLS);
|
||||
break;
|
||||
case TileType.CITY:
|
||||
result.Add(TileType.LAKE);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Color getLowestColor(TileType type)
|
||||
{
|
||||
Color32 result;
|
||||
switch (type)
|
||||
{
|
||||
case TileType.PLAIN:
|
||||
result = new Color32(0, 150, 0, 255);
|
||||
break;
|
||||
case TileType.HILLS:
|
||||
result = new Color32(0, 150, 0, 255);
|
||||
break;
|
||||
case TileType.FOREST:
|
||||
result = new Color32(0, 150, 0, 255);
|
||||
break;
|
||||
case TileType.MOUNTAINS:
|
||||
result = new Color32(0, 150, 0, 255);
|
||||
break;
|
||||
case TileType.LAKE:
|
||||
result = new Color32(30, 110, 190, 255);
|
||||
break;
|
||||
case TileType.DESERT:
|
||||
result = new Color32(219, 186, 162, 255);
|
||||
break;
|
||||
default:
|
||||
result = new Color32(0, 150, 0, 255);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Color32 getHighestColor(TileType type)
|
||||
{
|
||||
Color32 result;
|
||||
switch (type)
|
||||
{
|
||||
case TileType.PLAIN:
|
||||
result = new Color32(0, 185, 0, 255);
|
||||
break;
|
||||
case TileType.HILLS:
|
||||
result = new Color32(0, 185, 0, 255);
|
||||
break;
|
||||
case TileType.FOREST:
|
||||
result = new Color32(0, 110, 20, 255);
|
||||
break;
|
||||
case TileType.MOUNTAINS:
|
||||
result = new Color32(140, 140, 140, 255);
|
||||
break;
|
||||
case TileType.LAKE:
|
||||
result = new Color32(0, 150, 0, 255);
|
||||
break;
|
||||
case TileType.DESERT:
|
||||
result = new Color32(237, 201, 175, 255);
|
||||
break;
|
||||
default:
|
||||
result = new Color32(0, 185, 0, 255);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float[] generateSamples(TileType type, Vector3[] vertices, System.Random rand)
|
||||
{
|
||||
float[] result = new float[vertices.Length];
|
||||
float part1;
|
||||
float part2;
|
||||
float[] lowModifier = new float[2];
|
||||
float[] highModifier = new float[2];
|
||||
switch (type)
|
||||
{
|
||||
case TileType.PLAIN:
|
||||
lowModifier[0] = 0.2f;
|
||||
lowModifier[1] = 0.1f;
|
||||
highModifier[0] = 0.2f;
|
||||
highModifier[1] = 0.1f;
|
||||
break;
|
||||
case TileType.HILLS:
|
||||
lowModifier[0] = 0.2f;
|
||||
lowModifier[1] = 0.1f;
|
||||
highModifier[0] = 0.5f;
|
||||
highModifier[1] = 0.1f;
|
||||
break;
|
||||
case TileType.FOREST:
|
||||
lowModifier[0] = 0.15f;
|
||||
lowModifier[1] = 0.1f;
|
||||
highModifier[0] = 0.3f;
|
||||
highModifier[1] = 0.1f;
|
||||
break;
|
||||
case TileType.MOUNTAINS:
|
||||
lowModifier[0] = 0.2f;
|
||||
lowModifier[1] = 0.3f;
|
||||
highModifier[0] = 1.25f;
|
||||
highModifier[1] = 0.2f;
|
||||
break;
|
||||
case TileType.LAKE:
|
||||
lowModifier[0] = 0.2f;
|
||||
lowModifier[1] = 0.1f;
|
||||
highModifier[0] = 0.3f;
|
||||
highModifier[1] = 0.1f;
|
||||
break;
|
||||
case TileType.DESERT:
|
||||
lowModifier[0] = 0.2f;
|
||||
lowModifier[1] = 0.1f;
|
||||
highModifier[0] = 0.5f;
|
||||
highModifier[1] = 0.1f;
|
||||
break;
|
||||
case TileType.CITY:
|
||||
lowModifier[0] = 0.1f;
|
||||
lowModifier[1] = 0.1f;
|
||||
highModifier[0] = 0.1f;
|
||||
highModifier[1] = 0.1f;
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < result.Length; i++)
|
||||
{
|
||||
part1 = Mathf.PerlinNoise(vertices[i].x, vertices[i].z) - lowModifier[0] * rand.Next(0, 6);
|
||||
part2 = Mathf.PerlinNoise(vertices[i].x, vertices[i].z) + highModifier[0] * rand.Next(0, 6);
|
||||
|
||||
result[i] = part1 * lowModifier[1] + part2 * highModifier[0];
|
||||
}
|
||||
|
||||
result = adaptType(type, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static float[] adaptType(TileType type, float[] basis)
|
||||
{
|
||||
float[] result = basis;
|
||||
for (int i = 0; i < result.Length; i++)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case TileType.LAKE:
|
||||
result[i] = basis[i] - 3;
|
||||
break;
|
||||
case TileType.MOUNTAINS:
|
||||
result[i] = basis[i] + 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21edae6d584d6527bbb87c3393c1274f
|
||||
guid: 6ff18c0c54befd41f991b73e3835539c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -78,22 +78,11 @@ public class WorldGenerator : MonoBehaviour
|
||||
public void createSpawn()
|
||||
{
|
||||
Vector3 pos = new Vector3(0, 0, 0);
|
||||
string name = "";
|
||||
Vector3 mapPos = new Vector3(pos.x * 100, 0, pos.z * 100);
|
||||
GameObject newTile = Instantiate(tile, mapPos, Quaternion.identity);
|
||||
noise.applyNoise(newTile, name, tiles);
|
||||
if (name.Length <= 0)
|
||||
{
|
||||
name = tile.name;
|
||||
}
|
||||
if (name.Contains("_"))
|
||||
{
|
||||
name = name.Split('_')[0];
|
||||
}
|
||||
newTile.name = name + "_" + tiles.Count;
|
||||
newTile.GetComponent<Tile>().generateTile(pos, name);
|
||||
noise.applyNoise(newTile, tiles, pos);
|
||||
newTile.GetComponent<Tile>().generateTile(pos, (TileType)Enum.Parse(typeof(TileType), newTile.name.Split("_")[0]));
|
||||
tiles.Add(pos, newTile);
|
||||
renderedTiles.Add(newTile);
|
||||
currentTile = newTile;
|
||||
}
|
||||
|
||||
@@ -106,41 +95,13 @@ public class WorldGenerator : MonoBehaviour
|
||||
int chance = rand.Next(1, 11);
|
||||
Vector3 mapPos = new Vector3(pos.x * 100, 0, pos.z * 100);
|
||||
GameObject newTile = Instantiate(tile, mapPos, Quaternion.identity);
|
||||
if (chance == 1)
|
||||
{
|
||||
if (cityAmount > 0)
|
||||
{
|
||||
name = "City";
|
||||
cityAmount--;
|
||||
SteamWorksHandler.getStandardAchievement("CityAchievement");
|
||||
}
|
||||
}
|
||||
noise.applyNoise(newTile, name, tiles);
|
||||
if (name.Length <= 0)
|
||||
{
|
||||
name = tile.name;
|
||||
}
|
||||
if (name.Contains("_"))
|
||||
{
|
||||
name = name.Split('_')[0];
|
||||
}
|
||||
newTile.name = name + "_" + tiles.Count;
|
||||
newTile.GetComponent<Tile>().generateTile(pos, name);
|
||||
|
||||
noise.applyNoise(newTile, tiles, pos);
|
||||
newTile.GetComponent<Tile>().generateTile(pos, (TileType)Enum.Parse(typeof(TileType), newTile.name.Split("_")[0]));
|
||||
tiles.Add(pos, newTile);
|
||||
renderedTiles.Add(newTile);
|
||||
currentTile = newTile;
|
||||
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("find", newTile, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tiles.ContainsKey(pos) && pos.y == 0)
|
||||
{
|
||||
if (!tiles[pos].GetComponent<Renderer>().enabled)
|
||||
{
|
||||
tiles[pos].GetComponent<Tile>().changeRenderer();
|
||||
renderedTiles.Add(tiles[pos]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void changeCurrentTile(float playerX, float playerZ)
|
||||
@@ -178,7 +139,7 @@ public class WorldGenerator : MonoBehaviour
|
||||
savePath = "./save/tile" + counter + ".json";
|
||||
result = result + "\"tile" + counter + "\": \"" + savePath + "\"";
|
||||
tile.GetComponent<Tile>().saveTile(savePath);
|
||||
if (tile.GetComponent<Tile>().getTileType() == "CityTile")
|
||||
if (tile.GetComponent<Tile>().getTileType() == TileType.CITY)
|
||||
{
|
||||
FileHandler.saveNoise("\r\n}", savePath);
|
||||
}
|
||||
|
||||
@@ -2,187 +2,97 @@
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 3
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: WaterBasicDaytime
|
||||
m_Shader: {fileID: 4800000, guid: 9dccc8e8f0da4494991c26ef59019551, type: 3}
|
||||
m_ShaderKeywords: []
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 2
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
data:
|
||||
first:
|
||||
name: _MainTex
|
||||
second:
|
||||
m_Texture: {fileID: 2800000, guid: c2ef94ff9d11915d1100a04b44295342, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
data:
|
||||
first:
|
||||
name: _BumpMap
|
||||
second:
|
||||
m_Texture: {fileID: 2800000, guid: a53cf5449d11a15d1100a04b44295342, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
data:
|
||||
first:
|
||||
name: _ReflectionTex
|
||||
second:
|
||||
m_Texture: {fileID: 8400000, guid: 21bb33409d118354d000dcabe39e7c39, type: 2}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
data:
|
||||
first:
|
||||
name: _ColorControlCube
|
||||
second:
|
||||
m_Texture: {fileID: 8900000, guid: 98c330f39d11745ad0004adb8d76c639, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
data:
|
||||
first:
|
||||
name: _ColorControl
|
||||
second:
|
||||
m_Texture: {fileID: 2800000, guid: 047330f39d11745ad0004adb8d76c639, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
data:
|
||||
first:
|
||||
name: _WavesTex
|
||||
second:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
data:
|
||||
first:
|
||||
name: _BumpMap2
|
||||
second:
|
||||
m_Texture: {fileID: 2800000, guid: 279fb0a19d11d4a6d00051fa8d76c639, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
data:
|
||||
first:
|
||||
name: _ColorGradient
|
||||
second:
|
||||
m_Texture: {fileID: 2800000, guid: 8403d3349d112ba4d000be1be39e7c39, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 2800000, guid: a53cf5449d11a15d1100a04b44295342, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap2:
|
||||
m_Texture: {fileID: 2800000, guid: 279fb0a19d11d4a6d00051fa8d76c639, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ColorControl:
|
||||
m_Texture: {fileID: 2800000, guid: 047330f39d11745ad0004adb8d76c639, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ColorControlCube:
|
||||
m_Texture: {fileID: 8900000, guid: 98c330f39d11745ad0004adb8d76c639, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ColorControlLava:
|
||||
m_Texture: {fileID: 2800000, guid: e02cef1dae209d020bb6dc8c8b80fef4, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ColorGradient:
|
||||
m_Texture: {fileID: 2800000, guid: 8403d3349d112ba4d000be1be39e7c39, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 2800000, guid: c2ef94ff9d11915d1100a04b44295342, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ReflectionTex:
|
||||
m_Texture: {fileID: 8400000, guid: 21bb33409d118354d000dcabe39e7c39, type: 2}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _WavesTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
data:
|
||||
first:
|
||||
name: _Shininess
|
||||
second: 1
|
||||
data:
|
||||
first:
|
||||
name: _WaveScale
|
||||
second: .0702830181
|
||||
data:
|
||||
first:
|
||||
name: _Highlight
|
||||
second: 33.2075462
|
||||
data:
|
||||
first:
|
||||
name: _bScale
|
||||
second: .0700000003
|
||||
data:
|
||||
first:
|
||||
name: _BumpPeturb
|
||||
second: 82.07547
|
||||
data:
|
||||
first:
|
||||
name: _BumpPeturb2
|
||||
second: .745283008
|
||||
data:
|
||||
first:
|
||||
name: _bTwirl
|
||||
second: .0500000007
|
||||
data:
|
||||
first:
|
||||
name: _distort
|
||||
second: .100000001
|
||||
- _BumpPeturb: 82.07547
|
||||
- _BumpPeturb2: 0.745283
|
||||
- _Highlight: 33.207546
|
||||
- _Shininess: 1
|
||||
- _WaveScale: 0.07028302
|
||||
- _bScale: 0.07
|
||||
- _bTwirl: 0.05
|
||||
- _distort: 0.1
|
||||
- _isLava: 0
|
||||
m_Colors:
|
||||
data:
|
||||
first:
|
||||
name: _Color
|
||||
second: {r: 0, g: 0, b: 0, a: 1}
|
||||
data:
|
||||
first:
|
||||
name: _MainTex_ST
|
||||
second: {r: 1, g: 1, b: 0, a: 0}
|
||||
data:
|
||||
first:
|
||||
name: _SpecColor
|
||||
second: {r: 0, g: 0, b: 0, a: .400000006}
|
||||
data:
|
||||
first:
|
||||
name: _BumpMap_ST
|
||||
second: {r: 1, g: 1, b: 0, a: 0}
|
||||
data:
|
||||
first:
|
||||
name: WaveSpeed
|
||||
second: {r: 9, g: 4.5, b: -8, a: -3.5}
|
||||
data:
|
||||
first:
|
||||
name: _horizonColor
|
||||
second: {r: 0, g: .125133663, b: .191176474, a: 0}
|
||||
data:
|
||||
first:
|
||||
name: _ColorControl_ST
|
||||
second: {r: 1, g: 1, b: 0, a: 0}
|
||||
data:
|
||||
first:
|
||||
name: _ColorControlCube_ST
|
||||
second: {r: 1, g: 1, b: 0, a: 0}
|
||||
data:
|
||||
first:
|
||||
name: BumpParm
|
||||
second: {r: 1, g: 1, b: 1, a: 1}
|
||||
data:
|
||||
first:
|
||||
name: _EdgeColor
|
||||
second: {r: 0, g: .100000001, b: 0, a: .100000001}
|
||||
data:
|
||||
first:
|
||||
name: _RefTex_0
|
||||
second: {r: -1517.37024, g: -23.9408531, b: -3154.91675, a: 2715.94165}
|
||||
data:
|
||||
first:
|
||||
name: _RefTex_1
|
||||
second: {r: 356.584351, g: -313.125671, b: -962.84906, a: 2791.50659}
|
||||
data:
|
||||
first:
|
||||
name: _RefTex_2
|
||||
second: {r: 4.95644999, g: -.187056601, b: -13.3834057, a: 20.1233597}
|
||||
data:
|
||||
first:
|
||||
name: _RefTex_3
|
||||
second: {r: 4.95595503, g: -.18703793, b: -13.3820696, a: 20.2213535}
|
||||
data:
|
||||
first:
|
||||
name: horizonColor
|
||||
second: {r: .61500001, g: .796000004, b: .875999987, a: 1}
|
||||
data:
|
||||
first:
|
||||
name: uvParams
|
||||
second: {r: 10, g: .0199999996, b: .0299999993, a: 0}
|
||||
data:
|
||||
first:
|
||||
name: waveDirX
|
||||
second: {r: -2.5, g: 0, b: 7, a: 8}
|
||||
data:
|
||||
first:
|
||||
name: waveDirY
|
||||
second: {r: 0, g: 1.5, b: -7, a: 1}
|
||||
data:
|
||||
first:
|
||||
name: waveHeights
|
||||
second: {r: .800000012, g: 1, b: .100000001, a: .0500000007}
|
||||
data:
|
||||
first:
|
||||
name: _WaveSpeed
|
||||
second: {r: 1, g: -1, b: -1, a: 1}
|
||||
- BumpParm: {r: 1, g: 1, b: 1, a: 1}
|
||||
- WaveSpeed: {r: 9, g: 4.5, b: -8, a: -3.5}
|
||||
- _BumpMap_ST: {r: 1, g: 1, b: 0, a: 0}
|
||||
- _Color: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _ColorControlCube_ST: {r: 1, g: 1, b: 0, a: 0}
|
||||
- _ColorControl_ST: {r: 1, g: 1, b: 0, a: 0}
|
||||
- _EdgeColor: {r: 0, g: 0.1, b: 0, a: 0.1}
|
||||
- _MainTex_ST: {r: 1, g: 1, b: 0, a: 0}
|
||||
- _RefTex_0: {r: -1517.3702, g: -23.940853, b: -3154.9167, a: 2715.9417}
|
||||
- _RefTex_1: {r: 356.58435, g: -313.12567, b: -962.84906, a: 2791.5066}
|
||||
- _RefTex_2: {r: 4.95645, g: -0.1870566, b: -13.383406, a: 20.12336}
|
||||
- _RefTex_3: {r: 4.955955, g: -0.18703793, b: -13.38207, a: 20.221354}
|
||||
- _SpecColor: {r: 0, g: 0, b: 0, a: 0.4}
|
||||
- _WaveSpeed: {r: 1, g: -1, b: -1, a: 1}
|
||||
- _horizonColor: {r: 0, g: 0.12513366, b: 0.19117647, a: 0}
|
||||
- _horizonColorLava: {r: 0.36217052, g: 0, b: 0, a: 1}
|
||||
- horizonColor: {r: 0.615, g: 0.796, b: 0.876, a: 1}
|
||||
- uvParams: {r: 10, g: 0.02, b: 0.03, a: 0}
|
||||
- waveDirX: {r: -2.5, g: 0, b: 7, a: 8}
|
||||
- waveDirY: {r: 0, g: 1.5, b: -7, a: 1}
|
||||
- waveHeights: {r: 0.8, g: 1, b: 0.1, a: 0.05}
|
||||
m_BuildTextureStacks: []
|
||||
--- !u!1002 &2100001
|
||||
EditorExtensionImpl:
|
||||
serializedVersion: 6
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,127 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e02cef1dae209d020bb6dc8c8b80fef4
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 12
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
flipGreenChannel: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
ignoreMipmapLimit: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
swizzle: 50462976
|
||||
cookieLightType: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 32
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Server
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
nameFileIdTable: {}
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 1
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user