Changed spawn to be dynamically created
This commit is contained in:
parent
b9aa033c13
commit
509c207d32
File diff suppressed because it is too large
Load Diff
@ -58,10 +58,6 @@ namespace Assets.Scripts
|
|||||||
{
|
{
|
||||||
tiletype = tiletype.Replace("Tile", "");
|
tiletype = tiletype.Replace("Tile", "");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
tiletype = "Spawn";
|
|
||||||
}
|
|
||||||
coordinates.GetComponent<Text>().text = TextHandler.getText(tiletype) + "(" + (int)position.x + "/" + (int)position.y + "/" + (int)position.z + ")";
|
coordinates.GetComponent<Text>().text = TextHandler.getText(tiletype) + "(" + (int)position.x + "/" + (int)position.y + "/" + (int)position.z + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -146,24 +146,6 @@ public class Tile : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetSpawn()
|
|
||||||
{
|
|
||||||
foreach (Rigidbody rigid in gameObject.GetComponentsInChildren<Rigidbody>())
|
|
||||||
{
|
|
||||||
rigid.useGravity = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Renderer rend in gameObject.GetComponentsInChildren<Renderer>())
|
|
||||||
{
|
|
||||||
rend.enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Collider col in gameObject.GetComponentsInChildren<Collider>())
|
|
||||||
{
|
|
||||||
col.enabled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool enteredTile(float playerX, float playerZ)
|
public bool enteredTile(float playerX, float playerZ)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|||||||
@ -24,19 +24,15 @@ public class WorldGenerator : MonoBehaviour
|
|||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
tiles = new Dictionary<Vector3, GameObject>();
|
tiles = new Dictionary<Vector3, GameObject>();
|
||||||
tiles.Add(new Vector3(0, 0, 0), GameObject.Find("Spawn"));
|
|
||||||
renderedTiles = new List<GameObject>();
|
renderedTiles = new List<GameObject>();
|
||||||
currentTile = GameObject.Find("Spawn");
|
|
||||||
currentTile.GetComponent<Tile>().setPosition(new Vector3(0, 0, 0));
|
|
||||||
currentTile.GetComponent<Tile>().setBorders();
|
|
||||||
renderedTiles.Add(currentTile);
|
|
||||||
noise = new NoiseGenerator();
|
noise = new NoiseGenerator();
|
||||||
|
createSpawn();
|
||||||
cityAmount = 10;
|
cityAmount = 10;
|
||||||
maxCityAmount = 10;
|
maxCityAmount = 10;
|
||||||
}
|
}
|
||||||
@ -52,16 +48,12 @@ public class WorldGenerator : MonoBehaviour
|
|||||||
{
|
{
|
||||||
foreach (GameObject tile in tiles.Values)
|
foreach (GameObject tile in tiles.Values)
|
||||||
{
|
{
|
||||||
if (tile.name != "Spawn")
|
Destroy(tile);
|
||||||
{
|
|
||||||
Destroy(tile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
player.transform.position = new Vector3(0,1.5f,0);
|
player.transform.position = new Vector3(0, 1.5f, 0);
|
||||||
player.transform.rotation = Quaternion.identity;
|
player.transform.rotation = Quaternion.identity;
|
||||||
OnEnable();
|
OnEnable();
|
||||||
currentTile.GetComponent<Tile>().resetSpawn();
|
|
||||||
this.cityAmount = cityAmount;
|
this.cityAmount = cityAmount;
|
||||||
maxCityAmount = cityAmount;
|
maxCityAmount = cityAmount;
|
||||||
}
|
}
|
||||||
@ -83,13 +75,35 @@ 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);
|
||||||
|
tiles.Add(pos, newTile);
|
||||||
|
renderedTiles.Add(newTile);
|
||||||
|
currentTile = newTile;
|
||||||
|
}
|
||||||
|
|
||||||
public void createTile(float playerX, float playerZ)
|
public void createTile(float playerX, float playerZ)
|
||||||
{
|
{
|
||||||
Vector3 pos = currentTile.GetComponent<Tile>().needConnectedTile(playerX, playerZ);
|
Vector3 pos = currentTile.GetComponent<Tile>().needConnectedTile(playerX, playerZ);
|
||||||
if (!tiles.ContainsKey(pos) && pos.y == 0)
|
if (!tiles.ContainsKey(pos) && pos.y == 0)
|
||||||
{
|
{
|
||||||
string name = "";
|
string name = "";
|
||||||
int chance = rand.Next(1,11);
|
int chance = rand.Next(1, 11);
|
||||||
Vector3 mapPos = new Vector3(pos.x * 100, 0, pos.z * 100);
|
Vector3 mapPos = new Vector3(pos.x * 100, 0, pos.z * 100);
|
||||||
GameObject newTile = Instantiate(tile, mapPos, Quaternion.identity);
|
GameObject newTile = Instantiate(tile, mapPos, Quaternion.identity);
|
||||||
if (chance == 1)
|
if (chance == 1)
|
||||||
@ -102,7 +116,8 @@ public class WorldGenerator : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
noise.applyNoise(newTile, name, tiles);
|
noise.applyNoise(newTile, name, tiles);
|
||||||
if(name.Length <= 0){
|
if (name.Length <= 0)
|
||||||
|
{
|
||||||
name = tile.name;
|
name = tile.name;
|
||||||
}
|
}
|
||||||
if (name.Contains("_"))
|
if (name.Contains("_"))
|
||||||
@ -160,25 +175,22 @@ public class WorldGenerator : MonoBehaviour
|
|||||||
result = result + "\"map\": {\r\n";
|
result = result + "\"map\": {\r\n";
|
||||||
foreach (GameObject tile in tiles.Values)
|
foreach (GameObject tile in tiles.Values)
|
||||||
{
|
{
|
||||||
if (tile.name != "Spawn")
|
savePath = "./save/tile" + counter + ".json";
|
||||||
|
result = result + "\"tile" + counter + "\": \"" + savePath + "\"";
|
||||||
|
tile.GetComponent<Tile>().saveTile(savePath);
|
||||||
|
if (tile.GetComponent<Tile>().getTileType() == "CityTile")
|
||||||
{
|
{
|
||||||
savePath = "./save/tile" + counter + ".json";
|
FileHandler.saveNoise("\r\n}", savePath);
|
||||||
result = result + "\"tile" + counter + "\": \"" + savePath + "\"";
|
|
||||||
tile.GetComponent<Tile>().saveTile(savePath);
|
|
||||||
if (tile.GetComponent<Tile>().getTileType() == "CityTile")
|
|
||||||
{
|
|
||||||
FileHandler.saveNoise("\r\n}", savePath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
noise.saveTile(tile, savePath);
|
|
||||||
}
|
|
||||||
if (counter < tiles.Count - 2)
|
|
||||||
{
|
|
||||||
result = result + ",\r\n";
|
|
||||||
}
|
|
||||||
counter++;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
noise.saveTile(tile, savePath);
|
||||||
|
}
|
||||||
|
if (counter < tiles.Count - 2)
|
||||||
|
{
|
||||||
|
result = result + ",\r\n";
|
||||||
|
}
|
||||||
|
counter++;
|
||||||
}
|
}
|
||||||
result = result + "\r\n}";
|
result = result + "\r\n}";
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -18,4 +18,4 @@ MonoBehaviour:
|
|||||||
m_AssetTable:
|
m_AssetTable:
|
||||||
m_TableReference:
|
m_TableReference:
|
||||||
m_TableCollectionName: GUID:be998aea26820a30aa2217983d31b9c7
|
m_TableCollectionName: GUID:be998aea26820a30aa2217983d31b9c7
|
||||||
m_TrackingChanges: 1
|
m_TrackingChanges: 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user