SingleFightPlayerView = {} local mapIconConfig = ConfigManager.GetConfig(ConfigName.MainMapIconConfig) local iconAction = require("Modules/Fight/View/FightMapIconShowView") -- 角色对话气泡位置 local m_roleTextPos = { [3] = {pos = Vector3.New(172, 200, 0), angleOffset = 180}, -- 角色朝左, 气泡在右 [4] = {pos = Vector3.New(-177, 204, 0), angleOffset = 0} -- 反之 } local namePos = { [1] = {pos = Vector3.New(-1.86, 185.3, 0)}, -- 角色朝左,气泡在左 [2] = {pos = Vector3.New(-1.86, 273.5, 0)} -- 反之 } -- 老头对话气泡位置 local m_oldManTextPos = { [3] = {pos = Vector3.New(-176, 130, 0), angleOffset = 0}, -- 角色朝左,气泡在左 [4] = {pos = Vector3.New(154, 130, 0), angleOffset = 180} -- 反之 } function SingleFightPlayerView:AddListener() Game.GlobalEvent:AddEvent(GameEvent.GuaJi.getEvent, self.ReciveData,self) end function SingleFightPlayerView:ReciveData(data) if data.goData.userId == self.userId then self.eventPointPos = data.event self.state = 1 self:RoleWalkEnd(data) elseif (data.event and data.event.userId and data.event.userId == self.userId) then self.eventPointPos = data.goData self.state = 1 self:RoleWalkEnd(data) end return end function SingleFightPlayerView:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.GuaJi.getEvent, self.ReciveData, self) end function SingleFightPlayerView:New(gameObject) local b = {} b.gameObject = gameObject b.transform = gameObject.transform setmetatable(b, { __index = SingleFightPlayerView }) return b end local sortingorder = 0 local hitRootPath = "UI_Map_XunBaoEffect_hit" local npc1 = "live2d_npc_map_boy" local npc2 = "live2d_npc_map_nv" -- 飘血资源 local hurtRes = "FloatingText" function SingleFightPlayerView:InitComponent() self.root = Util.GetGameObject(self.gameObject, "root") self.ui = Util.GetGameObject(self.root, "ui") self.roleRoot = Util.GetGameObject(self.ui,"roleRoot") Util.GetGameObject(self.ui, "lizi effect").gameObject:SetActive(false) self.battleEffect = Util.GetGameObject(self.ui, "quickBattleEffect") self.bLeaderIsIdle = true -- 临时代码 self.dialogueRoot = Util.GetGameObject(self.ui, "Dialogue") self.context = Util.GetGameObject(self.dialogueRoot, "Text"):GetComponent("Text") -- buff特效 self.buffEffectRoot = Util.GetGameObject(self.roleRoot, "effectRoot") Util.SetParticleScale(self.buffEffectRoot, 2) -- 攻击buff self.buffAttack = Util.GetGameObject(self.buffEffectRoot, "r_MapEffect_NewEvent_011") self.buffAttack:SetActive(false) -- 防御buff self.buffDefend = Util.GetGameObject(self.buffEffectRoot, "r_MapEffect_NewEvent_012") self.buffEffectRoot:SetActive(false) -- 隐藏一堆东西 Util.GetGameObject(self.ui,"arrow"):SetActive(false) Util.GetGameObject(self.ui,"pos"):SetActive(false) Util.GetGameObject(self.ui,"blood"):SetActive(false) Util.GetGameObject(self.ui,"optionCancelBtn"):SetActive(false) Util.GetGameObject(self.ui,"roleOption"):SetActive(false) self:SetBattleState(false) --角色当前方向 self.curDir = nil self.gameObject:SetActive(true) --- 注册组件 self.callList = Stack.New() --当前选中点的位置 self.selectPointPos = 0 -- 角色停止行走时的朝向, 上 下 左 右,1 2 3 self.m_roleFaceDir = Vector2.New(-1, 0) --角色停止行走时的朝向 self.eventpoint = 0 --当前触发的事件点 self.eventPointPos = nil self.nameDi = Util.GetGameObject(self.ui, "nemeDi") self.name = Util.GetGameObject(self.nameDi, "name"):GetComponent("Text") self.hurtNum = {} end function SingleFightPlayerView:OnOpen(parent) self.parent = parent self.hitEffect = poolManager:LoadAsset(hitRootPath, PoolManager.AssetType.GameObject) self.hitEffect.transform:SetParent(parent.effectRoot.transform) self.hitEffect.transform.localScale = Vector3.one self.hitEffect:SetActive(false) if not self.buffTipList then self.buffTipList = {} end -- buff飘字 for i = 1, 3 do if not self.buffTipList[i] then self.buffTipList[i] = newObjToParent(parent.buffTip, parent.effectRoot) self.buffTipList[i].transform.localScale = Vector3.New(1.2, 1.2, 1.2) self.buffTipList[i]:SetActive(false) end end if not self.hurtNum then self.hurtNum = {} end for i = 1, 3 do self.hurtNum[i] = poolManager:LoadAsset(hurtRes, PoolManager.AssetType.GameObject) -- 设置父级 self.hurtNum[i].transform:SetParent(parent.effectRoot.transform) self.hurtNum[i].transform.localScale = Vector3.New(0.5, 0.5, 0.5) Util.GetGameObject(self.hurtNum[i], "anim"):GetComponent("Canvas").sortingOrder = parent.GetCurLayer() self.hurtNum[i]:SetActive(false) end end function SingleFightPlayerView:SetData(u,v,isSelf,data) self.isclose = false self._PlayTimeStamp = 0 if isSelf then self.ui:GetComponent("Canvas").worldCamera = TileMapView.GetCamera() end self.isSelf = isSelf local v3 = TileMapView.GetLiveTilePos(u, v) self.gameObject.transform.localPosition = Vector3(v3.x, v3.y, v3.z - 10) self.gameObject.transform.localScale = Vector3.one * 1.5 if self.playerLiveView then self.playerLiveView:OnClose() self.playerLiveView = nil end local npc,scale if self.isSelf then npc = NameManager.roleSex == ROLE_SEX.BOY and npc1 or npc2 scale = NameManager.roleSex == ROLE_SEX.BOY and 1 or 0.5 self.userId = PlayerManager.uid self.playerLiveView = PlayerLiveView:New(self.roleRoot,1,nil) self.nameDi.gameObject:SetActive(false) else npc = data.sex == ROLE_SEX.BOY and npc1 or npc2 scale = data.sex == ROLE_SEX.BOY and 1 or 0.5 self.userId = data.uid or data.roleUid or data.id self.playerLiveView = PlayerLiveView:New(self.roleRoot,2, { skin = data.userSkin, sex = data.sex, ride = data.userMount, designation = data.userTitle, }) if data.userMount == 0 then self.nameDi.transform.localPosition = namePos[1].pos else self.nameDi.transform.localPosition = namePos[2].pos end self.name.text = data.userName or data.name self.nameDi.gameObject:SetActive(true) end self.playerLiveView:OnOpen(GetPlayerRoleSingleConFig().Scale2) self.playerLiveView.name = "npc" --角色当前的uv self.roleCurPos = TileMapView.GetMapData():GetMapData(u, v) LogWarn(self.roleCurPos.u.."||"..self.roleCurPos.v) self.bLeaderIsIdle = true self:SetWalkDir(WALK_DIR.LAUCH) self:HideSomeTrash() self:OnSortingOrderChange(self.parent.GetCurLayer()) --当前状态 self.state = 0 PlayUIAnim(self.gameObject) end function SingleFightPlayerView:SetWalkDir(dir) if self.playerLiveView then self.playerLiveView:SetWalkDir(dir) end end function SingleFightPlayerView:SetBattleState(state) self.buffEffectRoot.gameObject:SetActive(state) end function SingleFightPlayerView:HideSomeTrash() for i = 1, 3 do self.buffTipList[i]:SetActive(false) end end function SingleFightPlayerView:OnSortingOrderChange(orginLayer) Util.AddParticleSortLayer(self.hitEffect, orginLayer - sortingorder) if #self.hurtNum > 0 then -- 初始化完成 for i = 1, 3 do Util.GetGameObject(self.hurtNum[i], "anim"):GetComponent("Canvas").sortingOrder = orginLayer - sortingorder end end sortingorder = orginLayer end -- 撞击事件结束后的回调 function SingleFightPlayerView:hitCallBack(pos) self:SetWalkDir(WALK_DIR.IDLE_FRONT) self.state = 0 self.parent.BattleEnd(pos) -- 战斗结束 if self.isSelf then self:SetEffect(self.selectPointPos) self.selectPointPos = nil end if self.targetTimer then self.targetTimer:Stop() self.targetTimer = nil end self:SetRoleHitTarget() self.targetTimer = Timer.New(function () -- 延迟生成下一个小怪 self.parent.LoadPointIcon(false) end, 0.5) self.targetTimer:Start() end -- 随机一个位置给大爷走走 function SingleFightPlayerView:SetRoleHitTarget() if self.thread then coroutine.stop(self.thread) self.thread=nil end self.thread = coroutine.start(function() --LogGreen("随机一个位置给大爷走走") --local eventPoint = self.parent.AsideTriggerJudge(self.roleCurPos,self.isSelf) --self.parent.AsideTriggerJudge(self.roleCurPos,self.isSelf) local pos while not pos do if self.isclose then coroutine.yield() end coroutine.wait(0.01) pos = self:SelectTargetPos() end --LogGreen("选中的点:"..tostring(pos).." "..tostring(self.userId)) local pathlist = self:SetRoleWalk(pos) self:RoleMove(pathlist) end) end -- 选择一个目标位置, 就近原则 function SingleFightPlayerView:SelectTargetPos() local iconList = self.parent.RequestIconList() --LogGreen("iconList:"..tostring(iconList)) if iconList and LengthOfTable(iconList) > 0 then --LogGreen("iconList:"..tostring(LengthOfTable(iconList))) local selectIconList = {} local minDis = 999 for i, v in pairs(iconList) do if self.parent.HasSelectIconList(i,self.userId) then local targetU, targetV = Map_Pos2UV(i) -- 计算相对距离 local dis = math.abs(self.roleCurPos.u - targetU) + math.abs(self.roleCurPos.v - targetV) minDis = minDis <= dis and minDis or dis local data = {} data.dis = dis data.x_axis = targetU data.pos = i selectIconList[#selectIconList + 1] = data end end -- 取出目标值. 相等则要x最小的 if #selectIconList > 1 then table.sort(selectIconList, function (a, b) if a.dis == b.dis then return a.x_axis < b.x_axis else return a.dis < b.dis end end ) end -- 万一图标还没生出来 local targetPos = 0 --LogGreen("#selectIconList:"..#selectIconList.." self.uid:"..self.userId) if #selectIconList > 1 then self.parent.AddSelectIconList(selectIconList[1].pos,self.userId) targetPos = self:GetTargetPos(selectIconList[1].pos) self.parent.RemoveSelectIconList(self.eventPointPos) else self.parent.ReleaseIconList() return end self.parent.ReleaseIconList() return targetPos end end -- 获取当前图标的目标值,传入图标的坐标值, 就近原则 function SingleFightPlayerView:GetTargetPos(iconPos) local u0, v0 = Map_Pos2UV(iconPos) local posList = { [1] = Vector2.New(u0, v0 - 1), -- 上 [2] = Vector2.New(u0, v0 + 1), -- 下 [3] = Vector2.New(u0 - 1, v0), -- 左 [4] = Vector2.New(u0 + 1, v0), -- 右 } local newList = {} for i = 1, 4 do local dis = math.abs(self.roleCurPos.u - posList[i].x) + math.abs(self.roleCurPos.v - posList[i].y) local data = {} data.dis = dis data.axis = posList[i] data.index = i newList[#newList + 1] = data end if #newList > 1 then table.sort(newList, function (a, b) if a.dis == b.dis then return a.axis.x < b.axis.x else return a.dis < b.dis end end) end local pos = posList[newList[1].index] return pos end function SingleFightPlayerView:SetRoleWalk(targetPos) local funcCanPass = function(data) return data.val <= 1 end local pathList = TileMapView.ShowPath(self.roleCurPos.u, self.roleCurPos.v, targetPos.x, targetPos.y, funcCanPass) TileMapView.ClearPath() return pathList end function SingleFightPlayerView:RoleMove(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 SingleFightPlayerView:PlayerMove() self.bLeaderIsIdle = false end function SingleFightPlayerView:PlayStepSound() local curTimeStamp = GetTimeStamp() if curTimeStamp - self._PlayTimeStamp >= 0.3 then self._PlayTimeStamp = curTimeStamp SoundManager.PlaySound(SoundConfig.Sound_FootStep..math.random(1,7)) end end -- 角色行走结束 function SingleFightPlayerView:RoleWalkEnd(eventPoint) self.callList:Clear() self:PlayerIdle() if self.eventPointPos then local iconType = self.eventPointPos.iconId or -1 if iconType == -1 then self.selectPointPos = Map_UV2Pos(self.eventPointPos.roleCurPos.u,self.eventPointPos.roleCurPos.v) else self.selectPointPos = eventPoint.pos end --LogGreen("eventPoint.pos:"..tostring(self.selectPointPos)) -- 检测方向 self:SetRoleDir(self.roleCurPos.u * 256 + self.roleCurPos.v, self.selectPointPos) -- 设置角色纵深 self:SetRoleLayer(self:IsRoleFront(self.selectPointPos)) self:SetIconShow(eventPoint) else self:SetRoleHitTarget() end end ---检查角色与图标的纵深关系 function SingleFightPlayerView:IsRoleFront(pos) local v0 = self.roleCurPos.v local u, v = Map_Pos2UV(pos) return v0 >= v end function SingleFightPlayerView:PlayerIdle() self.bLeaderIsIdle = true if self.SkeletonGraphic and self.SkeletonGraphic.AnimationState then self.SkeletonGraphic.AnimationState:SetAnimation(0, "idle", true) self.SkeletonGraphic.transform.localEulerAngles = Vector3.zero end self.curDir = nil end -- 角色停止行走时的朝向 function SingleFightPlayerView: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 ---设置角色纵深 ---@param isFront 设置是否角色在前 function SingleFightPlayerView:SetRoleLayer(isFront) local z_axis = isFront and -10 or 10 local v3 = self.gameObject.transform.localPosition self.gameObject.transform.localPosition = Vector3(v3.x, v3.y, z_axis) end -- 角色相关 function SingleFightPlayerView: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 SingleFightPlayerView:StackPop() if self.callList:Count() > 0 then self.callList:Pop()() end end -- 设置遇到图标时的表现 function SingleFightPlayerView:SetIconShow(_eventpoint) local iconType = self.eventPointPos.iconId or -1 --LogGreen("iconType:"..iconType) local index = (self.eventpoint == 4 or self.eventpoint == 1) and 4 or 3 if iconType == -1 then --显示对话框 self.dialogueRoot.gameObject:SetActive(true) self.dialogueRoot.transform.localEulerAngles = Vector3.New(0, m_roleTextPos[index].angleOffset, 0) self.context.transform.localEulerAngles = Vector3.New(0, m_roleTextPos[index].angleOffset, 0) self.dialogueRoot.transform.localPosition = m_roleTextPos[index].pos local str = "" local strList = {} if self.isSelf then str = ConfigManager.GetConfigData(ConfigName.SpecialConfig,111).Value else str = ConfigManager.GetConfigData(ConfigName.SpecialConfig,112).Value end strList = string.split(str,"#") self.context.text = strList[FightPointPassManager.randomNum] or "你好" self:NotBattleShow() elseif iconType == 8 or iconType == 11 then -- 宝箱 self:SetWalkDir(WALK_DIR.JINGYA) if self.isSelf then self.dialogueRoot.gameObject:SetActive(true) self.dialogueRoot.transform.localEulerAngles = Vector3.New(0, m_roleTextPos[index].angleOffset, 0) self.context.transform.localEulerAngles = Vector3.New(0, m_roleTextPos[index].angleOffset, 0) self.dialogueRoot.transform.localPosition = m_roleTextPos[index].pos local str = "" local strList = {} str = ConfigManager.GetConfigData(ConfigName.MainMapIconConfig,iconType).Desc strList = string.split(str,"#") local num = math.random(1,#strList) self.context.text = strList[num] local boxPos = self.selectPointPos Timer.New(function() if self.state == 1 then self:SetEffect(boxPos) end end,1.5):Start() end self:NotBattleShow() elseif iconType == 7 then -- NPC, 不一样的BB self:SetWalkDir(WALK_DIR.JINGYA) if self.isSelf then local str, str1 = "" local strList,strList1 = {} str = ConfigManager.GetConfigData(ConfigName.MainMapIconConfig,iconType).Desc str1 = ConfigManager.GetConfigData(ConfigName.MainMapIconConfig,iconType).DescNPC strList = string.split(str,"#") strList1 = string.split(str1,"#") local num = math.random(1,#strList) self.dialogueRoot.gameObject:SetActive(true) self.dialogueRoot.transform.localEulerAngles = Vector3.New(0, m_roleTextPos[index].angleOffset, 0) self.context.transform.localEulerAngles = Vector3.New(0, m_roleTextPos[index].angleOffset, 0) self.dialogueRoot.transform.localPosition = m_roleTextPos[index].pos self.context.text = strList[num] -- 设置老头 local oldManAngle = Vector3.New(0, m_oldManTextPos[index].angleOffset, 0) self.eventPointPos:SetDialogueDir(m_oldManTextPos[index].pos, oldManAngle) self.eventPointPos:ShowDialogue(false) self.eventPointPos:SetDialogueStr(strList1[num]) Timer.New(function() self.dialogueRoot.gameObject:SetActive(false) if self.state == 1 then self.eventPointPos:ShowDialogue(true) self:NotBattleShow() end end,1):Start() else self:NotBattleShow() end self:NotBattleShow() else -- 战斗 -- 设置战斗状态 self:EnterBattle() self.dialogueRoot.gameObject:SetActive(false) self:private_ShakeByTimes(_eventpoint, self.m_roleFaceDir, mapIconConfig[iconType].HurtNum,1,function() self:hitCallBack(_eventpoint.pos) end) end end -- 宝箱特效的位置 local boxEffectPos = { [1] = Vector3.New(44, 140, 0), [2] = Vector3.New(35, 188, 0), [3] = Vector3.New(169, 168, 0), } function SingleFightPlayerView:SetEffect(pos) local boxState = FightPointPassManager.GetBoxState() boxState = boxState == 0 and 1 or boxState local tartPos = boxEffectPos[boxState] --LogGreen("boxState:" ..boxState) if self.parent.moneyEffect then self.parent.moneyEffect:GetComponent("RectTransform").anchoredPosition = SetObjPosByUV(pos) Util.ClearTrailRender(self.parent.moneyEffect) self:SetBoxEffect(false, Vector3.zero) self.parent.moneyEffect:SetActive(true) self.parent.moneyEffect:GetComponent("RectTransform"):DOAnchorPos(Vector2.New(tartPos.x + 88, tartPos.y + 359), 0.6, false):OnComplete(function () self:SetBoxEffect(true, boxState) self.parent.moneyEffect:SetActive(false) end) end SoundManager.PlaySound(SoundConfig.Sound_FightArea_Gold) end -- 设置宝箱特效s function SingleFightPlayerView:SetBoxEffect(isShow, state) if not isShow then if self.parent.boxEffect then self.parent.boxEffect:SetActive(false) end else self.parent.boxEffect.transform.localPosition = boxEffectPos[state] self.parent.boxEffect:SetActive(true) end end function SingleFightPlayerView:private_ShakeByTimes(_point, roleFaceDir, shakeTime, index, func) local point = _point.event local icon = point.go local start = index local iconType = point.iconId local leftNum = math.floor(start % 2) -- 主动打击者 local go = leftNum == 1 and self.roleRoot or icon -- 受击对象 local hurtGo = leftNum ~= 1 and self.roleRoot or Util.GetGameObject(icon, "root") local isReverse = leftNum == 0 local objPos = isReverse and self.roleCurPos.u * 256 + self.roleCurPos.v or _point.pos local end_callBack = function() -- 受击结束动画 self.hitEffect:SetActive(false) --LogGreen("end_callBack:"..start) if start >= shakeTime then -- 执行最终回调 func() return else start = start + 1 self:private_ShakeByTimes(_point, roleFaceDir, shakeTime, start, func) end end local mid_callBack = function() -- 打击时间点 --LogGreen("mid_callBack:") self:private_BloodBlood(objPos, start, iconType, isReverse, 0) self:pravite_PlayHitEffect(objPos) if point then point:SetPointAnimation(iconType, 2) end --整个东西缩一下 self:PlayScale(hurtGo, 0.7) SoundManager.PlaySound(SoundConfig.Sound_FightArea_Attack[math.random(1, #SoundConfig.Sound_FightArea_Attack)]) end local func = function() self:pravite_ShakeObjOnce(go, isReverse, roleFaceDir, end_callBack, mid_callBack) end if self.callbackTimer then self.callbackTimer:Stop() self.callbackTimer = nil end self.callbackTimer = Timer.New(function () func() end, 0.2) self.callbackTimer:Start() end -- 怪物被打得吐血 --- @param showType 参数为0时表示为掉血,参数大于0时表示为补血 function SingleFightPlayerView:private_BloodBlood(objPos, index, iconType, isMonster, showType, func) local go = self.hurtNum[math.floor(index % 3 + 1)] -- 吐血随机值 local hurtNum, isCritical = iconAction.pravite_GetHurtValue(isMonster, iconType, showType) local v2 = SetObjPosByUV(objPos) go:GetComponent("RectTransform").anchoredPosition3D = Vector3.New(v2.x, v2.y, 0) + Vector3.New(0, 120, 0) Util.GetGameObject(go, "anim/Image"):SetActive(false) Util.GetGameObject(go, "anim/anim"):GetComponent("Text").text = iconAction.DecodeHurt(hurtNum, isCritical, showType) go:SetActive(true) self.hurtNumTimer = nil self.hurtNumTimer = Timer.New(function() if go then go:SetActive(false) end if func then func() end end, 1.5) self.hurtNumTimer:Start() end -- 震动动画 function SingleFightPlayerView:pravite_ShakeObjOnce(go, isReverse, roleFaceDir, func, mid_func) if self.isclose then return end --LogGreen("pravite_ShakeObjOnce:"..go.name.." isReverse:"..tostring(isReverse).." roleFaceDir:"..tostring(roleFaceDir)) local offSet = isReverse and 90 or 120 offSet = offSet / math.min(Screen.width/1080, Screen.height/1920) if go then local originPos = go:GetComponent("RectTransform").anchoredPosition local value = isReverse and -1 or 1 local targetPos = originPos + Vector2.New(offSet * roleFaceDir.x * value, offSet * roleFaceDir.y * value) go:GetComponent("RectTransform"):DOAnchorPos(targetPos, 0.1, false):OnComplete(function () if mid_func then mid_func() end go:GetComponent("RectTransform"):DOAnchorPos(originPos, 0.1, false):OnComplete(function () if func then func() end end) end) end end -- 缩放 function SingleFightPlayerView:PlayScale(go, scale) if self.isclose then return end if go then local originScale = go.transform.localScale go.transform:DOScale(originScale * scale, 0.1):OnComplete(function () go.transform:DOScale(originScale, 0.1) end) end end -- 受击特效 function SingleFightPlayerView:pravite_PlayHitEffect(pos) --local u, v = Map_Pos2UV(pos) --local v2 = RectTransformUtility.WorldToScreenPoint(TileMapView.GetCamera(), TileMapView.GetLiveTilePos(u, v)) --v2 = v2 / math.min(Screen.width/1080, Screen.height/1920) --LogGreen("self.hitEffect:") self.hitEffect.transform.localPosition = SetObjPosByUV(pos) self.hitEffect:SetActive(true) end -- 不是战斗的表现 function SingleFightPlayerView:NotBattleShow() if self.battleTimer then self.battleTimer:Stop() self.battleTimer = nil end if self.targetTimer then self.targetTimer:Stop() self.targetTimer = nil end self.battleTimer = Timer.New(function () self.dialogueRoot.gameObject:SetActive(false) self.parent.BattleEnd(self.selectPointPos) self:SetRoleLayer(true) self:SetBattleState(false) self.targetTimer = Timer.New(function () self.parent.LoadPointIcon(false) self:SetRoleHitTarget() self.state = 0 self.selectPointPos = nil self.eventPointPos = nil end, 0.5) self.targetTimer:Start() end, 1) self.battleTimer:Start() end -- 进入战斗状态 function SingleFightPlayerView:EnterBattle() self:SetBattleState(true) end function SingleFightPlayerView:StopAction() self.callList:Clear() self:SetWalkDir(WALK_DIR.IDLE_FRONT) self.hitEffect:SetActive(false) for i = 1, #self.hurtNum do self.hurtNum[i].gameObject:SetActive(false) end if self.targetTimer then self.targetTimer:Stop() self.targetTimer = nil end if self.callbackTimer then self.callbackTimer:Stop() self.callbackTimer = nil end if self.hurtNumTimer then self.hurtNumTimer:Stop() self.hurtNumTimer = nil end if self.battleTimer then self.battleTimer:Stop() self.battleTimer = nil end --LogGreen("停止协程") if self.thread then coroutine.stop(self.thread) self.thread = nil end end function SingleFightPlayerView:OnClose() self.isclose = true self.dialogueRoot.gameObject:SetActive(false) self:StopAction() self.buffTipList = {} if self.playerLiveView then self.playerLiveView:OnClose() self.playerLiveView = nil end --角色当前方向 self.curDir = nil --当前选中点的位置 self.selectPointPos = 0 --角色停止行走时的朝向 self.eventpoint = 0 --当前触发的事件点 self.eventPointPos = nil self.state = 0 end return SingleFightPlayerView