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 GenerateJob { map = map.mapDataStore, pathType = pathType, stepField = stepField, flowField = flowField, nextSet = nextSet, openSet = openSet }; myJob.Run(); UnityEngine.Profiling.Profiler.EndSample(); }
protected override void OnUpdate() { double elapsedTime = Time.ElapsedTime; EndSimulationEntityCommandBufferSystem endSimECBSystem = World.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>(); GenerateJob job = new GenerateJob { TweenInfoTypeIndex = TypeManager.GetTypeIndex(typeof(TTweenInfo)), ElapsedTime = elapsedTime, EntityType = GetEntityTypeHandle(), TweenCommandType = GetComponentTypeHandle <TTweenCommand>(true), TargetType = GetComponentTypeHandle <TTarget>(true), TweenBufferType = GetBufferTypeHandle <TweenState>(true), ParallelWriter = endSimECBSystem.CreateCommandBuffer().AsParallelWriter(), }; Dependency = job.ScheduleParallel(TweenCommandQuery, Dependency); endSimECBSystem.AddJobHandleForProducer(Dependency); }