源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

747 line
21 KiB

  1. SapManager = SapManager or BaseClass()
  2. local SapManager = SapManager
  3. local Status = Status
  4. local Time = Time
  5. local ScreenWidth = ScreenWidth
  6. local ScreenHeight = ScreenHeight
  7. local table_insert = table.insert
  8. local table_sort = table.sort
  9. SapManager.CONST_X_SIZE = 3000
  10. SapManager.CONST_Y_SIZE = 3000
  11. SapManager.XSize = 3000
  12. SapManager.YSize = 3000
  13. SapManager.viewDistanceMin = -1000 --视野可见范围最小值 真实值*100
  14. SapManager.viewDistanceMax = 6000 --视野可见范围最大值 真实值*100
  15. SapManager.ObjType =
  16. {
  17. JumpPoint = 1,
  18. NPC = 2,
  19. Door = 3,
  20. Tile = 4,
  21. Effect = 5,
  22. Model = 6,
  23. MoveObj = 7,
  24. SpecialModel = 8,--特殊模型,只摆放在场景装饰用
  25. CacheEffect = 9,
  26. }
  27. SapManager.OperateType =
  28. {
  29. CreateOBJ = 1,
  30. DestoryOBJ = 2,
  31. }
  32. function SapManager:__init()
  33. SapManager.Instance = self
  34. self.callback_func_list = {}
  35. self.objs_list = {}
  36. self.obj_state = {}
  37. self.last_update_time = 0
  38. self.scene_mgr = SceneManager:getInstance()
  39. self.main_camera = MainCamera:getInstance()
  40. self.scene = Scene:getInstance()
  41. self.screen_delta = co.TableXY(100,100)
  42. self.point_list = {}
  43. self.update_frame = 0
  44. self.check_create_far_frame = 0
  45. self.check_create_obj_frame = 0
  46. self.first_check = true
  47. self.main_role_pos = CoVector2.New(0,0)
  48. self.cur_model_pos = CoVector2.New(0,0)
  49. self.is_use_higher_check = false
  50. self.is_enabled = true
  51. self.last_create_effect_time = 0
  52. self.open_model_height_check_mode = false
  53. self.ignore_list = {}
  54. self.create_list = {}
  55. self.deleta_list = {}
  56. self.camera_rect = {}
  57. self.show_bound_max_size = 0
  58. -- if ApplicationPlatform ~= RuntimePlatform.IPhonePlayer then
  59. -- -- 检测模式 true为四叉树检测
  60. -- self.change_check_mode = true
  61. -- end
  62. self.change_check_mode = false
  63. for i=1,9 do
  64. self.point_list[i] = Vector3(0,0,0)
  65. end
  66. --加载完NPC传送点后强制检测一次区域对象
  67. local func = function()
  68. self.lastCamPos = nil
  69. end
  70. GlobalEventSystem:Bind(EventName.NPC_LOAD_FINISH,func)
  71. --小飞鞋传送上天后强制检测一次远景模型加载
  72. local fly_func = function()
  73. self.force_check_far_model_state = true
  74. end
  75. GlobalEventSystem:Bind(SceneEventType.DO_FLYSHOE_EFFECT_FINISH_UP,fly_func)
  76. --小飞鞋落地后强制检测一次SAP清理旧位置对象
  77. local fly_end_func = function()
  78. self.check_create_obj_frame = 1000
  79. self.check_create_far_frame = 1000
  80. self.force_check_far_model_state = true
  81. end
  82. GlobalEventSystem:Bind(SceneEventType.DO_FLYSHOE_EFFECT_FINISH_DOWN,fly_end_func)
  83. local scene_change_func = function()
  84. self.initTree = false
  85. end
  86. GlobalEventSystem:Bind(SceneEventType.SCENE_CHANGED, scene_change_func)
  87. end
  88. function SapManager:getInstance()
  89. if SapManager.Instance == nil then
  90. SapManager.New()
  91. end
  92. return SapManager.Instance
  93. end
  94. --[[ func结构
  95. operate:
  96. type:
  97. data:
  98. ]]
  99. function SapManager:RegisterCallbackFunc( func )
  100. table_insert(self.callback_func_list,func)
  101. end
  102. --[[ obj结构
  103. id:
  104. obj_type: SapManager.ObjType
  105. pos: co.TableXY
  106. size: co.TableXY
  107. ]]
  108. function SapManager:RegisterObj(obj)
  109. local id = obj.type .. "-" .. obj.id
  110. if not self.objs_list[id] then
  111. obj.size.z = obj.size.z or 1
  112. obj.bound_offset = obj.bound_offset or co.TableXYZ(0,0,0)
  113. obj.bound_offset.z = obj.bound_offset.z or 0
  114. obj.pos.z = obj.pos.z or 0
  115. obj.rect = {center = obj.pos,
  116. x1 = obj.pos.x - obj.size.x/2 + obj.bound_offset.x, y1 = obj.pos.y - obj.size.y/2 + obj.bound_offset.y, z1 = obj.pos.z - obj.size.z/2 + obj.bound_offset.z,
  117. x2 = obj.pos.x + obj.size.x/2 + obj.bound_offset.x, y2 = obj.pos.y + obj.size.y/2 + obj.bound_offset.y, z2 = obj.pos.z + obj.size.z/2 + obj.bound_offset.z,}
  118. self.objs_list[id] = obj
  119. self.obj_state[id] = false
  120. if self.change_check_mode then
  121. self:InsertTree(obj)
  122. end
  123. else
  124. logWarn("SapManager:RegisterObj id is registered",id)
  125. end
  126. end
  127. function SapManager:UnRegisterObj(obj_type,obj_index)
  128. local id = obj_type .. "-" .. obj_index
  129. if self.objs_list[id] then
  130. if self.obj_state[id] then
  131. local obj = self.objs_list[id]
  132. for k,func in pairs(self.callback_func_list) do
  133. func(SapManager.OperateType.DestoryOBJ,obj.type,obj.id)
  134. end
  135. end
  136. self.objs_list[id] = nil
  137. self.obj_state[id] = nil
  138. if self.change_check_mode then
  139. self:ClearTreeObj(id)
  140. end
  141. end
  142. end
  143. function SapManager:IsInScreen(screen_pos)
  144. if screen_pos.x > 0 and screen_pos.x < ScreenWidth + self.screen_delta.x and screen_pos.y > 0 and screen_pos.y < ScreenHeight + self.screen_delta.y then
  145. return true
  146. else
  147. return false
  148. end
  149. end
  150. function SapManager:IsOutSide(val1)
  151. if val1 > SapManager.viewDistanceMax or val1 < SapManager.viewDistanceMin then
  152. return true
  153. else
  154. return false
  155. end
  156. end
  157. --使用更加精细的检测模式
  158. function SapManager:SetUseCarefulCheckMode(bool, close_dis_check)
  159. self.is_use_higher_check = bool
  160. self.is_close_dis_check = close_dis_check
  161. end
  162. --[[
  163. ]]
  164. function SapManager:InRect( r1, obj)
  165. local r2 = obj.rect
  166. local is_far = obj.is_far
  167. if self.is_use_higher_check then
  168. if obj.is_far == false and obj.type == SapManager.ObjType.Model then
  169. --if SystemMemoryLevel.Cur == SystemMemoryLevel.Hight then --高端机采用更精确算法
  170. r2 = {x1 = obj.rect.x1,y1 = obj.rect.z1 , z1 = obj.rect.y1,
  171. x2 = obj.rect.x2,y2 = obj.rect.z2 , z2 = obj.rect.y2,
  172. center = obj.rect.center}
  173. is_far = true
  174. --end
  175. end
  176. end
  177. if is_far then
  178. if not obj.is_far then
  179. if self:InSmallRect(r1,r2) then
  180. return true
  181. end
  182. end
  183. self.cur_model_pos.x = obj.rect.center.x
  184. self.cur_model_pos.y = obj.rect.center.z
  185. local dis = CoVector2.distance(self.main_role_pos,self.cur_model_pos)
  186. if not self.is_close_dis_check and self:IsOutSide(dis)then
  187. return false
  188. end
  189. --判断条件:包围盒的任意一个顶点在屏幕内,就认为能看到
  190. self.point_list[1].x,self.point_list[1].y,self.point_list[1].z = r2.x1,r2.y1,r2.z1
  191. self.point_list[2].x,self.point_list[2].y,self.point_list[2].z = r2.x2,r2.y1,r2.z1
  192. self.point_list[3].x,self.point_list[3].y,self.point_list[3].z = r2.x2,r2.y1,r2.z2
  193. self.point_list[4].x,self.point_list[4].y,self.point_list[4].z = r2.x1,r2.y1,r2.z2
  194. self.point_list[5].x,self.point_list[5].y,self.point_list[5].z = r2.x1,r2.y2,r2.z1
  195. self.point_list[6].x,self.point_list[6].y,self.point_list[6].z = r2.x1,r2.y2,r2.z2
  196. self.point_list[7].x,self.point_list[7].y,self.point_list[7].z = r2.x2,r2.y2,r2.z1
  197. self.point_list[8].x,self.point_list[8].y,self.point_list[8].z = r2.x2,r2.y2,r2.z2
  198. self.point_list[9].x,self.point_list[9].y,self.point_list[9].z = r2.center.x,r2.center.y,r2.center.z
  199. local screen_pos = 1
  200. for i,v in ipairs(self.point_list) do
  201. screen_pos = self.main_camera:WorldToScreenPoint(v/MainCamera.PixelsToUnits)
  202. if self:IsInScreen(screen_pos) then
  203. return true
  204. end
  205. end
  206. return false
  207. end
  208. local state = self:InSmallRect(r1,r2)
  209. if state and self.open_model_height_check_mode and obj.type == SapManager.ObjType.Model then
  210. local offset = obj.pos.z - self.role_height
  211. if offset > 3000 or offset < -3000 then
  212. state = false
  213. end
  214. end
  215. return state
  216. end
  217. function SapManager:InSmallRect(r1,r2)
  218. local l1 = (r1.x1+r1.x2)*0.5-(r2.x1+r2.x2)*0.5 -- 2个包围盒的中心点的距离
  219. local l2 = (r1.x2+r2.x2-r1.x1-r2.x1)*0.5 -- [(r1.x2 - r1.x1) + (r2.x2 - r2.x1)] * 0.5 两个包围盒长的总和的一半
  220. local s1 = (r1.y1+r1.y2)*0.5-(r2.y1+r2.y2)*0.5
  221. local s2 = (r1.y2+r2.y2-r1.y1-r2.y1)*0.5
  222. if l1 < 0 then
  223. l1 = -l1
  224. end
  225. if l2 < 0 then
  226. l2 = -l2
  227. end
  228. if s1 < 0 then
  229. s1 = -s1
  230. end
  231. if s2 < 0 then
  232. s2 = -s2
  233. end
  234. if l1 < l2 and s1 < s2 then
  235. return true
  236. end
  237. return false
  238. end
  239. function SapManager:Update( cam_pos )
  240. if not self.is_enabled then
  241. return
  242. end
  243. if self.show_bound_max_size > 0 then
  244. self:DebugDrawBound(cam_pos)
  245. end
  246. self.update_frame = self.update_frame + 1
  247. self.check_create_far_frame = self.check_create_far_frame + 1
  248. self.check_create_obj_frame = self.check_create_obj_frame + 1
  249. if not self.scene:IsSceneLoaded() then
  250. self.first_check = true
  251. self.last_create_effect_time = 0
  252. return
  253. end
  254. if cam_pos and self.lastCamPos then
  255. local x_offset = cam_pos.x - self.lastCamPos.x
  256. local y_offset = cam_pos.y - self.lastCamPos.y
  257. local small_offset = 100
  258. if ( x_offset < small_offset and x_offset > -small_offset ) and ( y_offset < small_offset and y_offset > -small_offset ) then
  259. if not self.force_check_far_model_state and not self.wait_load_terrain_finish and not self.wait_load_particle_finish then
  260. return
  261. end
  262. end
  263. end
  264. if Time.time - self.last_update_time < 0.1 and not self.wait_load_terrain_finish and not self.wait_load_particle_finish then
  265. return
  266. end
  267. local main_role = self.scene:GetMainRole()
  268. if not main_role then
  269. return
  270. end
  271. self.main_role_pos.x = main_role.real_pos.x
  272. self.main_role_pos.y = main_role.real_pos.y
  273. self.last_update_time = Time.time
  274. if self.lastCamPos == nil then
  275. self.lastCamPos = {x = cam_pos.x, y = cam_pos.y}
  276. else
  277. self.lastCamPos.x = cam_pos.x
  278. self.lastCamPos.y = cam_pos.y
  279. end
  280. local scale = self.main_camera:GetCameraRatio()
  281. self.role_height = main_role.obj_pos_height * MainCamera.PixelsToUnits
  282. local low_offset = 1
  283. if SystemMemoryLevel.Cur == SystemMemoryLevel.Low then
  284. low_offset = 0.8
  285. if SystemRuntimePlatform.IsIphone() then
  286. low_offset = 0.6
  287. end
  288. end
  289. --跳跃的时候摄像机变高了,会影响视野范围,这里增加一个参数做偏移
  290. --0.1 这个参数如果最大跳跃高度改变了,可能需要调整
  291. local jump_offset = 0
  292. if main_role then
  293. jump_offset = (main_role.jump_height)/MainCamera.PixelsToUnits*0.15
  294. end
  295. scale = scale + jump_offset
  296. local now_width = SapManager.XSize * scale * low_offset
  297. local now_height = SapManager.YSize * scale * low_offset
  298. self.camera_rect.x1 = cam_pos.x - now_width * 0.7
  299. self.camera_rect.y1 = cam_pos.y - now_height * 0.3
  300. self.camera_rect.x2 = cam_pos.x + now_width * 0.7
  301. self.camera_rect.y2 = cam_pos.y + now_height * 1
  302. if MapView.OpenSceneOperate then
  303. self.camera_rect.y1 = cam_pos.y - now_height * 1
  304. end
  305. --远景对象一秒检测1次
  306. local check_far = false
  307. if self.update_frame > 60 then
  308. check_far = true
  309. self.update_frame = 0
  310. self.force_check_far_model_state = false
  311. end
  312. --已创建的远景对象5秒才检测是否要销毁
  313. local check_create_far = false
  314. if self.check_create_far_frame > 300 then
  315. check_create_far = true
  316. self.check_create_far_frame = 0
  317. end
  318. --已创建的场景对象3秒才检测是否要销毁
  319. local check_create_obj = false
  320. if self.check_create_obj_frame > 180 or SystemRuntimePlatform.IsIphone() then
  321. check_create_obj = true
  322. self.check_create_obj_frame = 0
  323. end
  324. --local cur_time = os.clock()
  325. if self.change_check_mode then
  326. if self.initTree then -- 初始化判断
  327. self:CheckChild(self.objTree,check_far,check_create_far,check_create_obj)
  328. end
  329. else
  330. self:CheckObj(check_far,check_create_far,check_create_obj)
  331. end
  332. if self.deleta_list then
  333. for key,id in pairs(self.deleta_list) do
  334. local obj = self.objs_list[id]
  335. for k,func in pairs(self.callback_func_list) do
  336. if obj.type == SapManager.ObjType.CacheEffect then
  337. func(SapManager.OperateType.DestoryOBJ,obj.type,obj.data.obj.obj_name)
  338. else
  339. func(SapManager.OperateType.DestoryOBJ,obj.type,obj.id)
  340. end
  341. end
  342. self.deleta_list[key] = nil
  343. end
  344. end
  345. if self.create_list then
  346. local sort_func = function(a,b)
  347. local i = self.objs_list[a]
  348. local j = self.objs_list[b]
  349. local di = co.PointDistance(i.pos,main_role.real_pos)
  350. local dj = co.PointDistance(j.pos,main_role.real_pos)
  351. if di < dj then
  352. return true
  353. end
  354. end
  355. table_sort(self.create_list,sort_func)
  356. for key,id in ipairs(self.create_list) do
  357. local obj = self.objs_list[id]
  358. for k,func in pairs(self.callback_func_list) do
  359. func(SapManager.OperateType.CreateOBJ,obj.type,obj.data)
  360. end
  361. self.create_list[key] = nil
  362. end
  363. end
  364. self.first_check = false
  365. end
  366. -- 递归遍历树节点
  367. function SapManager:CheckChild(parent,check_far,check_create_far,check_create_obj)
  368. for id,v in pairs(parent.obj) do
  369. local obj = self.objs_list[v]
  370. if not self.ignore_list[id] and (not obj.is_far or self.first_check or check_far) then
  371. if obj.is_far and self.obj_state[id] and not check_create_far then
  372. --已经加载的远景对象未到检测周期
  373. else
  374. if self.obj_state[id] and not check_create_obj then
  375. --已经加载的场景对象未到检测周期
  376. else
  377. if self:InRect(self.camera_rect,obj) then
  378. if not self.obj_state[id] then
  379. self.obj_state[id] = true
  380. table_insert(self.create_list,id)
  381. end
  382. else
  383. if self.obj_state[id] then
  384. self.obj_state[id] = false
  385. table_insert(self.deleta_list,id)
  386. end
  387. end
  388. end
  389. end
  390. end
  391. end
  392. for i,v in pairs(parent.childs) do
  393. if self:InSmallRect(self.camera_rect,v.rect) or parent.has_far==1 then
  394. self:CheckChild(v,check_far,check_create_far,check_create_obj)
  395. end
  396. end
  397. end
  398. -- 全遍历场景物体
  399. function SapManager:CheckObj(check_far,check_create_far,check_create_obj)
  400. for id,obj in pairs(self.objs_list) do
  401. if not self.ignore_list[id] and (not obj.is_far or self.first_check or check_far) then
  402. if obj.is_far and self.obj_state[id] and not check_create_far then
  403. --已经加载的远景对象未到检测周期
  404. else
  405. if self.obj_state[id] and not check_create_obj then
  406. --已经加载的场景对象未到检测周期
  407. else
  408. if self:InRect(self.camera_rect,obj) then
  409. if not self.obj_state[id] then
  410. --限制场景特效创建间隔
  411. local delay_state = false
  412. --[[
  413. if obj.type == SapManager.ObjType.Effect then
  414. if cur_time - self.last_create_effect_time <= 0.5 then
  415. delay_state = true
  416. else
  417. self.last_create_effect_time = cur_time
  418. end
  419. end
  420. ]]
  421. if not delay_state then
  422. self.obj_state[id] = true
  423. if self.create_list == nil then
  424. self.create_list = {}
  425. end
  426. table_insert(self.create_list,id)
  427. end
  428. end
  429. else
  430. if self.obj_state[id] then
  431. self.obj_state[id] = false
  432. if self.deleta_list == nil then
  433. self.deleta_list = {}
  434. end
  435. table_insert(self.deleta_list,id)
  436. end
  437. end
  438. end
  439. end
  440. end
  441. end
  442. end
  443. function SapManager:SetEnabled(bool)
  444. self.is_enabled = bool
  445. end
  446. function SapManager:AddIgnoreObj(id)
  447. self.ignore_list[id]=true
  448. self.obj_state[id] = false
  449. local obj = self.objs_list[id]
  450. if obj then
  451. for k,func in pairs(self.callback_func_list) do
  452. func(SapManager.OperateType.DestoryOBJ,obj.type,obj.id)
  453. end
  454. end
  455. end
  456. function SapManager:RemoveIgnoreObj(id)
  457. self.ignore_list[id]=nil
  458. end
  459. function SapManager:ForceCheckFarModelLoad()
  460. self.force_check_far_model_state = true
  461. end
  462. function SapManager:WaitLoadTerrainFinish(state)
  463. self.wait_load_terrain_finish = state
  464. end
  465. function SapManager:WaitLoadParticleFinish(state)
  466. self.wait_load_particle_finish = state
  467. end
  468. function SapManager:OpenModelHeightCheckMode( state )
  469. self.open_model_height_check_mode = state
  470. end
  471. ---------使用四叉树管理物体-----------
  472. function SapManager:InitTree()
  473. local map_size = MapView:getInstance():GetMapSize()
  474. local max_size = math.max(map_size.x, map_size.y)
  475. self.maxDepth = max_size > 22000 and 4 or 3
  476. self.objTree = {
  477. depth = 0,
  478. obj = {},
  479. childs= {},
  480. rect = {
  481. x1 = 0, y1 = 0,
  482. x2 = max_size, y2 = max_size,
  483. },
  484. }
  485. local scene_id = SceneManager.Instance:GetSceneId()
  486. -- 全加载地图
  487. if scene_id and MapView.AllLoadScene[scene_id] then
  488. self.maxDepth = 0
  489. end
  490. end
  491. -- 创建树节点
  492. function SapManager:CreatTreeNode(parent, i, obj_rect)
  493. local rect = parent.rect
  494. local pos_x = (rect.x2 + rect.x1) * 0.5
  495. local pos_y = (rect.y2 + rect.y1) * 0.5
  496. local rect_size = (rect.x2 - pos_x) * 0.5
  497. if i == 1 then
  498. pos = {x = pos_x + rect_size, y = pos_y + rect_size}
  499. elseif i == 2 then
  500. pos = {x = pos_x + rect_size, y = pos_y - rect_size}
  501. elseif i == 3 then
  502. pos = {x = pos_x - rect_size, y = pos_y - rect_size}
  503. else
  504. pos = {x = pos_x - rect_size, y = pos_y + rect_size}
  505. end
  506. local child_rect = {
  507. x1 = pos.x - rect_size, y1 = pos.y - rect_size,
  508. x2 = pos.x + rect_size, y2 = pos.y + rect_size,
  509. }
  510. -- 包含obj才创建节点
  511. if not self:InBound(child_rect,obj_rect) then return end
  512. parent.childs[i] = {
  513. depth = parent.depth + 1,
  514. obj = {},
  515. childs = {},
  516. rect = child_rect,
  517. }
  518. return parent.childs[i]
  519. end
  520. -- obj插入树,obj被子节点包含时,添加到子节点,否则添加到父节点
  521. function SapManager:InsertTree(obj)
  522. if not self.initTree then
  523. self:InitTree()
  524. self.initTree = true
  525. end
  526. local rect = obj.rect
  527. local id = obj.type .. "-" .. obj.id
  528. local is_far = obj.is_far and 1 or 0
  529. local Insert
  530. Insert = function ( parent)
  531. -- 标志有无远物
  532. parent.has_far = parent.has_far == 1 and 1 or is_far
  533. local inBound = false
  534. for i = 1,4 do
  535. local is_creat = false
  536. local child = parent.childs[i]
  537. if not child then
  538. -- 动态添加子节点
  539. child = self:CreatTreeNode(parent, i,rect)
  540. is_creat = true
  541. end
  542. if child and (is_creat or self:InBound(child.rect,rect)) then
  543. if child.depth < self.maxDepth then
  544. Insert(child)
  545. else
  546. if child.obj[id] == nil then
  547. -- 只存id,减少消耗
  548. child.obj[id] = id
  549. end
  550. end
  551. inBound = true
  552. break
  553. end
  554. end
  555. if not inBound and parent.obj[id] == nil then
  556. parent.obj[id] = id
  557. end
  558. end
  559. Insert(self.objTree)
  560. end
  561. -- r1 包含 r2
  562. function SapManager:InBound(r1,r2)
  563. if r1.x1 <= r2.x1 and r1.y1 <= r2.y1 and r1.x2 >= r2.x2 and r1.y2 >= r2.y2 then
  564. return true
  565. end
  566. return false
  567. end
  568. function SapManager:ClearTreeObj( id )
  569. local clearTree
  570. clearTree = function(parent)
  571. if parent.obj[id] then
  572. parent.obj[id] = nil
  573. return
  574. end
  575. parent.has_far = 0
  576. for i,v in pairs(parent.childs) do
  577. clearTree(v)
  578. end
  579. end
  580. clearTree(self.objTree)
  581. end
  582. -- 编辑器窗口下显示检测区域
  583. function SapManager:DebugDrawBound(cam_pos)
  584. if self.initTree and self.camera_rect.x1 and self.change_check_mode then
  585. self:DebugDrawBoundByRect(self.camera_rect,Color.red)
  586. local showChild
  587. showChild = function(parent)
  588. local len = TableSize(parent.obj)
  589. if len > 0 then
  590. for id,v in pairs(parent.obj) do
  591. local obj = self.objs_list[id]
  592. local r = obj.rect
  593. if obj and obj.size and obj.size.x < self.show_bound_max_size then
  594. if self:InRect(self.camera_rect,obj) then
  595. self:DebugDrawBoundByRect(r,Color.green)
  596. else
  597. self:DebugDrawBoundByRect(r,Color(1, 1, 1, 0.6))
  598. end
  599. end
  600. end
  601. end
  602. --local color = self:GetColorByDepth(parent.depth)
  603. self:DebugDrawBoundByRect(parent.rect,color)
  604. if TableSize(parent.childs) == 0 then return end
  605. for i,v in pairs(parent.childs) do
  606. -- 进入区域才检测
  607. if self:InSmallRect(self.camera_rect,v.rect) or parent.has_far==1 then
  608. showChild(v)
  609. end
  610. end
  611. end
  612. showChild(self.objTree)
  613. end
  614. -- 兼容遍历模式的区域显示
  615. if not self.change_check_mode and self.camera_rect.x1 then
  616. self:DebugDrawBoundByRect(self.camera_rect,Color.red)
  617. for id,obj in pairs(self.objs_list) do
  618. if obj.size and obj.size.x < self.show_bound_max_size then
  619. local r = obj.rect
  620. if self:InRect(self.camera_rect,obj) then
  621. self:DebugDrawBoundByRect(r,Color.green)
  622. else
  623. self:DebugDrawBoundByRect(r,Color(1, 1, 1, 0.6))
  624. end
  625. end
  626. end
  627. end
  628. end
  629. function SapManager:GetColorByDepth( depth )
  630. --最底层蓝色
  631. if depth == self.maxDepth then
  632. return Color.blue
  633. end
  634. end
  635. function SapManager:DebugDrawBoundByRect(r,color)
  636. color = color or Color.yellow
  637. r.z1 = r.z1 or -3000
  638. r.z2 = r.z2 or 5000
  639. if not self.point then
  640. self.point = {}
  641. for i=1,9 do
  642. self.point[i] = Vector3(0,0,0)
  643. end
  644. end
  645. self.point[1].x,self.point[1].z,self.point[1].y = r.x1/100,r.y1/100,r.z1/100
  646. self.point[2].x,self.point[2].z,self.point[2].y = r.x2/100,r.y1/100,r.z1/100
  647. self.point[3].x,self.point[3].z,self.point[3].y = r.x2/100,r.y1/100,r.z2/100
  648. self.point[4].x,self.point[4].z,self.point[4].y = r.x1/100,r.y1/100,r.z2/100
  649. self.point[5].x,self.point[5].z,self.point[5].y = r.x1/100,r.y2/100,r.z1/100
  650. self.point[6].x,self.point[6].z,self.point[6].y = r.x1/100,r.y2/100,r.z2/100
  651. self.point[7].x,self.point[7].z,self.point[7].y = r.x2/100,r.y2/100,r.z1/100
  652. self.point[8].x,self.point[8].z,self.point[8].y = r.x2/100,r.y2/100,r.z2/100
  653. UnityEngine.Debug.DrawLine(self.point[1], self.point[2],color);
  654. UnityEngine.Debug.DrawLine(self.point[2], self.point[3],color);
  655. UnityEngine.Debug.DrawLine(self.point[3], self.point[4],color);
  656. UnityEngine.Debug.DrawLine(self.point[4], self.point[1],color);
  657. UnityEngine.Debug.DrawLine(self.point[4], self.point[6],color);
  658. UnityEngine.Debug.DrawLine(self.point[3], self.point[8],color);
  659. UnityEngine.Debug.DrawLine(self.point[2], self.point[7],color);
  660. UnityEngine.Debug.DrawLine(self.point[1], self.point[5],color);
  661. UnityEngine.Debug.DrawLine(self.point[5], self.point[6],color);
  662. UnityEngine.Debug.DrawLine(self.point[6], self.point[8],color);
  663. UnityEngine.Debug.DrawLine(self.point[8], self.point[7],color);
  664. UnityEngine.Debug.DrawLine(self.point[7], self.point[5],color);
  665. end
  666. function SapManager:ChangeSize( size)
  667. self.show_bound_max_size = size or self.show_bound_max_size
  668. end