예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        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);
            }
        }