-- 剧情管理类, 包含副本以及关卡剧情 StoryManager = {}; local this = StoryManager local chapterDataConfig = ConfigManager.GetConfig(ConfigName.ChapterEventPointConfig) local chapterOptionData = ConfigManager.GetConfig(ConfigName.ChapterOptionConfig) local chapterTitleData = ConfigManager.GetConfig(ConfigName.LevelSetting) local dialogueSetData = ConfigManager.GetConfig(ConfigName.DialogueViewConfig) local FakeBattleNew = ConfigManager.GetConfig(ConfigName.FakeBattleNew) -- 当前对话的大关卡ID this.curAreaID = 0 local lastResName local lastLive2d --- 男主立绘 this.boyRes = "live2d_caomaolufei" --- 女主立绘 this.bitchRes = "live2d_namei" function this.Initialize() end -- 根据剧情传入的事件ID打开对应的对话面板 function this.EventTrigger(eventId, callBack) MyPCall(function() if not eventId then Log("传入的ID不存在") return end local showType = chapterDataConfig[eventId].ShowType local showValues = GetLanguageStrById(chapterDataConfig[eventId].ShowValues) local options = chapterDataConfig[eventId].Option if showType and showValues and options then -- LogError("showtype "..showType.." showvalue "..showValues) -- 如果是第一次打开,则打开开幕界面 if showType == 11 then -- 对话界面 if callBack then UIManager.OpenPanel(UIName.StoryDialoguePanel, eventId, false, callBack) else UIManager.OpenPanel(UIName.StoryDialoguePanel, eventId, false) end elseif showType == 12 then -- 选择界面 UIManager.OpenPanel(UIName.StoryDialoguePanel, eventId, false) --UIManager.OpenPanel(UIName.StoryOptionPopup, eventId) elseif showType == 10 then -- 起名字界面 UIManager.OpenPanel(UIName.CreateNamePopup, showType, eventId, showValues, options, callBack) elseif showType == 14 then -- 引导战斗 local fdata, fseed = BattleManager.GetFakeBattleData(options[1]) local testFightData = { fightData = fdata, fightSeed = fseed, fightType = BATTLE_SERVER_TYPE.StoryFight, maxRound = 20, bg = FakeBattleNew[options[1]].BgName } local panel = UIManager.OpenPanel(UIName.GuideBattlePanel, testFightData, function() StoryManager.StoryJumpType(options[3], nil, callBack) end, options[2]) elseif showType == 15 then -- 播放转场特效 SwitchPanel.PlayTransEffect(function() this.StoryJumpType(options[1], nil, callBack) end) end else Log("表数据不存在!!请检查表格!") end end) end --- 对话剧情触发 function this.DialogueTrigger(eventId, callback) MyPCall(function() if not eventId then Log("传入的ID不存在") return end local showType = chapterDataConfig[eventId].ShowType --- 对话弹窗 if showType == 13 then if callback then UIManager.OpenPanel(UIName.DialoguePopup, eventId, callback) else UIManager.OpenPanel(UIName.DialoguePopup, eventId) end end end) end -- 剧情跳转 function this.StoryJumpType(optionId, panel, callBack) local jumpType = chapterOptionData[optionId].JumpType if jumpType then if jumpType == 4 then -- 关闭所有界面,结束对话 if panel then panel:ClosePanel() end if UIManager.IsOpen(UIName.StoryDialoguePanel) then UIManager.ClosePanel(UIName.StoryDialoguePanel) end -- if callBack then callBack() end elseif jumpType == 5 then -- 打开主城 PatFaceManager.isLogin = true UIManager.OpenPanel(UIName.FightPointPassMainPanel) LoadingPanel.End() -- 关闭剧情 if panel then panel:ClosePanel() end if UIManager.IsOpen(UIName.StoryDialoguePanel) then UIManager.ClosePanel(UIName.StoryDialoguePanel) end elseif jumpType == 1 then -- 继续对话,往下跳转 local nextEventId = chapterOptionData[optionId].JumpTypeValues local nextEventShowType = chapterDataConfig[nextEventId].ShowType if nextEventShowType ~= 13 then this.EventTrigger(nextEventId, callBack) else this.DialogueTrigger(nextEventId,callBack) end end end end -- 返回当前关卡的标题 function this.GetTitle() local str = "" str = chapterTitleData[this.curAreaID].Title return str end -- ============================= 人物对话控制 =================================== -- -- 加载人物立绘并设置初始状态, 是否需要加载一次立绘 function this.InitLive2dState(setId, resPath, live2dRoot, effectRoot, isNeedLoad, dialoguePanel) -- 没有配置数据,直接返回 local setData = dialogueSetData[setId] if not setData then return end this.SetLive2dState(setData, isNeedLoad, resPath, live2dRoot, effectRoot, dialoguePanel) end -- 设置立绘的大小位置,入场动画以及是否抖动 function this.SetLive2dState(setData, isNeedLoad, resPath, live2dRoot, effectRoot, dialoguePanel) -- 加载立绘之前清空 ClearChild(live2dRoot) -- 立绘的位置大小 local scale = 0 local position = Vector3.New(0,0,0) if resPath == this.bitchRes then setData = dialogueSetData[5402] -- position = Vector3.New(0, -250, 0) -- scale = 0.5 end if not setData then return end scale = setData.Scale position = Vector3(setData.Position[1], setData.Position[2], 0) -- 设置立绘最终大小位置 local go if not resPath or resPath == "" then Log(Language[11921]) return end go = poolManager:LoadLive(resPath, live2dRoot.transform, Vector3.one * scale, position) if not go then Log(Language[11922]) return end lastLive2d = go -- 是否播放入场动画 local isPlay = true if isNeedLoad then isPlay = setData.isSkipShow == 1 local shakeTime = setData.ShakeTime local shakeDis = setData.ShakeScale local isNeedShake = setData.IsShake == 1 local ainIndex = setData.Animation this.InitAnim(go) if isPlay and isNeedShake then -- 震动,入场动画 PlayUIAnim(live2dRoot, function () this.SetShake(go, shakeTime, shakeDis[1], shakeDis[2], function () this.SetLive2dAnim(go, ainIndex, 0, setData, effectRoot, dialoguePanel) Log("振动入场动画") end) end) elseif isPlay and not isNeedShake then -- 入场动画无震动 PlayUIAnim(live2dRoot, function () this.SetLive2dAnim(go, ainIndex, 0, setData, effectRoot, dialoguePanel) Log("入场动画") end) elseif not isPlay and isNeedShake then -- 震动无入场动画 this.SetShake(go, shakeTime, shakeDis[1], shakeDis[2], function () this.SetLive2dAnim(go, ainIndex, 0, setData, effectRoot, dialoguePanel) Log("振动") end) elseif not isPlay and not isNeedShake then -- 都没有 this.SetLive2dAnim(go, ainIndex, 0, setData, effectRoot, dialoguePanel) Log("啥都没有!") end end end -- 设置图片以及表现 function this.InitImgState(setId, imgRoot, effectRoot, panel) -- 没有配置数据,直接返回 local setData = dialogueSetData[setId] if not setData then return end -- 设置需要显示的图片 local imgShowData = string.split(setData.isShowImage, "#") local imgResId = tonumber(imgShowData[1]) local imgName = imgShowData[2] Log(string.format("是否显示图片%s", imgResId)) local showImg = imgResId == 1 if not showImg then return end local img = imgRoot:GetComponent("Image") img.sprite = panel.spLoader:LoadSprite(imgName) img:SetNativeSize() -- 设置图片大小位置 local scale = setData.imgSizeAndPos[1] local position = Vector2.New(setData.imgSizeAndPos[2], setData.imgSizeAndPos[3]) imgRoot:GetComponent("RectTransform").anchoredPosition = position imgRoot.transform.localScale = Vector3.one * scale end -- 清除特效 function this.InitEffect(effectRoot) if lastResName then if effectRoot then ClearChild(effectRoot) end lastResName = nil end end --============================= 封装表现方法 ========================= -- 播放特效方法 local preLayer = 10 function this.PlayEffect(setData, effectRoot, dialoguePanel) local effectData = string.split(setData.isPlayEffect, "#") local isPlay = tonumber(effectData[1]) if isPlay == 1 then local resName = effectData[2] lastResName = resName local effect = this.LoadEffect(effectRoot, resName) --设置特效的位置方向 local pos = Vector2.New(setData.effectPos[2], setData.effectPos[3]) -- 黑人问号特殊处理 local dir = setData.effectPos[1] == 1 and 180 or 0 if resName == "UI_effect_emoji_3" then effect.transform.localRotation = Vector4.New(0, 0, 0, 1) local img = Util.GetGameObject(effect, "kuang") img.transform.localRotation = Vector4.New(0, dir, 0, 1) else effect.transform.localRotation = Vector4.New(0, dir, 0, 1) end effect:GetComponent("RectTransform").anchoredPosition = pos -- 设置特效层级 Util.AddParticleSortLayer(effectRoot, dialoguePanel.sortingOrder + preLayer) preLayer = dialoguePanel.sortingOrder end end -- 参数:object 抖动物体 timeScale 震动时长 dx, dy震动偏移量 function this.SetShake(object, timeScale, dx, dy, callBack) if not timeScale or timeScale == 0 then timeScale = 0.2 end if not dx or not dy or dy == 0 and dx == 0 then dx = 10 dy = 10 end object:GetComponent("RectTransform"):DOShakeAnchorPos(timeScale, Vector2.New(dx, dy), 500, 90, true, true):OnComplete(function () if callBack then callBack() end end) end -- 设置立绘动作 function this.SetLive2dAnim(object, ainIndex, delayTime, setData, effectRoot, dialoguePanel) -- 木有立绘资源 if not object or not object.gameObject then return end local skeletonAnim = object.gameObject:GetComponent("SkeletonGraphic") if not skeletonAnim then return end local animName = { [1] = "idle", [2] = "hit", [3] = "attack", [4] = "touch", } if not delayTime then delayTime = 0 end if not skeletonAnim then Log(Language[11923]) return end if animName[ainIndex] and ainIndex > 1 then -- idel状态不做处理 skeletonAnim.AnimationState:SetAnimation(delayTime, animName[ainIndex], false) end Log("播放立绘有的动作!") -- 播放特效 this.PlayEffect(setData, effectRoot, dialoguePanel) end -- 设置立绘初始化动作 function this.InitAnim(go) if not go then return end local skeletonAnim = go:GetComponent("SkeletonGraphic") local InitAnim = function() skeletonAnim.AnimationState:SetAnimation(0, "idle", true) end skeletonAnim.AnimationState.Complete = skeletonAnim.AnimationState.Complete + InitAnim end -- 加载特效 function this.LoadEffect(effectParent, resName) local go = poolManager:LoadAsset(resName, PoolManager.AssetType.GameObject) go.transform:SetParent(effectParent.transform) go.transform.localScale = Vector3.one go.transform.position = effectParent.transform.position go:SetActive(true) return go end -- 卸载特效 function this.UnLoadEffect(resName, res) poolManager:UnLoadAsset(resName, res, PoolManager.AssetType.GameObject) end return this