Initial commit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class UIInteractable : BaseInteractable, IPointerDownHandler
|
||||
{
|
||||
private UIManager uIManager;
|
||||
[SerializeField] private BlockData blockData;
|
||||
// private Button uIButton;
|
||||
private bool isSelected = false;
|
||||
private Color originalColor;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
uIManager = UIManager.getInstance();
|
||||
// uIButton = GetComponent<Button>();
|
||||
// originalColor = uIButton.image.color;
|
||||
|
||||
// Set icon from BlockData if available
|
||||
// if (blockData != null && blockData.icon != null)
|
||||
// {
|
||||
// uIButton.image.sprite = Sprite.Create(
|
||||
// blockData.icon,
|
||||
// new Rect(0, 0, blockData.icon.width, blockData.icon.height),
|
||||
// new Vector2(0.5f, 0.5f));
|
||||
// }
|
||||
|
||||
// if (uIButton != null)
|
||||
// uIButton.onClick.AddListener(onSelectEnter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void onSelectEnter()
|
||||
{
|
||||
if (!isSelected)
|
||||
{
|
||||
isSelected = true;
|
||||
uIManager.selectUIInteractable(this);
|
||||
// uIButton.image.color = Color.green;
|
||||
}
|
||||
base.onSelectEnter();
|
||||
}
|
||||
|
||||
public override void onSelectExit()
|
||||
{
|
||||
isSelected = false;
|
||||
// uIButton.image.color = originalColor;
|
||||
base.onSelectExit();
|
||||
}
|
||||
|
||||
internal BlockData getAssociatedBlockData() => blockData;
|
||||
|
||||
public void setBlockData(BlockData blockData)
|
||||
{
|
||||
this.blockData = blockData;
|
||||
}
|
||||
// public Button getButton() => uIButton;
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
onSelectEnter();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user