본문 바로가기

Game/MSW

메이플스토리 월드로 게임 만들기 - 2

UIStatus

UI 프리셋에서 상태창을 가져와 조금 수정했다.
단, 이대로 놔두면 이름과 체력 외의 수치는 작동하지 않는다.

 

PlayerStat 컴포넌트

레벨, 체력, 경험치 등의 정보를 관리하기 위해 DefaultPlayer에 PlayerStat 컴포넌트를 만들었다.
PlayerComponent에도 Hp, MaxHp가 있긴 하지만 하나의 컴포넌트에서 처리하고 싶어 새로 만들었다.

 

 

UIStatus 컴포넌트

--@ BeginMethod
--@ MethodExecSpace=ClientOnly
void OnBeginPlay()
{
self.nameText.Text = _UserService.LocalPlayer.PlayerComponent.Nickname
self._T.maxWidth = self.hpBar.RectSize.x
}
--@ EndMethod

--@ BeginMethod
--@ MethodExecSpace=ClientOnly
void OnUpdate(number delta)
{
self:UpdateUI()
}
--@ EndMethod

--@ BeginMethod
--@ MethodExecSpace=ClientOnly
void UpdateUI()
{
local playerStat = _UserService.LocalPlayer.PlayerStat

local level = playerStat.level
self.levelText.Text = string.format("LV. %d", level)

local hp = playerStat.hp
local maxHp = playerStat.maxHp
self.hpBar.RectSize = Vector2(hp / maxHp * self._T.maxWidth, self.hpBar.RectSize.y)
self.hpText.Text = string.format("%d / %d", hp, maxHp)

local exp = playerStat.exp
local maxExp = playerStat.maxExp
self.expBar.RectSize = Vector2(exp / maxExp * self._T.maxWidth, self.expBar.RectSize.y)
self.expText.Text = string.format("%d / %d", exp, maxExp)
}
--@ EndMethod

상태창 프리셋을 가져올 때 자동으로 생성된 UIMyInfo 컴포넌트를 수정하여 UIStatus 컴포넌트를 만들었다.

 

UIStatus가 정상적으로 작동하는 것을 확인할 수 있다.