animation is linked to speed slider

This commit is contained in:
Simon O'Shea
2023-08-09 14:23:24 -04:00
parent b56131d7fa
commit 8181a3426a
2 changed files with 17 additions and 6 deletions
@@ -1,6 +1,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using System;
public class CellMesh : MonoBehaviour public class CellMesh : MonoBehaviour
{ {
@@ -11,6 +12,8 @@ public class CellMesh : MonoBehaviour
Vector2[] m_uv; Vector2[] m_uv;
int[] m_triangles; int[] m_triangles;
Stack<Node> animateData;
private void Awake() private void Awake()
{ {
mesh = new Mesh(); mesh = new Mesh();
@@ -78,24 +81,32 @@ public class CellMesh : MonoBehaviour
mesh.triangles = triangles; mesh.triangles = triangles;
} }
public void Animate(Stack<Node> result) public void Animate(Stack<Node> result)
{ {
int count = result.Count; animateData = result;
StartCoroutine("AnimateGrid");
}
IEnumerator AnimateGrid()
{
int count = animateData.Count;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
Node n = result.Pop(); Node n = animateData.Pop();
//Debug.Log("Agent at: " + n.agent.x + ", " + n.agent.y); //Debug.Log("Agent at: " + n.agent.x + ", " + n.agent.y);
Debug.Log(n.lastMove); Debug.Log(n.lastMove);
grid.SetValue(n.agent.x, n.agent.y, 3); grid.SetValue(n.agent.x, n.agent.y, 3);
//grid.SetValue(n.parent.agent.x, n.parent.agent.y, 0); grid.SetValue(n.parent.agent.x, n.parent.agent.y, 0);
yield return new WaitForSeconds(nMain.speed);
UpdateCellVisual(); UpdateCellVisual();
} }
} }
void Start() void Start()
{ {
@@ -10,7 +10,7 @@ public class nMain : MonoBehaviour
private LogicGrid world; private LogicGrid world;
int placementValue; int placementValue;
public float speed = 3.0f; public static float speed = 3.0f;
int heuristic; int heuristic;
int algorithm; int algorithm;