-- Backslash toggles HUD only. Keep pages, dialogs and UI cameras visible. local Input = CS.UnityEngine.Input local KeyCode = CS.UnityEngine.KeyCode local Time = CS.UnityEngine.Time local GameObject = CS.UnityEngine.GameObject local CanvasGroup = CS.UnityEngine.CanvasGroup local Camera = CS.UnityEngine.Camera -- Names observed under UIRoot in this Client, plus the existing battle HUD. -- Never target an ancestor shared by HUD and character/reward dialogs. local HUD_PATHS = { "UIRoot/Page/MazeMainPage(Clone)", "UIRoot/Page/BattleGamePhaseUI(Clone)", "UIRoot/BelowPage/AdventureWaypointsPage(Clone)", "UIRoot/BelowPage/MazeJumpingText(Clone)", "UIRoot/BelowPage/MazeMonsterWarningPage(Clone)", "UIRoot/AboveDialog/BetaHintDialog(Clone)", "VersionText" } -- The old script did not record CanvasGroup state. Undo its blanket hide once -- on live upgrade; a fresh Client session avoids any lost legacy fade state. if _G.__HIDE_UI_REGISTERED and _G.__HIDE_UI_SCHEMA ~= 2 and _G.__HIDE_UI_ENABLED then pcall(function() local cams = Camera.allCameras for i = 0, cams.Length - 1 do local mask = (_G.__ORIG_CAM_MASKS or {})[cams[i]:GetInstanceID()] if mask ~= nil then cams[i].cullingMask = mask end end local function restore(obj) if obj then local cg = obj:GetComponent(typeof(CanvasGroup)) if cg then cg.alpha = 1; cg.blocksRaycasts = true; cg.interactable = true end end end local root = GameObject.Find("UIRoot") if root then restore(root) local t = root.transform for i = 0, t.childCount - 1 do local c = t:GetChild(i); restore(c.gameObject) for j = 0, c.childCount - 1 do restore(c:GetChild(j).gameObject) end end end local canvases = GameObject.FindObjectsOfType(typeof(CS.UnityEngine.Canvas)) for i = 0, canvases.Length - 1 do restore(canvases[i].gameObject) end end) end _G.__HIDE_UI_SCHEMA = 2 _G.__HIDE_UI_ENABLED = _G.__HIDE_UI_ENABLED or false _G.__HIDE_UI_TARGETS = _G.__HIDE_UI_TARGETS or {} local function restore_hud() for id, state in pairs(_G.__HIDE_UI_TARGETS) do pcall(function() if state.group then if state.added then CS.UnityEngine.Object.Destroy(state.group) else state.group.alpha = state.alpha state.group.blocksRaycasts = state.raycast state.group.interactable = state.interactable end end end) _G.__HIDE_UI_TARGETS[id] = nil end end local function hide_hud() for _, path in ipairs(HUD_PATHS) do pcall(function() local obj = GameObject.Find(path) if not obj then return end local id = obj:GetInstanceID() local state = _G.__HIDE_UI_TARGETS[id] if not state then local group = obj:GetComponent(typeof(CanvasGroup)) local added = not group if added then group = obj:AddComponent(typeof(CanvasGroup)) end state = {group=group, added=added, alpha=group.alpha, raycast=group.blocksRaycasts, interactable=group.interactable} _G.__HIDE_UI_TARGETS[id] = state end state.group.alpha = 0 state.group.blocksRaycasts = false state.group.interactable = false end) end end function _G.__HIDE_UI_TICK() pcall(function() local frame = Time.frameCount if _G.__HIDE_UI_LAST_FRAME == frame then return end _G.__HIDE_UI_LAST_FRAME = frame local toggled = Input.GetKeyDown(KeyCode.Backslash) if toggled then _G.__HIDE_UI_ENABLED = not _G.__HIDE_UI_ENABLED if not _G.__HIDE_UI_ENABLED then restore_hud() end end -- Only the small named HUD list is checked, four times a second. -- New pages/dialogs never inherit a hidden UIRoot or UI camera. if _G.__HIDE_UI_ENABLED then local now = Time.unscaledTime if toggled or now >= (_G.__HIDE_UI_NEXT_SCAN or 0) then _G.__HIDE_UI_NEXT_SCAN = now + 0.25 hide_hud() end end end) end -- Hook into render pipeline if not _G.__HIDE_UI_REGISTERED then _G.__HIDE_UI_REGISTERED = true local function hook(target, evt) pcall(function() target[evt]('+', function(c) _G.__HIDE_UI_TICK() end) end) pcall(function() target[evt] = target[evt] + function(c) _G.__HIDE_UI_TICK() end end) end hook(Camera, "onPreRender") hook(Camera, "onPreCull") hook(Camera, "onPostRender") pcall(function() CS.UnityEngine.Application.onBeforeRender('+', function() _G.__HIDE_UI_TICK() end) end) pcall(function() CS.UnityEngine.Application.onBeforeRender = CS.UnityEngine.Application.onBeforeRender + function() _G.__HIDE_UI_TICK() end end) CS.UnityEngine.Debug.Log("[UI Toggle Script] HUD-only HideUI loaded! Press 'ฃ' to toggle UI.") end