public virtual void Unregister() { if (m_Coords == null || m_Map == null) { return; } for (int i = 0; i < m_Coords.Count; ++i) { object obj = m_Coords[i]; Point2D start, end; if (obj is Rectangle2D) { Rectangle2D r2d = (Rectangle2D)obj; start = m_Map.Bound(r2d.Start); end = m_Map.Bound(r2d.End); } else if (obj is Rectangle3D) { Rectangle3D r3d = (Rectangle3D)obj; start = m_Map.Bound(new Point2D(r3d.Start)); end = m_Map.Bound(new Point2D(r3d.End)); } else { continue; } Sector startSector = m_Map.GetSector(start); Sector endSector = m_Map.GetSector(end); for (int x = startSector.X; x <= endSector.X; ++x) { for (int y = startSector.Y; y <= endSector.Y; ++y) { m_Map.GetRealSector(x, y).OnLeave(this); } } } }
public void Register() { if (m_Registered) { return; } OnRegister(); m_Registered = true; if (m_Parent != null) { m_Parent.m_Children.Add(this); m_Parent.OnChildAdded(this); } m_Regions.Add(this); m_Map.RegisterRegion(this); List <Sector> sectors = new List <Sector>(); for (int i = 0; i < m_Area.Length; i++) { Rectangle3D rect = m_Area[i]; Point2D start = m_Map.Bound(new Point2D(rect.Start)); Point2D end = m_Map.Bound(new Point2D(rect.End)); Sector startSector = m_Map.GetSector(start); Sector endSector = m_Map.GetSector(end); for (int x = startSector.X; x <= endSector.X; x++) { for (int y = startSector.Y; y <= endSector.Y; y++) { Sector sector = m_Map.GetRealSector(x, y); sector.OnEnter(this, rect); if (!sectors.Contains(sector)) { sectors.Add(sector); } } } } m_Sectors = sectors.ToArray(); }
private static bool NextSector( Map map, int x1, int y1, int x2, int y2, ref int index, ref int xSector, ref int ySector, out Sector s ) { if (map == null) { s = null; xSector = ySector = 0; return(false); } if (map == Map.Internal) { s = map.InvalidSector; xSector = ySector = 0; return(false); } if (index++ > 0) { if (++ySector > y2) { ySector = y1; if (++xSector > x2) { xSector = x1; s = map.InvalidSector; return(false); } } } s = map.GetRealSector(xSector, ySector); return(true); }