Pathfinding.LevelGridNode.SetPosition C# (CSharp) Method

SetPosition() public method

public SetPosition ( Int3 position ) : void
position Int3
return void
		public void SetPosition (Int3 position) {
			this.position = position;
		}
		

Usage Example

Ejemplo n.º 1
0
        public bool RecalculateCell(int x, int z, bool preserveExistingNodes)
        {
            LinkedLevelCell linkedLevelCell = new LinkedLevelCell();
            Vector3         position        = this.matrix.MultiplyPoint3x4(new Vector3((float)x + 0.5f, 0f, (float)z + 0.5f));

            RaycastHit[] array = this.collision.CheckHeightAll(position);
            for (int i = 0; i < array.Length / 2; i++)
            {
                RaycastHit raycastHit = array[i];
                array[i] = array[array.Length - 1 - i];
                array[array.Length - 1 - i] = raycastHit;
            }
            bool result = false;

            if (array.Length > 0)
            {
                LinkedLevelNode linkedLevelNode = null;
                for (int j = 0; j < array.Length; j++)
                {
                    LinkedLevelNode linkedLevelNode2 = new LinkedLevelNode();
                    linkedLevelNode2.position = array[j].point;
                    if (linkedLevelNode != null && linkedLevelNode2.position.y - linkedLevelNode.position.y <= this.mergeSpanRange)
                    {
                        linkedLevelNode.position = linkedLevelNode2.position;
                        linkedLevelNode.hit      = array[j];
                        linkedLevelNode.walkable = this.collision.Check(linkedLevelNode2.position);
                    }
                    else
                    {
                        linkedLevelNode2.walkable = this.collision.Check(linkedLevelNode2.position);
                        linkedLevelNode2.hit      = array[j];
                        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
                };
            }
            uint            graphIndex       = (uint)this.active.astarData.GetGraphIndex(this);
            LinkedLevelNode linkedLevelNode3 = linkedLevelCell.first;
            int             num = 0;
            int             k   = 0;

            while (true)
            {
                if (k >= this.layerCount)
                {
                    if (k + 1 > 255)
                    {
                        break;
                    }
                    this.AddLayers(1);
                    result = true;
                }
                LevelGridNode levelGridNode = this.nodes[z * this.width + x + this.width * this.depth * k];
                if (levelGridNode == null || !preserveExistingNodes)
                {
                    this.nodes[z * this.width + x + this.width * this.depth * k] = new LevelGridNode(this.active);
                    levelGridNode            = this.nodes[z * this.width + x + this.width * this.depth * k];
                    levelGridNode.Penalty    = this.initialPenalty;
                    levelGridNode.GraphIndex = graphIndex;
                    result = true;
                }
                levelGridNode.SetPosition((Int3)linkedLevelNode3.position);
                levelGridNode.Walkable        = linkedLevelNode3.walkable;
                levelGridNode.WalkableErosion = levelGridNode.Walkable;
                if (linkedLevelNode3.hit.normal != Vector3.zero)
                {
                    float num2 = Vector3.Dot(linkedLevelNode3.hit.normal.normalized, this.collision.up);
                    if (this.penaltyAngle)
                    {
                        levelGridNode.Penalty += (uint)Mathf.RoundToInt((1f - num2) * this.penaltyAngleFactor);
                    }
                    float num3 = Mathf.Cos(this.maxSlope * 0.0174532924f);
                    if (num2 < num3)
                    {
                        levelGridNode.Walkable = false;
                    }
                }
                levelGridNode.NodeInGridIndex = z * this.width + x;
                if (linkedLevelNode3.height < this.characterHeight)
                {
                    levelGridNode.Walkable = false;
                }
                num++;
                linkedLevelNode3 = linkedLevelNode3.next;
                k++;
                if (linkedLevelNode3 == null)
                {
                    goto Block_14;
                }
            }
            Debug.LogError("Too many layers, a maximum of LevelGridNode.MaxLayerCount are allowed (required " + (k + 1) + ")");
            return(result);

Block_14:
            while (k < this.layerCount)
            {
                this.nodes[z * this.width + x + this.width * this.depth * k] = null;
                k++;
            }
            linkedLevelCell.count = num;
            return(result);
        }
All Usage Examples Of Pathfinding.LevelGridNode::SetPosition