Last active
September 21, 2021 23:03
-
-
Save lucasmz-dev/a1b49191c39eff57156ac925314adf85 to your computer and use it in GitHub Desktop.
OOP BindToRenderStep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local RunService: RunService = game:GetService("RunService") | |
local ScriptBinding = {} | |
ScriptBinding.__index = ScriptBinding | |
local BindingId: number = 0 | |
function ScriptBinding:Unbind() | |
if self._binded == false then | |
return | |
end | |
self._binded = false | |
RunService:UnbindFromRenderStep( | |
self._bindingId | |
) | |
end | |
export type ScriptBinding = typeof( | |
setmetatable({}, ScriptBinding) | |
) | |
return function( | |
priority: number, | |
callback: (deltaTime: number) -> () | |
) | |
assert( | |
typeof(priority) == 'number', | |
"Must be number" | |
) | |
assert( | |
typeof(callback) == 'function', | |
"Must be function" | |
) | |
BindingId += 1 | |
local bindingId = "BindToRenderStep_".. BindingId | |
RunService:BindToRenderStep( | |
bindingId, | |
priority, | |
callback | |
) | |
return setmetatable({ | |
_binded = true, | |
_bindingId = bindingId | |
}, ScriptBinding) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment