local R=game:GetService("\087\111\114\107\115\112\097\099\101")local s=require(script.Parent:WaitForChild("\066\097\115\101\084\101\115\116"))local t=require((script.Parent:WaitForChild("\067\111\109\109\111\110")):WaitForChild("\080\114\111\098\108\101\109\072\105\103\104\108\105\103\104\116\115"))local W=s:Extend()W:SetClassName("\083\117\114\102\097\099\101\071\117\105\067\114\097\115\104\084\101\115\116")function W.__new(s)s:InitializeSuper()s.Name="\085\110\119\114\097\112\112\101\100 \067\108\105\099\107\068\101\116\101\099\116\111\114\115"s.Icon="\078\079\078\069"s.Status="\078\111\116 \068\101\116\101\099\116\101\100"s.ProblemText="\067\108\105\099\107\068\101\116\101\099\116\111\114\115 \099\097\110 \098\101 \104\097\114\100 \116\111 \105\110\116\101\114\097\099\116 \119\105\116\104 \105\110 \086\082\046 \084\104\101\121 \097\108\115\111 \099\097\110\'\116 \098\101 \105\110\116\101\114\097\099\116\101\100 \119\105\116\104 \103\097\109\101\112\097\100\115 \097\110\100 \099\097\110 \098\101 \100\105\102\102\105\099\117\108\116 \116\111 \105\100\101\110\116\105\102\121 \102\111\114 \109\111\098\105\108\101 \117\115\101\114\115\046"s.SolutionText="\087\104\101\110 \112\111\115\115\105\098\108\101\044 \080\114\111\120\105\109\105\116\121\080\114\111\109\112\116\115 \115\104\111\117\108\100 \098\101 \117\115\101\100\046 \073\102 \105\116 \105\115\110\'\116 \112\111\115\115\105\098\108\101\044 \115\117\099\104 \097\115 \115\101\118\101\114\097\108 \098\117\116\116\111\110\115 \098\101\105\110\103 \099\108\111\115\101 \116\111 \101\097\099\104 \111\116\104\101\114\044 \117\115\101 \078\101\120\117\115 \086\082 \067\111\114\101 \116\111 \119\114\097\112 \116\104\101\109\046"s.ClickDetectors={}s.Highlights=t.new(s)R.DescendantRemoving:Connect(function(R)if not R:IsA("\067\108\105\099\107\068\101\116\101\099\116\111\114")then return end s.ClickDetectors[R]=nil s:UpdateState()end)R.DescendantAdded:Connect(function(R)if not R:IsA("\067\108\105\099\107\068\101\116\101\099\116\111\114")then return end s.ClickDetectors[R]=true s:UpdateState()end)for R,t in pairs(R:GetDescendants())do if t:IsA("\067\108\105\099\107\068\101\116\101\099\116\111\114")then s.ClickDetectors[t]=true s:UpdateState()end end;(coroutine.wrap(function()while true do s:UpdateState()wait(.25)end end))()end function W.UpdateState(R)local s=R:GetNexusVRCore()local t=s and s:GetResource("\078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101")local W,V={},{}for R,s in pairs(R.ClickDetectors)do if R.Parent and(R.Parent:IsA("\066\097\115\101\080\097\114\116")and(not t or not t.CachedInstances[R]))then table.insert(W,R)table.insert(V,R.Parent)end end if#W>0 then R.Icon="\087\065\082\078\073\078\071"R.Status="\080\114\111\098\108\101\109 \068\101\116\101\099\116\101\100"else R.Icon="\078\079\078\069"R.Status="\078\111\116 \068\101\116\101\099\116\101\100"end R.Highlights.Objects=V end return W
--[[
TheNexusAvenger

Test for ClickDetectors not wrapped by Nexus VR Core.
--]]

local Workspace = game:GetService("Workspace")

local BaseTest = require(script.Parent:WaitForChild("BaseTest"))
local ProblemHighlights = require(script.Parent:WaitForChild("Common"):WaitForChild("ProblemHighlights"))

local SurfaceGuiCrashTest = BaseTest:Extend()
SurfaceGuiCrashTest:SetClassName("SurfaceGuiCrashTest")



--[[
Creates the test.
--]]
function SurfaceGuiCrashTest:__new()
    self:InitializeSuper()

    --Set up the initial state.
    self.Name = "Unwrapped ClickDetectors"
    self.Icon = "NONE"
    self.Status = "Not Detected"
    self.ProblemText = "ClickDetectors can be hard to interact with in VR. They also can't be interacted with gamepads and can be difficult to identify for mobile users."
    self.SolutionText = "When possible, ProximityPrompts should be used. If it isn't possible, such as several buttons being close to each other, use Nexus VR Core to wrap them."
    self.ClickDetectors = {}
    self.Highlights = ProblemHighlights.new(self)

    --Connect ClickDetectors in Workspace.
    Workspace.DescendantRemoving:Connect(function(Ins)
        if not Ins:IsA("ClickDetector") then return end
        self.ClickDetectors[Ins] = nil
        self:UpdateState()
    end)
    Workspace.DescendantAdded:Connect(function(Ins)
        if not Ins:IsA("ClickDetector") then return end
        self.ClickDetectors[Ins] = true
        self:UpdateState()
    end)
    for _,Ins in pairs(Workspace:GetDescendants()) do
        if Ins:IsA("ClickDetector") then
            self.ClickDetectors[Ins] = true
            self:UpdateState()
        end
    end

    --Occasionally update the ClickDetectors.
    coroutine.wrap(function()
        while true do
            self:UpdateState()
            wait(0.25)
        end
    end)()
end

--[[
Updates the state.
--]]
function SurfaceGuiCrashTest:UpdateState()
    --Determine the problematic ClickDetectors.
    local NexusVRCore = self:GetNexusVRCore()
    local NexusWrappedInstance = NexusVRCore and NexusVRCore:GetResource("NexusWrappedInstance")
    local ClickDetectors,ClickDetectorParts = {},{}
    for ClickDetector,_ in pairs(self.ClickDetectors) do
        if ClickDetector.Parent and ClickDetector.Parent:IsA("BasePart") and (not NexusWrappedInstance or not NexusWrappedInstance.CachedInstances[ClickDetector]) then
            table.insert(ClickDetectors,ClickDetector)
            table.insert(ClickDetectorParts,ClickDetector.Parent)
        end
    end

    --Set the state.
    if #ClickDetectors > 0 then
        self.Icon = "WARNING"
        self.Status = "Problem Detected"
    else
        self.Icon = "NONE"
        self.Status = "Not Detected"
    end
    self.Highlights.Objects = ClickDetectorParts
end



return SurfaceGuiCrashTest