/// <summary> /// Check on the given Pos if a combine to another Street is possible /// </summary> /// <param name="_hitPoint">The Pos to check around</param> /// <param name="_isStart">Is it the Start of the PreviewStreet</param> /// <returns></returns> private void CheckForCombine(Vector3 _hitPoint, bool _isStart) { Connection closestConnection = FindClosestConnection(_hitPoint); if (closestConnection != null && m_previewLastConnected != closestConnection) { //Recreate Dead End + Decombine DecombinePreview(false); } if (closestConnection == null) // if there is no valid Street GameObject around { //Recreate Dead End + Decombine DecombinePreview(false); //Unlock the Tangent of the Pos which is not Set if (pos1 == Vector3.zero) { isTangent1Locked = false; } if (pos3 == Vector3.zero) { isTangent2Locked = false; } return; } m_previewLastConnected = closestConnection; //check next Update if new closestConnection has chanded to create a DeadEnd on the old place if (m_previewStreet.GetStartConnection().m_OtherConnection == closestConnection) { return; } if (closestConnection.m_Owner is Street) { Street otherStreet = (Street)closestConnection.m_Owner; if (!closestConnection.m_OwnerStart) { if (_isStart) { //other Street End and previewStreet Start -> Combine Vector3 dir = -(otherStreet.m_Spline.Tangent2Pos - otherStreet.m_Spline.EndPos).normalized; //Get the point symmetrical Direction StreetComponentManager.UpdateStreetTangent1AndStartPoint( m_previewStreet, dir * 5f + otherStreet.m_Spline.EndPos, //Set the Tanget to the half point symmetrical Position otherStreet.m_Spline.EndPos ); //Set the EndPos isTangent1Locked = true; //Combine(_others End, preview Start) + Remove others DeadEnd at End if (otherStreet.m_EndConnection.m_OtherComponent is DeadEnd) { StreetComponentManager.DestroyDeadEnd((DeadEnd)otherStreet.m_EndConnection.m_OtherComponent); } CombinePreview(otherStreet, false, true); return; } else { //other Street End and previewStreet End -> Combine Vector3 dir = -(otherStreet.m_Spline.Tangent2Pos - otherStreet.m_Spline.EndPos).normalized; StreetComponentManager.UpdateStreetTangent2AndEndPoint( m_previewStreet, dir * 5f + otherStreet.m_Spline.EndPos, otherStreet.m_Spline.EndPos ); isTangent2Locked = true; //Combine(_others End, preview End) + Remove others DeadEnd at End if (otherStreet.m_EndConnection.m_OtherComponent is DeadEnd) { StreetComponentManager.DestroyDeadEnd((DeadEnd)otherStreet.m_EndConnection.m_OtherComponent); } CombinePreview(otherStreet, false, false); return; } } else if (closestConnection.m_OwnerStart) { if (_isStart) { //other Street Start and previewStreet Start -> Combine Vector3 dir = -(otherStreet.m_Spline.Tangent1Pos - otherStreet.m_Spline.StartPos).normalized; StreetComponentManager.UpdateStreetTangent1AndStartPoint( m_previewStreet, dir * 5f + otherStreet.m_Spline.StartPos, otherStreet.m_Spline.StartPos ); isTangent1Locked = true; //Combine(_others Start, preview Start) + Remove others DeadEnd at Start if (otherStreet.GetStartConnection().m_OtherComponent is DeadEnd) { StreetComponentManager.DestroyDeadEnd((DeadEnd)otherStreet.GetStartConnection().m_OtherComponent); } CombinePreview(otherStreet, true, true); return; } else { //other Street Start and previewStreet End -> Combine Vector3 dir = -(otherStreet.m_Spline.Tangent1Pos - otherStreet.m_Spline.StartPos).normalized; StreetComponentManager.UpdateStreetTangent2AndEndPoint( m_previewStreet, dir * 5f + otherStreet.m_Spline.StartPos, otherStreet.m_Spline.StartPos ); isTangent2Locked = true; //Combine(_others Start, preview Start) + Remove others DeadEnd at Start if (otherStreet.GetStartConnection().m_OtherComponent is DeadEnd) { StreetComponentManager.DestroyDeadEnd((DeadEnd)otherStreet.GetStartConnection().m_OtherComponent); } CombinePreview(otherStreet, true, false); return; } } } if (closestConnection.m_Owner is Cross) { Cross otherCross = (Cross)closestConnection.m_Owner; int otherCrossConnectionIndex = otherCross.GetIndexByConnection(closestConnection); OrientedPoint op = otherCross.m_OPs[otherCrossConnectionIndex]; if (otherCross.m_Connections[otherCrossConnectionIndex].m_OtherComponent is DeadEnd) { StreetComponentManager.DestroyDeadEnd((DeadEnd)otherCross.m_Connections[otherCrossConnectionIndex].m_OtherComponent); } if (_isStart) { StreetComponentManager.UpdateStreetTangent1AndStartPoint(m_previewStreet, op.Position + op.Rotation * Vector3.forward * 3f, op.Position); isTangent1Locked = true; Connection.Combine(m_previewStreet.GetStartConnection(), closestConnection); } else { StreetComponentManager.UpdateStreetTangent2AndEndPoint(m_previewStreet, op.Position + op.Rotation * Vector3.forward * 3f, op.Position); isTangent2Locked = true; Connection.Combine(m_previewStreet.m_EndConnection, closestConnection); } } }