예제 #1
0
    // анимация генерации алгоритма Growing tree
    //IEnumerator Anim3(List<DelCell> walls)
    //{
    //    //yield return new WaitForSeconds(2);
    //    var waitsec = new WaitForSeconds(SpeedAnimation);
    //    for (int i = 0; i < walls.Count; i++)
    //    {
    //        var w1 = walls[i].p;

    //        if (walls[i].type == 0)
    //        {
    //            tileMap[w1.i, w1.j].SetColor(Color.red);
    //            if (SpeedAnimation != 0)
    //                yield return waitsec;
    //        }
    //        else if (walls[i].type == 1)
    //        {
    //            tileMap[w1.i, w1.j].SetColor(Color.white);

    //            Point[] arr = new Point[] {
    //                new Point(w1.i, w1.j+1),
    //                new Point(w1.i, w1.j-1),
    //                new Point(w1.i+1, w1.j),
    //                new Point(w1.i-1, w1.j)};

    //            foreach (var a in arr)
    //            {
    //                if (a.i > 0 && a.j > 0 && a.i < height - 1 && a.j < width - 1)
    //                {
    //                    if (tileMap[a.i, a.j].type == 1)
    //                    {
    //                        tileMap[a.i, a.j].SetColor(Color.white);
    //                    }
    //                }
    //            }

    //            if (SpeedAnimation != 0)
    //                yield return waitsec;
    //        }
    //        else if (walls[i].type == 2)
    //        {
    //            tileMap[w1.i, w1.j].SetType(1);
    //            tileMap[w1.i, w1.j].SetColor(Color.red);

    //            if (SpeedAnimation != 0)
    //                yield return waitsec;
    //        }
    //    }
    //    coroutine = null;
    //    yield return waitsec;
    //}

    void AnimPathImmd(CollectPath cpath)
    {
        var listUsed = new List <NodeAS>();

        for (int i = 0; i < cpath.workList.Count; i++)
        {
            var tt = cpath.workList[i];
            tileMap[tt.i, tt.j].SetColor(Color.yellow);
            listUsed.Add(new NodeAS(tt.i, tt.j, true));

            NodeAS[] temp = new NodeAS[] {
                GetNodeAS(tt.i - 1, tt.j),
                GetNodeAS(tt.i + 1, tt.j),
                GetNodeAS(tt.i, tt.j - 1),
                GetNodeAS(tt.i, tt.j + 1)
            };

            foreach (var retVal in temp)
            {
                if (retVal != null && retVal.isWalkable && !listUsed.Contains(retVal))
                {
                    tileMap[retVal.i, retVal.j].SetColor(Color.cyan);
                }
            }
        }

        foreach (var tile in cpath.pathList)
        {
            tileMap[tile.i, tile.j].SetColor(Color.red);
        }
    }
예제 #2
0
    public void StartFindingPath(int i)
    {
        ResetGridForPathFinding();

        var spos = StartPath.transform.position;
        var epos = EndPath.transform.position;

        CollectPath cpath = new CollectPath(new Point(spos.z, spos.x), new Point(epos.z, epos.x), i);

        uiManager.SetPathFindingTime(cpath.time);
        uiManager.SetLengthPath(cpath.pathList.Count, cpath.workList.Count);
        //StopAnimation();
        //coroutine = StartCoroutine("AnimPath", cpath);
        AnimPathImmd(cpath);
    }