public EditorPortal(EditorScene editorScene) : base(editorScene) { Path = new PortalPath(); IsPortalable = false; Initialize(); }
/// <summary> /// Returns the shortest path based on all portals available. /// </summary> public static Vector3[] GetPath(Vector3 start, Vector3 target) { PortalPath path = new PortalPath(); path.pos = start; path.final = target; return path.GetShortestPath(); }
/// <summary> /// Returns the shortest path based on all portals available. /// </summary> public static Vector3[] GetPath(Vector3 start, Vector3 target) { PortalPath path = new PortalPath(); path.pos = start; path.final = target; return(path.GetShortestPath()); }
/// <summary> /// Constructor for setting up initial starting point and final destination. /// </summary> public PortalNode(PortalPath instance, Vector3 start) { path = instance; this.start = start; //initialize variables UnityEngine.AI.NavMeshPath p = new UnityEngine.AI.NavMeshPath(); //let Unity calculate this path and set target, if valid if (UnityEngine.AI.NavMesh.CalculatePath(start, instance.final, -1, p) && p.status == UnityEngine.AI.NavMeshPathStatus.PathComplete) { this.target = instance.final; } }
/// <summary> /// Returns all the portal intersections for a line in this path. /// TFirst is the t value for the line intersection. /// TLast is the t value for the portal intersection. /// </summary> /// <param name="line"></param> /// <returns></returns> public static IntersectCoord[] PathIntersections(PortalPath path, LineF line) { IntersectCoord[] intersections = new IntersectCoord[path.Portals.Count]; line = line.ShallowClone(); LineF[] portalLines = new LineF[path.Portals.Count]; for (int i = 0; i < path.Portals.Count; i++) { portalLines[i] = new LineF(GetWorldVerts(path.Portals[i])); } for (int i = path.Portals.Count - 1; i >= 0; i--) { Matrix4 mat = GetLinkedMatrix(path.Portals[i].Linked); line[1] = line.Transform(mat)[1]; for (int j = i + 1; j < path.Portals.Count; j++) { portalLines[j] = portalLines[j].Transform(mat); } } for (int i = 0; i < path.Portals.Count; i++) { intersections[i] = MathExt.LineLineIntersect(portalLines[i], line, true); } return intersections; }
/// <summary> /// Constructor for setting up initial starting point and final destination. /// </summary> public PortalNode(PortalPath instance, Vector3 start) { path = instance; this.start = start; //initialize variables NavMeshPath p = new NavMeshPath(); //let Unity calculate this path and set target, if valid if (NavMesh.CalculatePath(start, instance.final, -1, p) && p.status == NavMeshPathStatus.PathComplete) { this.target = instance.final; } }
public void PathIntersectionsTest0() { Scene scene = new Scene(); FloatPortal p0 = new FloatPortal(scene); p0.SetTransform(new Transform2(new Vector2(1, 0))); FloatPortal p1 = new FloatPortal(scene); p1.SetTransform(new Transform2(new Vector2(10, -1))); p0.Linked = p1; p1.Linked = p0; PortalCommon.UpdateWorldTransform(scene); LineF ray = new LineF(new Vector2(0, 0), new Vector2(8, -1)); PortalPath path = new PortalPath(); path.Enter(p0); var intersections = Portal.PathIntersections(path, ray); Assert.AreEqual(1, intersections.Length); Assert.AreEqual(0.5, intersections[0].TFirst, PATH_INTERSECTION_DELTA); Assert.AreEqual(1.0 / 3, intersections[0].TLast, PATH_INTERSECTION_DELTA); }
public void PathIntersectionsTest2() { Scene scene = new Scene(); FloatPortal p0 = new FloatPortal(scene); p0.SetTransform(new Transform2(new Vector2(1, 0))); FloatPortal p1 = new FloatPortal(scene); p1.SetTransform(new Transform2(new Vector2(2, 0), 1, (float)Math.PI)); p0.Linked = p1; p1.Linked = p0; FloatPortal p2 = new FloatPortal(scene); p2.SetTransform(new Transform2(new Vector2(3, 0))); FloatPortal p3 = new FloatPortal(scene); p3.SetTransform(new Transform2(new Vector2(6, 3), 1, (float)Math.PI/2)); p2.Linked = p3; p3.Linked = p2; PortalCommon.UpdateWorldTransform(scene); LineF ray = new LineF(new Vector2(0, 0), new Vector2(6, 2)); PortalPath path = new PortalPath(); path.Enter(p0); path.Enter(p2); var intersections = Portal.PathIntersections(path, ray); Assert.AreEqual(2, intersections.Length); Assert.AreEqual(0.5, intersections[0].TFirst, PATH_INTERSECTION_DELTA); Assert.AreEqual(1.0 / 3, intersections[0].TLast, PATH_INTERSECTION_DELTA); Assert.AreEqual(0.5, intersections[1].TFirst, PATH_INTERSECTION_DELTA); Assert.AreEqual(2.0 / 3, intersections[1].TLast, PATH_INTERSECTION_DELTA); }