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

87 lines
2.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using Data;
using HK;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Runtime.UI
{
public class Setting_Monetary : MonoBehaviour
{
[SerializeField] TMP_InputField inpMonetary;
[SerializeField] private Setting_Monetary_NoteBookInformationItem notebookPfb;
[SerializeField] Button btnSubmit;
List<Setting_Monetary_NoteBookInformationItem> notebookList =
new List<Setting_Monetary_NoteBookInformationItem>();
private void Awake()
{
// TODO:读取本地持久化数据如果持久化数据不存在则使用Excel数据进行填充。存在则使用本地数据
foreach (var data in ExcelManager.NoteBookInformation.Datas.NoteBookInformationList)
{
var item = GameObject.Instantiate(notebookPfb, notebookPfb.transform.parent);
item.gameObject.SetActive(true);
var bookPrice = $"{data.GetType().Name}_{data.ID}_{data.BookPrice}";
if (!PlayerPersistent.HasKey(bookPrice))
{
PlayerPersistent.SetInt(bookPrice, data.BookPrice);
}
else
{
data.BookPrice = PlayerPersistent.GetInt(bookPrice);
}
var designPrice = $"{data.GetType().Name}_{data.ID}_{data.DesignPrice}";
if (!PlayerPersistent.HasKey(designPrice))
{
PlayerPersistent.SetInt(designPrice, data.DesignPrice);
}
else
{
data.DesignPrice = PlayerPersistent.GetInt(designPrice);
}
var discountPrice = $"{data.GetType().Name}_{data.ID}_{data.DiscountPrice}";
if (!PlayerPersistent.HasKey(discountPrice))
{
PlayerPersistent.SetInt(discountPrice, data.DiscountPrice);
}
else
{
data.DiscountPrice = PlayerPersistent.GetInt(discountPrice);
}
item.SetData(data);
notebookList.Add(item);
}
var monetary = $"monetary";
if (!PlayerPersistent.HasKey(monetary))
{
PlayerPersistent.SetString(monetary, ShoppingCartManager.Instance.ShoppingCart.monetary);
}
inpMonetary.text = PlayerPersistent.GetString(monetary);
btnSubmit.onClick.AddListener(Submit);
}
private void Submit()
{
ShoppingCartManager.Instance.ShoppingCart.monetary = inpMonetary.text;
PlayerPersistent.SetString("monetary", inpMonetary.text);
// 保存
foreach (var item in notebookList)
{
item.SaveData();
}
gameObject.SetActive(false);
}
}
}