/// <summary> /// 找到指定位置所在的Grid /// </summary> /// <param name="self"></param> /// <param name="pos"></param> /// <param name="create">没有是否创建</param> public static AOICell GetAOIGrid(this AOISceneComponent self, Vector3 pos, bool create = true) { int xIndex = (int)Math.Floor(pos.x / self.gridLen); int yIndex = (int)Math.Floor(pos.z / self.gridLen); return(self.GetCell(xIndex, yIndex, create)); }
/// <summary> /// 获取指定位置为中心指定圈数的所有格子 /// </summary> /// <param name="self"></param> /// <param name="turnNum"></param> /// <param name="posx"></param> /// <param name="posy"></param> /// <returns></returns> public static ListComponent <AOICell> GetNearbyGrid(this AOISceneComponent self, int turnNum, int posx, int posy) { ListComponent <AOICell> res = ListComponent <AOICell> .Create(); for (int i = 0; i <= turnNum * 2 + 1; i++) { var x = posx - turnNum + i; for (int j = 0; j <= turnNum * 2 + 1; j++) { var y = posy - turnNum + j; res.Add(self.GetCell(x, y)); } } return(res); }