FM/Assets/Scripts/FUJIFILM/UI/Logic/ProductUI.cs

113 lines
3.6 KiB
C#
Raw Normal View History

2025-08-20 11:14:21 +08:00
using System.Collections.Generic;
using System.IO;
using Runtime;
2025-08-20 11:14:21 +08:00
using UnityEngine.UI;
using TMPro;
using UnityEngine;
using UnityEngine.Serialization;
2025-08-20 11:14:21 +08:00
using ZGame;
namespace HK.FUJIFILM
{
public class ProductUI : UIBase
{
[SerializeField] private UpMenuItem goUpMenu;
[SerializeField] private ScrollRect scrParent;
2025-08-20 11:14:21 +08:00
[SerializeField] private List<ProductScriptableObject> listProduct = new List<ProductScriptableObject>();
public override void OnInit()
{
base.OnInit();
#region AutoGen_Init
goUpMenu = GetValue<UpMenuItem>("goUpMenu");
scrParent = GetValue<ScrollRect>("scrParent");
2025-08-20 11:14:21 +08:00
#endregion
// var readAllLines = File.ReadAllLines(Path.Combine(Application.streamingAssetsPath,"testScrollRect.txt"));
// scrParent.elasticity = float.Parse(readAllLines[2]);
// scrParent.decelerationRate = float.Parse(readAllLines[1]);
// scrParent.scrollSensitivity = float.Parse(readAllLines[0]);
2025-08-20 11:14:21 +08:00
foreach (var productScriptableObject in listProduct)
{
var go = ResourcesManager.Instance.LoadGameObject(
AssetConst.Assets_Res_FUJIFILM_Prefabs_UI_Item_btnIProducttem_prefab,
scrParent.content);
2025-08-20 11:14:21 +08:00
go.SetActive(true);
var image = go.GetComponent<Image>();
image.sprite = productScriptableObject.icon;
var button = go.GetComponent<Button>();
if (!productScriptableObject.isCanGoNext)
2025-08-20 11:14:21 +08:00
{
button.interactable = false;
}
dict.Add(image, productScriptableObject);
button.onClick.AddListener(() => { OnClickbtnIProducttem(productScriptableObject); });
2025-08-20 11:14:21 +08:00
}
2025-08-21 13:10:17 +08:00
CommonHelper.RebuildLayout(scrParent.content);
LanguageChange(LanguageManager.Instance.type);
2025-08-20 11:14:21 +08:00
goUpMenu.ReturnAction += ReturnCallback;
LanguageManager.Instance.LanguageChange += LanguageChange;
}
Dictionary<Image, ProductScriptableObject> dict = new Dictionary<Image, ProductScriptableObject>();
private void LanguageChange(LanguageManager.LanguageType type)
{
foreach (var kv in dict)
{
if (type == LanguageManager.LanguageType.Chinese)
kv.Key.sprite = kv.Value.icon_Chin;
else
kv.Key.sprite = kv.Value.icon;
}
2025-08-20 11:14:21 +08:00
}
private void ReturnCallback()
{
}
private void OnClickbtnIProducttem(ProductScriptableObject product)
{
2025-08-21 13:10:17 +08:00
if (!product.isCanGoNext)
return;
GlobalGameData.productScriptableObject = product;
if (product.isShowTermPage)
{
var uiOnly = UIManager.Instance.ShowUI(nameof(TermAndConditionsUI), this);
}
else
{
var uiOnly = UIManager.Instance.ShowUI(nameof(ProductDesginUI), this);
EventManager.Instance.FireNow(this, new ProductEventArgs(GlobalGameData.productScriptableObject));
}
2025-08-20 11:14:21 +08:00
}
#region AutoGen_Method
private void OnClickbtnIProducttem()
{
}
#endregion
public override void OnDispose()
{
base.OnDispose();
goUpMenu.ReturnAction -= ReturnCallback;
#region AutoGen_Dispose
goUpMenu = null;
scrParent = null;
2025-08-20 11:14:21 +08:00
#endregion
}
}
}