public new void UpdateArea(GraphUpdateObject o) { if (this.nodes == null || this.nodes.Length != this.width * this.depth * this.layerCount) { Debug.LogWarning("The Grid Graph is not scanned, cannot update area "); return; } Bounds bounds = o.bounds; Vector3 a; Vector3 a2; base.GetBoundsMinMax(bounds, this.inverseMatrix, out a, out a2); int xmin = Mathf.RoundToInt(a.x - 0.5f); int xmax = Mathf.RoundToInt(a2.x - 0.5f); int ymin = Mathf.RoundToInt(a.z - 0.5f); int ymax = Mathf.RoundToInt(a2.z - 0.5f); IntRect intRect = new IntRect(xmin, ymin, xmax, ymax); IntRect intRect2 = intRect; IntRect b = new IntRect(0, 0, this.width - 1, this.depth - 1); IntRect intRect3 = intRect; bool flag = o.updatePhysics || o.modifyWalkability; bool flag2 = o is LayerGridGraphUpdate && ((LayerGridGraphUpdate)o).recalculateNodes; bool preserveExistingNodes = !(o is LayerGridGraphUpdate) || ((LayerGridGraphUpdate)o).preserveExistingNodes; int num = (!o.updateErosion) ? 0 : this.erodeIterations; if (o.trackChangedNodes && flag2) { Debug.LogError("Cannot track changed nodes when creating or deleting nodes.\nWill not update LayerGridGraph"); return; } if (o.updatePhysics && !o.modifyWalkability && this.collision.collisionCheck) { Vector3 a3 = new Vector3(this.collision.diameter, 0f, this.collision.diameter) * 0.5f; a -= a3 * 1.02f; a2 += a3 * 1.02f; intRect3 = new IntRect(Mathf.RoundToInt(a.x - 0.5f), Mathf.RoundToInt(a.z - 0.5f), Mathf.RoundToInt(a2.x - 0.5f), Mathf.RoundToInt(a2.z - 0.5f)); intRect2 = IntRect.Union(intRect3, intRect2); } if (flag || num > 0) { intRect2 = intRect2.Expand(num + 1); } IntRect intRect4 = IntRect.Intersection(intRect2, b); if (!flag2) { for (int i = intRect4.xmin; i <= intRect4.xmax; i++) { for (int j = intRect4.ymin; j <= intRect4.ymax; j++) { for (int k = 0; k < this.layerCount; k++) { o.WillUpdateNode(this.nodes[k * this.width * this.depth + j * this.width + i]); } } } } if (o.updatePhysics && !o.modifyWalkability) { this.collision.Initialize(this.matrix, this.nodeSize); intRect4 = IntRect.Intersection(intRect3, b); bool flag3 = false; for (int l = intRect4.xmin; l <= intRect4.xmax; l++) { for (int m = intRect4.ymin; m <= intRect4.ymax; m++) { flag3 |= this.RecalculateCell(l, m, preserveExistingNodes); } } for (int n = intRect4.xmin; n <= intRect4.xmax; n++) { for (int num2 = intRect4.ymin; num2 <= intRect4.ymax; num2++) { for (int num3 = 0; num3 < this.layerCount; num3++) { int num4 = num3 * this.width * this.depth + num2 * this.width + n; LevelGridNode levelGridNode = this.nodes[num4]; if (levelGridNode != null) { this.CalculateConnections(this.nodes, levelGridNode, n, num2, num3); } } } } } intRect4 = IntRect.Intersection(intRect, b); for (int num5 = intRect4.xmin; num5 <= intRect4.xmax; num5++) { for (int num6 = intRect4.ymin; num6 <= intRect4.ymax; num6++) { for (int num7 = 0; num7 < this.layerCount; num7++) { int num8 = num7 * this.width * this.depth + num6 * this.width + num5; LevelGridNode levelGridNode2 = this.nodes[num8]; if (levelGridNode2 != null) { if (flag) { levelGridNode2.Walkable = levelGridNode2.WalkableErosion; if (o.bounds.Contains((Vector3)levelGridNode2.position)) { o.Apply(levelGridNode2); } levelGridNode2.WalkableErosion = levelGridNode2.Walkable; } else if (o.bounds.Contains((Vector3)levelGridNode2.position)) { o.Apply(levelGridNode2); } } } } } if (flag && num == 0) { intRect4 = IntRect.Intersection(intRect2, b); for (int num9 = intRect4.xmin; num9 <= intRect4.xmax; num9++) { for (int num10 = intRect4.ymin; num10 <= intRect4.ymax; num10++) { for (int num11 = 0; num11 < this.layerCount; num11++) { int num12 = num11 * this.width * this.depth + num10 * this.width + num9; LevelGridNode levelGridNode3 = this.nodes[num12]; if (levelGridNode3 != null) { this.CalculateConnections(this.nodes, levelGridNode3, num9, num10, num11); } } } } } else if (flag && num > 0) { IntRect a4 = IntRect.Union(intRect, intRect3).Expand(num); IntRect a5 = a4.Expand(num); a4 = IntRect.Intersection(a4, b); a5 = IntRect.Intersection(a5, b); for (int num13 = a5.xmin; num13 <= a5.xmax; num13++) { for (int num14 = a5.ymin; num14 <= a5.ymax; num14++) { for (int num15 = 0; num15 < this.layerCount; num15++) { int num16 = num15 * this.width * this.depth + num14 * this.width + num13; LevelGridNode levelGridNode4 = this.nodes[num16]; if (levelGridNode4 != null) { bool walkable = levelGridNode4.Walkable; levelGridNode4.Walkable = levelGridNode4.WalkableErosion; if (!a4.Contains(num13, num14)) { levelGridNode4.TmpWalkable = walkable; } } } } } for (int num17 = a5.xmin; num17 <= a5.xmax; num17++) { for (int num18 = a5.ymin; num18 <= a5.ymax; num18++) { for (int num19 = 0; num19 < this.layerCount; num19++) { int num20 = num19 * this.width * this.depth + num18 * this.width + num17; LevelGridNode levelGridNode5 = this.nodes[num20]; if (levelGridNode5 != null) { this.CalculateConnections(this.nodes, levelGridNode5, num17, num18, num19); } } } } this.ErodeWalkableArea(a5.xmin, a5.ymin, a5.xmax + 1, a5.ymax + 1); for (int num21 = a5.xmin; num21 <= a5.xmax; num21++) { for (int num22 = a5.ymin; num22 <= a5.ymax; num22++) { if (!a4.Contains(num21, num22)) { for (int num23 = 0; num23 < this.layerCount; num23++) { int num24 = num23 * this.width * this.depth + num22 * this.width + num21; LevelGridNode levelGridNode6 = this.nodes[num24]; if (levelGridNode6 != null) { levelGridNode6.Walkable = levelGridNode6.TmpWalkable; } } } } } for (int num25 = a5.xmin; num25 <= a5.xmax; num25++) { for (int num26 = a5.ymin; num26 <= a5.ymax; num26++) { for (int num27 = 0; num27 < this.layerCount; num27++) { int num28 = num27 * this.width * this.depth + num26 * this.width + num25; LevelGridNode levelGridNode7 = this.nodes[num28]; if (levelGridNode7 != null) { this.CalculateConnections(this.nodes, levelGridNode7, num25, num26, num27); } } } } } }
public new void UpdateArea(GraphUpdateObject o) { if (this.nodes == null || this.nodes.Length != this.width * this.depth * this.layerCount) { Debug.LogWarning("The Grid Graph is not scanned, cannot update area "); return; } IntRect a; IntRect a2; IntRect intRect; bool flag; int num; base.CalculateAffectedRegions(o, out a, out a2, out intRect, out flag, out num); bool flag2 = o is LayerGridGraphUpdate && ((LayerGridGraphUpdate)o).recalculateNodes; bool flag3 = (!(o is LayerGridGraphUpdate)) ? (!o.resetPenaltyOnPhysics) : ((LayerGridGraphUpdate)o).preserveExistingNodes; if (o.trackChangedNodes && flag2) { Debug.LogError("Cannot track changed nodes when creating or deleting nodes.\nWill not update LayerGridGraph"); return; } IntRect b = new IntRect(0, 0, this.width - 1, this.depth - 1); IntRect intRect2 = IntRect.Intersection(a2, b); if (!flag2) { for (int i = intRect2.xmin; i <= intRect2.xmax; i++) { for (int j = intRect2.ymin; j <= intRect2.ymax; j++) { for (int k = 0; k < this.layerCount; k++) { o.WillUpdateNode(this.nodes[k * this.width * this.depth + j * this.width + i]); } } } } if (o.updatePhysics && !o.modifyWalkability) { this.collision.Initialize(base.transform, this.nodeSize); intRect2 = IntRect.Intersection(intRect, b); for (int l = intRect2.xmin; l <= intRect2.xmax; l++) { for (int m = intRect2.ymin; m <= intRect2.ymax; m++) { this.RecalculateCell(l, m, !flag3, false); } } for (int n = intRect2.xmin; n <= intRect2.xmax; n++) { for (int num2 = intRect2.ymin; num2 <= intRect2.ymax; num2++) { this.CalculateConnections(n, num2); } } } intRect2 = IntRect.Intersection(a, b); for (int num3 = intRect2.xmin; num3 <= intRect2.xmax; num3++) { for (int num4 = intRect2.ymin; num4 <= intRect2.ymax; num4++) { for (int num5 = 0; num5 < this.layerCount; num5++) { int num6 = num5 * this.width * this.depth + num4 * this.width + num3; LevelGridNode levelGridNode = this.nodes[num6]; if (levelGridNode != null) { if (flag) { levelGridNode.Walkable = levelGridNode.WalkableErosion; if (o.bounds.Contains((Vector3)levelGridNode.position)) { o.Apply(levelGridNode); } levelGridNode.WalkableErosion = levelGridNode.Walkable; } else if (o.bounds.Contains((Vector3)levelGridNode.position)) { o.Apply(levelGridNode); } } } } } if (flag && num == 0) { intRect2 = IntRect.Intersection(a2, b); for (int num7 = intRect2.xmin; num7 <= intRect2.xmax; num7++) { for (int num8 = intRect2.ymin; num8 <= intRect2.ymax; num8++) { this.CalculateConnections(num7, num8); } } } else if (flag && num > 0) { IntRect a3 = IntRect.Union(a, intRect).Expand(num); IntRect a4 = a3.Expand(num); a3 = IntRect.Intersection(a3, b); a4 = IntRect.Intersection(a4, b); for (int num9 = a4.xmin; num9 <= a4.xmax; num9++) { for (int num10 = a4.ymin; num10 <= a4.ymax; num10++) { for (int num11 = 0; num11 < this.layerCount; num11++) { int num12 = num11 * this.width * this.depth + num10 * this.width + num9; LevelGridNode levelGridNode2 = this.nodes[num12]; if (levelGridNode2 != null) { bool walkable = levelGridNode2.Walkable; levelGridNode2.Walkable = levelGridNode2.WalkableErosion; if (!a3.Contains(num9, num10)) { levelGridNode2.TmpWalkable = walkable; } } } } } for (int num13 = a4.xmin; num13 <= a4.xmax; num13++) { for (int num14 = a4.ymin; num14 <= a4.ymax; num14++) { this.CalculateConnections(num13, num14); } } base.ErodeWalkableArea(a4.xmin, a4.ymin, a4.xmax + 1, a4.ymax + 1); for (int num15 = a4.xmin; num15 <= a4.xmax; num15++) { for (int num16 = a4.ymin; num16 <= a4.ymax; num16++) { if (!a3.Contains(num15, num16)) { for (int num17 = 0; num17 < this.layerCount; num17++) { int num18 = num17 * this.width * this.depth + num16 * this.width + num15; LevelGridNode levelGridNode3 = this.nodes[num18]; if (levelGridNode3 != null) { levelGridNode3.Walkable = levelGridNode3.TmpWalkable; } } } } } for (int num19 = a4.xmin; num19 <= a4.xmax; num19++) { for (int num20 = a4.ymin; num20 <= a4.ymax; num20++) { this.CalculateConnections(num19, num20); } } } }
/** Returns a new rect which contains both \a r and \a r2 */ static IntRect ExpandToContain(IntRect r, IntRect r2) { return(IntRect.Union(r, r2)); }