private void Update() { if (EditMode) { if (Input.GetMouseButton(0)) { if (!GetPoint(out var point)) { return; } _SetCost(point, CostCell.IMPASSABLE); } else if (Input.GetMouseButton(1)) { if (!GetPoint(out var point)) { return; } _SetCost(point, 1); } } else { if (Input.GetMouseButtonDown(0)) { //test navigation result if (!GetPoint(out var point)) { return; } _navigationIndex = FlowFieldHelper.GetFlatIndexFromWorldPos(point, in _gridMap.GridMapData); return; new MemsetNativeArray <FlowFieldCell> { Source = _flowFieldCells, Value = new FlowFieldCell { BestCost = float.MaxValue, Direction = FlowFieldCell.NO_DIRECTION, } } .Run(_flowFieldCells.Length); var tempQueue = new NativeQueue <int>(Allocator.TempJob); //navigation mode var buildFlowField = new BuildFlowField { Map = _gridMap, DestinationCellIndex = _navigationIndex, FlowFieldCells = _flowFieldCells, CostWeightArray = FlowFieldHelper.CostWeightArray, IndicesToCheck = tempQueue, }; new BuildFlowFieldJob { BuildFlowFieldTask = buildFlowField }.Run(); tempQueue.Dispose(); } } }
private void _Save() { var startTime = Time.realtimeSinceStartup; var tempQueue = new NativeQueue <int>(Allocator.TempJob); NativeArray <FlowFieldCell>[] allFlowFieldCells = new NativeArray <FlowFieldCell> [_gridMap.GridMapData.CellCount]; for (int i = 0; i < _gridMap.GridMapData.CellCount; i++) { var flowFieldCells = new NativeArray <FlowFieldCell>(_gridMap.GridMapData.CellCount, Allocator.TempJob); new MemsetNativeArray <FlowFieldCell> { Source = flowFieldCells, Value = new FlowFieldCell { BestCost = float.MaxValue, Direction = FlowFieldCell.NO_DIRECTION, } }.Run(_flowFieldCells.Length); var buildFlowField = new BuildFlowField { Map = _gridMap, DestinationCellIndex = i, FlowFieldCells = flowFieldCells, CostWeightArray = FlowFieldHelper.CostWeightArray, IndicesToCheck = tempQueue, }; new BuildFlowFieldJob { BuildFlowFieldTask = buildFlowField }.Run(); allFlowFieldCells[i] = flowFieldCells; } tempQueue.Dispose(); FlowFieldBlobAssetSerializer.Serialize(Path, in _gridMap, allFlowFieldCells); foreach (var flowFieldCell in allFlowFieldCells) { flowFieldCell.Dispose(); } Debug.Log($"build time:{Time.realtimeSinceStartup - startTime}"); }