Exemplo n.º 1
0
    public void Generate()
    {
        int i, j, k;

        if (!initialised)
        {
            stepField   = new NativeArray <float>(map.width * map.height, Allocator.Persistent);
            flowField   = new NativeArray <Vector2>(map.width * map.height, Allocator.Persistent);
            openSet     = new NativeList <Vector2Int>(Allocator.Persistent);
            nextSet     = new NativeList <Vector2Int>(Allocator.Persistent);
            initialised = true;
        }

        openSet.Clear();
        nextSet.Clear();

        for (i = 0; i < targets.Count; i++)
        {
            openSet.Add(targets[i]);
        }
        for (i = 0; i < map.width; i++)
        {
            for (j = 0; j < map.height; j++)
            {
                stepField[i + j * map.width] = int.MaxValue;
                flowField[i + j * map.width] = Vector2.zero;
            }
        }

        for (i = 0; i < targets.Count; i++)
        {
            stepField[targets[i].x + targets[i].y * map.width] = 0;
        }

        UnityEngine.Profiling.Profiler.BeginSample("FlowGenerate");

        var myJob = new MyJob {
            map       = map.mapDataStore, pathType = pathType, stepField = stepField,
            flowField = flowField, nextSet = nextSet, openSet = openSet
        };

        myJob.Run();

        UnityEngine.Profiling.Profiler.EndSample();
    }