일반적으로 Quad 모듈에서 모든 Parent 처리는 Mount 를 이용합니다. Mount(to:any,...item:any?)->mounts 함수를 이용하면 다루는 오브젝트가 로블록스 Instance 인지, 향후 소개될 Quad 확장 클래스인지 상관없이 알아서 Parent 가 처리됩니다.
1 2 3 4 5 6 7 8 910111213141516
--- StarterGui 안에 ScreenGui 를 넣고 로컬스크립트로 입력해보세요localScreenGUI=script.ParentlocalQuad=require(path.to.module).Init()localClass,Mount=Quad.Class,Quad.MountlocalFrame=Class"Frame"Mount(ScreenGui,Frame{Name="Wow!";}--[[ , Frame {} , Frame {} 더많은 오브젝트를 다같이 Mount 할 수 있습니다 ]])
편의를 위해서 Mount 함수는 mounts 라는 객체를 반환합니다. 이것을 이용하면 필요에 따라서 Mount 상태를 해제하거나 추가 할 수 있습니다. mounts 객체는 다음과 같은 메소드를 가집니다.
:Unmount()
이렇게 하면 마운트된 Instance 를 지워버립니다. Quad 는 안전한 메모리 관리를 위해 gc 의 기능에 의존하므로, gc 시간차로 인해 Store.GetObject 에서 오브젝트가 사라지는데 시간이 걸릴 수 있습니다.
1 2 3 4 5 6 7 8 9101112131415
-- 용법localScreenGUI=script.ParentlocalQuad=require(path.to.module).Init()localClass,Mount=Quad.Class,Quad.MountlocalFrame=Class"Frame"localmainFrame=Frame{}Mount(ScreenGui,mainFrame)localchildFrame=Frame{}localchildFrameMount=Mount(mainFrame,childFrame)childFrameMount:Unmount()-- childFrame 은 단순히 .Parent = nil 되는 것을 넘어 메모리에서 사라집니다-- 즉, Destroy() 가 호출됩니다
:Add(item:any)
Mount 에 오브젝트를 추가합니다. 처음 설정한 to 값을 따라 부모가 결정됩니다.
이 동작은 리스트를 만들 때 유용할 수 있습니다. 다시로드 동작시 직접 제거가 필요하지 않습니다
1 2 3 4 5 6 7 8 91011121314151617181920212223
localScreenGUI=script.ParentlocalQuad=require(path.to.module).Init()localClass,Mount=Quad.Class,Quad.MountlocalFrame=Class"Frame"localmainFrame=Frame{}Mount(ScreenGui,mainFrame)locallastListMount=Mount(mainFrame)localfunctionrefreshList()lastListMount:Unmount()-- 이전 children 을 알아서 제거합니다fori=1,10dolastListMount:Add(Frame{Name=tostring(i)})endendtask.spawn(function()whiletruedorefreshList()task.wait(2)endend)
다음과 같이 이전 children 을 간접적으로 제거하고 새로운 오브젝트를 추가합니다. 단 ScrollFrame 의 경우 CanvasPosition이 초기화 되어버리므로 자식들을 :Unmount() 하기 전에 위치를 저장하고 다시 불러와야 합니다