FM/Assets/Scripts/Runtime/UI/Setting/Setting_Inventory.cs

55 lines
1.6 KiB
C#
Raw Normal View History

2025-07-13 15:53:13 +08:00
using System;
using System.Collections.Generic;
using Data;
using HK;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
namespace Runtime.UI
{
public class Setting_Inventory : MonoBehaviour
{
[SerializeField] private Setting_Inventory_NoteBookInformationItem notebookPfb;
[SerializeField] Button btnSubmit;
List<Setting_Inventory_NoteBookInformationItem> notebookList =
new List<Setting_Inventory_NoteBookInformationItem>();
private void Awake()
{
// TODO:读取本地持久化数据如果持久化数据不存在则使用Excel数据进行填充。存在则使用本地数据
foreach (var data in ExcelManager.Inventory.Datas.InventoryList)
{
var item = GameObject.Instantiate(notebookPfb, notebookPfb.transform.parent);
item.gameObject.SetActive(true);
var key = $"{data.GetType().Name}_{data.ID}";
if (!PlayerPersistent.HasKey(key))
{
PlayerPersistent.SetInt(key, data.Count);
}
else
{
data.Count = PlayerPersistent.GetInt(key);
}
item.SetData(data);
notebookList.Add(item);
}
btnSubmit.onClick.AddListener(Submit);
}
private void Submit()
{
// 保存
foreach (var item in notebookList)
{
item.SaveData();
}
gameObject.SetActive(false);
}
}
}