Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function unim(a)
- local class = a.ClassName
- local methods = {
- Model = {
- CFrame = function(frame)
- local origin = a:GetBoundingBox()
- local pivot = a.WorldPivot
- if not frame then
- return origin
- end
- a.WorldPivot = frame
- local all = a:GetDescendants()
- for _,v in pairs(all) do
- if not v:IsA("BasePart") then
- continue
- end
- local relative = origin:ToObjectSpace(v.CFrame)
- local new = frame*relative
- v.CFrame = new
- end
- end,
- Size = function(size)
- if not size then
- return a:GetScale()
- end
- a:ScaleTo(size)
- end,
- },
- BasePart = {}
- }
- for name,funcs in pairs(methods) do
- if not funcs.CFrame or not funcs.Size then
- continue
- end
- funcs.Position = function(position)
- if not position then
- return funcs.CFrame().Position
- end
- local rot = funcs.CFrame():ToOrientation()
- funcs.CFrame(CFrame.new(position)*rot)
- end
- funcs.Orientation = function(rotation)
- if not rotation then
- local rot = funcs.CFrame():ToEulerAnglesXYZ()
- return Vector3.new(rot.X,rot.Y,rot.Z)
- end
- local angles = CFrame.fromOrientation(math.rad(rotation.X),math.rad(rotation.Y),math.rad(rotation.Z))
- local res = funcs.CFrame(CFrame.new(funcs.Position())*angles)
- end
- end
- local function method(v)
- local find = methods[v.ClassName] and v.ClassName or (v:IsA("BasePart") and "BasePart" or v.ClassName)
- return methods[find] or error("unsupported class; ",v.ClassName)
- end
- local manipulator = setmetatable({},{
- __index = function(t,i)
- local func = method(a)[i]
- if func then
- return func()
- end
- return a[i]
- end,
- __newindex = function(t,i,v)
- local func = method(a)[i]
- if func then
- func(v)
- return
- end
- a[i] = v
- end,
- })
- return manipulator
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement