local SUIGamingPanel = {} local nWaitWaringTime = 3 local GAME_STATE_GAMEOVER = 0 local GAME_STATE_PREPARE = 1 local GAME_STATE_GAMING = 2 local GAME_STATE_END = 3 local coroutineTimeOutFun local coroutineDestoryFun -- todo for test local function ShowIsSomeOne() require("Base/UIHelper.lua"):SetTextInfo(SUIGamingPanel.rootPanel, "Panel_Test/Text_Is_Some_one", string.format("isSomeone: %s", CS.ZwnAmlogicHelperData.isSomeone)) end local function StopCoroutine() if coroutineTimeOutFun then require("Base/CoroutineHelper.lua"):Stop(coroutineTimeOutFun) end if coroutineDestoryFun then require("Base/CoroutineHelper.lua"):Stop(coroutineDestoryFun) end end local function SetTipsActive(sPath, bShow) local rootPanel = SUIGamingPanel.rootPanel local panelTips = rootPanel.transform:Find("Panel_Tips").gameObject local tips = panelTips.transform:Find(sPath).gameObject tips:SetActive(bShow) end local function SetPassWaringTime(PASS_WARING_TIME) local dataRelay = require("Base/DataRelay.lua") dataRelay:SetCache(dataRelay.KEY_TYPE.PASS_WARING_TIME, PASS_WARING_TIME) end local function SetPlayerOutScreenTime(PLAYER_OUT_SCREEN_TIME) local dataRelay = require("Base/DataRelay.lua") dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_OUT_SCREEN_TIME, PLAYER_OUT_SCREEN_TIME) end local function InitAreaInfo() SetPassWaringTime(0) SetTipsActive("Image_Too_Near", false) SetTipsActive("Image_Too_Far", false) require("Base/SMusicManager.lua"):StopSound("Audios/Align/goBack.mp3") require("Base/SMusicManager.lua"):StopSound("Audios/Align/goAlong.mp3") end local function CheckAreaInfo() local isSomeone = CS.ZwnAmlogicHelperData.isSomeone if not isSomeone then InitAreaInfo() return end local tTransformPose = CS.zwn_common_data.single.zwn_transform_pose local nAreaNowX = tTransformPose[5].x - tTransformPose[6].x local nAreaNowY = tTransformPose[5].y - tTransformPose[11].y local nAreaNow = math.abs(nAreaNowX * nAreaNowY) local dataRelay = require("Base/DataRelay.lua") local ALIGN_AREA = dataRelay:GetCache(dataRelay.KEY_TYPE.ALIGN_AREA) local PASS_WARING_TIME = dataRelay:GetCache(dataRelay.KEY_TYPE.PASS_WARING_TIME, 0) if nAreaNow > ALIGN_AREA * 2 then PASS_WARING_TIME = PASS_WARING_TIME + CS.UnityEngine.Time.deltaTime SetPassWaringTime(PASS_WARING_TIME) if PASS_WARING_TIME > nWaitWaringTime then SetTipsActive("Image_Too_Near", true) require("Base/SMusicManager.lua"):PlaySound("Audios/Align/goBack.mp3") PASS_WARING_TIME = 0; SetPassWaringTime(PASS_WARING_TIME) end return; end if nAreaNow < ALIGN_AREA * 0.5 and nAreaNow ~= 0 then PASS_WARING_TIME = PASS_WARING_TIME + CS.UnityEngine.Time.deltaTime SetPassWaringTime(PASS_WARING_TIME) if PASS_WARING_TIME > nWaitWaringTime then SetTipsActive("Image_Too_Far", true) require("Base/SMusicManager.lua"):PlaySound("Audios/Align/goAlong.mp3") PASS_WARING_TIME = 0; SetPassWaringTime(PASS_WARING_TIME) end return end InitAreaInfo(); end local function SetJoinImageFillAmount(fillValue) local rootPanel = SUIGamingPanel.rootPanel local panelTips = rootPanel.transform:Find("Panel_Tips") local panelRecheck = panelTips.transform:Find("Panel_Recheck").gameObject local fillImage = panelRecheck.transform:Find("Image_Circle").gameObject fillImage:GetComponent("Image").fillAmount = fillValue end local function GetJoinImageFillAmount() local rootPanel = SUIGamingPanel.rootPanel local panelTips = rootPanel.transform:Find("Panel_Tips") local panelRecheck = panelTips.transform:Find("Panel_Recheck").gameObject local fillImage = panelRecheck.transform:Find("Image_Circle").gameObject return fillImage:GetComponent("Image").fillAmount end local function NoPerson() local isSomeone = CS.ZwnAmlogicHelperData.isSomeone if isSomeone then return end local dataRelay = require("Base/DataRelay.lua") local PLAYER_IN_SCREEN = dataRelay:GetCache(dataRelay.KEY_TYPE.PLAYER_IN_SCREEN) local BREAK_OFF = dataRelay:GetCache(dataRelay.KEY_TYPE.BREAK_OFF) local PLAYER_OUT_SCREEN_TIME = dataRelay:GetCache(dataRelay.KEY_TYPE.PLAYER_OUT_SCREEN_TIME, 0) local BREAK_OFF_TIME = dataRelay:GetCache(dataRelay.KEY_TYPE.BREAK_OFF_TIME, 0) PLAYER_IN_SCREEN = false; dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_IN_SCREEN, PLAYER_IN_SCREEN) SetTipsActive("Panel_Recheck", false) if BREAK_OFF then SetJoinImageFillAmount(0) SetTipsActive("Panel_Recheck", false) SetTipsActive("Image_Back_Off", true) BREAK_OFF_TIME = BREAK_OFF_TIME + CS.UnityEngine.Time.deltaTime dataRelay:SetCache(dataRelay.KEY_TYPE.BREAK_OFF_TIME, BREAK_OFF_TIME) if BREAK_OFF_TIME >= 1 then SetTipsActive("Image_Back_Off", false) BREAK_OFF = false PLAYER_IN_SCREEN = false; PLAYER_OUT_SCREEN_TIME = 0 BREAK_OFF_TIME = 0 dataRelay:SetCache(dataRelay.KEY_TYPE.BREAK_OFF, BREAK_OFF) dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_IN_SCREEN, false) dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_OUT_SCREEN_TIME, PLAYER_OUT_SCREEN_TIME) dataRelay:SetCache(dataRelay.KEY_TYPE.BREAK_OFF_TIME, BREAK_OFF_TIME) end end PLAYER_OUT_SCREEN_TIME = PLAYER_OUT_SCREEN_TIME + CS.UnityEngine.Time.deltaTime if PLAYER_OUT_SCREEN_TIME >= 2 then SetTipsActive("Panel_No_Person", true) PLAYER_IN_SCREEN = false; PLAYER_OUT_SCREEN_TIME = 0 dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_IN_SCREEN, false) end SetPlayerOutScreenTime(PLAYER_OUT_SCREEN_TIME) end local function CheckPlayerInScreen() local isSomeone = CS.ZwnAmlogicHelperData.isSomeone local dataRelay = require("Base/DataRelay.lua") local BREAK_OFF = dataRelay:GetCache(dataRelay.KEY_TYPE.BREAK_OFF) local PLAYER_IN_SCREEN = dataRelay:GetCache(dataRelay.KEY_TYPE.PLAYER_IN_SCREEN) local PLAYER_OUT_SCREEN_TIME = dataRelay:GetCache(dataRelay.KEY_TYPE.PLAYER_OUT_SCREEN_TIME, 0) local PLAYER_JOIN_SCREEN_TIME = dataRelay:GetCache(dataRelay.KEY_TYPE.PLAYER_JOIN_SCREEN_TIME, 0) local PLAYER_UNDETECTED_TIME = dataRelay:GetCache(dataRelay.KEY_TYPE.PLAYER_UNDETECTED_TIME, 0) if not PLAYER_IN_SCREEN then PLAYER_UNDETECTED_TIME = PLAYER_UNDETECTED_TIME + CS.UnityEngine.Time.deltaTime dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_UNDETECTED_TIME, PLAYER_UNDETECTED_TIME) if PLAYER_UNDETECTED_TIME >= 3 then PLAYER_UNDETECTED_TIME = 0 dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_UNDETECTED_TIME, PLAYER_UNDETECTED_TIME) require("Base/SMusicManager.lua"):PlaySound("Audios/Align/backToGameArea.mp3"); end ShowIsSomeOne() if isSomeone then BREAK_OFF = false PLAYER_OUT_SCREEN_TIME = 0 PLAYER_JOIN_SCREEN_TIME = PLAYER_JOIN_SCREEN_TIME + CS.UnityEngine.Time.deltaTime dataRelay:SetCache(dataRelay.KEY_TYPE.BREAK_OFF, BREAK_OFF) SetPlayerOutScreenTime(PLAYER_OUT_SCREEN_TIME) dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_JOIN_SCREEN_TIME, PLAYER_JOIN_SCREEN_TIME) SetTipsActive("Panel_No_Person", false) SetTipsActive("Image_Back_Off", false) SetTipsActive("Panel_Recheck", true) SetJoinImageFillAmount(PLAYER_JOIN_SCREEN_TIME / 3) if GetJoinImageFillAmount() >= 1 then SetTipsActive("Panel_Recheck", false) SetJoinImageFillAmount(0) PLAYER_OUT_SCREEN_TIME = 0 BREAK_OFF = false PLAYER_IN_SCREEN = true SetPlayerOutScreenTime(PLAYER_OUT_SCREEN_TIME) dataRelay:SetCache(dataRelay.KEY_TYPE.BREAK_OFF, BREAK_OFF) dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_IN_SCREEN, PLAYER_IN_SCREEN) end end else PLAYER_UNDETECTED_TIME = 0 dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_UNDETECTED_TIME, PLAYER_UNDETECTED_TIME) end end local function CheckPersonInGame() NoPerson() CheckPlayerInScreen() end local function GetPlayerCoordinate() local dataRelay = require("Base/DataRelay.lua") local MAX_LEFT_X = dataRelay:GetCache(dataRelay.KEY_TYPE.MAX_LEFT_X, 0) local MAX_RIGHT_X = dataRelay:GetCache(dataRelay.KEY_TYPE.MAX_RIGHT_X, 0) local tTransformPose = CS.zwn_common_data.single.zwn_transform_pose local nCoordinate = tTransformPose[0].x - tTransformPose[6].x if nCoordinate > 0 then if MAX_RIGHT_X < nCoordinate then MAX_RIGHT_X = nCoordinate dataRelay:SetCache(dataRelay.KEY_TYPE.MAX_RIGHT_X, MAX_RIGHT_X) end return end if MAX_LEFT_X > nCoordinate then MAX_LEFT_X = nCoordinate dataRelay:SetCache(dataRelay.KEY_TYPE.MAX_LEFT_X, MAX_LEFT_X) end end local function SetCreateObjActive(bShow) local panelCreate = SUIGamingPanel.rootPanel.transform:Find("Panel_Create_Obj").gameObject panelCreate:SetActive(bShow) if not bShow then require("Base/CoroutineHelper.lua"):Stop(coroutineDestoryFun) end end local function SetGameState(gameState) local dataRelay = require("Base/DataRelay.lua") dataRelay:SetCache(dataRelay.KEY_TYPE.GAME_STATE, gameState) end local function SetLevelHighLight(nLevel, bShow) local rootPanel = SUIGamingPanel.rootPanel local panelLevel = rootPanel.transform:Find("Panel_Level").gameObject local imageLevel = panelLevel.transform:Find("Image_Level" .. nLevel).gameObject imageLevel:SetActive(bShow) end local function GetCreateObjConfig() local tConfigLinkGame = require("Config/SConfigManager.lua"):GetConfig("configLinkGame") local dataRelay = require("Base/DataRelay.lua") local GAME_TYPE = dataRelay:GetCache(dataRelay.KEY_TYPE.GAME_TYPE, 1) local tCreateObj if GAME_TYPE == 1 then tCreateObj = tConfigLinkGame.gameCreateObjPath.easy return tCreateObj end if GAME_TYPE == 2 then tCreateObj = tConfigLinkGame.gameCreateObjPath.normal return tCreateObj end if GAME_TYPE == 3 then tCreateObj = tConfigLinkGame.gameCreateObjPath.hard return tCreateObj end end local function GetGameLevelInfo() local dataRelay = require("Base/DataRelay.lua") local GAME_CURRENT_LEVEL = dataRelay:GetCache(dataRelay.KEY_TYPE.GAME_CURRENT_LEVEL, 1) local tConfigLinkGame = require("Config/SConfigManager.lua"):GetConfig("configLinkGame") local tGameLevelInfo = tConfigLinkGame.gameLevelInfo[GAME_CURRENT_LEVEL] dataRelay:SetCache(dataRelay.KEY_TYPE.GAME_LEVEL_INFO, tGameLevelInfo) return tGameLevelInfo end local function GetCreateObjList(tCreateObj, tGameLevelInfo) local tCreateObjCopy = require("Base/Utils.lua"):TableDeepCopy(tCreateObj) local nKindObj = tGameLevelInfo.createObj - tGameLevelInfo.couple local tNeedObj = {} for i = 1, nKindObj, 1 do local nRandomIndex = math.floor(CS.UnityEngine.Random.Range(1, #tCreateObjCopy)) table.insert(tNeedObj, tCreateObjCopy[nRandomIndex]) table.remove(tCreateObjCopy, nRandomIndex) end local tDoubleObj = {} for i = 1, tGameLevelInfo.couple, 1 do local nRandomIndex = math.floor(CS.UnityEngine.Random.Range(1, #tNeedObj)) local tObjItemOne = {} tObjItemOne.name = "double_" .. i tObjItemOne.path = tNeedObj[nRandomIndex].first local tObjItemTwo = {} tObjItemTwo.name = "double_" .. i tObjItemTwo.path = tNeedObj[nRandomIndex].second table.insert(tDoubleObj, tObjItemOne) table.insert(tDoubleObj, tObjItemTwo) table.remove(tNeedObj, nRandomIndex) end return tNeedObj, tDoubleObj end local function ClearAllObj() local dataRelay = require("Base/DataRelay.lua") local tCreateList = dataRelay:GetCache(dataRelay.KEY_TYPE.CREATE_OBJ_LIST) dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_CURRENT_PAIRED, 0) if nil == tCreateList then return end for _, create in pairs(tCreateList) do CS.UnityEngine.GameObject.Destroy(create.gameObject) end end local function SetGameEnd() local actionSequence = CS.DG.Tweening.DOTween.Sequence() actionSequence:AppendInterval(1) actionSequence:AppendCallback(function () local dataRelay = require("Base/DataRelay.lua") local GAME_STATE = dataRelay:GetCache(dataRelay.KEY_TYPE.GAME_STATE, GAME_STATE_PREPARE) if GAME_STATE == GAME_STATE_GAMING then GAME_STATE = GAME_STATE_END dataRelay:SetCache(dataRelay.KEY_TYPE.GAME_STATE, GAME_STATE) end end) end local function CheckDownLevel() local dataRelay = require("Base/DataRelay.lua") local ERROR_TIME = dataRelay:GetCache(dataRelay.KEY_TYPE.ERROR_TIME, 0) local GAME_CURRENT_LEVEL = dataRelay:GetCache(dataRelay.KEY_TYPE.GAME_CURRENT_LEVEL, 1) local tConfigLinkGame = require("Config/SConfigManager.lua"):GetConfig("configLinkGame") if GAME_CURRENT_LEVEL ~= 1 and ERROR_TIME >= tConfigLinkGame.maxErorrTime then SetLevelHighLight(GAME_CURRENT_LEVEL, false) ERROR_TIME = 0 GAME_CURRENT_LEVEL = GAME_CURRENT_LEVEL - 1 dataRelay:SetCache(dataRelay.KEY_TYPE.ERROR_TIME, ERROR_TIME) dataRelay:SetCache(dataRelay.KEY_TYPE.GAME_CURRENT_LEVEL, GAME_CURRENT_LEVEL) SetLevelHighLight(GAME_CURRENT_LEVEL, true) SetGameEnd() return true end return false end local function ResetGameInfo() local dataRelay = require("Base/DataRelay.lua") local ERROR_TIME = dataRelay:GetCache(dataRelay.KEY_TYPE.ERROR_TIME, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.COMBO, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.ERROR_TIME, ERROR_TIME + 1) local bLevelDown = CheckDownLevel() if not bLevelDown then SetGameEnd() end end local function AutoDestoryObj(tCreateList, tGameLevelInfo) require("Base/CoroutineHelper.lua"):Wait(tGameLevelInfo.objStayTime) ResetGameInfo() for _, create in pairs(tCreateList) do CS.UnityEngine.GameObject.Destroy(create.gameObject) end end local function CreateGameObj() ClearAllObj() local rootPanel = SUIGamingPanel.rootPanel local panelCreateObj = rootPanel.transform:Find("Panel_Create_Obj").gameObject local tCreateObj = GetCreateObjConfig() local tGameLevelInfo = GetGameLevelInfo() local tNeedObj, tDoubleObj = GetCreateObjList(tCreateObj, tGameLevelInfo) local dataRelay = require("Base/DataRelay.lua") local SUM_CREATE = dataRelay:GetCache(dataRelay.KEY_TYPE.SUM_CREATE, 0) local GAME_STATE = dataRelay:GetCache(dataRelay.KEY_TYPE.GAME_STATE, GAME_STATE_PREPARE) local tPointGroup = {1, 2, 3, 4, 5, 6} require("Base/SMusicManager.lua"):PlaySound("Audios/Gaming/collectItem.wav") local tCreateList = {} for i = 1, tGameLevelInfo.createObj, 1 do local nRandomGroupIndex = math.floor(CS.UnityEngine.Random.Range(1, #tPointGroup)) local nRandomIndex = math.floor(CS.UnityEngine.Random.Range(1, 3)) local nRealIndex = (tPointGroup[nRandomGroupIndex] - 1) * 3 + nRandomIndex - 1 table.remove(tPointGroup, nRandomGroupIndex) local childGameObject = rootPanel.transform:Find("Panel_Create_Obj_Base"):GetChild(nRealIndex).gameObject local childPos = childGameObject.transform.localPosition local create if #tNeedObj > 0 then SUM_CREATE = SUM_CREATE + 1 dataRelay:SetCache(dataRelay.KEY_TYPE.SUM_CREATE, SUM_CREATE) local tNeedObjPrefab = LoadResource(tNeedObj[1].first) create = CS.UnityEngine.GameObject.Instantiate(tNeedObjPrefab, panelCreateObj.transform) create.transform.localPosition = childPos create.transform.localScale = CS.UnityEngine.Vector3(150, 150, 150) table.remove(tNeedObj, 1) elseif #tDoubleObj > 0 then SUM_CREATE = SUM_CREATE + 1 dataRelay:SetCache(dataRelay.KEY_TYPE.SUM_CREATE, SUM_CREATE) local tDoubleObjPrefab = LoadResource(tDoubleObj[1].path) create = CS.UnityEngine.GameObject.Instantiate(tDoubleObjPrefab, panelCreateObj.transform) create.name = tDoubleObj[1].name create.transform.localPosition = childPos create.transform.localScale = CS.UnityEngine.Vector3(150, 150, 150) table.remove(tDoubleObj, 1) end create.transform:GetComponent("Collider2D").enabled = true table.insert(tCreateList, create) end dataRelay:SetCache(dataRelay.KEY_TYPE.CREATE_OBJ_LIST, tCreateList) SetCreateObjActive(true) coroutineDestoryFun = require("Base/CoroutineHelper.lua"):Start(function () AutoDestoryObj(tCreateList, tGameLevelInfo) end) if GAME_STATE == GAME_STATE_PREPARE then SetGameState(GAME_STATE_GAMING) end end local function ClearSelectObj() local dataRelay = require("Base/DataRelay.lua") dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_SELECT_ONE, nil) dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_SELECT_TWO, nil) end local function SetHandColliderEnabled(bEnabled) local jointFollow = SUIGamingPanel._rootCanvas.transform:Find("ZWNJointFollowHand") if not jointFollow then return end local tHandList = jointFollow.transform.childCount for i = 1, tHandList, 1 do local hand = jointFollow.transform:GetChild(i - 1).gameObject hand:GetComponent("Collider2D").enabled = bEnabled end end local function GamePrepare() CreateGameObj() SetHandColliderEnabled(true) end local function GameEnd() SetGameState(GAME_STATE_PREPARE) ClearSelectObj() end local function UpdateGameState() local dataRelay = require("Base/DataRelay.lua") GAME_STATE = dataRelay:GetCache(dataRelay.KEY_TYPE.GAME_STATE, GAME_STATE_PREPARE) if GAME_STATE == GAME_STATE_GAMEOVER then return end if GAME_STATE == GAME_STATE_PREPARE then GamePrepare() return end if GAME_STATE == GAME_STATE_GAMING then return end if GAME_STATE == GAME_STATE_END then GameEnd() return end end local function SetAllScore(nPercentCorrect, nFocus, nExerise, nReaction) local dataRelay = require("Base/DataRelay.lua") dataRelay:SetCache(dataRelay.KEY_TYPE.PERCENT_CORRECT, nPercentCorrect) dataRelay:SetCache(dataRelay.KEY_TYPE.FOCUS, nFocus) dataRelay:SetCache(dataRelay.KEY_TYPE.EXERISE, nExerise) dataRelay:SetCache(dataRelay.KEY_TYPE.REACTION, nReaction) end local function GetAllResult() local dataRelay = require("Base/DataRelay.lua") local REMAINING_TIME = require("Config/SConfigManager.lua"):GetConfig("configLinkGame").remaingTime local SUM_CREATE = dataRelay:GetCache(dataRelay.KEY_TYPE.SUM_CREATE, 0) local MAX_RIGHT_X = dataRelay:GetCache(dataRelay.KEY_TYPE.MAX_RIGHT_X, 0) local MAX_LEFT_X = dataRelay:GetCache(dataRelay.KEY_TYPE.MAX_LEFT_X, 0) local SUM_TOUCH_ALL = dataRelay:GetCache(dataRelay.KEY_TYPE.SUM_TOUCH_ALL, 0) local SUM_TOUCH_TRUE = dataRelay:GetCache(dataRelay.KEY_TYPE.SUM_TOUCH_TRUE, 0) local MAX_COMBO = dataRelay:GetCache(dataRelay.KEY_TYPE.MAX_COMBO, 0) local nFocus local nPercentCorrect local nReaction = SUM_CREATE / REMAINING_TIME local nExerise = ((MAX_RIGHT_X - MAX_LEFT_X) / CS.UnityEngine.Screen.width) + (SUM_TOUCH_ALL / SUM_CREATE) if 0 == SUM_TOUCH_ALL then nFocus = 0 nPercentCorrect = 0 SetAllScore(nPercentCorrect, nFocus, nExerise, nReaction) return end local nComboScale = 10 nPercentCorrect = ((SUM_TOUCH_TRUE / SUM_TOUCH_ALL) % 0.01) * 100 nFocus = (SUM_TOUCH_TRUE / SUM_TOUCH_ALL) + (MAX_COMBO / nComboScale) SetAllScore(nPercentCorrect, nFocus, nExerise, nReaction) end local function JumpToEndPage() local SUIEndPanel = require("UI/SUIEndPanel.lua") SUIEndPanel.SetRootPanelActive(true) SUIGamingPanel.SetRootPanelActive(false) -- require("Base/UIHelper.lua"):SwitchUI("UI/SUIEndPanel.lua", "UI/SUIGamingPanel.lua") end local function SetGameOver() GetAllResult() JumpToEndPage() end local function ShowEndBoom() local rootPanel = SUIGamingPanel.rootPanel local endBoom = rootPanel.transform:Find("EffectEndBoom").gameObject SetCreateObjActive(false) SetGameState(GAME_STATE_GAMEOVER) endBoom:SetActive(true) require("Base/CoroutineHelper.lua"):Wait(1) SetGameOver() end local function CountDown() local rootPanel = SUIGamingPanel.rootPanel local uiHelper = require("Base/UIHelper.lua") local textTime = rootPanel.transform:Find("Panel_Time/Text_Time").gameObject local REMAINING_TIME = require("Config/SConfigManager.lua"):GetConfig("configLinkGame").remaingTime local nTime = REMAINING_TIME local sCDTime = "时间: " .. nTime uiHelper:SetTextInfo(rootPanel, "Panel_Time/Text_Time", sCDTime) local nMinWaringTime = 3 for i = 1, REMAINING_TIME, 1 do require("Base/CoroutineHelper.lua"):Wait(1) local nTime = REMAINING_TIME - i local sCDTime = "时间: " .. nTime uiHelper:SetTextInfo(rootPanel, "Panel_Time/Text_Time", sCDTime) if nTime <= nMinWaringTime then textTime:GetComponent("Text").color = CS.UnityEngine.Color(255, 253, 0, 255) textTime:GetComponent("Text").fontSize = 60 if nTime == nMinWaringTime then require("Base/SMusicManager.lua"):PlaySound("Audios/Gaming/countDown.mp3") end end if nTime == 0 then local panelCreate = rootPanel.transform:Find("Panel_Create_Obj").gameObject panelCreate:SetActive(false) ShowEndBoom() end end end local function CheckUpLevel() local rootPanel = SUIGamingPanel.rootPanel local imageLevelUp = rootPanel.transform:Find("Image_Level_Up").gameObject local dataRelay = require("Base/DataRelay.lua") local tConfigLinkGame = require("Config/SConfigManager.lua"):GetConfig("configLinkGame") local GAME_CURRENT_LEVEL = dataRelay:GetCache(dataRelay.KEY_TYPE.GAME_CURRENT_LEVEL, 1) local COMBO = dataRelay:GetCache(dataRelay.KEY_TYPE.COMBO, 0) local MAX_LEVEL = dataRelay:GetCache(dataRelay.KEY_TYPE.MAX_LEVEL, 0) if GAME_CURRENT_LEVEL ~= tConfigLinkGame.maxGameLevel and COMBO >= tConfigLinkGame.maxComboUpLevel then SetLevelHighLight(GAME_CURRENT_LEVEL, false) GAME_CURRENT_LEVEL = GAME_CURRENT_LEVEL + 1 dataRelay:SetCache(dataRelay.KEY_TYPE.GAME_CURRENT_LEVEL, GAME_CURRENT_LEVEL) imageLevelUp:GetComponent("Image"):DOFade(1, 0) if GAME_CURRENT_LEVEL > MAX_LEVEL then MAX_LEVEL = GAME_CURRENT_LEVEL dataRelay:SetCache(dataRelay.KEY_TYPE.MAX_LEVEL, MAX_LEVEL) end dataRelay:SetCache(dataRelay.KEY_TYPE.COMBO, 0) SetLevelHighLight(GAME_CURRENT_LEVEL, true) imageLevelUp:GetComponent("Image"):DOFade(0, 2) SetCreateObjActive(false) -- ClearAllObj() SetGameEnd() end end local function SelectSuccessEffect(targetSelect, successEffect) local targetSelectPos = targetSelect.transform.localPosition successEffect.transform.localPosition = targetSelectPos CS.UnityEngine.GameObject.Destroy(targetSelect) successEffect:SetActive(true) local actionSequence = CS.DG.Tweening.DOTween.Sequence() actionSequence:AppendInterval(1) actionSequence:AppendCallback(function () successEffect:SetActive(false) end) end local function RefreshScore(GAME_LEVEL_INFO, nCurrentScore) local rootPanel = SUIGamingPanel.rootPanel local textAddScore = rootPanel.transform:Find("Text_Add_Score").gameObject:GetComponent("Text") require("Base/UIHelper.lua"):SetTextInfo(rootPanel, "Panel_Score/Text_Score", "得分: " .. nCurrentScore) textAddScore.color = CS.UnityEngine.Color(255, 255, 0, 255) textAddScore.text = "+" .. GAME_LEVEL_INFO.levelScore textAddScore:DOFade(0, 1) end local function AddScore(successOne, successTwo) local dataRelay = require("Base/DataRelay.lua") local CURRENT_SCORE = dataRelay:GetCache(dataRelay.KEY_TYPE.CURRENT_SCORE, 0) local GAME_LEVEL_INFO = dataRelay:GetCache(dataRelay.KEY_TYPE.GAME_LEVEL_INFO, {}) successOne:SetActive(false) successTwo:SetActive(false) CURRENT_SCORE = CURRENT_SCORE + GAME_LEVEL_INFO.levelScore dataRelay:SetCache(dataRelay.KEY_TYPE.CURRENT_SCORE, CURRENT_SCORE) require("Base/SMusicManager.lua"):PlaySound("Audios/Gaming/addScore.wav") RefreshScore(GAME_LEVEL_INFO, CURRENT_SCORE) end local function ShowStarAddScore(selectOne, selectTwo) local rootPanel = SUIGamingPanel.rootPanel local textAddScore = rootPanel.transform:Find("Text_Add_Score").gameObject local starToPos = textAddScore.transform.localPosition local successOne = rootPanel.transform:Find("EffectAddScore_1").gameObject local successTwo = rootPanel.transform:Find("EffectAddScore_2").gameObject successOne.transform.localPosition = selectOne.transform.localPosition successTwo.transform.localPosition = selectTwo.transform.localPosition successOne:SetActive(true) successTwo:SetActive(true) successOne.transform:DOLocalMove(starToPos, 1):OnComplete(function () AddScore(successOne, successTwo) end) successTwo.transform:DOLocalMove(starToPos, 1) end local function SelectSuccess() local dataRelay = require("Base/DataRelay.lua") local COMBO = dataRelay:GetCache(dataRelay.KEY_TYPE.COMBO, 0) local MAX_COMBO = dataRelay:GetCache(dataRelay.KEY_TYPE.MAX_COMBO, 0) local GAMING_CURRENT_PAIRED = dataRelay:GetCache(dataRelay.KEY_TYPE.GAMING_CURRENT_PAIRED, 0) local SUM_TOUCH_TRUE = dataRelay:GetCache(dataRelay.KEY_TYPE.SUM_TOUCH_TRUE, 0) local GAMING_SELECT_ONE = dataRelay:GetCache(dataRelay.KEY_TYPE.GAMING_SELECT_ONE) local GAMING_SELECT_TWO = dataRelay:GetCache(dataRelay.KEY_TYPE.GAMING_SELECT_TWO) local GAME_LEVEL_INFO = dataRelay:GetCache(dataRelay.KEY_TYPE.GAME_LEVEL_INFO, {}) local effectStarBurstOne = SUIGamingPanel.rootPanel.transform:Find("EffectStarBurst2D_1").gameObject local effectStarBurstTwo = SUIGamingPanel.rootPanel.transform:Find("EffectStarBurst2D_2").gameObject COMBO = COMBO + 1 SUM_TOUCH_TRUE = SUM_TOUCH_TRUE + 2 GAMING_CURRENT_PAIRED = GAMING_CURRENT_PAIRED + 1 dataRelay:SetCache(dataRelay.KEY_TYPE.COMBO, COMBO) dataRelay:SetCache(dataRelay.KEY_TYPE.SUM_TOUCH_TRUE, SUM_TOUCH_TRUE) dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_CURRENT_PAIRED, GAMING_CURRENT_PAIRED) dataRelay:SetCache(dataRelay.KEY_TYPE.ERROR_TIME, 0) if COMBO > MAX_COMBO then MAX_COMBO = COMBO dataRelay:SetCache(dataRelay.KEY_TYPE.MAX_COMBO, MAX_COMBO) end CheckUpLevel() SelectSuccessEffect(GAMING_SELECT_ONE, effectStarBurstOne) SelectSuccessEffect(GAMING_SELECT_TWO, effectStarBurstTwo) require("Base/SMusicManager.lua"):PlaySound("Audios/Gaming/selectSuccess.mp3") if GAMING_CURRENT_PAIRED >= GAME_LEVEL_INFO.couple then -- ClearAllObj() SetCreateObjActive(false) SetGameEnd() end ShowStarAddScore(GAMING_SELECT_ONE, GAMING_SELECT_TWO) GAMING_SELECT_ONE = nil GAMING_SELECT_TWO = nil dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_SELECT_ONE, GAMING_SELECT_ONE) dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_SELECT_TWO, GAMING_SELECT_TWO) SetHandColliderEnabled(true) end local function SelectFailedEffect(targetSelect, failedEffect) local targetSelectPos = targetSelect.transform.localPosition failedEffect.transform.localPosition = targetSelectPos targetSelect:SetActive(false) -- CS.UnityEngine.GameObject.Destroy(targetSelect) failedEffect:SetActive(true) local actionSequence = CS.DG.Tweening.DOTween.Sequence() actionSequence:AppendInterval(1) actionSequence:AppendCallback(function () failedEffect:SetActive(false) end) end local function SelectFailed() local dataRelay = require("Base/DataRelay.lua") local COMBO = dataRelay:GetCache(dataRelay.KEY_TYPE.COMBO, 0) local ERROR_TIME = dataRelay:GetCache(dataRelay.KEY_TYPE.ERROR_TIME, 0) local GAMING_SELECT_ONE = dataRelay:GetCache(dataRelay.KEY_TYPE.GAMING_SELECT_ONE) local GAMING_SELECT_TWO = dataRelay:GetCache(dataRelay.KEY_TYPE.GAMING_SELECT_TWO) local effectFadeOne = SUIGamingPanel.rootPanel.transform:Find("EffectFade_1").gameObject local effectFadeTwo = SUIGamingPanel.rootPanel.transform:Find("EffectFade_2").gameObject COMBO = 0 ERROR_TIME = ERROR_TIME + 1 dataRelay:SetCache(dataRelay.KEY_TYPE.COMBO, COMBO) dataRelay:SetCache(dataRelay.KEY_TYPE.ERROR_TIME, ERROR_TIME) require("Base/SMusicManager.lua"):PlaySound("Audios/Gaming/selectError.mp3") SetCreateObjActive(false) -- ClearAllObj() CheckDownLevel() SelectFailedEffect(GAMING_SELECT_ONE, effectFadeOne) SelectFailedEffect(GAMING_SELECT_TWO, effectFadeTwo) SetGameEnd() end local function CheckSelectResult(selectGameObjectOne, selectGameObjectTwo) local rootPanel = SUIGamingPanel.rootPanel local lineLink = rootPanel.transform:Find("Line_Link").gameObject local line = lineLink:GetComponent("LineRenderer") local selectOnePos = selectGameObjectOne.transform.position local selectTwoPos = selectGameObjectTwo.transform.position line:SetPosition(0, selectOnePos) line:SetPosition(1, selectTwoPos) local nWaitClearTime = 0.1 local actionSequence = CS.DG.Tweening.DOTween.Sequence() actionSequence:AppendInterval(nWaitClearTime) actionSequence:AppendCallback(function () local defaultPos = CS.UnityEngine.Vector3(0, 0, 0) line:SetPosition(0, defaultPos) line:SetPosition(1, defaultPos) end) require("Base/SMusicManager.lua"):PlaySound("Audios/Gaming/lineLink.wav") if selectGameObjectOne.name == selectGameObjectTwo.name then SelectSuccess() return end SelectFailed() end local function RefreshUI() coroutineTimeOutFun = require("Base/CoroutineHelper.lua"):Start(CountDown) end local function InitData() local dataRelay = require("Base/DataRelay.lua") dataRelay:SetCache(dataRelay.KEY_TYPE.PASS_WARING_TIME, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_OUT_SCREEN_TIME, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.BREAK_OFF_TIME, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_UNDETECTED_TIME, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_IN_SCREEN, true) dataRelay:SetCache(dataRelay.KEY_TYPE.BREAK_OFF, false) dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_JOIN_SCREEN_TIME, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.MAX_RIGHT_X, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.MAX_LEFT_X, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.GAME_STATE, GAME_STATE_PREPARE) dataRelay:SetCache(dataRelay.KEY_TYPE.GAME_CURRENT_LEVEL, 1) dataRelay:SetCache(dataRelay.KEY_TYPE.SUM_CREATE, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.SUM_TOUCH_ALL, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.SUM_TOUCH_TRUE, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.MAX_COMBO, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.COMBO, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.ERROR_TIME, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_CURRENT_PAIRED, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.GAME_LEVEL_INFO, nil) dataRelay:SetCache(dataRelay.KEY_TYPE.MAX_LEVEL, 1) dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_SELECT_ONE, nil) dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_SELECT_TWO, nil) dataRelay:SetCache(dataRelay.KEY_TYPE.CREATE_OBJ_LIST, nil) -- for panelEnd dataRelay:SetCache(dataRelay.KEY_TYPE.CURRENT_SCORE, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.PERCENT_CORRECT, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.FOCUS, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.EXERISE, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.REACTION, 0) end local function UnInitData() local dataRelay = require("Base/DataRelay.lua") dataRelay:SetCache(dataRelay.KEY_TYPE.ALIGN_AREA, nil) dataRelay:SetCache(dataRelay.KEY_TYPE.PASS_WARING_TIME, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_OUT_SCREEN_TIME, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.BREAK_OFF_TIME, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_UNDETECTED_TIME, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_IN_SCREEN, true) dataRelay:SetCache(dataRelay.KEY_TYPE.BREAK_OFF, false) dataRelay:SetCache(dataRelay.KEY_TYPE.PLAYER_JOIN_SCREEN_TIME, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.MAX_RIGHT_X, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.MAX_LEFT_X, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.GAME_STATE, GAME_STATE_PREPARE) dataRelay:SetCache(dataRelay.KEY_TYPE.GAME_CURRENT_LEVEL, 1) dataRelay:SetCache(dataRelay.KEY_TYPE.SUM_CREATE, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.SUM_TOUCH_ALL, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.SUM_TOUCH_TRUE, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.MAX_COMBO, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.COMBO, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.ERROR_TIME, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_CURRENT_PAIRED, 0) dataRelay:SetCache(dataRelay.KEY_TYPE.GAME_LEVEL_INFO, nil) dataRelay:SetCache(dataRelay.KEY_TYPE.MAX_LEVEL, 1) dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_SELECT_ONE, nil) dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_SELECT_TWO, nil) dataRelay:SetCache(dataRelay.KEY_TYPE.CREATE_OBJ_LIST, nil) end local function UnInitUI() local rootPanel = SUIGamingPanel.rootPanel local endBoom = rootPanel.transform:Find("EffectEndBoom").gameObject local panelCreate = rootPanel.transform:Find("Panel_Create_Obj").gameObject local textTime = rootPanel.transform:Find("Panel_Time/Text_Time").gameObject local dataRelay = require("Base/DataRelay.lua") local GAME_CURRENT_LEVEL = dataRelay:GetCache(dataRelay.KEY_TYPE.GAME_CURRENT_LEVEL, 1) panelCreate:SetActive(true) ClearAllObj() SetLevelHighLight(GAME_CURRENT_LEVEL, false) SetLevelHighLight(1, true) textTime:GetComponent("Text").color = CS.UnityEngine.Color(255, 255, 255, 255) textTime:GetComponent("Text").fontSize = 80 endBoom:SetActive(false) require("Base/UIHelper.lua"):SetTextInfo(rootPanel, "Panel_Score/Text_Score", "得分: " .. 0) end local function InitAllData() InitData() RefreshUI() end local function UnInitAllData() UnInitUI() UnInitData() StopCoroutine() end function SUIGamingPanel.SetRootPanelActive(bShow) SUIGamingPanel.rootPanel:SetActive(bShow) if bShow then InitAllData() return end UnInitAllData() end function SUIGamingPanel:SelectShape(selectObj) assert(selectObj, "selectObj not exit") local dataRelay = require("Base/DataRelay.lua") local SUM_TOUCH_ALL = dataRelay:GetCache(dataRelay.KEY_TYPE.SUM_TOUCH_ALL, 0) local GAMING_SELECT_ONE = dataRelay:GetCache(dataRelay.KEY_TYPE.GAMING_SELECT_ONE, nil) SUM_TOUCH_ALL = SUM_TOUCH_ALL + 1 dataRelay:SetCache(dataRelay.KEY_TYPE.SUM_TOUCH_ALL, SUM_TOUCH_ALL) if not GAMING_SELECT_ONE then GAMING_SELECT_ONE = selectObj dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_SELECT_ONE, GAMING_SELECT_ONE) return end if GAMING_SELECT_ONE.transform.position.x == selectObj.transform.position.x and GAMING_SELECT_ONE.transform.position.y == selectObj.transform.position.y then return end local GAMING_SELECT_TWO = dataRelay:GetCache(dataRelay.KEY_TYPE.GAMING_SELECT_TWO, nil) if GAMING_SELECT_TWO then return end GAMING_SELECT_TWO = selectObj dataRelay:SetCache(dataRelay.KEY_TYPE.GAMING_SELECT_TWO, GAMING_SELECT_TWO) SetHandColliderEnabled(false) CheckSelectResult(GAMING_SELECT_ONE, GAMING_SELECT_TWO) end function SUIGamingPanel.Awake(luaRoot) SUIGamingPanel.luaRoot = luaRoot local canvas = CS.UnityEngine.GameObject.Find("Canvas") SUIGamingPanel._rootCanvas = canvas local prefabPanelGaming = LoadResource("Prefabs/UI/SUIGamingPanel.prefab") local rootPanel = CS.UnityEngine.GameObject.Instantiate(prefabPanelGaming, SUIGamingPanel._rootCanvas.transform) SUIGamingPanel.rootPanel = rootPanel end function SUIGamingPanel.Start() end function SUIGamingPanel.Update() if not SUIGamingPanel.rootPanel.activeSelf then return end CheckAreaInfo() CheckPersonInGame() GetPlayerCoordinate() UpdateGameState() end function SUIGamingPanel.OnDestroy() CS.UnityEngine.GameObject.Destroy(SUIGamingPanel.rootPanel) end return SUIGamingPanel