diff --git a/Assets/Scripts/Clue/ClueManager.cs b/Assets/Scripts/Clue/ClueManager.cs index c0ffbb34b..3627bffb4 100644 --- a/Assets/Scripts/Clue/ClueManager.cs +++ b/Assets/Scripts/Clue/ClueManager.cs @@ -3,7 +3,7 @@ using AibisDream; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; -using Yarn.Unity; +using Yarn.Unity; using RainbowArt.CleanFlatUI; using System; @@ -24,15 +24,15 @@ public class ClueManager : MonoBehaviour MouseCursorManager mouseManager; void Start() { - clueBaord=FindObjectOfType(); + clueBaord = FindObjectOfType(); } void Update() { - if(Input.GetKeyDown(KeyCode.U)) - { + if (Input.GetKeyDown(KeyCode.U)) + { DialogController.Instance.StartDialogNode("AddAllClueToFavorites"); - //GenerateUFClue("错误绘制","UFView","can_grass_error","绿色"); - } + //GenerateUFClue("错误绘制","UFView","can_grass_error","绿色"); + } // if(Input.GetKeyDown(KeyCode.M)) // { // GenerateMemoryClue("草地","MemoryView","liuying1-2","绿色"); @@ -65,76 +65,36 @@ public class ClueManager : MonoBehaviour // 实例化打孔带线索 PunchTape punchTape = new PunchTape(category, name, memoryIndex); GameObject clueGO = Instantiate(punchTapecluePrefab, canvas.transform); - + ClueItem clueItem = clueGO.GetComponent(); clueItem.Setup(punchTape); } //用于生成打孔带的函数 [YarnCommand("generate_PunchTape")] - public void GeneratePunchTapeWindow(string clueName, string category, string memoryIndex,bool directlyAddToFavorites=false) + public void GeneratePunchTapeWindow(string clueName, string category, string memoryIndex, bool directlyAddToFavorites = false) { PunchTape punchTape = new PunchTape(category, clueName, memoryIndex); - if(directlyAddToFavorites) + if (directlyAddToFavorites) { - FavoritesManager.Instance.AddClue(punchTape); + FavoritesManager.Instance.AddClue(punchTape); return; } GameObject clueGO = Instantiate(punchTapecluePrefab, canvas.transform); - + ClueItem clueItem = clueGO.GetComponent(); ClueInteraction clueInteraction = clueGO.GetComponent(); - currentClue=clueGO; + currentClue = clueGO; clueItem.Setup(punchTape); } - // [YarnCommand("generate_UFClue")] - // public void GenerateUFClue(string clueName, string imageName,bool directlyAddToFavorites=false) - // { - // Sprite UFSprite = Resources.Load("Art/Photos/" + imageName); - // ImageClue imageClue=new ImageClue("UFView", clueName, UFSprite); - // // if(directlyAddToFavorites) - // // { - // // FavoritesManager.Instance.AddClue(imageClue); - // // return; - // // } - // GameObject clueGO = Instantiate(imageCluePrefab, canvas.transform); - // ClueItem clueItem = clueGO.GetComponent(); - // currentClue=clueGO; - // clueItem.Setup(imageClue); - // // ClueInteraction clueInteraction = clueGO.GetComponent(); - // // clueInteraction.enabled=false; - // // currentClueInteraction=clueInteraction; - - // // currentClueInteraction.OnInteraction+=ShowClueBoardNotification; - - // } - // [YarnCommand("generate_MemoryClue")] - // public void GenerateMemoryClue(string nodeID, string imageName,string mathCode,bool directlyAddToFavorites=false) - // { - // Sprite UFSprite = Resources.Load("Art/Memory/" + imageName); - // ImageClue imageClue=new ImageClue("MemoryView", clueName, UFSprite,mathCode); - // if(directlyAddToFavorites) - // { - // FavoritesManager.Instance.AddClue(imageClue); - // return; - // } - // GameObject clueGO = Instantiate(imageCluePrefab, canvas.transform); - // ClueItem clueItem = clueGO.GetComponent(); - // ClueInteraction clueInteraction = clueGO.GetComponent(); - // clueInteraction.enabled=false; - // currentClueInteraction=clueInteraction; - // currentClueInteraction.OnInteraction+=ShowClueBoardNotification; - // clueItem.Setup(imageClue); - // } - - [YarnCommand("CollectionClue")] - public void EnabeClueInteraction(string nodeID=null) - { if(nodeID!=null) + public void EnabeClueInteraction(string nodeID = null) + { + if (nodeID != null) { - //Debug.Log("收藏线索版成功!"); + //Debug.Log("收藏线索版成功!"); //clueBaord.CreateNode(nodeID); return; } @@ -145,42 +105,34 @@ public class ClueManager : MonoBehaviour // return; // } ClueItem clueItem = currentClue.GetComponent(); - Clue clue=clueItem.GetClueData(); - ClueInteraction clueInteraction=currentClue.GetComponent(); + Clue clue = clueItem.GetClueData(); + ClueInteraction clueInteraction = currentClue.GetComponent(); - if(clue.ClueType==ClueType.PunchTape) - { - FavoritesManager.Instance.AddClue(clueItem.GetClueData()); - Destroy(currentClue.gameObject); - Debug.Log("收藏文件夹成功!"); - clueInteraction.isFavorited=true; - currentClue=null; - } + if (clue.ClueType == ClueType.PunchTape) + { + FavoritesManager.Instance.AddClue(clueItem.GetClueData()); + Destroy(currentClue.gameObject); + Debug.Log("收藏文件夹成功!"); + clueInteraction.isFavorited = true; + currentClue = null; + } else - { - Debug.Log("收藏线索版成功!"); - //clueBaord.CreateNode(clue.ClueName); - Destroy(currentClue.gameObject); - currentClue=null; - } + { + Debug.Log("收藏线索版成功!"); + //clueBaord.CreateNode(clue.ClueName); + Destroy(currentClue.gameObject); + currentClue = null; + } } - // public void ShowFavouriteNotification() - // { - // FavouriteNotification.ShowNotification(); - // currentClueInteraction.OnInteraction-=ShowFavouriteNotification; - // } - [YarnCommand("ShowNotification")] - public void ShowNotification(string Title,string message) + [YarnCommand("ShowNotification")] + public void ShowNotification(string Title, string message) { - TopNotification.TitleValue=Title; - TopNotification.DescriptionValue=message; + TopNotification.TitleValue = Title; + TopNotification.DescriptionValue = message; TopNotification.ShowNotification(); //currentClueInteraction.OnInteraction-=ShowFavouriteNotification; } - // public void ShowClueBoardNotification() - // { - // clueBaord.CreateNode(currentClueInteraction.GetComponent().ClueName); - // } + diff --git a/Assets/Scripts/Clue/FavoritesManager.cs b/Assets/Scripts/Clue/FavoritesManager.cs index 785ed2301..a0106d2f7 100644 --- a/Assets/Scripts/Clue/FavoritesManager.cs +++ b/Assets/Scripts/Clue/FavoritesManager.cs @@ -1,22 +1,18 @@ using UnityEngine; using System.Collections.Generic; using UnityEngine.UI; -using DG.Tweening; +using DG.Tweening; +using AibisDream.Framework; +using AibisDream; +using System; public class FavoritesManager : MonoBehaviour { public static FavoritesManager Instance; + private ClueData _clueData; + public Button toggleFavoritesButton; // 用于打开/关闭收藏夹的按钮 - - private void Awake() - { - Instance = this; - } - [HideInInspector] - public List punchTapeFavorites = new List(); - //public List screenshotFavorites = new List(); - public GameObject favoritesUI; // 收藏夹UI private RectTransform favoritesUIRectTransform; public Transform punchTapeContent; // 打孔带分类的Content @@ -36,12 +32,23 @@ public class FavoritesManager : MonoBehaviour 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(); - hiddenPosition = new Vector2(favoritesUIRectTransform.anchoredPosition.x, -Screen.height); - visiblePosition = new Vector2(favoritesUIRectTransform.anchoredPosition.x, 0); + favoritesUIRectTransform = favoritesUI.GetComponent(); + hiddenPosition = new Vector2(favoritesUIRectTransform.anchoredPosition.x, -Screen.height); + visiblePosition = new Vector2(favoritesUIRectTransform.anchoredPosition.x, 0); // // 设置收藏夹的初始位置为隐藏 favoritesUIRectTransform.anchoredPosition = hiddenPosition; favoritesUI.SetActive(false); @@ -50,8 +57,6 @@ public class FavoritesManager : MonoBehaviour // 绑定按钮事件 //punchTapeTabButton.onClick.AddListener(ShowPunchTapeFavorites); //screenshotTabButton.onClick.AddListener(ShowScreenshotFavorites); - - // 默认显示打孔带收藏 ShowPunchTapeFavorites(); } public void ToggleFavorites() @@ -68,82 +73,70 @@ public class FavoritesManager : MonoBehaviour public void AddClue(Clue clue) { - if (clue.ClueType==ClueType.PunchTape) + if (clue.ClueType == ClueType.PunchTape) { - if (!punchTapeFavorites.Contains(clue)) + if (!_clueData.punchTapeFavorites.Contains(clue)) { - punchTapeFavorites.Add(clue); + _clueData.punchTapeFavorites.Add(clue); UpdateFavoritesUI(); } } - else if (clue.ClueType==ClueType.ImageClue) - if (!punchTapeFavorites.Contains(clue)) + else if (clue.ClueType == ClueType.ImageClue) + if (!_clueData.punchTapeFavorites.Contains(clue)) { - punchTapeFavorites.Add(clue); + _clueData.punchTapeFavorites.Add(clue); UpdateFavoritesUI(); } } public void RemoveClue(Clue clue) { - // if (clue.ClueType==ClueType.PunchTape) - // { - // if (punchTapeFavorites.Contains(clue)) - // { - punchTapeFavorites.Remove(clue); - UpdateFavoritesUI(); - // } - // } - // if (clue.ClueType==ClueType.ImageClue) - // { - // if (punchTapeFavorites.Contains(clue)) - // { - // punchTapeFavorites.Remove(clue); - // UpdateFavoritesUI(); - // } - // } - } - private void UpdateFavoritesUI() -{ - // 清空现有的UI元素 - foreach (Transform child in punchTapeContent) - { - Destroy(child.gameObject); - } - - // 重新创建剩余线索的UI - foreach (Clue clue in punchTapeFavorites) - { - GameObject clueItemGO; - ClueItem clueItem; - ClueInteraction clueInteraction; - - // 根据 ClueType 实例化不同的预制件 if (clue.ClueType == ClueType.PunchTape) { - clueItemGO = Instantiate(clueItemPrefab, punchTapeContent); + 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(); + + clueInteraction = clueItemGO.GetComponent(); + clueItem.Setup(clue); + clueInteraction.SetIsFavorited(true); } - else if (clue.ClueType == ClueType.ImageClue) - { - clueItemGO = Instantiate(imageClueItemPrefab, punchTapeContent); - } - else - { - continue; // 如果有其他 ClueType,不处理并继续 - } - - // 设置 ClueItem 和 ClueInteraction - clueItem = clueItemGO.GetComponent(); - - clueInteraction = clueItemGO.GetComponent(); - clueItem.Setup(clue); - clueInteraction.SetIsFavorited(true); - // if(clueItem.used==true) - // { - // clueItem.clueImageUI.color=Color.gray; - // } } -} public void OpenFavorites() { @@ -158,7 +151,7 @@ public class FavoritesManager : MonoBehaviour public void CloseFavorites() { - UpdateFavoritesUI(); + UpdateFavoritesUI(); isFavoritesOpen = false; // 用DOTween移动回右侧屏幕外 @@ -172,26 +165,17 @@ public class FavoritesManager : MonoBehaviour { UpdateFavoritesUI(); punchTapePanel.SetActive(true); - //screenshotPanel.SetActive(false); - + } - // public void ShowScreenshotFavorites() - // { - // punchTapePanel.SetActive(false); - // screenshotPanel.SetActive(true); - - // // 清空内容 - // foreach (Transform child in screenshotContent) - // { - // Destroy(child.gameObject); - // } - - // // 显示截图收藏 - // foreach (var screenshot in screenshotFavorites) - // { - // GameObject item = Instantiate(clueItemPrefab, screenshotContent); - // item.GetComponent().Setup(screenshot); - // } - // } } + public class ClueData : IData + { + public List punchTapeFavorites = new List(); + public event Action LoadEvent; + + public void Load() + { + LoadEvent?.Invoke(this); + } + } \ No newline at end of file diff --git a/Assets/Scripts/MiniGame/Peipei/Eye/EyeSystem.cs b/Assets/Scripts/MiniGame/Peipei/Eye/EyeSystem.cs index 3b847c31e..a8d78042d 100644 --- a/Assets/Scripts/MiniGame/Peipei/Eye/EyeSystem.cs +++ b/Assets/Scripts/MiniGame/Peipei/Eye/EyeSystem.cs @@ -15,37 +15,17 @@ public class EyeSystem : MonoBehaviour { [SerializeField] private List targets = new List(); // 保存目标列表 public List Targets => targets; // 提供目标列表的公共访问 - private EyeTarget currentTarget; // 当前选中的目标 - public EyeTarget CurrentTarget => currentTarget; // 提供当前目标的公共访问 - public RawImage eyeImage; - public Image memoryRender; - public Button backToFaceButton; - public GameObject eyeView; - - public enum EyeState - { - CanImagineColor, - CannotImagineColor, - EyeDisorder, - CanSeeColor, - HaveChip - } - public ViewCameraManager cameraManager; - private IEyeStateEffect eyeStateEffect; - - private EyeState currentState = EyeState.CannotImagineColor; - + private EyeData _eyeData; private Tween hsvShiftTween; private MouseFollowAndZoom mouseFollowAndZoom; - private void Awake() { Init(); @@ -56,6 +36,14 @@ public class EyeSystem : MonoBehaviour FixSystemCenter.SystemDic.Register(this); var virtualCam = transform.Find("Eye Camera").GetComponent(); CameraKit.Instance.RegisterCamera(FixState.Eye, virtualCam); + GameLoopManager.FixDataContainer.Register(_eyeData); + // 添加加载逻辑 + _eyeData.LoadEvent += LoadData; + } + private void LoadData(EyeData eyedata) + { + SetEyeColorState(eyedata.currentState); + } public void OnEnter() @@ -87,14 +75,14 @@ public class EyeSystem : MonoBehaviour { eyeStateEffect?.CleanupEffect(CurrentTarget); mouseFollowAndZoom.SetIsActive(false); - currentTarget=null; + currentTarget = null; // 离开视图时的逻辑 Debug.Log("EyeView exited."); } private void Start() { - SetEyeState(currentState); + SetEyeColorState(_eyeData.currentState); if (targets.Count > 0) { SetInitialTargetState(targets[1]); @@ -105,6 +93,7 @@ public class EyeSystem : MonoBehaviour //LostColor(); } + public void SetInitialTargetState(EyeTarget target) { currentTarget = target; @@ -226,44 +215,43 @@ public class EyeSystem : MonoBehaviour } } - [YarnCommand("set_EyeState")] - public void SetEyeStateForYarn(string state) + [YarnCommand("set_EyeColorState")] + public void SetEyeColorStateForYarn(string state) { - EyeState eyeState; + EyeData.EyeColorState eyeState; - // Try to parse the string as an EyeState + // Try to parse the string as an EyeColorState if (!Enum.TryParse(state, true, out eyeState)) { throw new ArgumentException("Invalid eye state: " + state, nameof(state)); } // Start the coroutine for setting the eye state - SetEyeState(eyeState); + SetEyeColorState(eyeState); } - private void SetEyeState(EyeState state) + private void SetEyeColorState(EyeData.EyeColorState state) { - // 保存旧的状态 - //oldEyeStateEffect = eyeStateEffect; + _eyeData.currentState=state; switch (state) { - case EyeState.CanImagineColor: + case EyeData.EyeColorState.CanImagineColor: eyeStateEffect = new CanImagineColorEffect(); //isFirstSetTargetAfterStateChange = true; break; - case EyeState.CannotImagineColor: + case EyeData.EyeColorState.CannotImagineColor: eyeStateEffect = new CannotImagineColorEffect(); //isFirstSetTargetAfterStateChange = true; break; - case EyeState.EyeDisorder: + case EyeData.EyeColorState.EyeDisorder: eyeStateEffect = new EyeDisorderEffect(); //isFirstSetTargetAfterStateChange = true; break; - case EyeState.CanSeeColor: + case EyeData.EyeColorState.CanSeeColor: eyeStateEffect = new CanSeeColorEffect(); //isFirstSetTargetAfterStateChange = false; break; - case EyeState.HaveChip: + case EyeData.EyeColorState.HaveChip: eyeStateEffect = new HaveChip(); //isFirstSetTargetAfterStateChange = false; break; @@ -444,7 +432,7 @@ public class EyeSystem : MonoBehaviour [YarnCommand("EyeGetColor")] public void GetColor() { - SetEyeState(EyeState.CanImagineColor); + SetEyeColorState(EyeData.EyeColorState.CanImagineColor); // 对目标列表中的每个目标执行 ColorBack 方法 foreach (EyeTarget target in targets) { @@ -462,4 +450,23 @@ public class EyeSystem : MonoBehaviour target.ColorLost(); } } +} +public class EyeData : IData +{ + public enum EyeColorState + { + CanImagineColor, + CannotImagineColor, + EyeDisorder, + CanSeeColor, + HaveChip + } + + public EyeColorState currentState = EyeColorState.CannotImagineColor; + public event Action LoadEvent; + + public void Load() + { + LoadEvent?.Invoke(this); + } } \ No newline at end of file