GetConnectionValue() public method

public GetConnectionValue ( int dir ) : int
dir int
return int
Ejemplo n.º 1
0
        public override void OnDrawGizmos(bool drawNodes)
        {
            if (!drawNodes)
            {
                return;
            }
            base.OnDrawGizmos(false);
            if (this.nodes == null)
            {
                return;
            }
            PathHandler debugPathData = AstarPath.active.debugPathData;

            for (int i = 0; i < this.nodes.Length; i++)
            {
                LevelGridNode levelGridNode = this.nodes[i];
                if (levelGridNode != null && levelGridNode.Walkable)
                {
                    Gizmos.color = this.NodeColor(levelGridNode, AstarPath.active.debugPathData);
                    if (AstarPath.active.showSearchTree && AstarPath.active.debugPathData != null)
                    {
                        if (NavGraph.InSearchTree(levelGridNode, AstarPath.active.debugPath))
                        {
                            PathNode pathNode = debugPathData.GetPathNode(levelGridNode);
                            if (pathNode != null && pathNode.parent != null)
                            {
                                Gizmos.DrawLine((Vector3)levelGridNode.position, (Vector3)pathNode.parent.node.position);
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            int connectionValue = levelGridNode.GetConnectionValue(j);
                            if (connectionValue != 255)
                            {
                                int num = levelGridNode.NodeInGridIndex + this.neighbourOffsets[j] + this.width * this.depth * connectionValue;
                                if (num >= 0 && num < this.nodes.Length)
                                {
                                    GraphNode graphNode = this.nodes[num];
                                    if (graphNode != null)
                                    {
                                        Gizmos.DrawLine((Vector3)levelGridNode.position, (Vector3)graphNode.position);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public new bool SnappedLinecast(Vector3 _a, Vector3 _b, GraphNode hint, out GraphHitInfo hit)
        {
            hit = default(GraphHitInfo);
            LevelGridNode levelGridNode  = base.GetNearest(_a, NNConstraint.None).node as LevelGridNode;
            LevelGridNode levelGridNode2 = base.GetNearest(_b, NNConstraint.None).node as LevelGridNode;

            if (levelGridNode == null || levelGridNode2 == null)
            {
                hit.node  = null;
                hit.point = _a;
                return(true);
            }
            _a    = this.inverseMatrix.MultiplyPoint3x4((Vector3)levelGridNode.position);
            _a.x -= 0.5f;
            _a.z -= 0.5f;
            _b    = this.inverseMatrix.MultiplyPoint3x4((Vector3)levelGridNode2.position);
            _b.x -= 0.5f;
            _b.z -= 0.5f;
            Int3 ob   = new Int3(Mathf.RoundToInt(_a.x), Mathf.RoundToInt(_a.y), Mathf.RoundToInt(_a.z));
            Int3 @int = new Int3(Mathf.RoundToInt(_b.x), Mathf.RoundToInt(_b.y), Mathf.RoundToInt(_b.z));

            hit.origin = (Vector3)ob;
            if (!levelGridNode.Walkable)
            {
                hit.node    = levelGridNode;
                hit.point   = this.matrix.MultiplyPoint3x4(new Vector3((float)ob.x + 0.5f, 0f, (float)ob.z + 0.5f));
                hit.point.y = ((Vector3)hit.node.position).y;
                return(true);
            }
            int           num  = Mathf.Abs(ob.x - @int.x);
            int           num2 = Mathf.Abs(ob.z - @int.z);
            LevelGridNode levelGridNode4;

            for (LevelGridNode levelGridNode3 = levelGridNode; levelGridNode3 != levelGridNode2; levelGridNode3 = levelGridNode4)
            {
                if (levelGridNode3.NodeInGridIndex == levelGridNode2.NodeInGridIndex)
                {
                    hit.node  = levelGridNode3;
                    hit.point = (Vector3)levelGridNode3.position;
                    return(true);
                }
                num  = Math.Abs(ob.x - @int.x);
                num2 = Math.Abs(ob.z - @int.z);
                int num3 = 0;
                if (num >= num2)
                {
                    num3 = ((@int.x <= ob.x) ? 3 : 1);
                }
                else if (num2 > num)
                {
                    num3 = ((@int.z <= ob.z) ? 0 : 2);
                }
                if (!this.CheckConnection(levelGridNode3, num3))
                {
                    hit.node  = levelGridNode3;
                    hit.point = (Vector3)levelGridNode3.position;
                    return(true);
                }
                levelGridNode4 = this.nodes[levelGridNode3.NodeInGridIndex + this.neighbourOffsets[num3] + this.width * this.depth * levelGridNode3.GetConnectionValue(num3)];
                if (!levelGridNode4.Walkable)
                {
                    hit.node  = levelGridNode4;
                    hit.point = (Vector3)levelGridNode4.position;
                    return(true);
                }
                ob = (Int3)this.inverseMatrix.MultiplyPoint3x4((Vector3)levelGridNode4.position);
            }
            return(false);
        }
Ejemplo n.º 3
0
        protected override GridNodeBase GetNeighbourAlongDirection(GridNodeBase node, int direction)
        {
            LevelGridNode levelGridNode = node as LevelGridNode;

            if (levelGridNode.GetConnection(direction))
            {
                return(this.nodes[levelGridNode.NodeInGridIndex + this.neighbourOffsets[direction] + this.width * this.depth * levelGridNode.GetConnectionValue(direction)]);
            }
            return(null);
        }