using System; using System.Collections; using System.Collections.Generic; using System.Numerics; using JetBrains.Annotations; using Newtonsoft.Json; using TMPro; using Unity.VisualScripting; using UnityEditor.Rendering.LookDev; using UnityEngine; using UnityEngine.UI; public class FreePanelManager : MonoBehaviour { [Header("测试")] public Sprite TestImage; [Header("面板")] //职业选择面板 public GameObject OccupationPanel; //特殊情况弹窗 public GameObject TipPanel; public GameObject AccidentIPanel; //职业介绍框框 public List OpcList; //疏散顺序的确定按钮 public GameObject EvacuateSurePanel; //疏散顺序面板 public GameObject EvacuatePanel; [Header("图像")] //特殊情况弹窗背景图 public Image TipBg; //事故点截图 public Image AccidentImage; [Header("按钮")] public Button AccidentButton; public Button OpcLeft; public Button OpcRight; public Button EvacuateButton; public Button EvacuateSure; public Button Evacuate1Button; public Button Evacuate2Button; public Button Evacuate3Button; public Button Evacuate4Button; [Header("文本")] //特殊情况弹窗文本 public Text TipText; //疏散顺序描述 public Text EvacuateText1; public Text EvacuateText2; public Text EvacuateText3; public Text EvacuateText4; [Header("一些奇奇怪怪的东西")] #region 特殊情况淡入淡出效果 public float fadeInDuration = 1f; // 淡出时间 public float fadeOutDuration = 1f; // 淡出持续时间 public float displayDuration = 2f; // 2秒后自己淡出 private bool isFadingIn = true; private bool isFadingOut = false; // 指示文本当前是否正在淡入或淡出 private bool isFading = false; private bool isFadeEnd = false; // 运行中的淡入淡出协程引用 private Coroutine fadeCoroutine; #endregion #region 创建职业介绍 public List createdItems = new List();//保存内容用的列表 public List Order = new List();//保存底板的字段 public GameObject content1; // Scroll View 的 Content 物体 public List OpcName = new List(); //保存职业任务介绍 public Sprite InfoBg;//介绍的底板 private int itemCount = 1; // 要创建的物体数量 public GameObject itemPrefab; // 子物体的预制件 public JSONReader JSONReader; #endregion #region 创建职业面板 public List OpcItems = new List(); //保存需要创建几个职业 public List DirectChildren = new List();//用于保存Item的子物体 方便左右 public List TagChildren = new List();//用于保存Item子物体带有标签的,用与放职业介绍 public GameObject Item;//创建在谁的jio下 public List TaskId = new List();//保存玩家接取的任务 public GameObject OpcPrefab;//职业预制体 public Image OpcImage;//预制体图片 public Text OpcText;//预制体文本内容 #endregion private static int a = 0; public void Start() { ContainsValue(11002); #region 初始化的东西 InitializeChild(); #endregion //职业介绍框左按钮 OpcLeft.onClick.AddListener(() => { LeftRight(a, -1); }); //职业介绍框右按钮 OpcRight.onClick.AddListener(() => { LeftRight(a, 1); }); //疏散顺序的选项 #region 疏散顺序选项 Evacuate1Button.onClick.AddListener(() => { EvacuateSurePanel.SetActive(true); }); Evacuate2Button.onClick.AddListener(() => { EvacuateSurePanel.SetActive(true); }); Evacuate3Button.onClick.AddListener(() => { EvacuateSurePanel.SetActive(true); }); Evacuate4Button.onClick.AddListener(() => { EvacuateSurePanel.SetActive(true); }); #endregion //疏散顺序的箭头 EvacuateButton.onClick.AddListener(() => { EvacuatePanel.SetActive(false); EvacuateSurePanel.SetActive(false); }); //职业面板点击事件 #region 面板点击 #endregion } public void Update() { #region 测试 if (Input.GetKeyDown("j")) { // PopAccident(TestImage); } #endregion if (isFadeEnd) { StopCoroutine(FadeInOutRoutine()); isFadeEnd = false; } } /// /// 打开特殊情况弹窗 /// public void PopTipPanel() { TipPanel.SetActive(true); StopCoroutine(FadeInOutRoutine()); } /// /// 弹出事故框框并且修改图片 /// /// 传入一张事故图片(Spite) public void PopAccident(Sprite image) { AccidentImage.sprite = image; AccidentIPanel.SetActive(true); } /// /// 提示面板淡入淡出的携程 /// /// IEnumerator FadeInOutRoutine() { isFading = true; // 设置正在淡入淡出标志 //// 淡入 float elapsedTime = 0f; while (elapsedTime < fadeInDuration) { elapsedTime += Time.deltaTime; //Color textColor = TipText.color; //textColor.a = elapsedTime / fadeInDuration; // 根据时间计算alpha值 //TipText.color = textColor; //TipBg.color = textColor; yield return null; // 等待下一帧 } // 显示文本一段时间 yield return new WaitForSeconds(displayDuration); // 淡出 elapsedTime = 0f; while (elapsedTime < fadeOutDuration) { elapsedTime += Time.deltaTime; Color textColor = TipText.color; textColor.a = 1f - (elapsedTime / fadeOutDuration); // 根据时间计算alpha值 TipText.color = textColor; TipBg.color = textColor; yield return null; // 等待下一帧 } isFading = false; // 重置正在淡入淡出标志 isFadeEnd = true;//这个携程结束的标志 TipPanel.SetActive(false); } /// /// 打开关闭职业选择面板 /// public void OpenOccupation() { bool isActive = OccupationPanel.activeSelf; // 如果面板已激活,则关闭,否则打开 OccupationPanel.SetActive(!isActive); } /// /// 获取职业名字并且赋值到面板上 /// /// 职业的ID /// 第几个面板(从1开始) public void OcpNameChoose(int ID) { string str = JSONReader.GetOcpName(ID); OpcText.text = str; } /// /// 创建职业介绍内容(这个方法要联动OcpNameChoose方法的) /// /// 职业的ID /// 放在那个一个子物体下 public void CreateOcpText(string ID, GameObject content) { OpcName.Clear(); Order.Clear(); // 确保 Order 清空,避免重复数据 createdItems.Clear(); // 确保 createdItems 清空,避免重复数据 // 遍历 SelectDictionary foreach (var kvp in JSONReader.ZZSelectsDictionary) { // 这里 kvp.Key 是字典的键,kvp.Value 是 Select 对象 Select select = kvp.Value; // 判断 UIDetails 是否匹配,并且填充数据 if (select.UIDetails == ID.ToString()) { // 将 Note 添加到 OpcName 列表 OpcName.Add(select.Note); Order.Add(select.AppliedUI); } } // 动态创建指定数量的子物体并保存它们 for (int i = 0; i < OpcName.Count; i++) { GameObject newItem = Instantiate(itemPrefab, content.transform); // 找到子物体的文本组件并设置内容 Text left = newItem.transform.Find("Text").GetComponent(); left.text = OpcName[i]; // 如果 Order[i] 是 "order2",修改背景图片 if (Order[i] == "order2") { Image image = newItem.GetComponent(); image.sprite = InfoBg; // 添加点击事件 Button button = newItem.GetComponent