tile generation
This commit is contained in:
@@ -52,16 +52,34 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
|
||||
internal void InstantiateSpace(Transform parent, string name)
|
||||
{
|
||||
_spaceObject = new GameObject($"Space {name}", typeof(MeshFilter), typeof(MeshRenderer));
|
||||
_spaceObject = new GameObject($"Space {name}");
|
||||
_spaceObject.transform.SetParent(parent, false);
|
||||
_spaceObject.transform.localPosition = new Vector3(rrDimensions.x, 0, rrDimensions.z);
|
||||
|
||||
var meshFilter = _spaceObject.GetComponent<MeshFilter>();
|
||||
meshFilter.mesh = GenerateMesh();
|
||||
|
||||
var meshRenderer = _spaceObject.GetComponent<MeshRenderer>();
|
||||
meshRenderer.material = Engine.DefaultEngine.roomMaterial;
|
||||
|
||||
// build the space floor out of tiles
|
||||
for (var z = 0; z < rrDimensions.length; z++)
|
||||
{
|
||||
for (var x = 0; x < rrDimensions.width; x++)
|
||||
{
|
||||
var left = x == 0;
|
||||
var right = x == rrDimensions.width - 1;
|
||||
var bottom = z == 0;
|
||||
var top = z == rrDimensions.length - 1;
|
||||
|
||||
TileLocation location;
|
||||
if (bottom)
|
||||
location = left ? TileLocation.SW : right ? TileLocation.SE : TileLocation.S;
|
||||
else if (top)
|
||||
location = left ? TileLocation.NW : right ? TileLocation.NE : TileLocation.N;
|
||||
else
|
||||
location = left ? TileLocation.W : right ? TileLocation.E : TileLocation.C;
|
||||
|
||||
var tileObject = Object.Instantiate(Engine.DefaultEngine.config.spaceTile, _spaceObject.transform, false);
|
||||
tileObject.transform.localPosition = new Vector3(x, 0, z);
|
||||
tileObject.showTile = location;
|
||||
}
|
||||
}
|
||||
|
||||
// instantiate all modules inside this space
|
||||
Modules.ForEach(module => module.InstantiateModule(_spaceObject.transform));
|
||||
}
|
||||
@@ -77,41 +95,6 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
/// <param name="rrPosition">The room relative (<i>RR</i>) position that should be converted to a space relative (<i>SR</i>) position.</param>
|
||||
internal Vector2Int ToSpaceRelative(Vector2Int rrPosition) => rrPosition - rrDimensions.Position;
|
||||
|
||||
private Mesh GenerateMesh()
|
||||
{
|
||||
var mesh = new Mesh();
|
||||
|
||||
mesh.vertices = new[]
|
||||
{
|
||||
new Vector3(0, 0, 0),
|
||||
new Vector3(rrDimensions.width, 0, 0),
|
||||
new Vector3(0, 0, rrDimensions.length),
|
||||
new Vector3(rrDimensions.width, 0, rrDimensions.length)
|
||||
};
|
||||
|
||||
mesh.triangles = new[]
|
||||
{
|
||||
0, 2, 1,
|
||||
2, 3, 1
|
||||
};
|
||||
|
||||
var normal = Vector3.up;
|
||||
mesh.normals = new[]
|
||||
{
|
||||
normal, normal, normal, normal
|
||||
};
|
||||
|
||||
mesh.uv = new[]
|
||||
{
|
||||
new Vector2(0, 0),
|
||||
new Vector2(1, 0),
|
||||
new Vector2(0, 1),
|
||||
new Vector2(1, 1)
|
||||
};
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
internal void Destroy()
|
||||
{
|
||||
Object.Destroy(_spaceObject);
|
||||
|
||||
Reference in New Issue
Block a user