UI 관련 스크립트 추가
All checks were successful
Code Review / code-review (pull_request) Successful in 9s

This commit is contained in:
SullyunShin
2025-04-30 17:55:20 +09:00
parent 860e0a5294
commit c26d94636d
5 changed files with 147 additions and 67 deletions

View File

@@ -1,10 +1,8 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
namespace XED.Core public abstract class UnitySingleton<T> : UnityEngine.MonoBehaviour where T : UnitySingleton<T>
{ {
public abstract class UnitySingleton<T> : UnityEngine.MonoBehaviour where T : UnitySingleton<T>
{
private static T instance; private static T instance;
private static object _lock = new object(); private static object _lock = new object();
protected static bool applicationIsQuitting = false; protected static bool applicationIsQuitting = false;
@@ -76,10 +74,10 @@ namespace XED.Core
applicationIsQuitting = true; applicationIsQuitting = true;
#endif #endif
} }
} }
public abstract class ISingleton<T> where T : class, new() public abstract class ISingleton<T> where T : class, new()
{ {
static volatile T instance = default(T); static volatile T instance = default(T);
static readonly object padlock = new object(); static readonly object padlock = new object();
protected ISingleton() protected ISingleton()
@@ -101,5 +99,4 @@ namespace XED.Core
} }
} }
public virtual void Init() { } public virtual void Init() { }
}
} }

View File

@@ -0,0 +1,26 @@
using UnityEngine;
using TMPro;
using System.Collections;
public class TextPopup : UnitySingleton<TextPopup>
{
public GameObject uiObj;
public TMP_Text log;
public void Show(string text, float showTime)
{
log.text = text;
uiObj.SetActive(true);
StopAllCoroutines();
StartCoroutine(ShowTextCoroutine(showTime));
}
IEnumerator ShowTextCoroutine(float time)
{
while (time >= 0)
{
time -= Time.deltaTime;
yield return null;
}
uiObj.SetActive(false);
yield return null;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1ae5ce061e3746f4d841bab193d90076

View File

@@ -0,0 +1,53 @@
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.EventSystems;
public class UIDragSpawner : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
public GameObject prefabToSpawn;
public Canvas canvas;
private RectTransform rectTransform;
private CanvasGroup canvasGroup;
private GameObject dragPreview;
void Awake()
{
rectTransform = GetComponent<RectTransform>();
//canvasGroup = gameObject.AddComponent<CanvasGroup>();
canvasGroup = gameObject.GetOrAddComponent<CanvasGroup>();
}
public void OnBeginDrag(PointerEventData eventData)
{
if (canvasGroup == null)
canvasGroup = gameObject.AddComponent<CanvasGroup>();
canvasGroup.alpha = 0.6f;
canvasGroup.blocksRaycasts = false;
dragPreview = Instantiate(gameObject, canvas.transform);
dragPreview.GetComponent<CanvasGroup>().blocksRaycasts = false;
}
public void OnDrag(PointerEventData eventData)
{
if (dragPreview)
{
dragPreview.GetComponent<RectTransform>().position = eventData.position;
}
}
public void OnEndDrag(PointerEventData eventData)
{
canvasGroup.alpha = 1f;
canvasGroup.blocksRaycasts = true;
if (dragPreview)
Destroy(dragPreview);
Ray ray = Camera.main.ScreenPointToRay(eventData.position);
if (Physics.Raycast(ray, out RaycastHit hit))
{
Instantiate(prefabToSpawn, hit.point, Quaternion.identity);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c83beb55043dab346a0cf9439add61ec