-
-
Notifications
You must be signed in to change notification settings - Fork 124
/
onRenderStepFrame.lua
37 lines (31 loc) · 894 Bytes
/
onRenderStepFrame.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
--[=[
Executes code at a specific point in render step priority queue
@class onRenderStepFrame
]=]
local RunService = game:GetService("RunService")
local HttpService = game:GetService("HttpService")
--[=[
Executes code at a specific point in render step priority queue.
@function onRenderStepFrame
@param priority number
@return MaidTask
@within onRenderStepFrame
]=]
return function(priority, callback)
assert(type(priority) == "number", "Bad priority")
assert(type(callback) == "function", "Bad callback")
local key = HttpService:GenerateGUID(false) .. "_onRenderStepFrame"
local unbound = false
RunService:BindToRenderStep(key, priority, function()
if not unbound then -- Probably not needed
RunService:UnbindFromRenderStep(key)
callback()
end
end)
return function()
if not unbound then
RunService:UnbindFromRenderStep(key)
unbound = true
end
end
end