187 lines
5.5 KiB
C#
187 lines
5.5 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
using AibisDream.Framework;
|
|
using AibisDream;
|
|
using System;
|
|
|
|
public class FavoritesManager : MonoBehaviour
|
|
{
|
|
public static FavoritesManager Instance;
|
|
|
|
private ClueData _clueData=new ClueData();
|
|
|
|
public Button toggleFavoritesButton; // 用于打开/关闭收藏夹的按钮
|
|
|
|
public GameObject favoritesUI; // 收藏夹UI
|
|
private RectTransform favoritesUIRectTransform;
|
|
|
|
public Transform punchTapeContent; // 打孔带分类的Content
|
|
|
|
//public Transform screenshotContent; // 截图分类的Content
|
|
public GameObject clueItemPrefab; // 收藏夹中线索Item的预制件
|
|
|
|
public GameObject imageClueItemPrefab; // 收藏夹中线索Item的预制件
|
|
|
|
//public Button punchTapeTabButton; // 切换到打孔带
|
|
//public Button screenshotTabButton; // 切换到截图
|
|
|
|
//public ScrollRect scrollRect; // 滚动视图
|
|
public GameObject punchTapePanel; // 打孔带分类面板
|
|
|
|
//public GameObject screenshotPanel; // 截图分类面板
|
|
private Vector2 hiddenPosition; // 收藏夹隐藏时的位置
|
|
private Vector2 visiblePosition; // 收藏夹显示时的位置
|
|
public bool isFavoritesOpen = false; // 收藏夹是否打开的状态
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
GameLoopManager.FixDataContainer.Register(_clueData);
|
|
// 添加加载逻辑
|
|
_clueData.LoadEvent += LoadData;
|
|
}
|
|
|
|
private void LoadData(ClueData cluedata)
|
|
{
|
|
UpdateFavoritesUI();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
favoritesUIRectTransform = favoritesUI.GetComponent<RectTransform>();
|
|
hiddenPosition = new Vector2(favoritesUIRectTransform.anchoredPosition.x, -Screen.height);
|
|
visiblePosition = new Vector2(favoritesUIRectTransform.anchoredPosition.x, 0);
|
|
// // 设置收藏夹的初始位置为隐藏
|
|
favoritesUIRectTransform.anchoredPosition = hiddenPosition;
|
|
favoritesUI.SetActive(false);
|
|
// // 绑定按钮事件
|
|
toggleFavoritesButton.onClick.AddListener(ToggleFavorites);
|
|
// 绑定按钮事件
|
|
//punchTapeTabButton.onClick.AddListener(ShowPunchTapeFavorites);
|
|
//screenshotTabButton.onClick.AddListener(ShowScreenshotFavorites);
|
|
ShowPunchTapeFavorites();
|
|
}
|
|
|
|
public void ToggleFavorites()
|
|
{
|
|
if (isFavoritesOpen)
|
|
{
|
|
CloseFavorites();
|
|
}
|
|
else
|
|
{
|
|
OpenFavorites();
|
|
}
|
|
}
|
|
|
|
public void AddClue(Clue clue)
|
|
{
|
|
if (clue.ClueType == ClueType.PunchTape)
|
|
{
|
|
if (!_clueData.punchTapeFavorites.Contains(clue))
|
|
{
|
|
_clueData.punchTapeFavorites.Add(clue);
|
|
UpdateFavoritesUI();
|
|
}
|
|
}
|
|
else if (clue.ClueType == ClueType.ImageClue)
|
|
if (!_clueData.punchTapeFavorites.Contains(clue))
|
|
{
|
|
_clueData.punchTapeFavorites.Add(clue);
|
|
UpdateFavoritesUI();
|
|
}
|
|
}
|
|
|
|
public void RemoveClue(Clue clue)
|
|
{
|
|
if (clue.ClueType == ClueType.PunchTape)
|
|
{
|
|
if (_clueData.punchTapeFavorites.Contains(clue))
|
|
{
|
|
_clueData.punchTapeFavorites.Remove(clue);
|
|
UpdateFavoritesUI();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UpdateFavoritesUI()
|
|
{
|
|
// 清空现有的UI元素
|
|
foreach (Transform child in punchTapeContent)
|
|
{
|
|
Destroy(child.gameObject);
|
|
}
|
|
|
|
// 重新创建剩余线索的UI
|
|
foreach (Clue 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();
|
|
isFavoritesOpen = true;
|
|
|
|
// 用DOTween从右侧移动到可见区域
|
|
favoritesUIRectTransform.DOAnchorPos(visiblePosition, 0.5f); // 移动动画,持续0.5秒
|
|
}
|
|
|
|
public void CloseFavorites()
|
|
{
|
|
UpdateFavoritesUI();
|
|
isFavoritesOpen = false;
|
|
|
|
// 用DOTween移动回右侧屏幕外
|
|
favoritesUIRectTransform.DOAnchorPos(hiddenPosition, 0.5f).OnComplete(() =>
|
|
{
|
|
favoritesUI.SetActive(false); // 移动完成后隐藏UI
|
|
});
|
|
}
|
|
|
|
public void ShowPunchTapeFavorites()
|
|
{
|
|
UpdateFavoritesUI();
|
|
punchTapePanel.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public class ClueData : IData
|
|
{
|
|
public List<Clue> punchTapeFavorites = new List<Clue>();
|
|
public event Action<ClueData> LoadEvent;
|
|
|
|
public void Load()
|
|
{
|
|
LoadEvent?.Invoke(this);
|
|
}
|
|
} |