ready for logan?

getting ready to piece UI elements together with the logic of the grid
This commit is contained in:
Simon O'Shea
2023-08-08 12:31:23 -04:00
parent 7c3fd8d563
commit fe38db5f37
4 changed files with 137 additions and 64 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

@@ -138,7 +138,7 @@ GameObject:
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 2147483647
m_IsActive: 1 m_IsActive: 1
--- !u!114 &144141394 --- !u!114 &144141394
MonoBehaviour: MonoBehaviour:
@@ -356,6 +356,74 @@ MeshFilter:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1473159508} m_GameObject: {fileID: 1473159508}
m_Mesh: {fileID: 0} m_Mesh: {fileID: 0}
--- !u!1 &1836453007
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1836453010}
- component: {fileID: 1836453009}
- component: {fileID: 1836453008}
m_Layer: 0
m_Name: EventSystem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1836453008
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1836453007}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Name:
m_EditorClassIdentifier:
m_SendPointerHoverToParent: 1
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
--- !u!114 &1836453009
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1836453007}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}
m_sendNavigationEvents: 1
m_DragThreshold: 10
--- !u!4 &1836453010
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1836453007}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1660057539 &9223372036854775807 --- !u!1660057539 &9223372036854775807
SceneRoots: SceneRoots:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -363,3 +431,4 @@ SceneRoots:
- {fileID: 144141395} - {fileID: 144141395}
- {fileID: 519420032} - {fileID: 519420032}
- {fileID: 1473159510} - {fileID: 1473159510}
- {fileID: 1836453010}
@@ -7,6 +7,10 @@ public class CellMesh : MonoBehaviour
private LogicGrid grid; private LogicGrid grid;
private Mesh mesh; private Mesh mesh;
Vector3[] m_vertices;
Vector2[] m_uv;
int[] m_triangles;
private void Awake() private void Awake()
{ {
mesh = new Mesh(); mesh = new Mesh();
@@ -24,12 +28,30 @@ public class CellMesh : MonoBehaviour
private void GridValueChanged(object sender, LogicGrid.OnGridValueChangedEventArgs e) private void GridValueChanged(object sender, LogicGrid.OnGridValueChangedEventArgs e)
{ {
Debug.Log("FIRE!!"); Debug.Log(e.x + " " + e.y);
UpdateCellVisual(); 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() private void UpdateCellVisual()
{ {
Debug.Log("Updated as a group");
MeshUtils.CreateEmptyMeshArrays(grid.GetWidth() * grid.GetHeight(), out Vector3[] vertices, out Vector2[] uv, out int[] triangles); MeshUtils.CreateEmptyMeshArrays(grid.GetWidth() * grid.GetHeight(), out Vector3[] vertices, out Vector2[] uv, out int[] triangles);
for(int x = 0; x < grid.GetWidth(); x++) for(int x = 0; x < grid.GetWidth(); x++)
@@ -40,13 +62,17 @@ public class CellMesh : MonoBehaviour
Vector3 quadSize = new Vector3(1, 1) * grid.GetCellSize(); Vector3 quadSize = new Vector3(1, 1) * grid.GetCellSize();
int gridValue = grid.GetValue(x, y); int gridValue = grid.GetValue(x, y);
float gridValueNormalized = gridValue / 4f; float gridValueNormalized = gridValue / 3f;
Vector2 gridValueUV = new Vector2(gridValueNormalized, 0f); Vector2 gridValueUV = new Vector2(gridValueNormalized, 0f);
MeshUtils.AddToMeshArrays(vertices, uv, triangles, index, grid.GetWorldPosition(x, y) + (quadSize * .5f), 0f, quadSize, gridValueUV, gridValueUV); 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.vertices = vertices;
mesh.uv = uv; mesh.uv = uv;
mesh.triangles = triangles; 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() 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);
}*/
} }
} }
+41 -19
View File
@@ -16,10 +16,10 @@ public class Main : MonoBehaviour
void Start() void Start()
{ {
// Create world // 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 // Set default placement to Obstacle
placementValue = -1; placementValue = 1;
placementMode = 'o'; placementMode = 'o';
cellMesh.SetGrid(world); cellMesh.SetGrid(world);
@@ -32,21 +32,7 @@ public class Main : MonoBehaviour
void Update() void Update()
{ {
// Change Placement Modes: // Change Placement Modes:
// Place Agent in grid
// TODO change modes via UI button
if(Input.GetKeyDown("a"))
{
Debug.Log("Placing Mode: Agent");
placementMode = 'a';
placementValue = 3;
}
// Place Sample in grid
if(Input.GetKeyDown("s"))
{
Debug.Log("Placing Mode: Sample");
placementMode = 's';
placementValue = 2;
}
// Place Obstacle in grid // Place Obstacle in grid
if (Input.GetKeyDown("o")) if (Input.GetKeyDown("o"))
{ {
@@ -54,16 +40,35 @@ public class Main : MonoBehaviour
placementMode = 'o'; placementMode = 'o';
placementValue = 1; placementValue = 1;
} }
// Place Sample in cell
if(Input.GetKeyDown("s"))
{
Debug.Log("Placing Mode: Sample");
placementMode = 's';
placementValue = 2;
}
// Place agent in cell
if (Input.GetKeyDown("a"))
{
Debug.Log("Placing Mode: Agent");
placementMode = 'a';
placementValue = 3;
}
// Reset Canvas
if (Input.GetKeyDown("r"))
{
}
// Update Cell: // Update Cell:
// Change cell to obstacle // Change cell to obstacle
if (Input.GetMouseButtonDown(0)) if (Input.GetMouseButton(0))
{ {
world.SetValue(CodeMonkey.Utils.UtilsClass.GetMouseWorldPosition(), placementValue); world.SetValue(CodeMonkey.Utils.UtilsClass.GetMouseWorldPosition(), placementValue);
} }
// Clear cell // Clear cell
if (Input.GetMouseButtonDown(1)) if (Input.GetMouseButton(1))
{ {
world.SetValue(CodeMonkey.Utils.UtilsClass.GetMouseWorldPosition(), 0); world.SetValue(CodeMonkey.Utils.UtilsClass.GetMouseWorldPosition(), 0);
} }
@@ -73,4 +78,21 @@ public class Main : MonoBehaviour
// and perform the selected algorithm // and perform the selected algorithm
} }
public void SetModeObstacle()
{
placementValue = 1;
}
public void SetModeSample()
{
placementValue = 2;
}
public void SetModeAgent()
{
placementValue = 3;
}
} }