/** * Check if this platform is connected by the special starting link */ public bool isConnectedToStart(LinkBehavior startingLink) { List <ConnectableEntityBehavior> alreadySearched = new List <ConnectableEntityBehavior>(); ConnectableEntityBehavior temp = startingLink.connectableEntity; while (temp != null) { if (temp == this) { return(true); } if (temp.GetComponent <ContainerEntityBehavior>() != null && temp.GetComponent <ContainerEntityBehavior>().GetChildComponent <LinkBehavior>() != null && temp.GetComponent <ContainerEntityBehavior>().GetChildComponent <LinkBehavior>().connectableEntity != null) { alreadySearched.Add(temp); temp = temp.GetComponent <ContainerEntityBehavior>().GetChildComponent <LinkBehavior>().connectableEntity; if (alreadySearched.Contains(temp)) // you have reached the end of the list or there is an infinite loop { return(false); } } else { return(false); } } return(false); }
private void removeCurrentConnection() { if (connectableEntity != null) { connectableEntity.removeIncomingLink(this); connectableEntity = null; if (containerEntity != null) { containerEntity.UpdateChildLinkRendering(); } } }
/** * Instantiate an arrow that goes from the given link block to the given platform using the given color. */ private Transform[] createArrowInstanceToEntity(ConnectableEntityBehavior ce, Color color) { // determine the start and end points of the arrow. Bounds linkBounds = GetComponent <SpriteRenderer>().bounds; Bounds platBounds = ce.getSpriteBounds(); // find the closest points on both bounding boxes to the center point to make the arrow. Vector3 betweenPoint = new Vector3((linkBounds.center.x + platBounds.center.x) / 2, (linkBounds.center.y + platBounds.center.y) / 2, 0); Vector3 closestToLink = linkBounds.ClosestPoint(betweenPoint); closestToLink = new Vector3(closestToLink.x, closestToLink.y, 0); Vector3 closestToPlat = platBounds.ClosestPoint(betweenPoint); closestToPlat = new Vector3(closestToPlat.x, closestToPlat.y, 0); return(createArrowInstanceBetweenPoints(closestToLink, closestToPlat, color)); }
public void setConnectionTo(ConnectableEntityBehavior ce) { // remove current connection removeCurrentConnection(); connectableEntity = ce; if (ce != null) { ce.addIncomingLink(this); } UpdateRendering(); if (containerEntity != null) { containerEntity.UpdateChildLinkRendering(); if (containerEntity.GetComponent <HelicopterRobotBehavior>() != null) { containerEntity.GetComponent <HelicopterRobotBehavior>().MoveAboveLinkedPlatform(); } } }
public void setPreviewConnection(ConnectableEntityBehavior ce) { previewConnectableEntity = ce; UpdateRendering(); }