diff --git a/.codacy.yml b/.codacy.yml
new file mode 100644
index 0000000..5658121
--- /dev/null
+++ b/.codacy.yml
@@ -0,0 +1,2 @@
+exclude_paths:
+ - '*.md'
diff --git a/Images/Preview.png b/Images/Preview.png
new file mode 100644
index 0000000..eef5cf3
Binary files /dev/null and b/Images/Preview.png differ
diff --git a/Images/Preview.png.meta b/Images/Preview.png.meta
new file mode 100644
index 0000000..137b3b2
--- /dev/null
+++ b/Images/Preview.png.meta
@@ -0,0 +1,92 @@
+fileFormatVersion: 2
+guid: 68ff1beb749c9d74fa8c49d6e1ee5ab9
+TextureImporter:
+ internalIDToNameTable: []
+ externalObjects: {}
+ serializedVersion: 11
+ 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
+ isReadable: 0
+ streamingMipmaps: 0
+ streamingMipmapsPriority: 0
+ grayScaleToAlpha: 0
+ generateCubemap: 6
+ cubemapConvolution: 0
+ seamlessCubemap: 0
+ textureFormat: 1
+ maxTextureSize: 2048
+ textureSettings:
+ serializedVersion: 2
+ filterMode: -1
+ aniso: -1
+ mipBias: -100
+ 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
+ maxTextureSizeSet: 0
+ compressionQualitySet: 0
+ textureFormatSet: 0
+ applyGammaDecoding: 0
+ platformSettings:
+ - serializedVersion: 3
+ buildTarget: DefaultTexturePlatform
+ maxTextureSize: 2048
+ resizeAlgorithm: 0
+ textureFormat: -1
+ textureCompression: 1
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ androidETC2FallbackOverride: 0
+ forceMaximumCompressionQuality_BC6H_BC7: 0
+ spriteSheet:
+ serializedVersion: 2
+ sprites: []
+ outline: []
+ physicsShape: []
+ bones: []
+ spriteID:
+ internalID: 0
+ vertices: []
+ indices:
+ edges: []
+ weights: []
+ secondaryTextures: []
+ spritePackingTag:
+ pSDRemoveMatte: 0
+ pSDShowRemoveMatteOption: 0
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/README.md b/README.md
index aa6f6da..455f68d 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,11 @@
Gameframe.Procgen 👋
-
-
-
-
-
-
+
+
+
+[](https://github.com/coryleach/UnityProcgen/blob/master/LICENSE)
+
+[](https://twitter.com/coryleach)
+
Library of utilitities for procedural generation
@@ -13,7 +14,7 @@ Library of utilitities for procedural generation
#### Using UnityPackageManager (for Unity 2019.3 or later)
Open the package manager window (menu: Window > Package Manager)
Select "Add package from git URL...", fill in the pop-up with the following link:
-https://github.com/coryleach/UnityProcgen.git#0.0.3
+https://github.com/coryleach/UnityProcgen.git#0.0.4
#### Using UnityPackageManager (for Unity 2019.1 or later)
@@ -21,7 +22,7 @@ Find the manifest.json file in the Packages folder of your project and edit it t
```js
{
"dependencies": {
- "com.gameframe.procgen": "https://github.com/coryleach/UnityProcgen.git#0.0.3",
+ "com.gameframe.procgen": "https://github.com/coryleach/UnityProcgen.git#0.0.4",
...
},
}
diff --git a/Runtime/Utility/HexMeshUtility.cs b/Runtime/Utility/HexMeshUtility.cs
index 1c5860f..8fee395 100644
--- a/Runtime/Utility/HexMeshUtility.cs
+++ b/Runtime/Utility/HexMeshUtility.cs
@@ -16,18 +16,29 @@ public enum HexDirection
public class HexMeshData
{
- public float outerRadius;
- public float innerRadius;
- public List vertices;
- public List triangles;
- public List colors;
- public List uv;
- public Vector3[] corners;
-
- private float border = 0.25f;
+ private readonly float _outerRadius;
+ private readonly float _innerRadius;
+ private readonly List _vertices;
+ private readonly List _triangles;
+ private readonly List _colors;
+ private readonly List _uv;
+ private readonly Vector3[] _corners;
+ private readonly float _border = 0.25f;
- public float Border => border;
- public float Solid => 1 - border;
+ public float Border => _border;
+ public float Solid => 1 - _border;
+
+ public float OuterRadius => _outerRadius;
+
+ public float InnerRadius => _innerRadius;
+
+ public List Vertices => _vertices;
+
+ public List Triangles => _triangles;
+
+ public List Colors => _colors;
+
+ public List Uv => _uv;
public HexMeshData()
{
@@ -35,57 +46,59 @@ public HexMeshData()
public HexMeshData(float radius, float border = 0.2f)
{
- this.border = Mathf.Clamp01(border);
+ this._border = Mathf.Clamp01(border);
- outerRadius = radius;
- innerRadius = outerRadius * Mathf.Sqrt(3f) * 0.5f;
- vertices = new List();
- triangles = new List();
- colors = new List();
- uv = new List();
- corners = new [] {
- new Vector3(0f, 0f, outerRadius),
- new Vector3(innerRadius, 0f, 0.5f * outerRadius),
- new Vector3(innerRadius, 0f, -0.5f * outerRadius),
- new Vector3(0f, 0f, -outerRadius),
- new Vector3(-innerRadius, 0f, -0.5f * outerRadius),
- new Vector3(-innerRadius, 0f, 0.5f * outerRadius),
- new Vector3(0f, 0f, outerRadius)
+ _outerRadius = radius;
+ _innerRadius = HexMeshUtility.GetInnerRadius(_outerRadius);
+ _vertices = new List();
+ _triangles = new List();
+ _colors = new List();
+ _uv = new List();
+ _corners = new [] {
+ new Vector3(0f, 0f, _outerRadius),
+ new Vector3(_innerRadius, 0f, 0.5f * _outerRadius),
+ new Vector3(_innerRadius, 0f, -0.5f * _outerRadius),
+ new Vector3(0f, 0f, -_outerRadius),
+ new Vector3(-_innerRadius, 0f, -0.5f * _outerRadius),
+ new Vector3(-_innerRadius, 0f, 0.5f * _outerRadius),
+ new Vector3(0f, 0f, _outerRadius)
};
}
public Vector3 GetBridge(HexDirection direction)
{
- return (corners[(int)direction] + corners[(int)direction + 1]) * 0.5f * border;
+ return (_corners[(int)direction] + _corners[(int)direction + 1]) * 0.5f * _border;
}
public Vector3 GetFirstCorner(HexDirection direction)
{
- return corners[(int) direction];
+ return _corners[(int) direction];
}
public Vector3 GetSecondCorner(HexDirection direction)
{
- return corners[(int) direction + 1];
+ return _corners[(int) direction + 1];
}
public Vector3 GetFirstSolidCorner(HexDirection direction)
{
- return corners[(int) direction] * Solid;
+ return _corners[(int) direction] * Solid;
}
public Vector3 GetSecondSolidCorner(HexDirection direction)
{
- return corners[(int) direction + 1] * Solid;
+ return _corners[(int) direction + 1] * Solid;
}
public Mesh CreateMesh()
{
- Mesh mesh = new Mesh();
- mesh.vertices = vertices.ToArray();
- mesh.triangles = triangles.ToArray();
- mesh.colors = colors.ToArray();
- mesh.uv = uv.ToArray();
+ var mesh = new Mesh
+ {
+ vertices = _vertices.ToArray(),
+ triangles = _triangles.ToArray(),
+ colors = _colors.ToArray(),
+ uv = _uv.ToArray()
+ };
mesh.RecalculateNormals();
return mesh;
}
@@ -94,6 +107,12 @@ public Mesh CreateMesh()
public static class HexMeshUtility
{
+ //Calculates the inner radius from the outer radius
+ public static float GetInnerRadius(float outerRadius)
+ {
+ return outerRadius * Mathf.Sqrt(3f) * 0.5f;
+ }
+
public static HexDirection Previous(this HexDirection direction)
{
return direction == HexDirection.NE ? HexDirection.NW : (direction - 1);
@@ -180,7 +199,7 @@ public static Mesh GenerateHexagonMesh(float radius, float border, int startX, i
var index = (y * mapWidth) + x;
var xOffset = x + y * 0.5f - (int)(y / 2);
- var center = new Vector3(xOffset*meshData.innerRadius*2,0,y*meshData.outerRadius*1.5f);
+ var center = new Vector3(xOffset*meshData.InnerRadius*2,0,y*meshData.OuterRadius*1.5f);
for (var direction = 0; direction < 6; direction++)
{
@@ -248,51 +267,51 @@ private static void AddTriangle(HexMeshData meshData, Vector3 center, Vector3 uv
private static void AddTriangle(HexMeshData meshData, Vector3 v1, Vector3 v2, Vector3 v3, Color color, Vector3 uv)
{
- var vertexIndex = meshData.vertices.Count;
+ var vertexIndex = meshData.Vertices.Count;
- meshData.vertices.Add(v1);
- meshData.vertices.Add(v2);
- meshData.vertices.Add(v3);
+ meshData.Vertices.Add(v1);
+ meshData.Vertices.Add(v2);
+ meshData.Vertices.Add(v3);
- meshData.colors.Add(color);
- meshData.colors.Add(color);
- meshData.colors.Add(color);
+ meshData.Colors.Add(color);
+ meshData.Colors.Add(color);
+ meshData.Colors.Add(color);
- meshData.uv.Add(uv);
- meshData.uv.Add(uv);
- meshData.uv.Add(uv);
+ meshData.Uv.Add(uv);
+ meshData.Uv.Add(uv);
+ meshData.Uv.Add(uv);
- meshData.triangles.Add(vertexIndex);
- meshData.triangles.Add(vertexIndex + 1);
- meshData.triangles.Add(vertexIndex + 2);
+ meshData.Triangles.Add(vertexIndex);
+ meshData.Triangles.Add(vertexIndex + 1);
+ meshData.Triangles.Add(vertexIndex + 2);
}
private static void AddQuad(HexMeshData meshData, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, Color color, Vector3 uv)
{
- var vertexIndex = meshData.vertices.Count;
+ var vertexIndex = meshData.Vertices.Count;
- meshData.vertices.Add(v1);
- meshData.vertices.Add(v2);
- meshData.vertices.Add(v3);
- meshData.vertices.Add(v4);
+ meshData.Vertices.Add(v1);
+ meshData.Vertices.Add(v2);
+ meshData.Vertices.Add(v3);
+ meshData.Vertices.Add(v4);
- meshData.colors.Add(color);
- meshData.colors.Add(color);
- meshData.colors.Add(color);
- meshData.colors.Add(color);
+ meshData.Colors.Add(color);
+ meshData.Colors.Add(color);
+ meshData.Colors.Add(color);
+ meshData.Colors.Add(color);
- meshData.uv.Add(uv);
- meshData.uv.Add(uv);
- meshData.uv.Add(uv);
- meshData.uv.Add(uv);
+ meshData.Uv.Add(uv);
+ meshData.Uv.Add(uv);
+ meshData.Uv.Add(uv);
+ meshData.Uv.Add(uv);
- meshData.triangles.Add(vertexIndex);
- meshData.triangles.Add(vertexIndex + 2);
- meshData.triangles.Add(vertexIndex + 1);
+ meshData.Triangles.Add(vertexIndex);
+ meshData.Triangles.Add(vertexIndex + 2);
+ meshData.Triangles.Add(vertexIndex + 1);
- meshData.triangles.Add(vertexIndex + 1);
- meshData.triangles.Add(vertexIndex + 2);
- meshData.triangles.Add(vertexIndex + 3);
+ meshData.Triangles.Add(vertexIndex + 1);
+ meshData.Triangles.Add(vertexIndex + 2);
+ meshData.Triangles.Add(vertexIndex + 3);
}
}
diff --git a/Runtime/Utility/VoxelMeshUtility.cs b/Runtime/Utility/VoxelMeshUtility.cs
index 23eb3ee..ebe22a0 100644
--- a/Runtime/Utility/VoxelMeshUtility.cs
+++ b/Runtime/Utility/VoxelMeshUtility.cs
@@ -145,21 +145,21 @@ public static VoxelMeshData CreateMeshData(float[] heightMap, int width, int hei
public class VoxelMeshData
{
- private List vertices = new List();
- private List uv = new List();
- private List triangles = new List();
+ private readonly List _vertices = new List();
+ private readonly List _uv = new List();
+ private readonly List _triangles = new List();
- private int width;
- private int height;
- private int quadCount;
- private Vector2Int offset;
+ private readonly int _width;
+ private readonly int _height;
+ private int _quadCount;
+ private readonly Vector2Int _offset;
public VoxelMeshData(int width, int height, Vector2Int offset)
{
- this.width = width;
- this.height = height;
- this.offset = offset;
- quadCount = 0;
+ _width = width;
+ _height = height;
+ _offset = offset;
+ _quadCount = 0;
}
///
@@ -177,10 +177,10 @@ public void AddUpQuad(int x, int y, float elevation)
var topRight = new Vector3(x + 1, elevation, y + 1);
var bottomRight = new Vector3(x + 1, elevation, y);
- vertices.Add(bottomLeft);
- vertices.Add(topLeft);
- vertices.Add(topRight);
- vertices.Add(bottomRight);
+ _vertices.Add(bottomLeft);
+ _vertices.Add(topLeft);
+ _vertices.Add(topRight);
+ _vertices.Add(bottomRight);
AddUV(x, y);
AddTriangles();
@@ -201,10 +201,10 @@ public void AddLeftQuad(int x, int y, float elevation, float depth)
var topRight = new Vector3(x, elevation, y);
var bottomRight = new Vector3(x, elevation - depth, y);
- vertices.Add(bottomLeft);
- vertices.Add(topLeft);
- vertices.Add(topRight);
- vertices.Add(bottomRight);
+ _vertices.Add(bottomLeft);
+ _vertices.Add(topLeft);
+ _vertices.Add(topRight);
+ _vertices.Add(bottomRight);
AddUV(x, y);
AddTriangles();
@@ -225,10 +225,10 @@ public void AddRightQuad(int x, int y, float elevation, float depth)
var topRight = new Vector3(x + 1, elevation, y + 1);
var bottomRight = new Vector3(x + 1, elevation - depth, y + 1);
- vertices.Add(bottomLeft);
- vertices.Add(topLeft);
- vertices.Add(topRight);
- vertices.Add(bottomRight);
+ _vertices.Add(bottomLeft);
+ _vertices.Add(topLeft);
+ _vertices.Add(topRight);
+ _vertices.Add(bottomRight);
AddUV(x, y);
AddTriangles();
@@ -249,10 +249,10 @@ public void AddBackQuad(int x, int y, float elevation, float depth)
var topRight = new Vector3(x + 1, elevation, y);
var bottomRight = new Vector3(x + 1, elevation - depth, y);
- vertices.Add(bottomLeft);
- vertices.Add(topLeft);
- vertices.Add(topRight);
- vertices.Add(bottomRight);
+ _vertices.Add(bottomLeft);
+ _vertices.Add(topLeft);
+ _vertices.Add(topRight);
+ _vertices.Add(bottomRight);
AddUV(x, y);
AddTriangles();
@@ -273,10 +273,10 @@ public void AddFrontQuad(int x, int y, float elevation, float depth)
var topRight = new Vector3(x, elevation, y + 1);
var bottomRight = new Vector3(x, elevation - depth, y + 1);
- vertices.Add(bottomLeft);
- vertices.Add(topLeft);
- vertices.Add(topRight);
- vertices.Add(bottomRight);
+ _vertices.Add(bottomLeft);
+ _vertices.Add(topLeft);
+ _vertices.Add(topRight);
+ _vertices.Add(bottomRight);
AddUV(x, y);
AddTriangles();
@@ -291,15 +291,15 @@ public void AddFrontQuad(int x, int y, float elevation, float depth)
private void AddUV(int x, int y, float padding = 0.1f)
{
//We need to add the offset so UVs are shifted to correct texture chunk
- var uvBottomLeft = new Vector2((x + offset.x + padding) / width, (y + offset.y + padding) / height);
- var uvTopLeft = new Vector2((x + offset.x + padding) / width, (y + offset.y + 1 - padding) / height);
- var uvTopRight = new Vector2((x + offset.x + 1 - padding) / width, (y + offset.y + 1 - padding) / height);
- var uvBottomRight = new Vector2((x + offset.x + 1 - padding) / width, (y + offset.y + padding) / height);
-
- uv.Add(uvBottomLeft);
- uv.Add(uvTopLeft);
- uv.Add(uvTopRight);
- uv.Add(uvBottomRight);
+ var uvBottomLeft = new Vector2((x + _offset.x + padding) / _width, (y + _offset.y + padding) / _height);
+ var uvTopLeft = new Vector2((x + _offset.x + padding) / _width, (y + _offset.y + 1 - padding) / _height);
+ var uvTopRight = new Vector2((x + _offset.x + 1 - padding) / _width, (y + _offset.y + 1 - padding) / _height);
+ var uvBottomRight = new Vector2((x + _offset.x + 1 - padding) / _width, (y + _offset.y + padding) / _height);
+
+ _uv.Add(uvBottomLeft);
+ _uv.Add(uvTopLeft);
+ _uv.Add(uvTopRight);
+ _uv.Add(uvBottomRight);
}
///
@@ -307,17 +307,17 @@ private void AddUV(int x, int y, float padding = 0.1f)
///
private void AddTriangles()
{
- int triangleIndex = quadCount * 4;
+ int triangleIndex = _quadCount * 4;
- triangles.Add(triangleIndex + 0);
- triangles.Add(triangleIndex + 1);
- triangles.Add(triangleIndex + 2);
+ _triangles.Add(triangleIndex + 0);
+ _triangles.Add(triangleIndex + 1);
+ _triangles.Add(triangleIndex + 2);
- triangles.Add(triangleIndex + 0);
- triangles.Add(triangleIndex + 2);
- triangles.Add(triangleIndex + 3);
+ _triangles.Add(triangleIndex + 0);
+ _triangles.Add(triangleIndex + 2);
+ _triangles.Add(triangleIndex + 3);
- quadCount++;
+ _quadCount++;
}
@@ -325,9 +325,9 @@ public Mesh CreateMesh()
{
var mesh = new Mesh
{
- vertices = vertices.ToArray(),
- triangles = triangles.ToArray(),
- uv = uv.ToArray()
+ vertices = _vertices.ToArray(),
+ triangles = _triangles.ToArray(),
+ uv = _uv.ToArray()
};
mesh.RecalculateNormals();
return mesh;
diff --git a/Runtime/Visualizers/PoissonVisualizer.cs b/Runtime/Visualizers/PoissonVisualizer.cs
index b1ee331..39d29b7 100644
--- a/Runtime/Visualizers/PoissonVisualizer.cs
+++ b/Runtime/Visualizers/PoissonVisualizer.cs
@@ -6,12 +6,20 @@ namespace Gameframe.Procgen
{
public class PoissonVisualizer : MonoBehaviour
{
- public int seed = 0;
- public Vector2Int imageSize;
- public float radius = 1f;
- public int maxSamplesPerPoint = 100;
+ [SerializeField]
+ private int seed;
+
+ [SerializeField]
+ private Vector2Int imageSize;
+
+ [SerializeField]
+ private float radius = 1f;
+
+ [SerializeField]
+ private int maxSamplesPerPoint = 100;
- [SerializeField] private MeshRenderer _renderer;
+ [SerializeField]
+ private MeshRenderer _renderer;
private void Start()
{
diff --git a/Runtime/Visualizers/VoronoiVisualizer.cs b/Runtime/Visualizers/VoronoiVisualizer.cs
index ce0f2e1..e2bf2e9 100644
--- a/Runtime/Visualizers/VoronoiVisualizer.cs
+++ b/Runtime/Visualizers/VoronoiVisualizer.cs
@@ -7,15 +7,23 @@ namespace Gameframe.Procgen
{
public class VoronoiVisualizer : MonoBehaviour
{
- public int seed = 0;
- public Vector2Int imageSize;
- public int regionAmount;
+ [SerializeField]
+ private int seed;
+
+ [SerializeField]
+ private Vector2Int imageSize;
+
+ [SerializeField]
+ private int regionAmount;
[SerializeField]
private MeshRenderer _renderer;
- public bool UseMainTexture = true;
- public string texturePropertyName = "_BaseMap";
+ [SerializeField]
+ private bool UseMainTexture = true;
+
+ [SerializeField]
+ private string texturePropertyName = "_BaseMap";
private void Start()
{
diff --git a/Runtime/WorldMap/Layers/PoissonMapLayerGenerator.cs b/Runtime/WorldMap/Layers/PoissonMapLayerGenerator.cs
index 153b4ea..2ce9d15 100644
--- a/Runtime/WorldMap/Layers/PoissonMapLayerGenerator.cs
+++ b/Runtime/WorldMap/Layers/PoissonMapLayerGenerator.cs
@@ -5,10 +5,17 @@ namespace Gameframe.Procgen
[CreateAssetMenu(menuName = "Gameframe/Procgen/Layers/PoissonMapLayerGenerator")]
public class PoissonMapLayerGenerator : WorldMapLayerGenerator
{
- public float radius = 10;
- public int maxSamplesPerPoint = 30;
- public bool useRegions = true;
- public int edgeAvoidance = 0;
+ [SerializeField]
+ private float radius = 10;
+
+ [SerializeField]
+ private int maxSamplesPerPoint = 30;
+
+ [SerializeField]
+ private bool useRegions = true;
+
+ [SerializeField]
+ private int edgeAvoidance;
public override void AddToWorld(WorldMapData mapData)
{
diff --git a/Runtime/WorldMap/Views/WoldMapTerrainMeshView.cs b/Runtime/WorldMap/Views/WoldMapTerrainMeshView.cs
index bfb52e3..4d915f3 100644
--- a/Runtime/WorldMap/Views/WoldMapTerrainMeshView.cs
+++ b/Runtime/WorldMap/Views/WoldMapTerrainMeshView.cs
@@ -5,7 +5,7 @@
namespace Gameframe.Procgen
{
- public class WoldMapTerrainMeshView : MonoBehaviour, IWorldMapView
+ public class WoldMapTerrainMeshView : WorldMapView, IWorldMapView
{
[SerializeField] private MeshFilter _meshFilter = null;
@@ -24,7 +24,7 @@ private void Start()
{
}
- public void DisplayMap(WorldMapData worldMapData)
+ public override void DisplayMap(WorldMapData worldMapData)
{
if (!enabled)
{
diff --git a/Runtime/WorldMap/Views/WorldMapHexMeshView.cs b/Runtime/WorldMap/Views/WorldMapHexMeshView.cs
index 76acb55..1120501 100644
--- a/Runtime/WorldMap/Views/WorldMapHexMeshView.cs
+++ b/Runtime/WorldMap/Views/WorldMapHexMeshView.cs
@@ -5,7 +5,7 @@
namespace Gameframe.Procgen
{
- public class WorldMapHexMeshView : MonoBehaviour, IWorldMapView
+ public class WorldMapHexMeshView : WorldMapView, IWorldMapView
{
[SerializeField] private WorldMapViewChunk _prefab = null;
[SerializeField] private float radius = 1f;
@@ -21,6 +21,9 @@ public class WorldMapHexMeshView : MonoBehaviour, IWorldMapView
[SerializeField] private List chunkList = new List();
private readonly Dictionary _chunks = new Dictionary();
+ private WorldMapData _mapData = null;
+ private float[] _heightMap = null;
+
private void Start()
{
//This is here just to show the enable checkbox in editor
@@ -30,15 +33,29 @@ private void OnDisable()
{
ClearChunks();
}
-
- public void DisplayMap(WorldMapData mapData)
+
+ public override Vector3 MapToWorldPosition(Vector2Int point)
+ {
+ var innerRadius = HexMeshUtility.GetInnerRadius(radius);
+ var xOffset = point.x + point.y * 0.5f - (int)(point.y / 2);
+ var pt = new Vector3
+ {
+ x = xOffset * innerRadius * 2,
+ y = _mapData == null || _heightMap == null ? 0 : GetElevation(_heightMap[point.y * _mapData.width + point.x]),
+ z = point.y * radius * 1.5f
+ };
+ return pt;
+ }
+
+ public override void DisplayMap(WorldMapData mapData)
{
if (!enabled)
{
return;
}
-
- var heightMap = mapData.GetLayer().heightMap;
+
+ _mapData = mapData;
+ _heightMap = _mapData.GetLayer().heightMap;
ClearChunks();
@@ -55,7 +72,7 @@ public void DisplayMap(WorldMapData mapData)
var startY = chunkY * chunkHeight;
var chunkView = GetChunk(new Vector2Int(chunkX,chunkY));
chunkView.transform.localPosition = new Vector3(0,0,0);
- var mesh = HexMeshUtility.GenerateHexagonMesh(radius, border, startX, startY, chunkWidth, chunkHeight, mapData.width, mapData.height, heightMap, GetColor, GetElevation);
+ var mesh = HexMeshUtility.GenerateHexagonMesh(radius, border, startX, startY, chunkWidth, chunkHeight, mapData.width, mapData.height, _heightMap, GetColor, GetElevation);
chunkView.SetMesh(mesh);
}
}
diff --git a/Runtime/WorldMap/Views/WorldMapView.cs b/Runtime/WorldMap/Views/WorldMapView.cs
new file mode 100644
index 0000000..a7b807a
--- /dev/null
+++ b/Runtime/WorldMap/Views/WorldMapView.cs
@@ -0,0 +1,14 @@
+using UnityEngine;
+
+namespace Gameframe.Procgen
+{
+ public abstract class WorldMapView : MonoBehaviour, IWorldMapView
+ {
+ public virtual Vector3 MapToWorldPosition(Vector2Int point)
+ {
+ return new Vector3(point.x, 0, point.y);
+ }
+
+ public abstract void DisplayMap(WorldMapData mapData);
+ }
+}
\ No newline at end of file
diff --git a/Runtime/WorldMap/Views/WorldMapView.cs.meta b/Runtime/WorldMap/Views/WorldMapView.cs.meta
new file mode 100644
index 0000000..eab600d
--- /dev/null
+++ b/Runtime/WorldMap/Views/WorldMapView.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e7b96a817794263478ff0a3d9c0e72eb
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Runtime/WorldMap/Views/WorldMapVoxelMeshView.cs b/Runtime/WorldMap/Views/WorldMapVoxelMeshView.cs
index 6c5decd..bbffeba 100644
--- a/Runtime/WorldMap/Views/WorldMapVoxelMeshView.cs
+++ b/Runtime/WorldMap/Views/WorldMapVoxelMeshView.cs
@@ -6,7 +6,7 @@
namespace Gameframe.Procgen
{
- public class WorldMapVoxelMeshView : MonoBehaviour, IWorldMapView
+ public class WorldMapVoxelMeshView : WorldMapView, IWorldMapView
{
[SerializeField] private TerrainTable _terrainTable;
@@ -36,7 +36,7 @@ private void OnDisable()
ClearChunks();
}
- public void DisplayMap(WorldMapData mapData)
+ public override void DisplayMap(WorldMapData mapData)
{
if (!enabled)
{
diff --git a/Runtime/csc.rsp b/Runtime/csc.rsp
new file mode 100644
index 0000000..2f6b821
--- /dev/null
+++ b/Runtime/csc.rsp
@@ -0,0 +1 @@
+-nowarn:CS0649
diff --git a/Runtime/csc.rsp.meta b/Runtime/csc.rsp.meta
new file mode 100644
index 0000000..67d3e21
--- /dev/null
+++ b/Runtime/csc.rsp.meta
@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 8a003ef853bf53c4f8cef961840b3677
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/package.json b/package.json
index 07494c4..98226da 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,7 @@
"name": "com.gameframe.procgen",
"displayName": "Gameframe.Procgen",
"repositoryName": "UnityProcgen",
- "version": "0.0.3",
+ "version": "0.0.4",
"description": "Library of utilitities for procedural generation",
"type": "library",
"keywords": [],