169 lines
5.4 KiB
Lua
169 lines
5.4 KiB
Lua
SingleStoryPlayerView = {}
|
|
local MapPointConfig = ConfigManager.GetConfig(ConfigName.MapPointConfig)
|
|
|
|
function SingleStoryPlayerView:New(gameObject)
|
|
local b = {}
|
|
b.gameObject = gameObject
|
|
b.transform = gameObject.transform
|
|
setmetatable(b, { __index = SingleStoryPlayerView })
|
|
return b
|
|
end
|
|
|
|
function SingleStoryPlayerView:InitComponent()
|
|
self.roleRoot = Util.GetGameObject(self.gameObject,"roleRoot")
|
|
self.nameDi = Util.GetGameObject(self.gameObject, "nemeDi")
|
|
self.name = Util.GetGameObject(self.nameDi, "name"):GetComponent("Text")
|
|
self.roads = {}
|
|
self.startPos = {}
|
|
end
|
|
|
|
function SingleStoryPlayerView:OnOpen(parent)
|
|
self.parent = parent
|
|
end
|
|
|
|
function SingleStoryPlayerView:SetData(data,playerType)
|
|
if self.playerLiveView then
|
|
self.playerLiveView:OnClose()
|
|
self.playerLiveView = nil
|
|
end
|
|
LogGreen("playerType:"..playerType)
|
|
if playerType == 0 then
|
|
self:SetRoads0(data)
|
|
elseif playerType == 1 then
|
|
self:SetRoads1(data)
|
|
end
|
|
self.gameObject.transform.localPosition = self.startPos
|
|
self.gameObject.transform.localScale = Vector3.one * 1.5
|
|
end
|
|
|
|
function SingleStoryPlayerView:SetRoads0(data)
|
|
for i = 2 ,#data do
|
|
local road = {}
|
|
road.indexType = 0
|
|
local vecs = string.split(data[i],',')
|
|
road.vec = Vector3.New(tonumber(vecs[1] or 0),tonumber(vecs[2] or 0),tonumber(vecs[2] or 0))
|
|
table.insert(self.roads,road)
|
|
end
|
|
self.startPos = self.roads[1].vec
|
|
local pointId = data[1]
|
|
self.playerLiveView = MonsterLiveView.New(self.roleRoot,pointId)
|
|
end
|
|
|
|
function SingleStoryPlayerView:SetRoads1(data)
|
|
self.playerLiveView = PlayerLiveView:New(self.roleRoot,1,nil)
|
|
self.playerLiveView:OnOpen(GetPlayerRoleSingleConFig().Scale2)
|
|
self.playerLiveView.name = "npc"
|
|
self:SetWalkDir(WALK_DIR.IDLE_BACK)
|
|
PlayUIAnim(self.gameObject)
|
|
for i = 1 ,#data do
|
|
local road = {}
|
|
road.indexType = tonumber(data[i][1]) --这个点是人的还是地图的
|
|
local vecs = string.split(data[i][2],',')
|
|
road.vec = Vector3.New(tonumber(vecs[1] or 0),tonumber(vecs[2] or 0),tonumber(vecs[2] or 0))
|
|
table.insert(self.roads,road)
|
|
end
|
|
self.startPos = self.roads[1].vec
|
|
end
|
|
|
|
function SingleStoryPlayerView:SetWalkDir(dir)
|
|
self.playerLiveView:SetWalkDir(dir)
|
|
end
|
|
|
|
function SingleStoryPlayerView:RunMap(pathList)
|
|
if not pathList or #pathList == 0 then
|
|
self.parent.AsideTriggerJudge(self.roleCurPos,self.isSelf,self)
|
|
return
|
|
end
|
|
|
|
-- --把最终回调最先入栈
|
|
-- self.callList:Push(function ()
|
|
-- local eventPoint = self.parent.AsideTriggerJudge(self.roleCurPos,self.isSelf,self)
|
|
-- self:RoleWalkEnd(eventPoint)
|
|
-- end)
|
|
|
|
for i=1, #pathList-1 do --最后的点为起点,不处理
|
|
local data = pathList[i]
|
|
local v3 = TileMapView.GetLiveTilePos(data.u, data.v)
|
|
self.callList:Push(function ()
|
|
self:SetRoleDirAction(data.u, data.v)
|
|
self.roleCurPos = data
|
|
local speed = 0.5
|
|
self.gameObject.transform:DOLocalMove(Vector3(v3.x, v3.y, v3.z - 10), speed, false):OnStart(function () end):OnUpdate(function() --TODO:测试速度
|
|
self:PlayStepSound()
|
|
if self.isSelf then
|
|
local v4 = self.gameObject.transform.localPosition
|
|
v4.z = TileMapView.ViewCameraPos.z
|
|
TileMapView.SetCameraPos(v4)
|
|
end
|
|
end):OnComplete(function ()
|
|
self.parent.AsideTriggerJudge(data,self.isSelf,self)
|
|
--self:SetRoleHitTarget()
|
|
if self.state == 0 then
|
|
self:StackPop()
|
|
end
|
|
end):SetEase(Ease.Linear)
|
|
end)
|
|
end
|
|
self:StackPop()
|
|
self:PlayerMove()
|
|
end
|
|
|
|
-- 角色停止行走时的朝向
|
|
function SingleStoryPlayerView:SetRoleDir(rolePos, iconPos)
|
|
local u0, v0 = Map_Pos2UV(rolePos)
|
|
local u, v = Map_Pos2UV(iconPos)
|
|
if v0 == v then
|
|
if u0 > u then
|
|
self.m_roleFaceDir = Vector2.New(-1, 0)
|
|
--LogGreen("他要朝左左左左左")
|
|
self.eventpoint = 3
|
|
else
|
|
self.m_roleFaceDir = Vector2.New(1, 0)
|
|
--LogGreen("他要朝右右右右")
|
|
self.eventpoint = 4
|
|
end
|
|
else
|
|
if v0 > v then
|
|
self.m_roleFaceDir = Vector2.New(0, 1)
|
|
--LogGreen("他要朝上上上上")
|
|
self.eventpoint = 2
|
|
else
|
|
self.m_roleFaceDir = Vector2.New(0, -1)
|
|
--LogGreen("他要朝下下下下下下")
|
|
self.eventpoint = 1
|
|
end
|
|
end
|
|
self:SetWalkDir(self.eventpoint)
|
|
end
|
|
|
|
|
|
-- 角色相关
|
|
function SingleStoryPlayerView:SetRoleDirAction(u, v, isBack)
|
|
local dU = isBack and self.roleCurPos.u - u or u - self.roleCurPos.u
|
|
local dV = isBack and self.roleCurPos.v - v or v - self.roleCurPos.v
|
|
|
|
if dU > 0 then
|
|
self:SetWalkDir(WALK_DIR.RUN_RIGHT)
|
|
elseif dU < 0 then
|
|
self:SetWalkDir(WALK_DIR.RUN_LEFT)
|
|
elseif dV < 0 then
|
|
self:SetWalkDir(WALK_DIR.RUN_UP)
|
|
elseif dV > 0 then
|
|
self:SetWalkDir(WALK_DIR.RUN_DOWN)
|
|
end
|
|
end
|
|
|
|
function SingleStoryPlayerView:StackPop()
|
|
if self.callList:Count() > 0 then
|
|
self.callList:Pop()()
|
|
end
|
|
end
|
|
|
|
function SingleStoryPlayerView:StopAction()
|
|
|
|
end
|
|
|
|
function SingleStoryPlayerView:OnClose()
|
|
|
|
end
|
|
return SingleStoryPlayerView |