156 lines
4.3 KiB
C#
156 lines
4.3 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using AibisDream.Framework;
|
|
using AibisDream;
|
|
using System;
|
|
using System.Collections;
|
|
|
|
public class FavoritesManager : MonoBehaviour
|
|
{
|
|
public static FavoritesManager Instance;
|
|
|
|
private readonly ClueData _clueData = new();
|
|
|
|
public GameObject favoritesUI; // 收藏夹UI
|
|
private RectTransform favoritesUIRectTransform;
|
|
|
|
public Transform punchTapeContent; // 打孔带分类的Content
|
|
|
|
public GameObject clueItemPrefab; // 收藏夹中线索Item的预制件
|
|
|
|
public GameObject imageClueItemPrefab; // 收藏夹中线索Item的预制件
|
|
|
|
public GameObject punchTapePanel; // 打孔带分类面板
|
|
|
|
private Vector2 hiddenPosition; // 收藏夹隐藏时的位置
|
|
private Vector2 visiblePosition; // 收藏夹显示时的位置
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
StorageSystem.Instance.RegisterData(_clueData);
|
|
// 添加加载逻辑
|
|
_clueData.LoadEvent += LoadData;
|
|
}
|
|
|
|
private void LoadData(ClueData cluedata)
|
|
{
|
|
UpdateFavoritesUI();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
favoritesUIRectTransform = favoritesUI.GetComponent<RectTransform>();
|
|
hiddenPosition = new Vector2(favoritesUIRectTransform.anchoredPosition.x * 2,
|
|
favoritesUIRectTransform.anchoredPosition.y);
|
|
visiblePosition = new Vector2(favoritesUIRectTransform.anchoredPosition.x, 0);
|
|
// 设置收藏夹的初始位置为隐藏
|
|
favoritesUIRectTransform.anchoredPosition = hiddenPosition;
|
|
favoritesUI.SetActive(false);
|
|
|
|
ShowPunchTapeFavorites();
|
|
}
|
|
|
|
public void AddClue(Clue clue)
|
|
{
|
|
if (clue is PunchTape punchTape)
|
|
{
|
|
if (!_clueData.punchTapeFavorites.Contains(punchTape))
|
|
{
|
|
_clueData.punchTapeFavorites.Add(punchTape);
|
|
UpdateFavoritesUI();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void RemoveClue(Clue clue)
|
|
{
|
|
if (clue is PunchTape punchTape)
|
|
{
|
|
if (_clueData.punchTapeFavorites.Contains(punchTape))
|
|
{
|
|
_clueData.punchTapeFavorites.Remove(punchTape);
|
|
UpdateFavoritesUI();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UpdateFavoritesUI()
|
|
{
|
|
// 清空现有的UI元素
|
|
foreach (Transform child in punchTapeContent)
|
|
{
|
|
Destroy(child.gameObject);
|
|
}
|
|
|
|
// 重新创建剩余线索的UI
|
|
foreach (PunchTape clue in _clueData.punchTapeFavorites)
|
|
{
|
|
GameObject clueItemGO;
|
|
ClueItem clueItem;
|
|
ClueInteraction clueInteraction;
|
|
|
|
// 根据 ClueType 实例化不同的预制件
|
|
if (clue.ClueType == ClueType.PunchTape)
|
|
{
|
|
clueItemGO = Instantiate(clueItemPrefab, punchTapeContent);
|
|
}
|
|
else if (clue.ClueType == ClueType.ImageClue)
|
|
{
|
|
clueItemGO = Instantiate(imageClueItemPrefab, punchTapeContent);
|
|
}
|
|
else
|
|
{
|
|
continue; // 如果有其他 ClueType,不处理并继续
|
|
}
|
|
|
|
// 设置 ClueItem 和 ClueInteraction
|
|
clueItem = clueItemGO.GetComponent<ClueItem>();
|
|
|
|
clueInteraction = clueItemGO.GetComponent<ClueInteraction>();
|
|
clueItem.Setup(clue);
|
|
clueInteraction.SetIsFavorited(true);
|
|
}
|
|
}
|
|
|
|
public void OpenFavorites()
|
|
{
|
|
UpdateFavoritesUI();
|
|
favoritesUI.SetActive(true);
|
|
ShowPunchTapeFavorites();
|
|
|
|
// 用DOTween从右侧移动到可见区域
|
|
favoritesUIRectTransform.DOAnchorPos(visiblePosition, 0.5f); // 移动动画,持续0.5秒
|
|
}
|
|
|
|
public void CloseFavorites()
|
|
{
|
|
UpdateFavoritesUI();
|
|
|
|
// 用DOTween移动回右侧屏幕外
|
|
favoritesUIRectTransform.DOAnchorPos(hiddenPosition, 0.5f).OnComplete(() =>
|
|
{
|
|
favoritesUI.SetActive(false); // 移动完成后隐藏UI
|
|
});
|
|
}
|
|
|
|
private void ShowPunchTapeFavorites()
|
|
{
|
|
UpdateFavoritesUI();
|
|
punchTapePanel.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public class ClueData : IData
|
|
{
|
|
public readonly List<PunchTape> punchTapeFavorites = new();
|
|
public event Action<ClueData> LoadEvent;
|
|
|
|
public IEnumerator Load()
|
|
{
|
|
LoadEvent?.Invoke(this);
|
|
yield break;
|
|
}
|
|
} |