/* Debug */ /*public List<Bezier2> debugDraw = new List<Bezier2>(); * public List<Vector3> debugDrawPositions = new List<Vector3>(); * bool yes = true; // :)*/ public void BuildEllipse() { if (ellipse == null) { UIWindow2.instance.ThrowErrorMsg("Invalid radii!"); } Ellipse toBeBuiltEllipse = ellipse; Ellipse ellipseWithPadding = ellipse; /* When the old snapping algorithm is enabled, we create secondary (bigger) ellipse, so the newly connected roads obtained by the * graph traveller are not too short. They will be at least as long as the padding. */ if (RoundAboutBuilder.UseOldSnappingAlgorithm.value) { ellipseWithPadding = new Ellipse(NetAccess.Node(centralNode).m_position, NetAccess.Node(axisNode).m_position - NetAccess.Node(centralNode).m_position, prevRadius1 + DISTANCE_PADDING, prevRadius2 + DISTANCE_PADDING); } UIWindow2.instance.LostFocus(); UIWindow2.instance.GoBack(); try { GraphTraveller2 traveller = new GraphTraveller2(centralNode, ellipseWithPadding); EdgeIntersections2 intersections = new EdgeIntersections2(traveller, centralNode, toBeBuiltEllipse); FinalConnector finalConnector = new FinalConnector(NetAccess.Node(centralNode).Info, intersections, toBeBuiltEllipse, ControlVertices); // Easter egg RoundAboutBuilder.EasterEggToggle(); } catch (Exception e) { Debug.LogError(e); UIWindow2.instance.ThrowErrorMsg(e.ToString(), true); } }
private void PreviewRoundabout(float radius) { /* These lines of code do all the work. See documentation in respective classes. */ /* When the old snapping algorithm is enabled, we create secondary (bigger) ellipse, so the newly connected roads obtained by the * graph traveller are not too short. They will be at least as long as the padding. */ bool reverseDirection = (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && RoundAboutBuilder.CtrlToReverseDirection.value; if (m_radius == radius && m_hoverNode == m_nodeID && m_roundabout != null && m_roundabout.m_reverseDirection == reverseDirection) { return; } try { m_radius = radius; m_nodeID = m_hoverNode; Ellipse ellipse = new Ellipse(NetUtil.Node(m_nodeID).m_position, new Vector3(0f, 0f, 0f), radius, radius); Ellipse ellipseWithPadding = ellipse; if (RoundAboutBuilder.UseOldSnappingAlgorithm.value) { ellipseWithPadding = new Ellipse(NetUtil.Node(m_nodeID).m_position, new Vector3(0f, 0f, 0f), radius + DISTANCE_PADDING, radius + DISTANCE_PADDING); } GraphTraveller2 traveller; EdgeIntersections2 intersections = null; if (!RoundAboutBuilder.DoNotRemoveAnyRoads) { traveller = new GraphTraveller2(m_nodeID, ellipse); intersections = new EdgeIntersections2(traveller, m_nodeID, ellipse, GetFollowTerrain()); } m_roundabout = new FinalConnector(NetUtil.Node(m_nodeID).Info, intersections, ellipse, true, GetFollowTerrain(), reverseDirection); } catch (Exception e) { Debug.LogError(e); } }
//string m_radiusField.text = RADIUS_DEF.ToString(); /* Main method , called when user cliks on a node to create a roundabout */ public void CreateRoundabout(ushort nodeID) { //Debug.Log(string.Format("Clicked on node ID {0}!", nodeID)); float?radiusQ = UIWindow2.instance.P_RoundAboutPanel.RadiusField.Value; if (radiusQ == null) { UIWindow2.instance.ThrowErrorMsg("Radius out of bounds!"); return; } float radius = (float)radiusQ; if (!UIWindow2.instance.keepOpen) { UIWindow2.instance.LostFocus(); } /* These lines of code do all the work. See documentation in respective classes. */ /* When the old snapping algorithm is enabled, we create secondary (bigger) ellipse, so the newly connected roads obtained by the * graph traveller are not too short. They will be at least as long as the padding. */ Ellipse ellipse = new Ellipse(NetAccess.Node(nodeID).m_position, new Vector3(0f, 0f, 0f), radius, radius); Ellipse ellipseWithPadding = ellipse; if (RoundAboutBuilder.UseOldSnappingAlgorithm.value) { ellipseWithPadding = new Ellipse(NetAccess.Node(nodeID).m_position, new Vector3(0f, 0f, 0f), radius + DISTANCE_PADDING, radius + DISTANCE_PADDING); } try { GraphTraveller2 traveller; EdgeIntersections2 intersections = null; if (!RoundAboutBuilder.DoNotRemoveAnyRoads) { traveller = new GraphTraveller2(nodeID, ellipse); intersections = new EdgeIntersections2(traveller, nodeID, ellipse); } FinalConnector finalConnector = new FinalConnector(NetAccess.Node(nodeID).Info, intersections, ellipse, true); // Easter egg RoundAboutBuilder.EasterEggToggle(); // Debug, don't forget to remove /*foreach(VectorNodeStruct intersection in intersections.Intersections) * { * Debug.Log($"May have/Has restrictions: {TrafficManager.Manager.Impl.JunctionRestrictionsManager.Instance.MayHaveJunctionRestrictions(intersection.nodeId)}, {TrafficManager.Manager.Impl.JunctionRestrictionsManager.Instance.HasJunctionRestrictions(intersection.nodeId)}"); * }*/ } catch (Exception e) { Debug.LogError(e); UIWindow2.instance.ThrowErrorMsg(e.ToString(), true); } }
/* Debug */ /*public List<Bezier2> debugDraw = new List<Bezier2>(); * public List<Vector3> debugDrawPositions = new List<Vector3>(); * bool yes = true; // :)*/ public void BuildEllipse() { if (ellipse == null) { UIWindow.instance.ThrowErrorMsg("Invalid radii!"); } Ellipse toBeBuiltEllipse = ellipse; Ellipse ellipseWithPadding = ellipse; /* When the old snapping algorithm is enabled, we create secondary (bigger) ellipse, so the newly connected roads obtained by the * graph traveller are not too short. They will be at least as long as the padding. */ if (RoundAboutBuilder.UseOldSnappingAlgorithm.value) { ellipseWithPadding = new Ellipse(NetUtil.Node(centralNode).m_position, NetUtil.Node(axisNode).m_position - NetUtil.Node(centralNode).m_position, prevRadius1 + DISTANCE_PADDING, prevRadius2 + DISTANCE_PADDING); } UIWindow.instance.LostFocus(); Instance.GoToFirstStage(); try { bool reverseDirection = (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && RoundAboutBuilder.CtrlToReverseDirection.value; GraphTraveller2 traveller = new GraphTraveller2(centralNode, ellipseWithPadding); EdgeIntersections2 intersections = new EdgeIntersections2(traveller, centralNode, toBeBuiltEllipse, GetFollowTerrain()); FinalConnector finalConnector = new FinalConnector(NetUtil.Node(centralNode).Info, intersections, toBeBuiltEllipse, ControlVertices, GetFollowTerrain(), reverseDirection); finalConnector.Build(); // Easter egg RoundAboutBuilder.EasterEggToggle(); } catch (ActionException e) { UIWindow.instance.ThrowErrorMsg(e.Message); } catch (Exception e) { Debug.LogError(e); UIWindow.instance.ThrowErrorMsg(e.ToString(), true); } }