Finalised json save, added newtonsoft to project, v1.3.0

This commit is contained in:
Nicola Sovic 2022-06-10 10:35:23 +02:00
parent 14f62410f5
commit a026b9b1f5
26 changed files with 74660 additions and 1437 deletions

8
Assets/Plugins.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3f551e260fd255942ae7feb52fe1b4f1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 0a26f55bc3f508441bb3d6ea70973bc5
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,6 +1,8 @@
using Assets.Scripts;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
public class NoiseGenerator
{
@ -227,4 +229,31 @@ public class NoiseGenerator
mesh.colors32 = colors;
tile.GetComponent<MeshCollider>().sharedMesh = mesh;
}
public string saveTile(GameObject tile)
{
string result = "";
Vector3[] vertices = tile.GetComponent<MeshFilter>().mesh.vertices;
Color32[] colors = tile.GetComponent<MeshFilter>().mesh.colors32;
result = result + "\"vertices\": {\r\n";
for (int i = 0; i < vertices.Length; i++)
{
result = result + FileHandler.generateJSON("vertice"+i, "\"" + vertices[i].x + "/" + vertices[i].y + "/" + vertices[i].z + "\"");
if (i < vertices.Length - 1)
{
result = result + ",\r\n";
}
}
result = result + "\r\n},\"colors\": {\r\n";
for (int i = 0; i < colors.Length; i++)
{
result = result + FileHandler.generateJSON("color" + i, "\"" + colors[i].r + "/" + colors[i].g + "/" + colors[i].b + "\"");
if (i < colors.Length - 1)
{
result = result + ",\r\n";
}
}
result = result + "\r\n}";
return result;
}
}

View File

@ -220,17 +220,13 @@ public class Tile : MonoBehaviour
string result = "";
GameObject obj;
result = result + FileHandler.generateJSON("tiletype", "\"" + tiletype + "\"") + ",\r\n";
result = result + FileHandler.generateJSON("positionX", position.x) + ",\r\n";
result = result + FileHandler.generateJSON("positionY", position.y) + ",\r\n";
result = result + FileHandler.generateJSON("positionZ", position.z) + ",\r\n";
result = result + "\"Objects\": {\r\n";
result = result + FileHandler.generateJSON("position", "\"" + position.x + "/" + position.y + "/" + position.z + "\"") + ",\r\n";
result = result + "\"objects\": {\r\n";
for (int i = 0; i < gameObject.transform.childCount; i++)
{
obj = gameObject.transform.GetChild(i).gameObject;
result = result + "\"Object" + i + "\": {\r\n";
result = result + FileHandler.generateJSON("positionX", obj.transform.position.x) + ",\r\n";
result = result + FileHandler.generateJSON("positionY", obj.transform.position.y) + ",\r\n";
result = result + FileHandler.generateJSON("positionZ", obj.transform.position.z) + ",\r\n";
result = result + "\"object" + i + "\": {\r\n";
result = result + FileHandler.generateJSON("position", "\"" + obj.transform.position.x + "/" + obj.transform.position.y + "/" + obj.transform.position.z + "\"") + ",\r\n";
if (obj.tag.Contains("Enemy"))
{
result = result + obj.GetComponent<Enemy>().saveEnemy() + "\r\n}";
@ -247,4 +243,11 @@ public class Tile : MonoBehaviour
result = result + "\r\n}";
return result;
}
public string saveCurrent()
{
string result = "";
result = result + "\"" + position.x + "/" + position.y + "/" + position.z + "\"";
return result;
}
}

View File

@ -186,19 +186,22 @@ public class WorldGenerator : MonoBehaviour
int counter = 0;
result = result + FileHandler.generateJSON("cityAmount", cityAmount) + ",\r\n";
result = result + FileHandler.generateJSON("maxCityAmount", maxCityAmount) + ",\r\n";
result = result + "\"currentTile\": {\r\n";
result = result + currentTile.GetComponent<Tile>().saveTile() + "\r\n},\r\n";
result = result + "\"Map\": {\r\n";
result = result + "\"currentTile\": " + currentTile.GetComponent<Tile>().saveCurrent() + ",\r\n";
result = result + "\"map\": {\r\n";
foreach (GameObject tile in tiles.Values)
{
result = result + "\"Tile"+counter+"\": {\r\n";
result = result + tile.GetComponent<Tile>().saveTile() + "\r\n}";
if (tile.name != "Spawn")
{
result = result + "\"tile" + counter + "\": {\r\n";
result = result + tile.GetComponent<Tile>().saveTile() + ",\r\n";
result = result + noise.saveTile(tile) + "\r\n}";
if (counter < tiles.Count - 1)
{
result = result + ",\r\n";
}
counter++;
}
}
result = result + "\r\n}";
return result;
}

Binary file not shown.

View File

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2007 James Newton-King
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

4
packages.config Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net471" />
</packages>

1771
save.json

File diff suppressed because it is too large Load Diff