public static void create(long key, WayReference endPoint, string materialId) { bool isNode1 = endPoint.isNode1(NodeIndex.getPosById(key)); bool isSmall = endPoint.SmallWay; Vector3 originalScale = endPoint.gameObject.transform.localScale; Vector3 nodeCameraPos = Game.getCameraPosition(isNode1 ? endPoint.node1 : endPoint.node2); Vector3 fromPos = nodeCameraPos - new Vector3(0f, originalScale.y / 2f, 0f); Vector3 toPos = fromPos + new Vector3((isSmall ? originalScale.x / 2f : originalScale.y / 2f), originalScale.y, 0f); GameObject endPointObj = MapSurface.createPlaneMeshForPoints(fromPos, toPos, MapSurface.Anchor.LEFT_CENTER); endPointObj.name = "End of way (" + key + ")"; Vector3 zOffset = new Vector3(0, 0, Game.WAYS_Z_POSITION); endPointObj.transform.position = endPointObj.transform.position + zOffset - (isNode1 ? Vector3.zero : endPoint.transform.rotation * new Vector3(isSmall ? originalScale.x / 2f : originalScale.y / 2f, 0f, 0f)); endPointObj.transform.parent = Game.instance.waysParent; endPointObj.transform.rotation = endPoint.transform.rotation; AutomaticMaterialObject endPointMaterialObject = endPointObj.AddComponent <AutomaticMaterialObject> () as AutomaticMaterialObject; endPointMaterialObject.requestMaterial(materialId, null); // TODO - Default material // Add rigidbody and mesh collider, so that they will fall onto the underlying plane Misc.AddGravityToWay(endPointObj); Misc.AddWayObjectComponent(endPointObj); }
static List <Bounds> getWayBounds(List <WayReference> wayReferences) { List <Bounds> wayBounds = new List <Bounds> (); foreach (WayReference wayReference in wayReferences) { GameObject wayMeshObj = GameObject.Find("Plane Mesh for " + wayReference.gameObject.name); Misc.AddGravityToWay(wayMeshObj); Misc.AddWayObjectComponent(wayMeshObj); Renderer wayRenderer = wayMeshObj.GetComponent <Renderer>(); Bounds wayBound = wayRenderer.bounds; wayBounds.Add(wayBound); } return(wayBounds); }
public static void create(long key, List <WayReference> wayReferences, string materialId) { if (off) { return; } Pos pos = NodeIndex.getPosById(key); // Sort based on rotation in the point closest to the intersection wayReferences.Sort(delegate(WayReference x, WayReference y) { float angleDiff = AngleAroundNode(pos, x) - AngleAroundNode(pos, y); // Ignoring float to int issues (if there are any) int angleDiffInt = (int)angleDiff; return(angleDiffInt); }); // Gather our way bounds (used for checking if ways intersects each other) List <Bounds> wayBounds = getWayBounds(wayReferences); // List of positions where to draw the mesh List <Vector3> meshPoints; List <WayReference> intersectionList = Misc.CloneBaseNodeList(wayReferences); bool isComplex = false; if (intersectionList.Count == 2 && wayBounds [0].Intersects(wayBounds [1])) { // Only two ways and they intersect, special logic meshPoints = getMeshPointsForComplexTwoWay(intersectionList, wayBounds, pos); isComplex = true; } else { meshPoints = getMeshPointsForNonComplex(intersectionList, wayBounds, pos); } // Debug.Log ("Intersection"); GameObject intersectionObj = MapSurface.createPlaneMeshForPoints(meshPoints); intersectionObj.name = "Intersection " + (isComplex ? "complex " : "") + (intersectionList.Count - 1) + "-way (" + key + ")"; Vector3 zOffset = new Vector3(0, 0, Game.WAYS_Z_POSITION); intersectionObj.transform.position = intersectionObj.transform.position + zOffset; intersectionObj.transform.parent = Game.instance.waysParent; AutomaticMaterialObject intersectionMaterialObject = intersectionObj.AddComponent <AutomaticMaterialObject> () as AutomaticMaterialObject; intersectionMaterialObject.requestMaterial(materialId, null); // TODO - Should have same material as connecting way(s) Misc.AddGravityToWay(intersectionObj); Misc.AddWayObjectComponent(intersectionObj); // Need waylines for all straight ways if (wayReferences.Count == 2) { bool wayQualifiedForCrossing = wayReferences[0].way.WayWidthFactor >= WayHelper.LIMIT_WAYWIDTH && wayReferences[0].way.CarWay; if (pos.getTagValue("highway") == "crossing" && wayQualifiedForCrossing) { WayCrossing.Create(intersectionObj, key, wayReferences); } else { WayLine.CreateCurved(intersectionObj, key, wayReferences); } } }