-- ============================================================================== -- Hide UI Lua Script for Honkai: Star Rail (FFGO Method) -- Press "ฃ" (Backslash '\' on keyboard) to toggle UI visibility -- Uses /UIRoot/Page CanvasGroup alpha - character rendering stays completely intact! -- ============================================================================== 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 _G.__HIDE_UI_ENABLED = _G.__HIDE_UI_ENABLED or false _G.__HIDE_UI_LAST_FRAME = _G.__HIDE_UI_LAST_FRAME or 0 -- Ensure all cameras and canvases are restored if previously disabled pcall(function() local allCams = Camera.allCameras if allCams and allCams.Length > 0 then for i = 0, allCams.Length - 1 do local c = allCams[i] if c and (c.name == "UICamera" or string.find(c.name, "UI") or string.find(c.name, "ui")) then c.enabled = true end end end local canvases = GameObject.FindObjectsOfType(typeof(CS.UnityEngine.Canvas)) if canvases and canvases.Length > 0 then for i = 0, canvases.Length - 1 do if canvases[i] then canvases[i].enabled = true end end end end) local function ensure_canvas_and_set_alpha(obj, visible) if not obj then return end pcall(function() local cg = obj:GetComponent(typeof(CanvasGroup)) if not cg then cg = obj:AddComponent(typeof(CanvasGroup)) end if cg then cg.alpha = visible and 1.0 or 0.0 cg.interactable = true cg.blocksRaycasts = true end end) end local function set_canvasgroup_visible(obj, visible) if not obj then return end pcall(function() local cg = obj:GetComponent(typeof(CanvasGroup)) if cg then cg.alpha = visible and 1.0 or 0.0 cg.interactable = true cg.blocksRaycasts = true end for i = 0, obj.transform.childCount - 1 do local child = obj.transform:GetChild(i).gameObject local childCg = child:GetComponent(typeof(CanvasGroup)) if childCg then childCg.alpha = visible and 1.0 or 0.0 childCg.interactable = true childCg.blocksRaycasts = true end end end) end local function set_ui_visible(visible) pcall(function() local gameUI = GameObject.Find("/UIRoot/Page") or GameObject.Find("UIRoot/Page") if gameUI then ensure_canvas_and_set_alpha(gameUI, visible) local battleGameUI = GameObject.Find("/UIRoot/Page/BattleGamePhaseUI(Clone)") or GameObject.Find("UIRoot/Page/BattleGamePhaseUI(Clone)") if battleGameUI then ensure_canvas_and_set_alpha(battleGameUI, visible) set_canvasgroup_visible(battleGameUI, visible) end end end) end function _G.__HIDE_UI_TICK() pcall(function() local curFrame = Time.frameCount if _G.__HIDE_UI_LAST_FRAME == curFrame then return end -- Check physical key 'ฃ' on keyboard (KeyCode.Backslash) if Input.GetKeyDown(KeyCode.Backslash) then _G.__HIDE_UI_LAST_FRAME = curFrame _G.__HIDE_UI_ENABLED = not _G.__HIDE_UI_ENABLED set_ui_visible(not _G.__HIDE_UI_ENABLED) if _G.__HIDE_UI_ENABLED then CS.UnityEngine.Debug.Log("[UI Toggle] UI Hidden (ซ่อน UI แล้ว)") else CS.UnityEngine.Debug.Log("[UI Toggle] UI Restored (แสดง UI ตามปกติ)") end end -- When hidden, keep enforcing /UIRoot/Page visibility if _G.__HIDE_UI_ENABLED then set_ui_visible(false) 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] Loaded successfully (FFGO method)! Press 'ฃ' to toggle UI.") end