UIManager 생성 및 PopupUI 기능 구현
This commit is contained in:
59
Assets/Scripts/UI/Popup/UI_Button.cs
Normal file
59
Assets/Scripts/UI/Popup/UI_Button.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UI_Button : UI_Popup
|
||||
{
|
||||
enum Buttons
|
||||
{
|
||||
PointButton,
|
||||
}
|
||||
|
||||
enum Texts
|
||||
{
|
||||
PointText,
|
||||
ScoreText,
|
||||
}
|
||||
|
||||
enum GameObjects
|
||||
{
|
||||
TestObject
|
||||
}
|
||||
|
||||
enum Images
|
||||
{
|
||||
ItemIcon,
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Reflection
|
||||
Bind<Button>(typeof(Buttons));
|
||||
// Text 대신 TextMeshProUGUI로 변경
|
||||
Bind<TextMeshProUGUI>(typeof(Texts));
|
||||
Bind<GameObject>(typeof(GameObjects));
|
||||
Bind<Image>(typeof(Images));
|
||||
|
||||
// Get 호출 시에도 타입을 맞춰줍니다.
|
||||
// Get<TextMeshProUGUI>((int)Texts.ScoreText).text = "Bind Test";
|
||||
|
||||
GetButton((int)Buttons.PointButton).gameObject.AddUIEvent(OnButtonClicked);
|
||||
|
||||
GameObject go = GetImage((int)Images.ItemIcon).gameObject;
|
||||
AddUIEvent(go, (PointerEventData data) => { go.transform.position = data.position; }, Define.UIEvent.Drag);
|
||||
}
|
||||
|
||||
private int _score = 0;
|
||||
|
||||
public void OnButtonClicked(PointerEventData data)
|
||||
{
|
||||
// GetComponentInChildren<TextMeshProUGUI>().text = "텍스트 변경 완료!";
|
||||
|
||||
_score += 1;
|
||||
|
||||
GetText((int)Texts.ScoreText).text = $"점수 : {_score}점";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user