|
---------------移动跨场景寻路操作包----------------
|
|
|
|
SourceOperateCrossSceneAction = SourceOperateCrossSceneAction or BaseClass(SourceOperate)
|
|
local SourceOperateCrossSceneAction = SourceOperateCrossSceneAction
|
|
function SourceOperateCrossSceneAction:__init(scene_id, end_pos, change_scene_callback, action_func, arg_list)
|
|
|
|
self.type = OperateManager.SourceOperateType.CrossScene
|
|
|
|
self.init_time = 0
|
|
|
|
self.src_scene_id = SceneManager.Instance:GetSceneId()
|
|
self.target_scene_id = scene_id
|
|
self.target_scene_pos = end_pos
|
|
self.change_scene_callback = change_scene_callback
|
|
self.action_func = action_func
|
|
self.arg_list = arg_list
|
|
|
|
self.is_path_valid = false
|
|
self.path_list = nil
|
|
|
|
self.now_move_src_oper = false
|
|
self.scene_path = nil
|
|
|
|
self.now_scene_id = nil
|
|
|
|
end
|
|
|
|
function SourceOperateCrossSceneAction:__delete( )
|
|
if self.now_move_src_oper then
|
|
self.now_move_src_oper:DeleteMe()
|
|
self.now_move_src_oper = false
|
|
end
|
|
end
|
|
|
|
function SourceOperateCrossSceneAction:Init()
|
|
self.init_time = Status.NowTime
|
|
|
|
local target_scene_info = ConfigItemMgr.Instance:GetSceneItem(self.target_scene_id)
|
|
if not target_scene_info then
|
|
return false
|
|
end
|
|
|
|
self.scene_path = SceneConnectMap.Instance:FindPath(self.src_scene_id, self.target_scene_id)
|
|
|
|
|
|
if List.Empty(self.scene_path) then
|
|
return false
|
|
end
|
|
return true
|
|
|
|
end
|
|
|
|
function SourceOperateCrossSceneAction:BeforeDelete()
|
|
local now_scene_id = SceneManager.Instance:GetSceneId()
|
|
local cur_src_oper = self.now_move_src_oper
|
|
if not self.is_finish and cur_src_oper and cur_src_oper.now_use_pair and cur_src_oper.total_pair and cur_src_oper.now_use_pair < cur_src_oper.total_pair then
|
|
local cross_scene = {id = self.target_scene_id,pos = self.target_scene_pos,change_scene_callback = self.change_scene_callback}
|
|
OperateManager.Instance:CheckJumpAction(cur_src_oper.now_use_pair,cur_src_oper.path_list,self.action_func,self.arg_list,cross_scene)
|
|
end
|
|
end
|
|
|
|
function SourceOperateCrossSceneAction:ClearNowMoveSrcOper()
|
|
if self.now_move_src_oper then
|
|
self.now_move_src_oper:DeleteMe()
|
|
self.now_move_src_oper = false
|
|
end
|
|
end
|
|
|
|
function SourceOperateCrossSceneAction:GetOperImpl()
|
|
local now_scene_id = SceneManager.Instance:GetSceneId()
|
|
--由于现在走到传送门附近就会触发传送,所以可能now_move_src_oper还没完成,就传到另一个场景,导致主角卡住不动了
|
|
--切换了场景,就要删掉
|
|
if self.now_scene_id ~= now_scene_id then
|
|
self:ClearNowMoveSrcOper()
|
|
end
|
|
if self.now_move_src_oper and not self.now_move_src_oper:IsFinish() then
|
|
return self.now_move_src_oper:GetOper()
|
|
end
|
|
|
|
|
|
if self.src_scene_id ~= now_scene_id and self.change_scene_callback then
|
|
local is_finish = self.change_scene_callback(now_scene_id)
|
|
if is_finish ~= nil and is_finish == true then
|
|
self.is_finish = true --由外部来终止这个操作包
|
|
return self:GenerateNop(0.2)
|
|
end
|
|
end
|
|
|
|
if self.now_scene_id == now_scene_id then
|
|
return self:GenerateNop(0.2)
|
|
elseif not Scene.Instance:IsSceneLoaded() then
|
|
return self:GenerateNop(0.2)
|
|
end
|
|
|
|
if self.target_scene_id == now_scene_id then
|
|
if self.target_scene_pos then
|
|
self.now_move_src_oper = SourceOperateMove.New(self.target_scene_pos, nil)
|
|
self.target_scene_pos = nil
|
|
else
|
|
self.is_finish = true
|
|
if self.action_func then
|
|
self.action_func(unpack(self.arg_list))
|
|
end
|
|
return self:GenerateNop(0.2)
|
|
end
|
|
else
|
|
if self.scene_path == nil then
|
|
return nil
|
|
end
|
|
|
|
local path_now_scene_id = List.PopFront(self.scene_path)
|
|
if path_now_scene_id ~= now_scene_id then
|
|
self.is_finish = true
|
|
return self:GenerateNop(0.2)
|
|
end
|
|
|
|
local now_target_scene_id = List.GetFront(self.scene_path)
|
|
local door_info = SceneManager.Instance:GetSceneDoorInfo(now_target_scene_id, path_now_scene_id)
|
|
if not door_info then
|
|
self.is_finish = true
|
|
return self:GenerateNop(0.2)
|
|
end
|
|
|
|
self.now_scene_id = now_scene_id
|
|
|
|
local door_pos = co.TableXY(door_info.x / SceneObj.LogicRealRatio.x, door_info.y / SceneObj.LogicRealRatio.y)
|
|
local cross_scene_req = function ()
|
|
-- EventSystem.Fire(GlobalEventSystem,SceneEventType.REQUEST_CHANGE_SCENE, door_info.id)
|
|
end
|
|
self.now_move_src_oper = SourceOperateMove.New(door_pos, cross_scene_req, self.arg_list)
|
|
|
|
EventSystem.Fire(GlobalEventSystem,EventName.FINDWAY_STARTED)
|
|
end
|
|
|
|
return self.now_move_src_oper:GetOper()
|
|
end
|