/// <summary> /// Initialize the DeadEnd /// </summary> /// <param name="_comp">The Street the Dead End is connected to</param> /// <param name="_isStart">Is it the Start of the Street?</param> /// <param name="_op">The OrientedPoint of the DeadEnd</param> /// <returns>The new Dead End</returns> public DeadEnd Init(Street _comp, bool _isStart, OrientedPoint _op) { base.Init(false); ID = -2; m_Shape = new DeadEndShape(); SetStartConnection(new Connection(null, this, true)); if (_isStart) { //Move the Start Point half the width of the Street | Street width is 2 Vector3 start = _op.Position + (_op.Rotation * -Vector3.right) * 0.5f; //Move the Tangent 1 up above the start Point Vector3 tangent1 = start - _op.Rotation * Vector3.forward * 0.8f; //Move the End Point half the width of the Street | Street width is 2 Vector3 end = _op.Position + (_op.Rotation * Vector3.right) * 0.5f; //Move the Tangent 2 up above the end Point Vector3 tangent2 = end - _op.Rotation * Vector3.forward * 0.8f; m_Spline = new Spline( start, tangent1, tangent2, end, 10, this ); Connection.Combine(GetStartConnection(), _comp.GetStartConnection()); } else { //Move the Start Point half the width of the Street | Street width is 2 Vector3 start = _op.Position + (_op.Rotation * Vector3.right) * 0.5f; //Move the Tangent 1 up above the start Point Vector3 tangent1 = start + _op.Rotation * Vector3.forward * 0.8f; //Move the End Point half the width of the Street | Street width is 2 Vector3 end = _op.Position + (_op.Rotation * -Vector3.right) * 0.5f; //Move the Tangent 2 up above the end Point Vector3 tangent2 = end + _op.Rotation * Vector3.forward * 0.8f; m_Spline = new Spline( start, tangent1, tangent2, end, 10, this ); Connection.Combine(GetStartConnection(), _comp.m_EndConnection); } m_MeshFilter = gameObject.AddComponent <MeshFilter>(); m_MeshRenderer = gameObject.AddComponent <MeshRenderer>(); m_MeshRenderer.material = StreetComponentManager.Instance.DeadEndMat; transform.SetParent(_comp.transform); MeshGenerator.Extrude(this); return(this); }
private static Street CreateCollisionStreet(Vector3 _startPos, Vector3 _tangent1, Vector3 _tangent2, Vector3 _endPos, Connection _startConnection, Connection _endConnection) { GameObject obj = new GameObject("Street_Col"); obj.transform.position = _startPos; obj.layer = 8; obj.transform.SetParent(Instance.StreetCollisionParent.transform); MeshFilter mf = obj.gameObject.AddComponent <MeshFilter>(); MeshRenderer mr = obj.gameObject.AddComponent <MeshRenderer>(); mr.material = Instance.streetMatColl; Street s = obj.gameObject.AddComponent <Street>(); Vector3[] pos = new Vector3[] { _startPos, _tangent1, _tangent2, _endPos }; s.Init(pos, null, null, 20, false); return(s); }
/// <summary> /// Initialize / Create a CollisionStreet for the Preview /// </summary> /// <param name="_startPos"></param> /// <returns></returns> public static Street InitStreetForPreviewColl(Vector3 _startPos) { GameObject obj = new GameObject("StreetColl_Preview"); obj.transform.position = _startPos; obj.layer = 8; obj.transform.SetParent(Instance.StreetCollisionParent.transform); obj.gameObject.AddComponent <MeshFilter>(); MeshRenderer mr = obj.gameObject.AddComponent <MeshRenderer>(); mr.material = Instance.previewStreetMatColl; Street s = obj.gameObject.AddComponent <Street>(); Vector3[] pos = new Vector3[] { _startPos, _startPos, _startPos, _startPos }; s.Init(pos, null, null, 20, false, true); return(s); }
/// <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 SetCollisionStreet(Street _collStreet) { m_collisionStreet = _collStreet; }