Skip to content

Instantly share code, notes, and snippets.

@lucasmz-dev
Last active September 21, 2021 23:03
Show Gist options
  • Save lucasmz-dev/a1b49191c39eff57156ac925314adf85 to your computer and use it in GitHub Desktop.
Save lucasmz-dev/a1b49191c39eff57156ac925314adf85 to your computer and use it in GitHub Desktop.
OOP BindToRenderStep
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