using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEngine.UI; public class UI_Panel_Mail : MonoBehaviour { //1234567890 [SerializeField] float anim_Time = 0.5f; float Anim_Speed => 1f / anim_Time; [SerializeField] List ui_Anim; [Header("paths")] [SerializeField] private string editor_mailSO_Path = "Assets/Resources/so/mail_so"; [SerializeField] private string runtime_mailSO_Path = "so/mail_so"; [Header("mail objects")] public GameObject noticeSlotPrefab; [SerializeField] Transform content_Notice_Slot; [Header("rewards objects")] public GameObject rewardSlotPrefab; [SerializeField] Transform content_Reward_Slot; [Header("texts")] public Text thisMail_title; public Text thisMail_body; public Text thisMail_time; public Text thisMail_sender; List cachedMails = new List(); mailSlotPrefab selectedSlot; [Header("buttons")] public Button receive_this_mail; private void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { gameObject.SetActive(false); } } void Start() { foreach (var item in ui_Anim) { item.speed = Anim_Speed; } BuildMailSlots(); } void BuildMailSlots() { if (noticeSlotPrefab == null || content_Notice_Slot == null) return; for (int i = content_Notice_Slot.childCount - 1; i >= 0; i--) { Destroy(content_Notice_Slot.GetChild(i).gameObject); } var mails = LoadMailAssets(); if (mails == null || mails.Count == 0) return; cachedMails = mails; ApplySavedState(cachedMails); for (int i = 0; i < mails.Count; i++) { var mail = mails[i]; if (mail == null) continue; var go = Instantiate(noticeSlotPrefab, content_Notice_Slot); var slot = go.GetComponent(); if (selectedSlot == null) selectedSlot = slot; if (slot != null) { if (slot.mailTitle != null) slot.mailTitle.text = mail.mail_title; if (slot.mailSender != null) slot.mailSender.text = mail.mail_sender; if (slot.mailTime != null) slot.mailTime.text = mail.mail_date; if (slot.mailImage != null) slot.mailImage.sprite = mail.mail_image; UpdateSlotVisuals(slot, mail); SetSelectedState(slot, false); var openButton = slot.openButton != null ? slot.openButton : go.GetComponent