diff --git a/Pathfinding Visualizer/Assets/GridColorMaterials/MATERIAL.png b/Pathfinding Visualizer/Assets/GridColorMaterials/MATERIAL.png index b660f24..58de9ae 100644 Binary files a/Pathfinding Visualizer/Assets/GridColorMaterials/MATERIAL.png and b/Pathfinding Visualizer/Assets/GridColorMaterials/MATERIAL.png differ diff --git a/Pathfinding Visualizer/Assets/Scenes/MainScene.unity b/Pathfinding Visualizer/Assets/Scenes/MainScene.unity index fa0a3ec..6fb686c 100644 --- a/Pathfinding Visualizer/Assets/Scenes/MainScene.unity +++ b/Pathfinding Visualizer/Assets/Scenes/MainScene.unity @@ -138,7 +138,7 @@ GameObject: m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 + m_StaticEditorFlags: 2147483647 m_IsActive: 1 --- !u!114 &144141394 MonoBehaviour: @@ -356,6 +356,74 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1473159508} 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 SceneRoots: m_ObjectHideFlags: 0 @@ -363,3 +431,4 @@ SceneRoots: - {fileID: 144141395} - {fileID: 519420032} - {fileID: 1473159510} + - {fileID: 1836453010} diff --git a/Pathfinding Visualizer/Assets/Scripts/CellMesh.cs b/Pathfinding Visualizer/Assets/Scripts/CellMesh.cs index 5fc6bd8..2b30d2f 100644 --- a/Pathfinding Visualizer/Assets/Scripts/CellMesh.cs +++ b/Pathfinding Visualizer/Assets/Scripts/CellMesh.cs @@ -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(); - 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); - }*/ } } diff --git a/Pathfinding Visualizer/Assets/Scripts/Main.cs b/Pathfinding Visualizer/Assets/Scripts/Main.cs index cdc64db..fcac001 100644 --- a/Pathfinding Visualizer/Assets/Scripts/Main.cs +++ b/Pathfinding Visualizer/Assets/Scripts/Main.cs @@ -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; + } + + }