ready for logan?
getting ready to piece UI elements together with the logic of the grid
This commit is contained in:
@@ -7,6 +7,10 @@ public class CellMesh : MonoBehaviour
|
||||
private LogicGrid grid;
|
||||
private Mesh mesh;
|
||||
|
||||
Vector3[] m_vertices;
|
||||
Vector2[] m_uv;
|
||||
int[] m_triangles;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
mesh = new Mesh();
|
||||
@@ -24,12 +28,30 @@ public class CellMesh : MonoBehaviour
|
||||
|
||||
private void GridValueChanged(object sender, LogicGrid.OnGridValueChangedEventArgs e)
|
||||
{
|
||||
Debug.Log("FIRE!!");
|
||||
Debug.Log(e.x + " " + e.y);
|
||||
UpdateCellVisual();
|
||||
}
|
||||
|
||||
// TODO: implement this so we can update a single cell, given an x, y coordinate
|
||||
private void UpdateCellVisual(int x, int y)
|
||||
{
|
||||
//Debug.Log("Updated in Isolation 8)");
|
||||
Vector3 quadSize = new Vector3(1, 1) * grid.GetCellSize();
|
||||
int index = x * grid.GetHeight() + y;
|
||||
|
||||
int gridValue = grid.GetValue(x, y);
|
||||
float gridValueNormalized = gridValue / 3f;
|
||||
Vector2 gridValueUV = new Vector2(gridValueNormalized, 0f);
|
||||
|
||||
MeshUtils.AddToMeshArrays(m_vertices, m_uv, m_triangles, index, grid.GetWorldPosition(x, y) + (quadSize * .5f), 0f, quadSize, gridValueUV, gridValueUV);
|
||||
|
||||
}
|
||||
|
||||
// Update all cells at once
|
||||
private void UpdateCellVisual()
|
||||
{
|
||||
Debug.Log("Updated as a group");
|
||||
|
||||
MeshUtils.CreateEmptyMeshArrays(grid.GetWidth() * grid.GetHeight(), out Vector3[] vertices, out Vector2[] uv, out int[] triangles);
|
||||
|
||||
for(int x = 0; x < grid.GetWidth(); x++)
|
||||
@@ -40,13 +62,17 @@ public class CellMesh : MonoBehaviour
|
||||
Vector3 quadSize = new Vector3(1, 1) * grid.GetCellSize();
|
||||
|
||||
int gridValue = grid.GetValue(x, y);
|
||||
float gridValueNormalized = gridValue / 4f;
|
||||
float gridValueNormalized = gridValue / 3f;
|
||||
Vector2 gridValueUV = new Vector2(gridValueNormalized, 0f);
|
||||
|
||||
|
||||
MeshUtils.AddToMeshArrays(vertices, uv, triangles, index, grid.GetWorldPosition(x, y) + (quadSize * .5f), 0f, quadSize, gridValueUV, gridValueUV);
|
||||
}
|
||||
|
||||
m_vertices = vertices;
|
||||
m_uv = uv;
|
||||
m_triangles = triangles;
|
||||
|
||||
mesh.vertices = vertices;
|
||||
mesh.uv = uv;
|
||||
mesh.triangles = triangles;
|
||||
@@ -57,52 +83,8 @@ public class CellMesh : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* MeshRenderer myRenderer = GetComponent<MeshRenderer>();
|
||||
Material m_material;
|
||||
if (myRenderer != null)
|
||||
{
|
||||
m_material = myRenderer.material;
|
||||
|
||||
if(gridValue == -1)
|
||||
{
|
||||
m_material.color = Color.black;
|
||||
}
|
||||
if (gridValue == 0)
|
||||
{
|
||||
m_material.color = Color.white;
|
||||
}
|
||||
if (gridValue == 1)
|
||||
{
|
||||
m_material.color = Color.green;
|
||||
}
|
||||
if (gridValue == 2)
|
||||
{
|
||||
m_material.color = Color.cyan;
|
||||
}*//*
|
||||
}
|
||||
*/
|
||||
private void Update()
|
||||
{
|
||||
/* if(Input.GetKeyDown("1"))
|
||||
{
|
||||
Debug.Log("1");
|
||||
m_Material.color = Color.white;
|
||||
//m_Material.SetColor("_Color", Color.white);
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown("2"))
|
||||
{
|
||||
Debug.Log("2");
|
||||
m_Material.color = Color.black;
|
||||
//m_Material.SetColor("_Color", Color.white);
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown("3"))
|
||||
{
|
||||
Debug.Log("3");
|
||||
m_Material.color = Color.green;
|
||||
//m_Material.SetColor("_Color", Color.white);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ public class Main : MonoBehaviour
|
||||
void Start()
|
||||
{
|
||||
// Create world
|
||||
world = new LogicGrid(5, 5, 10f, new Vector3(0, 0));
|
||||
world = new LogicGrid(100, 100, 5f, new Vector3(-110, -110));
|
||||
|
||||
// Set default placement to Obstacle
|
||||
placementValue = -1;
|
||||
placementValue = 1;
|
||||
placementMode = 'o';
|
||||
|
||||
cellMesh.SetGrid(world);
|
||||
@@ -32,38 +32,43 @@ public class Main : MonoBehaviour
|
||||
void Update()
|
||||
{
|
||||
// Change Placement Modes:
|
||||
// Place Agent in grid
|
||||
// TODO change modes via UI button
|
||||
if(Input.GetKeyDown("a"))
|
||||
|
||||
// Place Obstacle in grid
|
||||
if (Input.GetKeyDown("o"))
|
||||
{
|
||||
Debug.Log("Placing Mode: Agent");
|
||||
placementMode = 'a';
|
||||
placementValue = 3;
|
||||
Debug.Log("Placing Mode: Obstacle");
|
||||
placementMode = 'o';
|
||||
placementValue = 1;
|
||||
}
|
||||
// Place Sample in grid
|
||||
// Place Sample in cell
|
||||
if(Input.GetKeyDown("s"))
|
||||
{
|
||||
Debug.Log("Placing Mode: Sample");
|
||||
placementMode = 's';
|
||||
placementValue = 2;
|
||||
}
|
||||
// Place Obstacle in grid
|
||||
if(Input.GetKeyDown("o"))
|
||||
// Place agent in cell
|
||||
if (Input.GetKeyDown("a"))
|
||||
{
|
||||
Debug.Log("Placing Mode: Obstacle");
|
||||
placementMode = 'o';
|
||||
placementValue = 1;
|
||||
Debug.Log("Placing Mode: Agent");
|
||||
placementMode = 'a';
|
||||
placementValue = 3;
|
||||
}
|
||||
// Reset Canvas
|
||||
if (Input.GetKeyDown("r"))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Update Cell:
|
||||
// Change cell to obstacle
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
if (Input.GetMouseButton(0))
|
||||
{
|
||||
world.SetValue(CodeMonkey.Utils.UtilsClass.GetMouseWorldPosition(), placementValue);
|
||||
}
|
||||
// Clear cell
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
world.SetValue(CodeMonkey.Utils.UtilsClass.GetMouseWorldPosition(), 0);
|
||||
}
|
||||
@@ -73,4 +78,21 @@ public class Main : MonoBehaviour
|
||||
// and perform the selected algorithm
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void SetModeObstacle()
|
||||
{
|
||||
placementValue = 1;
|
||||
}
|
||||
public void SetModeSample()
|
||||
{
|
||||
placementValue = 2;
|
||||
}
|
||||
|
||||
public void SetModeAgent()
|
||||
{
|
||||
placementValue = 3;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user