UI 에디터의 이해
스크립트를 이용한 UI 엔티티 제어
- 월드에서의 엔티티로의 접근법과 동일
- 클라이언트 공간에서만 존재하는 UI 엔티티는 서버에서 접근 불가
- 꼭 클라이언트 함수에서만 참조
- 버튼 클릭 사 서버에서의 처리를 요청하는 예시
Function:
[server only]
void OnbeginPlay()
{
local button = _EntityService:GetEntityByPath("ButtonEntityPath")
-- 가져 올 버튼 엔티티 경로를 "ButtonEntityPath"에 입력합니다.
button:Connect("ButtonClickEvernt", self.OnButtonClickClient, self)
}
[client only]
Void OnButtonClickClient()
{
--processing in client..
self:OnButtonClickServer()
}
[server]
void OnButtonClickServer()
{
log("Start processing on the server")
}
Property:
[sync]
number time=0
Function:
[server only]
void OnUpdate(number delta)
{
self.time = self.time + delta
if self.time >= 3 then
self.time = 0
self:ShowToastMessage("Time Reset")
end
}[client]
void ShowToastMessage (string text)
{
local toastUiEntity = _EntityService:GetEntityByPath("UIEntityPath")
-- 가져 올 UI 엔티티 경로를 "UIEntityPath"에 입력합니다.
local textComponent = toastUIEntity.TextComponent
-- print toast message
textComponent.Text = text
toastUIEntity:SetEnable(true)
--reservate hide toast message
local callback = function()
toastUIEntity:SetEnable(false)
end
_TimerService:SetTimerOnce(callback,3)
}
상황과 조건에 따른 UI 노출
- setEnable 을 통해 알림 팝업, 토스트 메시지 출력 가능
void ShowToastMessage ()
{
local toastUIEntity = _EntityService:GetEntityByPath("/ui/.../EntityPath")
toastUIEntity:SetEnable(true)
}
void HideToastMessage ()
{
local toastUIEntity = _EntityService:GetEntityByPath("/ui/.../EntityPath")
toastUIEntity:SetEnable(false)
}
- toastUIEntity:SetEnable의 Bool값을 바꿔줌으로써 출력 조절
- 계층 구조를 사용하여 UI 노출을 처리
void ShowPopupUI ()
{
local PopupUIEntity = _EntityService:GetEntityByPath("/ui/DefaultGroup/MODImage_1")
PopupUIEntity:SetEnable(true)
}
void HidePopupUI ()
{
local PopupUIEntity = _EntityService:GetEntityByPath("/ui/DefaultGroup/MODImage_1")
PopupUIEntity:SetEnable(false)
}