/// <summary> /// Give the Component a new ID if needed (Attention: Call it only for fineshed Streets, not Preview) /// </summary> /// <param name="_needID">Need an new ID?</param> public virtual void Init(bool _needID) { if (_needID) { ID = StreetComponentManager.GetNewStreetComponentID(); } }
/// <summary> /// Initialize the Street /// </summary> /// <param name="_splinePos">The 4 Locations for the Spline (Start, Tangent 1, Tangent 2, End)</param> /// <param name="_startConnection">The Start Connection of the Street Component</param> /// <param name="_endConnection">The End Connection of the Street</param> /// <param name="_segmentAmount">The Amount of Segments the Street needs</param> /// <param name="_needID">Need the Street an ID?</param> /// <param name="_updateSpline">Should the Spline be Updated?</param> /// <returns>Returns the new Street</returns> public Street Init(Vector3[] _splinePos, Connection _startConnection, Connection _endConnection, int _segmentAmount = 10, bool _needID = true, bool _updateSpline = false) { ID = 0; if (_needID) { base.Init(_needID); } m_Spline = new Spline(_splinePos[0], _splinePos[1], _splinePos[2], _splinePos[3], _segmentAmount, this); m_MeshFilter = GetComponent <MeshFilter>(); if (m_MeshFilter == null) { Debug.LogError("No MeshFilter found in: " + ID); } m_MeshRenderer = GetComponent <MeshRenderer>(); if (m_MeshRenderer == null) { Debug.LogError("No MeshRenderer found in: " + ID); } m_Shape = new StreetShape(); m_Spline.UpdateOPs(); MeshGenerator.Extrude(this); updateSpline = _updateSpline; //Create Start and End Connections SetStartConnection(new Connection(null, this, true)); m_EndConnection = new Connection(null, this, false); //If its an finished Street Combine the Connections from the Preview Street if (_needID) { if (_startConnection?.m_OtherConnection != null) //if the preview Street had a connection to something { Connection.Combine(GetStartConnection(), _startConnection.m_OtherConnection); //combine the new Street with the preview other connection } else { StreetComponentManager.CreateDeadEnd(this, true); //If there is no Connections to Combine, Create a DeadEnd } if (_endConnection?.m_OtherConnection != null) { Connection.Combine(m_EndConnection, _endConnection.m_OtherConnection); } else { StreetComponentManager.CreateDeadEnd(this, false); } } CreateSegments(); if (_needID) //if its isnt a Collision Street { StartCoroutine(PlaceBuildings()); } return(this); }
public void CreateDeadEnds() { for (int i = 0; i < m_Connections.Length; i++) { if (m_Connections[i].m_OtherConnection == null) { StreetComponentManager.CreateDeadEnd(this, i); } } }
/// <summary> /// Check the Street - Cell Collision and Update the Grid of other Streets if needed /// </summary> public void CheckCollision() { HashSet <int> StreetsToRecreate = new HashSet <int>(); //Create an HashSet of int (StreetComponent IDs) to save the Streets Grid thats needs to be recreated foreach (StreetSegment segment in m_Segments) { foreach (int id in segment.CheckCollision(GridManager.m_AllCells)) { //Saves the IDs of Streets which the segment collide with StreetsToRecreate.Add(id); } } //Recreate the Streets Grid Mesh foreach (int id in StreetsToRecreate) { Street s = StreetComponentManager.GetStreetByID(id); GridManager.RemoveGridMesh(s); MeshGenerator.CreateGridMesh(s, s.m_GridObj.GetComponent <MeshFilter>(), s.m_GridRenderer); } }
public void CheckGridCollision() { m_center = new Vector2(transform.position.x, transform.position.z); m_corners[0] = m_center + new Vector2(1.2f, 1.2f); m_corners[1] = m_center + new Vector2(-1.2f, 1.2f); m_corners[2] = m_center + new Vector2(-1.2f, -1.2f); m_corners[3] = m_center + new Vector2(1.2f, -1.2f); HashSet <int> StreetsToRecreate = new HashSet <int>(); List <Cell> PolyPolyCheckList = new List <Cell>(); List <Cell> CellsToCheck = GridManager.m_AllCells; //Sphere Sphere Coll for (int i = 0; i < CellsToCheck.Count; i++) { if (MyCollision.SphereSphere(m_center, 1.7f, CellsToCheck[i].m_PosCenter, CellsToCheck[i].m_Radius)) { PolyPolyCheckList.Add(CellsToCheck[i]); } } //Poly Poly Coll for (int i = 0; i < PolyPolyCheckList.Count; i++) { if (MyCollision.PolyPoly(PolyPolyCheckList[i].m_Corner, m_corners)) { PolyPolyCheckList[i].Delete(); int id = PolyPolyCheckList[i].m_Street.ID; StreetsToRecreate.Add(id); } } //Recreate Grid foreach (int i in StreetsToRecreate) { Street s = StreetComponentManager.GetStreetByID(i); GridManager.RemoveGridMesh(s); MeshGenerator.CreateGridMesh(s, s.m_GridObj.GetComponent <MeshFilter>(), s.m_GridRenderer); } }
public void SetID() { ID = StreetComponentManager.GetNewStreetComponentID(); }