Image를 마우스로 드래그할 수 있는 이벤트를 구현하기 위해 UI EventHandler 추가
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UI_Button : UI_Base
|
||||
@@ -22,6 +23,11 @@ public class UI_Button : UI_Base
|
||||
TestObject
|
||||
}
|
||||
|
||||
enum Images
|
||||
{
|
||||
ItemIcon,
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Reflection
|
||||
@@ -29,10 +35,15 @@ public class UI_Button : UI_Base
|
||||
// Text 대신 TextMeshProUGUI로 변경
|
||||
Bind<TextMeshProUGUI>(typeof(Texts));
|
||||
Bind<GameObject>(typeof(GameObjects));
|
||||
Bind<Image>(typeof(Images));
|
||||
|
||||
// Get 호출 시에도 타입을 맞춰줍니다.
|
||||
// Get<TextMeshProUGUI>((int)Texts.ScoreText).text = "Bind Test";
|
||||
GetText((int)Texts.ScoreText).text = "Bind Test";
|
||||
|
||||
GameObject go = GetImage((int)Images.ItemIcon).gameObject;
|
||||
UI_EventHandler evt = go.GetComponent<UI_EventHandler>();
|
||||
evt.OnDragHandler += ((PointerEventData data) => { evt.gameObject.transform.position = data.position; });
|
||||
}
|
||||
|
||||
private int _score = 0;
|
||||
|
||||
26
Assets/Scripts/UI/UI_EventHandler.cs
Normal file
26
Assets/Scripts/UI/UI_EventHandler.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
|
||||
public class UI_EventHandler : MonoBehaviour, IBeginDragHandler, IDragHandler
|
||||
{
|
||||
public Action<PointerEventData> OnBeginDragHandler = null;
|
||||
public Action<PointerEventData> OnDragHandler = null;
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
if (OnBeginDragHandler != null)
|
||||
{
|
||||
OnBeginDragHandler.Invoke(eventData);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (OnDragHandler != null)
|
||||
{
|
||||
OnDragHandler.Invoke(eventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/UI_EventHandler.cs.meta
Normal file
2
Assets/Scripts/UI/UI_EventHandler.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 668ca21f9fefb404388f30bd6902a7c3
|
||||
Reference in New Issue
Block a user