This commit is contained in:
@@ -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() { }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
26
Assets/Scripts/UI/TextPopup.cs
Normal file
26
Assets/Scripts/UI/TextPopup.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Scripts/UI/TextPopup.cs.meta
Normal file
2
Assets/Scripts/UI/TextPopup.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1ae5ce061e3746f4d841bab193d90076
|
||||||
53
Assets/Scripts/UI/UIDragSpawner.cs
Normal file
53
Assets/Scripts/UI/UIDragSpawner.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Scripts/UI/UIDragSpawner.cs.meta
Normal file
2
Assets/Scripts/UI/UIDragSpawner.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c83beb55043dab346a0cf9439add61ec
|
||||||
Reference in New Issue
Block a user