Ejemplo n.º 1
0
        public override bool GetPortal(GraphNode other, List <Vector3> left, List <Vector3> right, bool backwards)
        {
            if (backwards)
            {
                return(true);
            }
            GridGraph gridGraph = GridNode.GetGridGraph(base.GraphIndex);

            int[]      neighbourOffsets = gridGraph.neighbourOffsets;
            GridNode[] nodes            = gridGraph.nodes;
            for (int i = 0; i < 4; i++)
            {
                if (this.HasConnectionInDirection(i) && other == nodes[base.NodeInGridIndex + neighbourOffsets[i]])
                {
                    Vector3 a      = (Vector3)(this.position + other.position) * 0.5f;
                    Vector3 vector = Vector3.Cross(gridGraph.collision.up, (Vector3)(other.position - this.position));
                    vector.Normalize();
                    vector *= gridGraph.nodeSize * 0.5f;
                    left.Add(a - vector);
                    right.Add(a + vector);
                    return(true);
                }
            }
            for (int j = 4; j < 8; j++)
            {
                if (this.HasConnectionInDirection(j) && other == nodes[base.NodeInGridIndex + neighbourOffsets[j]])
                {
                    bool flag  = false;
                    bool flag2 = false;
                    if (this.HasConnectionInDirection(j - 4))
                    {
                        GridNode gridNode = nodes[base.NodeInGridIndex + neighbourOffsets[j - 4]];
                        if (gridNode.Walkable && gridNode.HasConnectionInDirection((j - 4 + 1) % 4))
                        {
                            flag = true;
                        }
                    }
                    if (this.HasConnectionInDirection((j - 4 + 1) % 4))
                    {
                        GridNode gridNode2 = nodes[base.NodeInGridIndex + neighbourOffsets[(j - 4 + 1) % 4]];
                        if (gridNode2.Walkable && gridNode2.HasConnectionInDirection(j - 4))
                        {
                            flag2 = true;
                        }
                    }
                    Vector3 a2      = (Vector3)(this.position + other.position) * 0.5f;
                    Vector3 vector2 = Vector3.Cross(gridGraph.collision.up, (Vector3)(other.position - this.position));
                    vector2.Normalize();
                    vector2 *= gridGraph.nodeSize * 1.4142f;
                    left.Add(a2 - (flag2 ? vector2 : Vector3.zero));
                    right.Add(a2 + (flag ? vector2 : Vector3.zero));
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
		public override bool GetPortal (GraphNode other, List<Vector3> left, List<Vector3> right, bool backwards) {
			if (backwards) return true;

			GridGraph gg = GetGridGraph(GraphIndex);
			int[] neighbourOffsets = gg.neighbourOffsets;
			GridNode[] nodes = gg.nodes;

			for (int i = 0; i < 4; i++) {
				if (HasConnectionInDirection(i) && other == nodes[NodeInGridIndex + neighbourOffsets[i]]) {
					Vector3 middle = ((Vector3)(position + other.position))*0.5f;
					Vector3 cross = Vector3.Cross(gg.collision.up, (Vector3)(other.position-position));
					cross.Normalize();
					cross *= gg.nodeSize*0.5f;
					left.Add(middle - cross);
					right.Add(middle + cross);
					return true;
				}
			}

			for (int i = 4; i < 8; i++) {
				if (HasConnectionInDirection(i) && other == nodes[NodeInGridIndex + neighbourOffsets[i]]) {
					bool rClear = false;
					bool lClear = false;
					if (HasConnectionInDirection(i-4)) {
						GridNode n2 = nodes[NodeInGridIndex + neighbourOffsets[i-4]];
						if (n2.Walkable && n2.HasConnectionInDirection((i-4+1)%4)) {
							rClear = true;
						}
					}

					if (HasConnectionInDirection((i-4+1)%4)) {
						GridNode n2 = nodes[NodeInGridIndex + neighbourOffsets[(i-4+1)%4]];
						if (n2.Walkable && n2.HasConnectionInDirection(i-4)) {
							lClear = true;
						}
					}

					Vector3 middle = ((Vector3)(position + other.position))*0.5f;
					Vector3 cross = Vector3.Cross(gg.collision.up, (Vector3)(other.position-position));
					cross.Normalize();
					cross *= gg.nodeSize*1.4142f;
					left.Add(middle - (lClear ? cross : Vector3.zero));
					right.Add(middle + (rClear ? cross : Vector3.zero));
					return true;
				}
			}

			return false;
		}