using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using DG.Tweening; using AibisDream; using AibisDream.Kit; public class ClueSlotBase : MonoBehaviour, IDropHandler { public Image filmImage; // 新增的胶片Image public Image RoateImage; // 新增的胶片Image private Transform filmStartPos; protected ClueType expectedClueType; // 期望的 Clue 类型 protected ClueInteraction interaction; // Clue 的交互 protected RectTransform OriginalTransform; // Clue 的交互 [HideInInspector] public ClueItem currentClueItem; // 当前插入的 ClueItem public Image punchTapeImage; public Image coverClose; public Image coverOpen; private RectTransform punchtapeStartpos; [HideInInspector] public bool isOccupied = false; // 插槽是否已占用 [HideInInspector] public bool isLocked = false; // 插槽是否已占用 protected virtual void Start() { currentClueItem = null; coverClose.enabled=true; coverOpen.enabled=false; punchTapeImage.enabled=false; punchtapeStartpos=punchTapeImage.rectTransform; //slotFrame.color=Color.white; filmStartPos=filmImage.rectTransform; } public void SetSlotCorrect() { SetSlotLockState(true); } public void OnDrop(PointerEventData eventData) { ClueItem clueItem = eventData.pointerDrag.GetComponent(); if (clueItem != null) { Clue clue = clueItem.GetClueData(); interaction = clueItem.GetComponent(); if (clue != null && interaction != null&&!isOccupied) { interaction.SetClueParentAndPosition(transform); // 更新当前的 ClueItem currentClueItem = clueItem; isOccupied = true; punchTapeImage.enabled=true; // AudioManager.RandomPlayInteraction("punchtape"); AudioManager.Instance.PlaySfx("event:/ActionFB/mem_insert"); StartFilmAnimation(); FavoritesManager.Instance.CloseFavorites(); punchTapeImage.rectTransform.DOAnchorPosY(-473f,4f) .OnComplete(() => { punchTapeImage.enabled=false; punchTapeImage.rectTransform.DOAnchorPosY(-3f,0.1f); OnClueInserted(clue); StopFilmAnimation(); }); } else { // 如果类型不匹配,返回 ClueItem 到原位 interaction?.ReturnToOriginalPosition(); } } } // 释放插槽时调用 public virtual void ReleaseSlot() { Debug.Log("释放记忆插槽"); coverClose.enabled=false; coverOpen.enabled=true; isOccupied = false; currentClueItem = null; interaction = null; filmImage.rectTransform.localPosition=filmStartPos.localPosition; } // 将 ClueItem 返回到集合的逻辑 protected void ReturnClueToCollection(ClueItem clueItem) { // 这里调用 ClueInteraction 的返回逻辑 if (clueItem != null) { ClueInteraction clueInteraction = clueItem.GetComponent(); 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; } private void StartFilmAnimation() { // 使用 DOTween 实现胶片的循环移动 filmImage.rectTransform.DOLocalMoveX(-1256f, 1f) .SetLoops(-1, LoopType.Restart) .SetEase(Ease.Linear); RoateImage.rectTransform.DORotate(new Vector3(0, 0, 360), 1f, RotateMode.FastBeyond360) .SetLoops(-1, LoopType.Restart) .SetEase(Ease.Linear); } private void StopFilmAnimation() { // 停止胶片动画 filmImage.rectTransform.DOKill(); RoateImage.rectTransform.DOKill(); } }