projectEli/Assets/Inventory System/Scripts/UI/DragWindowUI.cs

65 lines
1.8 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
2023-01-15 11:39:47 +00:00
using TMPro;
2023-01-15 11:39:47 +00:00
namespace SimpleInventorySystem
{
2023-01-15 11:39:47 +00:00
public class DragWindowUI : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler, IPointerDownHandler
{
2023-01-15 11:39:47 +00:00
private RectTransform dragRectTransform;
private Canvas canvas;
private Image backgroundImage;
private Color backgroundColor;
public TextMeshProUGUI title;
2023-01-15 11:39:47 +00:00
public void OnBeginDrag(PointerEventData eventData)
{
backgroundColor.a = .4f;
backgroundImage.color = backgroundColor;
}
2023-01-15 11:39:47 +00:00
public void OnDrag(PointerEventData eventData)
{
dragRectTransform.anchoredPosition += eventData.delta / canvas.scaleFactor;
}
2023-01-15 11:39:47 +00:00
public void OnEndDrag(PointerEventData eventData)
{
backgroundColor.a = .8f;
backgroundImage.color = backgroundColor;
}
2023-01-15 11:39:47 +00:00
public void OnPointerDown(PointerEventData eventData)
{
dragRectTransform.SetAsLastSibling();
}
2023-01-15 11:39:47 +00:00
public void CloseWindow()
{
//Destroy(dragRectTransform.gameObject);
transform.parent.gameObject.SetActive(false);
}
2023-01-15 11:39:47 +00:00
void Awake()
{
dragRectTransform = transform.parent.GetComponent<RectTransform>();
backgroundImage = GetComponent<Image>();
backgroundColor = backgroundImage.color;
}
2023-01-15 11:39:47 +00:00
// Start is called before the first frame update
void Start()
{
canvas = SimpleInventorySystem.InventorySystem.instance.inventoryUI;
}
// Update is called once per frame
void Update()
{
}
}
2023-01-15 11:39:47 +00:00
}