public override void Register(GridGraphRules rules) { int[] layerToTag = new int[32]; bool[] layerToUnwalkable = new bool[32]; for (int i = 0; i < layerRules.Length; i++) { var rule = layerRules[i]; if (rule.action == RuleAction.SetTag) { layerToTag[rule.layer] = SetTagBit | rule.tag; } else { layerToUnwalkable[rule.layer] = true; } } rules.Add(Pass.BeforeConnections, context => { new JobSurfaceAction { layerToTag = layerToTag, layerToUnwalkable = layerToUnwalkable, raycastHits = context.data.heightHits, nodeWalkable = context.data.nodeWalkable, nodeTags = context.data.nodeTags, }.ScheduleManagedInMainThread(context.tracker); }); }
public override void Register(GridGraphRules rules) { if (!angleToPenalty.IsCreated) { angleToPenalty = new NativeArray <float>(32, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); } for (int i = 0; i < angleToPenalty.Length; i++) { angleToPenalty[i] = Mathf.Max(0, curve.Evaluate(90.0f * i / (angleToPenalty.Length - 1)) * penaltyScale); } rules.Add(Pass.BeforeConnections, context => { new JobPenaltyAngle { angleToPenalty = angleToPenalty, up = context.data.up, nodeNormals = context.data.nodeNormals, penalty = context.data.nodePenalties, }.Schedule(context.tracker); }); }
public override void Register(GridGraphRules rules) { int[] layerToTag = new int[32]; bool[] layerToUnwalkable = new bool[32]; for (int i = 0; i < layerRules.Length; i++) { var rule = layerRules[i]; if (rule.action == RuleAction.SetTag) { layerToTag[rule.layer] = SetTagBit | rule.tag; } else { layerToUnwalkable[rule.layer] = true; } } rules.AddMainThreadPass(Pass.BeforeConnections, context => { var raycastHits = context.data.heightHits; var nodeWalkable = context.data.nodeWalkable; var nodeTags = context.data.nodeTags; for (int i = 0; i < raycastHits.Length; i++) { var coll = raycastHits[i].collider; if (coll != null) { var layer = coll.gameObject.layer; if (layerToUnwalkable[layer]) { nodeWalkable[i] = false; } var tag = layerToTag[layer]; if ((tag & SetTagBit) != 0) { nodeTags[i] = tag & 0xFF; } } } }); }
public override void Register(GridGraphRules rules) { if (!elevationToPenalty.IsCreated) { elevationToPenalty = new NativeArray <float>(64, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); } for (int i = 0; i < elevationToPenalty.Length; i++) { elevationToPenalty[i] = Mathf.Max(0, penaltyScale * curve.Evaluate(i * 1.0f / (elevationToPenalty.Length - 1))); } var clampedElevationRange = new Vector2(math.max(0, elevationRange.x), math.max(1, elevationRange.y)); rules.AddJobSystemPass(Pass.BeforeConnections, context => { //var elevationRangeScale = Matrix4x4.TRS(new Vector3(0, -clampedElevationRange.x, 0), Quaternion.identity, new Vector3(1, 1/(clampedElevationRange.y - clampedElevationRange.x), 1)); var elevationRangeScale = Matrix4x4.Scale(new Vector3(1, 1 / (clampedElevationRange.y - clampedElevationRange.x), 1)) * Matrix4x4.Translate(new Vector3(0, -clampedElevationRange.x, 0)); new JobElevationPenalty { elevationToPenalty = elevationToPenalty, nodePositions = context.data.nodePositions, worldToGraph = elevationRangeScale * context.data.transform.matrix.inverse, penalty = context.data.nodePenalties, }.Schedule(context.tracker); }); }
public override void Register(GridGraphRules rules) { if (texture == null) { return; } if (!texture.isReadable) { Debug.LogError("Texture for the texture rule on a grid graph is not marked as readable.", texture); return; } if (colors.IsCreated) { colors.Dispose(); } colors = new NativeArray <Color32>(texture.GetPixels32(), Allocator.Persistent).Reinterpret <int>(); // Make sure this is done outside the delegate, just in case the texture is later resized var textureSize = new int2(texture.width, texture.height); float4 channelPenaltiesCombined = float4.zero; bool4 channelDeterminesWalkability = false; float4 channelPositionScalesCombined = float4.zero; for (int i = 0; i < 4; i++) { channelPenaltiesCombined[i] = channels[i] == ChannelUse.Penalty || channels[i] == ChannelUse.WalkablePenalty ? channelScales[i] : 0; channelDeterminesWalkability[i] = channels[i] == ChannelUse.Walkable || channels[i] == ChannelUse.WalkablePenalty; channelPositionScalesCombined[i] = channels[i] == ChannelUse.Position ? channelScales[i] : 0; } channelPositionScalesCombined /= 255.0f; channelPenaltiesCombined /= 255.0f; if (math.any(channelPositionScalesCombined)) { rules.Add(Pass.BeforeCollision, context => { new JobTexturePosition { colorData = colors, nodePositions = context.data.nodePositions, bounds = context.data.bounds, colorDataSize = textureSize, scale = scalingMode == ScalingMode.FixedScale ? 1.0f / math.max(0.01f, nodesPerPixel) : textureSize / new float2(context.graph.width, context.graph.depth), channelPositionScale = channelPositionScalesCombined, graphToWorld = context.data.transform.matrix, }.Schedule(context.tracker); }); } rules.Add(Pass.BeforeConnections, context => { new JobTexturePenalty { colorData = colors, penalty = context.data.nodePenalties, walkable = context.data.nodeWalkable, bounds = context.data.bounds, colorDataSize = textureSize, scale = scalingMode == ScalingMode.FixedScale ? 1.0f / math.max(0.01f, nodesPerPixel) : textureSize / new float2(context.graph.width, context.graph.depth), channelPenalties = channelPenaltiesCombined, channelDeterminesWalkability = channelDeterminesWalkability, }.Schedule(context.tracker); }); }
/// <summary>Does preprocessing and adds callbacks to the <see cref="GridGraphRules"/> object</summary> public virtual void Register(GridGraphRules rules) { }