370 lines
19 KiB
Lua
370 lines
19 KiB
Lua
PlayerLiveView = {}
|
|
local this=PlayerLiveView
|
|
local mapNpcOp = "PlayerLiveView"
|
|
-- PlayerLiveViewData = {
|
|
-- ride = 80008
|
|
-- skin = 80012
|
|
-- designation = 80010
|
|
-- }
|
|
function PlayerLiveView:New(gameObject,_Type, PlayerLiveViewData,orginLayer)
|
|
-- Type = _Type
|
|
-- local b = {}
|
|
-- b.gameObject = gameObject
|
|
-- b.transform = gameObject.transform
|
|
-- setmetatable(b, { __index = PlayerLiveView })
|
|
-- return b
|
|
local instance = {}
|
|
instance.leader = poolManager:LoadAsset(mapNpcOp, PoolManager.AssetType.GameObject)
|
|
instance.gameObject = gameObject
|
|
instance._Type = _Type--1 自己的数据 2 传入PlayerLiveViewData
|
|
if _Type == 2 then
|
|
instance.PlayerLiveViewData = PlayerLiveViewData
|
|
else
|
|
instance.PlayerLiveViewData = {
|
|
ride = PlayerManager.GetPlayerRide(),
|
|
skin = PlayerManager.GetPlayerSkin(),
|
|
sex = NameManager.roleSex,
|
|
designation = PlayerManager.GetPlayerDesignation()
|
|
}
|
|
end
|
|
instance.orginLayer = orginLayer
|
|
instance.transform = gameObject.transform
|
|
instance.leader:SetActive(true)
|
|
instance.leader.transform:SetParent(gameObject.transform)
|
|
instance.leader.transform.localPosition = Vector3.zero
|
|
instance.leader.transform.localScale = Vector3.one
|
|
instance.liveParent = Util.GetGameObject(instance.leader, "liveParent")
|
|
instance.rideLiveGo = Util.GetGameObject(instance.leader, "liveParent/rideLive")
|
|
instance.playerLiveGo = Util.GetGameObject(instance.leader, "liveParent/playerLive")
|
|
instance.titleLiveGo = Util.GetGameObject(instance.leader, "liveParent/titleLive")
|
|
|
|
|
|
--立绘对象
|
|
instance.rideLive = nil
|
|
instance.playerLive = nil
|
|
instance.titleLive = nil
|
|
--立绘资源名字
|
|
instance.rideLiveStr = ""
|
|
instance.playerLiveStr = ""
|
|
instance.titleLiveStr = ""
|
|
--立绘动画控制
|
|
instance.rideLivSkeletonGraphic = nil
|
|
instance.playerLiveSkeletonGraphic = nil
|
|
instance.titleLiveSkeletonGraphic = nil
|
|
|
|
|
|
instance.oldPlayerDirAnimation = nil
|
|
instance.oldPlayerDiry = nil
|
|
instance.oldRideDirAnimation = nil
|
|
instance.oldRideDiry = nil
|
|
|
|
setmetatable(instance, { __index = PlayerLiveView })
|
|
return instance
|
|
end
|
|
--初始化组件(用于子类重写)
|
|
function PlayerLiveView:InitComponent()
|
|
|
|
|
|
end
|
|
|
|
--绑定事件(用于子类重写)
|
|
function PlayerLiveView:BindEvent()
|
|
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function PlayerLiveView:AddListener()
|
|
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function PlayerLiveView:RemoveListener()
|
|
|
|
end
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
function PlayerLiveView:OnOpen(scale,pos,dir)
|
|
self:OnShowLive()
|
|
if scale then
|
|
self.leader.transform.localScale = Vector3.New(scale,scale,scale)
|
|
end
|
|
if pos then
|
|
self.leader.transform.localPosition = pos
|
|
end
|
|
if dir then
|
|
self:SetWalkDir(dir)
|
|
end
|
|
end
|
|
|
|
--加载三个立绘(称号 坐骑 皮肤)
|
|
function PlayerLiveView:OnShowLive()
|
|
-- LogBlue("self.rideLiveGo "..self.rideLiveGo.name)
|
|
self.rideLiveGo:SetActive(false)
|
|
self.playerLiveGo:SetActive(false)
|
|
self.titleLiveGo:SetActive(false)
|
|
if self.rideLive then
|
|
poolManager:UnLoadLive(self.rideLiveStr, self.rideLive, PoolManager.AssetType.GameObject)
|
|
self.rideLive = nil
|
|
end
|
|
if self.playerLive then
|
|
poolManager:UnLoadLive(self.playerLiveStr, self.playerLive, PoolManager.AssetType.GameObject)
|
|
self.playerLive = nil
|
|
end
|
|
if self.titleLive then
|
|
poolManager:UnLoadAsset(self.titleLiveStr, self.titleLive, PoolManager.AssetType.GameObject)
|
|
self.titleLive = nil
|
|
end
|
|
--时装
|
|
if self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0 then
|
|
self.playerLiveGo:SetActive(true)
|
|
local skinId = tonumber( tostring(self.PlayerLiveViewData.skin) .. tostring(self.PlayerLiveViewData.sex))--皮肤 有男女之分 所以在id后加0 or 1
|
|
local curPlayerRole = ConfigManager.GetConfigData(ConfigName.PlayerRole,skinId)
|
|
local curArtResourcesConfig = ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig,curPlayerRole.LiveAnimName)
|
|
local curLocalScale = Vector3.New(curArtResourcesConfig.Scale,curArtResourcesConfig.Scale,curArtResourcesConfig.Scale)
|
|
local curLocalPosition = Vector3.New(curArtResourcesConfig.Position[1],curArtResourcesConfig.Position[2],0)
|
|
self.playerLiveStr = curArtResourcesConfig.Name--"live2d_npc_map"
|
|
self.playerLive = poolManager:LoadLive(self.playerLiveStr, self.playerLiveGo.transform, curLocalScale, curLocalPosition)
|
|
self.playerLiveSkeletonGraphic = self.playerLive:GetComponent("SkeletonGraphic")
|
|
if self.playerLiveSkeletonGraphic then
|
|
if self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 then
|
|
self.playerLiveSkeletonGraphic.AnimationState:SetAnimation(0, PLAYER_WALK_DIR.IDLE_FRONT.animation, true)
|
|
else
|
|
self.playerLiveSkeletonGraphic.AnimationState:SetAnimation(0, PLAYER_WALK_DIR.IDLE.animation, true)
|
|
end
|
|
end
|
|
end
|
|
--坐骑
|
|
if self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 then
|
|
self.rideLiveGo:SetActive(true)
|
|
local curPlayerRole = ConfigManager.GetConfigData(ConfigName.PlayerRole,self.PlayerLiveViewData.ride)
|
|
local curArtResourcesConfig = ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig,curPlayerRole.LiveAnimName)
|
|
local curLocalScale = Vector3.New(curArtResourcesConfig.Scale,curArtResourcesConfig.Scale,curArtResourcesConfig.Scale)
|
|
local curLocalPosition = Vector3.New(curArtResourcesConfig.Position[1],curArtResourcesConfig.Position[2],0)
|
|
self.rideLiveStr = curArtResourcesConfig.Name
|
|
self.rideLive = poolManager:LoadLive(self.rideLiveStr, self.rideLiveGo.transform, curLocalScale,curLocalPosition)
|
|
self.rideLivSkeletonGraphic = self.rideLive:GetComponent("SkeletonGraphic")
|
|
if self.rideLivSkeletonGraphic then
|
|
self.rideLivSkeletonGraphic.AnimationState:SetAnimation(0, RIDE_WALK_DIR.IDLE_FRONT.animation, true)
|
|
end
|
|
end
|
|
--称号
|
|
if self.PlayerLiveViewData.designation and self.PlayerLiveViewData.designation > 0 then
|
|
self.titleLiveGo:SetActive(true)
|
|
local curPlayerRole = ConfigManager.GetConfigData(ConfigName.PlayerRole,self.PlayerLiveViewData.designation)
|
|
local curArtResourcesConfig = ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig,curPlayerRole.LiveAnimName)
|
|
local curLocalScale = Vector3.New(curArtResourcesConfig.Scale,curArtResourcesConfig.Scale,curArtResourcesConfig.Scale)
|
|
local curLocalPosition = Vector3.New(curArtResourcesConfig.Position[1],curArtResourcesConfig.Position[2],0)
|
|
self.titleLiveStr = curArtResourcesConfig.Name--GetResourcePath(ConfigManager.GetConfigData(ConfigName.PlayerAppearance,PlayerManager.designation).Live)
|
|
self.titleLive = poolManager:LoadAsset(self.titleLiveStr, PoolManager.AssetType.GameObject)
|
|
self.titleLive.transform:SetParent(self.titleLiveGo.transform)
|
|
self.titleLive.transform.localPosition = curLocalPosition
|
|
self.titleLive.transform.localScale = curLocalScale
|
|
end
|
|
end
|
|
|
|
|
|
function PlayerLiveView:SetWalkDir(dir)
|
|
-- LogBlue("PlayerLiveView dir : "..dir)
|
|
if dir == WALK_DIR.IDLE_FRONT then-- 站立_向前
|
|
if (self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0) and (self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.IDLE_FRONT,RIDE_WALK_DIR.IDLE_FRONT)
|
|
elseif self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0 and (not self.PlayerLiveViewData.ride or self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride <= 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.IDLE,nil)
|
|
elseif self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 and (not self.PlayerLiveViewData.skin or self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin <= 0) then
|
|
self:SetWalkDirInfo(nil,RIDE_WALK_DIR.IDLE_FRONT)
|
|
end
|
|
self:SetSiblingIndexPlayerOrRide(1)
|
|
elseif dir == WALK_DIR.IDLE_BACK then-- 站立_向后
|
|
if (self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0) and (self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.IDLE_BACK,RIDE_WALK_DIR.IDLE_BACK)
|
|
elseif self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0 and (not self.PlayerLiveViewData.ride or self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride <= 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.IDLEBACK,nil)
|
|
elseif self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 and (not self.PlayerLiveViewData.skin or self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin <= 0) then
|
|
self:SetWalkDirInfo(nil,RIDE_WALK_DIR.IDLE_BACK)
|
|
end
|
|
self:SetSiblingIndexPlayerOrRide(2)
|
|
elseif dir == WALK_DIR.IDLE_LEFT then-- 站立_向左
|
|
if (self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0) and (self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.IDLE_LEFT,RIDE_WALK_DIR.IDLE_LEFT)
|
|
elseif self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0 and (not self.PlayerLiveViewData.ride or self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride <= 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.IDLE,nil)
|
|
elseif self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 and (not self.PlayerLiveViewData.skin or self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin <= 0) then
|
|
self:SetWalkDirInfo(nil,RIDE_WALK_DIR.IDLE_LEFT)
|
|
end
|
|
self:SetSiblingIndexPlayerOrRide(2)
|
|
elseif dir == WALK_DIR.IDLE_RIGHT then-- 站立_向右
|
|
if (self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0) and (self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.IDLE_RIGHT,RIDE_WALK_DIR.IDLE_RIGHT)
|
|
elseif self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0 and (not self.PlayerLiveViewData.ride or self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride <= 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.IDLE,nil)
|
|
elseif self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 and (not self.PlayerLiveViewData.skin or self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin <= 0) then
|
|
self:SetWalkDirInfo(nil,RIDE_WALK_DIR.IDLE_RIGHT)
|
|
end
|
|
self:SetSiblingIndexPlayerOrRide(2)
|
|
elseif dir == WALK_DIR.RUN_RIGHT then-- 跑_向右
|
|
if (self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0) and (self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.RUN_RIGHT,RIDE_WALK_DIR.RUN_RIGHT)
|
|
elseif self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0 and (not self.PlayerLiveViewData.ride or self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride <= 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.RIGHT,nil)
|
|
elseif self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 and (not self.PlayerLiveViewData.skin or self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin <= 0) then
|
|
self:SetWalkDirInfo(nil,RIDE_WALK_DIR.RUN_RIGHT)
|
|
end
|
|
self:SetSiblingIndexPlayerOrRide(2)
|
|
elseif dir == WALK_DIR.RUN_LEFT then-- 跑_向左
|
|
if (self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0) and (self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.RUN_LEFT,RIDE_WALK_DIR.RUN_LEFT)
|
|
elseif self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0 and (not self.PlayerLiveViewData.ride or self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride <= 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.LEFT,nil)
|
|
elseif self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 and (not self.PlayerLiveViewData.skin or self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin <= 0) then
|
|
self:SetWalkDirInfo(nil,RIDE_WALK_DIR.RUN_LEFT)
|
|
end
|
|
self:SetSiblingIndexPlayerOrRide(2)
|
|
elseif dir == WALK_DIR.RUN_UP then-- 跑_向上
|
|
if (self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0) and (self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.RUN_UP,RIDE_WALK_DIR.RUN_UP)
|
|
elseif self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0 and (not self.PlayerLiveViewData.ride or self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride <= 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.UP,nil)
|
|
elseif self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 and (not self.PlayerLiveViewData.skin or self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin <= 0) then
|
|
self:SetWalkDirInfo(nil,RIDE_WALK_DIR.RUN_UP)
|
|
end
|
|
self:SetSiblingIndexPlayerOrRide(2)
|
|
elseif dir == WALK_DIR.RUN_DOWN then-- 跑_向下
|
|
if (self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0) and (self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.RUN_DOWN,RIDE_WALK_DIR.RUN_DOWN)
|
|
elseif self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin > 0 and (not self.PlayerLiveViewData.ride or self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride <= 0) then
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.DOWN,nil)
|
|
elseif self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 and (not self.PlayerLiveViewData.skin or self.PlayerLiveViewData.skin and self.PlayerLiveViewData.skin <= 0) then
|
|
self:SetWalkDirInfo(nil,RIDE_WALK_DIR.DOWN)
|
|
end
|
|
self:SetSiblingIndexPlayerOrRide(1)
|
|
elseif dir == WALK_DIR.JINGYA then-- 惊讶
|
|
if self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 then
|
|
-- self:SetWalkDirInfo(PLAYER_WALK_DIR.IDLE_FRONT,RIDE_WALK_DIR.IDLE_FRONT)
|
|
else
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.JINGYA)
|
|
end
|
|
elseif dir == WALK_DIR.LAUCH then-- 发射
|
|
if self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 then
|
|
-- self:SetWalkDirInfo(PLAYER_WALK_DIR.IDLE_FRONT,RIDE_WALK_DIR.IDLE_FRONT)
|
|
else
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.LAUCH)
|
|
end
|
|
elseif dir == WALK_DIR.TOUCH then-- 轻按
|
|
if self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 then
|
|
-- self:SetWalkDirInfo(PLAYER_WALK_DIR.IDLE_FRONT,RIDE_WALK_DIR.IDLE_FRONT)
|
|
else
|
|
self:SetWalkDirInfo(PLAYER_WALK_DIR.TOUCH)
|
|
end
|
|
end
|
|
end
|
|
function PlayerLiveView:SetWalkDirInfo(playerDir,RideDir)
|
|
if playerDir and (self.oldPlayerDirAnimation ~= playerDir.animation or self.oldPlayerDiry ~= playerDir.y) then
|
|
LogBlue("PlayerLiveView playerDir : "..playerDir.animation .." ".. playerDir.y)
|
|
self.playerLiveSkeletonGraphic.transform.localEulerAngles = Vector3.New(0, playerDir.y, 0)
|
|
self.playerLiveSkeletonGraphic.AnimationState:SetAnimation(0, playerDir.animation, true)
|
|
self.oldPlayerDirAnimation = playerDir.animation
|
|
self.oldPlayerDiry = playerDir.y
|
|
end
|
|
if RideDir and (self.oldRideDirAnimation ~= RideDir.animation or self.oldRideDiry ~= RideDir.y) then
|
|
LogBlue("PlayerLiveView RideDir : "..RideDir.animation .." ".. RideDir.y)
|
|
self.rideLivSkeletonGraphic.transform.localEulerAngles = Vector3.New(0, RideDir.y, 0)
|
|
self.rideLivSkeletonGraphic.AnimationState:SetAnimation(0, RideDir.animation, true)
|
|
self.oldRideDirAnimation = RideDir.animation
|
|
self.oldRideDiry = RideDir.y
|
|
end
|
|
end
|
|
function PlayerLiveView:SetSiblingIndexPlayerOrRide(type)
|
|
if type == 1 then--坐骑靠前
|
|
self.playerLiveGo.transform:SetSiblingIndex(2)
|
|
self.rideLiveGo.transform:SetSiblingIndex(3)
|
|
else--时装靠前
|
|
self.rideLiveGo.transform:SetSiblingIndex(2)
|
|
self.playerLiveGo.transform:SetSiblingIndex(3)
|
|
end
|
|
end
|
|
--界面销毁时调用(用于子类重写)
|
|
function PlayerLiveView:OnClose()
|
|
if self.rideLive then
|
|
poolManager:UnLoadLive(self.rideLiveStr, self.rideLive, PoolManager.AssetType.GameObject)
|
|
self.rideLive = nil
|
|
end
|
|
if self.playerLive then
|
|
poolManager:UnLoadLive(self.playerLiveStr, self.playerLive, PoolManager.AssetType.GameObject)
|
|
self.playerLive = nil
|
|
end
|
|
if self.titleLive then
|
|
poolManager:UnLoadAsset(self.titleLiveStr, self.titleLive, PoolManager.AssetType.GameObject)
|
|
self.titleLive = nil
|
|
end
|
|
if self.leader then
|
|
poolManager:UnLoadAsset("PlayerLiveView",self.leader, PoolManager.AssetType.GameObject)
|
|
self.leader = nil
|
|
end
|
|
end
|
|
|
|
--判断动画是否存在
|
|
-- function PlayerLiveView:CurAnimationState()
|
|
-- -- SkeletonGraphic and SkeletonGraphic.AnimationState
|
|
-- return true
|
|
-- end
|
|
--判断动画是否存在
|
|
function PlayerLiveView:CurAnimationCompleteAddFun(idleFunc)
|
|
if self.playerLiveSkeletonGraphic then
|
|
if self.PlayerLiveViewData.ride and self.PlayerLiveViewData.ride > 0 then
|
|
if self.rideLivSkeletonGraphic then
|
|
self.rideLivSkeletonGraphic.AnimationState.Complete = self.rideLivSkeletonGraphic.AnimationState.Complete + idleFunc
|
|
end
|
|
else
|
|
self.playerLiveSkeletonGraphic.AnimationState.Complete = self.playerLiveSkeletonGraphic.AnimationState.Complete + idleFunc
|
|
end
|
|
end
|
|
end
|
|
--设置位置
|
|
function PlayerLiveView:SelectRenPos(ChapterRolePosition,localScaleVer,_parent)
|
|
if self.liveParent then
|
|
self.liveParent:SetActive(true)
|
|
if _parent then
|
|
self.liveParent.transform:SetParent(_parent.transform)
|
|
end
|
|
self.liveParent.transform.localScale = Vector3.New(localScaleVer[1],localScaleVer[2],1)
|
|
self.liveParent:GetComponent("RectTransform").anchoredPosition3D = Vector3.New(ChapterRolePosition[1], ChapterRolePosition[2], 10)
|
|
end
|
|
end
|
|
|
|
-- 走动 传 起始位置 和 目标位置
|
|
function PlayerLiveView:SetRoleWalk(_pos,_tagerPos,_fun)
|
|
local pos = _pos
|
|
local targetPos = _tagerPos
|
|
local speed = 5 -- 越大越慢 到时候 会读表
|
|
self.liveParent.transform:DOLocalMove(targetPos, speed / 5, false):OnStart(function ()
|
|
PlayerLiveView:SetRoleDirAction(targetPos.x, targetPos.y, pos.x, pos.y)
|
|
end):OnUpdate(function() --TODO:测试速度
|
|
|
|
end):OnComplete(function ()
|
|
Log("行走完毕")
|
|
if self.rideLive then
|
|
self.rideLivSkeletonGraphic.AnimationState:SetAnimation(0, "idle", true)
|
|
else
|
|
self.playerLiveSkeletonGraphic.AnimationState:SetAnimation(0, "idle", true)
|
|
end
|
|
if _fun then
|
|
_fun()
|
|
_fun = nil
|
|
end
|
|
end):SetEase(Ease.Linear)
|
|
end
|
|
|
|
function PlayerLiveView:SetRoleDirAction(targetU, targetV, u0, v0)
|
|
local dU = targetU - u0
|
|
local dV = targetV - v0
|
|
if dU > 0 then
|
|
PlayerLiveView:SetWalkDir(WALK_DIR.RUN_RIGHT)
|
|
elseif dU < 0 then
|
|
PlayerLiveView:SetWalkDir(WALK_DIR.RUN_LEFT)
|
|
elseif dV < 0 then
|
|
PlayerLiveView:SetWalkDir(WALK_DIR.RUN_UP)
|
|
elseif dV > 0 then
|
|
PlayerLiveView:SetWalkDir(WALK_DIR.RUN_DOWN)
|
|
end
|
|
end
|
|
return PlayerLiveView |