大lao们,我想在unity实现一个快速排序算法的可视化,这是我脚本中快排算法的部分,并且利用了协程给动画时间,但是在前端执行的时候就不会动了,这个算法哪个地方出现了问题啊,下面是算法的代码
private IEnumerator F(int begin, int end)
{
if (begin > end)
yield break;
float tmp = Obj[begin].GetComponent<Transform>().lossyScale.y;
int i = begin;
int j = end;
while (i != j)
{
while (Obj[j].GetComponent<Transform>().lossyScale.y >= tmp && j > i)
j--;
while (Obj[i].GetComponent<Transform>().lossyScale.y <= tmp && j > i)
i++;
Debug.Log(Obj[0]);
if (i < j)
{
GameObject x, y;
Sequence s = DOTween.Sequence();
Material mal = Obj[j].GetComponent<MeshRenderer>().material;
Material mal1 = Obj[j + 1].GetComponent<MeshRenderer>().material;
Debug.Log(Obj[j]);
Debug.Log(Obj[j + 1]);
Vector3 a = Obj[j + 1].GetComponent<Transform>().position;
Vector3 b = Obj[j].GetComponent<Transform>().position;
Vector3 c = Obj1[j + 1].GetComponent<Transform>().position;
Vector3 d = Obj1[j].GetComponent<Transform>().position;
var tweener = Obj[j].GetComponent<Transform>().DOMoveX(a.x, 2).SetId("1");
var tweener1 = Obj[j + 1].GetComponent<Transform>().DOMoveX(b.x, 2).SetId("1");
var tweener2 = Obj1[j].GetComponent<Transform>().DOMoveX(c.x, 2).SetId("1");
var tweener3 = Obj1[j + 1].GetComponent<Transform>().DOMoveX(d.x, 2).SetId("1");
mal.DOBlendableColor(Color.yellow, 2).OnComplete(() => { mal.DOColor(Color.white, 0).OnComplete(() => { mal.DOKill(); }); }).SetId("1");
mal1.DOBlendableColor(Color.yellow, 2).OnComplete(() => { mal1.DOColor(Color.white, 0).OnComplete(() => { mal1.DOKill(); }); }).SetId("1");
x = Obj[j];
Obj[j] = Obj[j + 1];
Obj[j + 1] = x;
y = Obj1[j];
Obj1[j] = Obj1[j + 1];
Obj1[j + 1] = y;
Debug.Log(Obj[j]);
Debug.Log(Obj[j + 1]);
yield return new WaitForSeconds(3);
}
}
Obj[begin] = Obj[i];
//arr[i] = tmp;
Obj[i].GetComponent<Transform>().localScale = new Vector3(1, tmp, 1);
IEnumerator coroutine1 = F(begin, i - 1);
IEnumerator coroutine2 = F(i + 1, end);
StartCoroutine(coroutine1);
StartCoroutine(coroutine2);
}
public void Pause()
{
//play = 0;
Time.timeScale = 0;
StopAllCoroutines();
}
public void Play()
{
//play = 1;
Time.timeScale = 1;
IEnumerator coroutine = F(0, count-1);
StartCoroutine(coroutine);
}