Some checks failed
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Successful in 5m54s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Successful in 5m43s
Build project / Publish to itch.io (StandaloneLinux64) (push) Successful in 11s
Build project / Publish to itch.io (StandaloneWindows64) (push) Successful in 9s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (pull_request) Has been cancelled
Build project / Publish to itch.io (StandaloneLinux64) (pull_request) Has been cancelled
Build project / Publish to itch.io (StandaloneWindows64) (pull_request) Has been cancelled
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (pull_request) Has been cancelled
66 lines
1.4 KiB
C#
66 lines
1.4 KiB
C#
using System.Reflection;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class DropMe : MonoBehaviour, IDropHandler, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
public Image containerImage;
|
|
public Image receivingImage;
|
|
private Color normalColor;
|
|
public Color highlightColor = Color.yellow;
|
|
|
|
public void OnEnable ()
|
|
{
|
|
if (containerImage != null)
|
|
normalColor = containerImage.color;
|
|
}
|
|
|
|
public void OnDrop(PointerEventData data)
|
|
{
|
|
containerImage.color = normalColor;
|
|
|
|
if (receivingImage == null)
|
|
return;
|
|
|
|
Sprite dropSprite = GetDropSprite (data);
|
|
if (dropSprite != null)
|
|
receivingImage.overrideSprite = dropSprite;
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData data)
|
|
{
|
|
if (containerImage == null)
|
|
return;
|
|
|
|
Sprite dropSprite = GetDropSprite (data);
|
|
if (dropSprite != null)
|
|
containerImage.color = highlightColor;
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData data)
|
|
{
|
|
if (containerImage == null)
|
|
return;
|
|
|
|
containerImage.color = normalColor;
|
|
}
|
|
|
|
private Sprite GetDropSprite(PointerEventData data)
|
|
{
|
|
var originalObj = data.pointerDrag;
|
|
if (originalObj == null)
|
|
return null;
|
|
|
|
var dragMe = originalObj.GetComponent<DragMe>();
|
|
if (dragMe == null)
|
|
return null;
|
|
|
|
var srcImage = originalObj.GetComponent<Image>();
|
|
if (srcImage == null)
|
|
return null;
|
|
|
|
return srcImage.sprite;
|
|
}
|
|
}
|