public static SetGridGraph ( int graphIndex, |
||
graphIndex | int | |
graph | ||
Результат | void |
public override void PostDeserialization() { base.UpdateTransform(); this.lastScannedWidth = this.width; this.lastScannedDepth = this.depth; this.SetUpOffsetsAndCosts(); LevelGridNode.SetGridGraph((int)this.graphIndex, this); if (this.nodes == null || this.nodes.Length == 0) { return; } if (this.width * this.depth * this.layerCount != this.nodes.Length) { Debug.LogError("Node data did not match with bounds data. Probably a change to the bounds/width/depth data was made after scanning the graph just prior to saving it. Nodes will be discarded"); this.nodes = new LevelGridNode[0]; return; } for (int i = 0; i < this.layerCount; i++) { for (int j = 0; j < this.depth; j++) { for (int k = 0; k < this.width; k++) { LevelGridNode levelGridNode = this.nodes[j * this.width + k + this.width * this.depth * i]; if (levelGridNode != null) { levelGridNode.NodeInGridIndex = j * this.width + k; levelGridNode.LayerCoordinateInGrid = i; } } } } }
public override void PostDeserialization() { base.GenerateMatrix(); this.lastScannedWidth = this.width; this.lastScannedDepth = this.depth; this.SetUpOffsetsAndCosts(); if (this.nodes == null || this.nodes.Length == 0) { return; } LevelGridNode.SetGridGraph(AstarPath.active.astarData.GetGraphIndex(this), this); for (int i = 0; i < this.depth; i++) { for (int j = 0; j < this.width; j++) { for (int k = 0; k < this.layerCount; k++) { LevelGridNode levelGridNode = this.nodes[i * this.width + j + this.width * this.depth * k]; if (levelGridNode != null) { levelGridNode.NodeInGridIndex = i * this.width + j; } } } } }
public override IEnumerable <Progress> ScanInternal() { if (this.nodeSize <= 0f) { yield break; } base.UpdateTransform(); if (this.width > 1024 || this.depth > 1024) { Debug.LogError("One of the grid's sides is longer than 1024 nodes"); yield break; } this.lastScannedWidth = this.width; this.lastScannedDepth = this.depth; this.SetUpOffsetsAndCosts(); LevelGridNode.SetGridGraph((int)this.graphIndex, this); this.maxClimb = Mathf.Clamp(this.maxClimb, 0f, this.characterHeight); LinkedLevelNode[] linkedCells = new LinkedLevelNode[this.width * this.depth]; this.collision = (this.collision ?? new GraphCollision()); this.collision.Initialize(base.transform, this.nodeSize); int progressCounter = 0; for (int z = 0; z < this.depth; z++) { if (progressCounter >= 1000) { progressCounter = 0; yield return(new Progress(Mathf.Lerp(0.1f, 0.5f, (float)z / (float)this.depth), "Calculating positions")); } progressCounter += this.width; for (int i = 0; i < this.width; i++) { linkedCells[z * this.width + i] = this.SampleCell(i, z); } } this.layerCount = 0; for (int j = 0; j < linkedCells.Length; j++) { int num = 0; for (LinkedLevelNode linkedLevelNode = linkedCells[j]; linkedLevelNode != null; linkedLevelNode = linkedLevelNode.next) { num++; } this.layerCount = Math.Max(this.layerCount, num); } if (this.layerCount > 255) { Debug.LogError(string.Concat(new object[] { "Too many layers, a maximum of ", 255, " (LevelGridNode.MaxLayerCount) layers are allowed (found ", this.layerCount, ")" })); yield break; } this.nodes = new LevelGridNode[this.width * this.depth * this.layerCount]; for (int z2 = 0; z2 < this.depth; z2++) { if (progressCounter >= 1000) { progressCounter = 0; yield return(new Progress(Mathf.Lerp(0.5f, 0.8f, (float)z2 / (float)this.depth), "Creating nodes")); } progressCounter += this.width; for (int k = 0; k < this.width; k++) { this.RecalculateCell(k, z2, true, true); } } for (int z3 = 0; z3 < this.depth; z3++) { if (progressCounter >= 1000) { progressCounter = 0; yield return(new Progress(Mathf.Lerp(0.8f, 0.9f, (float)z3 / (float)this.depth), "Calculating connections")); } progressCounter += this.width; for (int l = 0; l < this.width; l++) { this.CalculateConnections(l, z3); } } yield return(new Progress(0.95f, "Calculating Erosion")); for (int m = 0; m < this.nodes.Length; m++) { LevelGridNode levelGridNode = this.nodes[m]; if (levelGridNode != null) { if (!levelGridNode.HasAnyGridConnections()) { levelGridNode.Walkable = false; levelGridNode.WalkableErosion = levelGridNode.Walkable; } } } this.ErodeWalkableArea(); yield break; }
private void RemoveGridGraphFromStatic() { LevelGridNode.SetGridGraph(this.active.data.GetGraphIndex(this), null); }
public new void RemoveGridGraphFromStatic() { LevelGridNode.SetGridGraph(this.active.astarData.GetGraphIndex(this), null); }
public override void ScanInternal(OnScanStatus status) { this.scans++; if (this.nodeSize <= 0f) { return; } base.GenerateMatrix(); if (this.width > 1024 || this.depth > 1024) { Debug.LogError("One of the grid's sides is longer than 1024 nodes"); return; } this.lastScannedWidth = this.width; this.lastScannedDepth = this.depth; this.SetUpOffsetsAndCosts(); LevelGridNode.SetGridGraph(this.active.astarData.GetGraphIndex(this), this); this.maxClimb = Mathf.Clamp(this.maxClimb, 0f, this.characterHeight); LinkedLevelCell[] array = new LinkedLevelCell[this.width * this.depth]; if (this.collision == null) { this.collision = new GraphCollision(); } this.collision.Initialize(this.matrix, this.nodeSize); for (int i = 0; i < this.depth; i++) { for (int j = 0; j < this.width; j++) { array[i * this.width + j] = new LinkedLevelCell(); LinkedLevelCell linkedLevelCell = array[i * this.width + j]; Vector3 position = this.matrix.MultiplyPoint3x4(new Vector3((float)j + 0.5f, 0f, (float)i + 0.5f)); RaycastHit[] array2 = this.collision.CheckHeightAll(position); for (int k = 0; k < array2.Length / 2; k++) { RaycastHit raycastHit = array2[k]; array2[k] = array2[array2.Length - 1 - k]; array2[array2.Length - 1 - k] = raycastHit; } if (array2.Length > 0) { LinkedLevelNode linkedLevelNode = null; for (int l = 0; l < array2.Length; l++) { LinkedLevelNode linkedLevelNode2 = new LinkedLevelNode(); linkedLevelNode2.position = array2[l].point; if (linkedLevelNode != null && linkedLevelNode2.position.y - linkedLevelNode.position.y <= this.mergeSpanRange) { linkedLevelNode.position = linkedLevelNode2.position; linkedLevelNode.hit = array2[l]; linkedLevelNode.walkable = this.collision.Check(linkedLevelNode2.position); } else { linkedLevelNode2.walkable = this.collision.Check(linkedLevelNode2.position); linkedLevelNode2.hit = array2[l]; linkedLevelNode2.height = float.PositiveInfinity; if (linkedLevelCell.first == null) { linkedLevelCell.first = linkedLevelNode2; linkedLevelNode = linkedLevelNode2; } else { linkedLevelNode.next = linkedLevelNode2; linkedLevelNode.height = linkedLevelNode2.position.y - linkedLevelNode.position.y; linkedLevelNode = linkedLevelNode.next; } } } } else { linkedLevelCell.first = new LinkedLevelNode { position = position, height = float.PositiveInfinity, walkable = !this.collision.unwalkableWhenNoGround }; } } } int num = 0; this.layerCount = 0; for (int m = 0; m < this.depth; m++) { for (int n = 0; n < this.width; n++) { LinkedLevelCell linkedLevelCell2 = array[m * this.width + n]; LinkedLevelNode linkedLevelNode3 = linkedLevelCell2.first; int num2 = 0; do { num2++; num++; linkedLevelNode3 = linkedLevelNode3.next; }while (linkedLevelNode3 != null); this.layerCount = ((num2 <= this.layerCount) ? this.layerCount : num2); } } if (this.layerCount > 255) { Debug.LogError("Too many layers, a maximum of LevelGridNode.MaxLayerCount are allowed (found " + this.layerCount + ")"); return; } this.nodes = new LevelGridNode[this.width * this.depth * this.layerCount]; for (int num3 = 0; num3 < this.nodes.Length; num3++) { this.nodes[num3] = new LevelGridNode(this.active); this.nodes[num3].Penalty = this.initialPenalty; } int num4 = 0; float num5 = Mathf.Cos(this.maxSlope * 0.0174532924f); for (int num6 = 0; num6 < this.depth; num6++) { for (int num7 = 0; num7 < this.width; num7++) { LinkedLevelCell linkedLevelCell3 = array[num6 * this.width + num7]; LinkedLevelNode linkedLevelNode4 = linkedLevelCell3.first; linkedLevelCell3.index = num4; int num8 = 0; int num9 = 0; do { LevelGridNode levelGridNode = this.nodes[num6 * this.width + num7 + this.width * this.depth * num9]; levelGridNode.SetPosition((Int3)linkedLevelNode4.position); levelGridNode.Walkable = linkedLevelNode4.walkable; if (linkedLevelNode4.hit.normal != Vector3.zero && (this.penaltyAngle || num5 < 1f)) { float num10 = Vector3.Dot(linkedLevelNode4.hit.normal.normalized, this.collision.up); if (this.penaltyAngle) { levelGridNode.Penalty += (uint)Mathf.RoundToInt((1f - num10) * this.penaltyAngleFactor); } if (num10 < num5) { levelGridNode.Walkable = false; } } levelGridNode.NodeInGridIndex = num6 * this.width + num7; if (linkedLevelNode4.height < this.characterHeight) { levelGridNode.Walkable = false; } levelGridNode.WalkableErosion = levelGridNode.Walkable; num4++; num8++; linkedLevelNode4 = linkedLevelNode4.next; num9++; }while (linkedLevelNode4 != null); while (num9 < this.layerCount) { this.nodes[num6 * this.width + num7 + this.width * this.depth * num9] = null; num9++; } linkedLevelCell3.count = num8; } } this.nodeCellIndices = new int[array.Length]; for (int num11 = 0; num11 < this.depth; num11++) { for (int num12 = 0; num12 < this.width; num12++) { for (int num13 = 0; num13 < this.layerCount; num13++) { GraphNode node = this.nodes[num11 * this.width + num12 + this.width * this.depth * num13]; this.CalculateConnections(this.nodes, node, num12, num11, num13); } } } uint graphIndex = (uint)this.active.astarData.GetGraphIndex(this); for (int num14 = 0; num14 < this.nodes.Length; num14++) { LevelGridNode levelGridNode2 = this.nodes[num14]; if (levelGridNode2 != null) { this.UpdatePenalty(levelGridNode2); levelGridNode2.GraphIndex = graphIndex; if (!levelGridNode2.HasAnyGridConnections()) { levelGridNode2.Walkable = false; levelGridNode2.WalkableErosion = levelGridNode2.Walkable; } } } this.ErodeWalkableArea(0, 0, this.width, this.depth); }