111 lines
3.2 KiB
C#
111 lines
3.2 KiB
C#
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class ClueSlotBase : MonoBehaviour, IDropHandler
|
|
{
|
|
protected ClueType expectedClueType; // 期望的 Clue 类型
|
|
protected ClueInteraction interaction; // Clue 的交互
|
|
|
|
protected RectTransform OriginalTransform; // Clue 的交互
|
|
[HideInInspector]
|
|
public ClueItem currentClueItem; // 当前插入的 ClueItem
|
|
|
|
[HideInInspector]
|
|
public bool isOccupied = false; // 插槽是否已占用
|
|
|
|
// [HideInInspector]
|
|
//public bool isLocked = false; // 插槽是否已占用
|
|
|
|
private Image slotFrame;
|
|
|
|
protected virtual void Start()
|
|
{
|
|
currentClueItem = null;
|
|
slotFrame=transform.GetChild(0).GetComponent<Image>();
|
|
//slotFrame.color=Color.white;
|
|
}
|
|
public void SetSlotCorrect()
|
|
{
|
|
slotFrame.color=Color.green;
|
|
SetSlotLockState(true);
|
|
}
|
|
|
|
public void OnDrop(PointerEventData eventData)
|
|
{
|
|
// if (isOccupied)
|
|
// {
|
|
// Debug.Log("ClueSlot locked");
|
|
// return;
|
|
// }
|
|
ClueItem clueItem = eventData.pointerDrag.GetComponent<ClueItem>();
|
|
if (clueItem != null)
|
|
{
|
|
Clue clue = clueItem.GetClueData();
|
|
interaction = clueItem.GetComponent<ClueInteraction>();
|
|
|
|
if (clue != null && interaction != null&&!isOccupied)
|
|
{
|
|
|
|
// 更新当前的 ClueItem
|
|
currentClueItem = clueItem;
|
|
isOccupied = true;
|
|
// 调整位置和父对象
|
|
RectTransform slotRectTransform = GetComponent<RectTransform>();
|
|
interaction.SetClueParentAndPosition(slotRectTransform);
|
|
|
|
// 调用虚方法处理插入逻辑
|
|
OnClueInserted(clue);
|
|
}
|
|
else
|
|
{
|
|
// 如果类型不匹配,返回 ClueItem 到原位
|
|
interaction?.ReturnToOriginalPosition();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// 释放插槽时调用
|
|
public virtual void ReleaseSlot()
|
|
{
|
|
//FavoritesManager.Instance.RemoveClue(currentClueItem.GetClueData());
|
|
if (currentClueItem != null)
|
|
{
|
|
currentClueItem.used=true;
|
|
ReturnClueToCollection(currentClueItem);
|
|
}
|
|
isOccupied = false;
|
|
currentClueItem = null;
|
|
interaction = null;
|
|
}
|
|
|
|
// 将 ClueItem 返回到集合的逻辑
|
|
protected void ReturnClueToCollection(ClueItem clueItem)
|
|
{
|
|
// 这里调用 ClueInteraction 的返回逻辑
|
|
if (clueItem != null)
|
|
{
|
|
ClueInteraction clueInteraction = clueItem.GetComponent<ClueInteraction>();
|
|
clueInteraction?.ReturnToOriginalPosition(); // 返回到原位的逻辑
|
|
|
|
FavoritesManager.Instance.AddClue(clueItem.GetClueData());
|
|
// 你也可以在这里添加额外的逻辑来处理集合的更新
|
|
}
|
|
}
|
|
|
|
// 插入线索时调用的虚方法,子类可以重写此方法以实现特定功能
|
|
protected virtual void OnClueInserted(Clue clue)
|
|
{
|
|
//FavoritesManager.Instance.RemoveClue(clue);
|
|
// 默认不做任何操作
|
|
Debug.Log("Clue inserted in base slot.");
|
|
}
|
|
public void SetSlotLockState(bool lockState)
|
|
{
|
|
isLocked=lockState;
|
|
|
|
}
|
|
}
|