// --------------------------------------------------------------------------------------------------- // // 取某点周围一定范围内的格子内的所有实体 // @param dist : 距离半径(注意,这里不是精确匹配的,是把一个单元格内的所有对象都返回,误差为单元格大小) // --------------------------------------------------------------------------------------------------- // public static IList <EntityView> Nearest(UnityEngine.Vector3 loc, int dist, SPELL.CampFlag flag) { if (m_finder == null) { return(null); } return(m_finder.Nearest(loc, dist, flag)); }
// 这个只能取出基于单元格的近似数据,如需要精确匹配对象的距离,则需要取出去之后应用层再自行比对 public int k_nearest(SPELL.CampFlag flag, UnityEngine.Vector3 v, int dist, ref List <U3D_Render.EntityView> list) { int[,] range = new int[DIM, 2]; int[] loc = new int[2]; loc[0] = (int)v.x; loc[1] = (int)v.z; grid_range(loc, dist, range); return(__k_nearest_loop(flag, loc, range, 0, ref list)); }
// 取某点周围一定范围内的格子内的所有实体 public IList <U3D_Render.EntityView> Nearest(UnityEngine.Vector3 loc, int dist, SPELL.CampFlag flag) { UnityEngine.Vector3 normalLoc = AdjustLoc(loc); List <U3D_Render.EntityView> result = new List <EntityView>(); m_gridTree.k_nearest(flag, normalLoc, dist, ref result); return(result); }
// 获取阵营序号 private INNER_CAMP getCampIndex(SPELL.CampFlag flag) { if (flag == SPELL.CampFlag.CampFlag_Friend || flag == SPELL.CampFlag.CampFlag_Self) { return(INNER_CAMP.CAMP_SELF); } if (flag == SPELL.CampFlag.CampFlag_Enemy) { return(INNER_CAMP.CAMP_ENEMY); } return(INNER_CAMP.CAMP_NEUTRAL); }
public NOD_CheckAroundEntityByPropertyID(int _nPropertyID, int _nSearchNearRadius, SPELL.CampFlag _eCampFlag = SPELL.CampFlag.CampFlag_Enemy) { m_nPropertyID = _nPropertyID; m_nSearchNearRadius = _nSearchNearRadius; m_eCampFlag = _eCampFlag; }
public CON_IsEntityDeadByPropertyID(int _nPropertyID, SPELL.CampFlag _eCampFlag = SPELL.CampFlag.CampFlag_Enemy) { m_nPropertyID = _nPropertyID; m_eCampFlag = _eCampFlag; }
public CON_IsNearbyPropertyIDEntityExit(int _nPropertyID, int _nSearchNearRadius, SPELL.CampFlag _eCampFlag = SPELL.CampFlag.CampFlag_Enemy) { m_nPropertyID = _nPropertyID; m_nSearchNearRadius = _nSearchNearRadius; m_eCampFlag = _eCampFlag; }
int __k_nearest_loop(SPELL.CampFlag flag, int[] travel_loc, int[,] range, int dim, ref List <U3D_Render.EntityView> list) { int[] temp_loc = new int[DIM]; // 用个临时变量效率还高点,直接用travel_loc效率还低,不明白原因 temp_loc = travel_loc; int start = range[dim, 0]; int end = range[dim, 1]; int index = -1; int dimspan = 1; for (int i = start; i <= end; ++i) { if (i < 0 || i >= m_arrGridNum[dim]) { continue; } temp_loc[dim] = m_arrOrigin[dim] + i * m_gridSize; int count = 0; if (dim < DIM - 1) { count = __k_nearest_loop(flag, temp_loc, range, dim + 1, ref list); } else { if (index < 0) { index = loc2index(new UnityEngine.Vector3(temp_loc[0], 0, temp_loc[1])); for (int d = 0; d < dim; ++d) { dimspan *= m_arrGridNum[d]; } } else { index += dimspan; } // 快速取出格子中的所有对象 if (flag == SPELL.CampFlag.CampFlag_Unknow) { Dictionary <UID, U3D_Render.EntityView> result = index2node(index).getAll(); if (result.Count > 0) { list.AddRange(result.Values.ToList <U3D_Render.EntityView>()); } } else { Dictionary <UID, U3D_Render.EntityView> result = index2node(index).getCampEntities(flag); if (result.Count > 0) { list.AddRange(result.Values.ToList <U3D_Render.EntityView>()); } } } } return(list.Count); }
internal Dictionary <UID, U3D_Render.EntityView> getCampEntities(SPELL.CampFlag flag) { return(m_campObjList[getCampIndex(flag)]); }