153 lines
4.8 KiB
C#
153 lines
4.8 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Newtonsoft.Json;
|
|
using Runtime;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
using ZGame;
|
|
|
|
namespace HK.FUJIFILM
|
|
{
|
|
[System.Serializable]
|
|
public class ProductData
|
|
{
|
|
public List<ProductItemData> listProduct = new List<ProductItemData>();
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class ProductItemData
|
|
{
|
|
public string productID;
|
|
public string productName;
|
|
public bool isCanGoNext;
|
|
}
|
|
|
|
public class ProductUI : UIBase
|
|
{
|
|
[SerializeField] private UpMenuItem goUpMenu;
|
|
[SerializeField] private ScrollRect scrParent;
|
|
[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");
|
|
|
|
#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]);
|
|
|
|
foreach (var productScriptableObject in listProduct)
|
|
{
|
|
var go = ResourcesManager.Instance.LoadGameObject(
|
|
AssetConst.Assets_Res_FUJIFILM_Prefabs_UI_Item_btnIProducttem_prefab,
|
|
scrParent.content);
|
|
go.SetActive(true);
|
|
var image = go.GetComponent<Image>();
|
|
image.sprite = productScriptableObject.icon;
|
|
var button = go.GetComponent<Button>();
|
|
if (!productScriptableObject.isCanGoNext)
|
|
{
|
|
button.interactable = false;
|
|
}
|
|
|
|
dict.Add(image, productScriptableObject);
|
|
button.onClick.AddListener(() => { OnClickbtnIProducttem(productScriptableObject); });
|
|
}
|
|
|
|
CommonHelper.RebuildLayout(scrParent.content);
|
|
LanguageChange(LanguageManager.Instance.type);
|
|
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;
|
|
}
|
|
}
|
|
|
|
private ProductData data;
|
|
|
|
public override void OnOpen(UIBase lastUI = null)
|
|
{
|
|
base.OnOpen(lastUI);
|
|
var json = File.ReadAllText(Path.Combine(Application.streamingAssetsPath, "ProductSetting.json"));
|
|
data = JsonConvert.DeserializeObject<ProductData>(json);
|
|
foreach (var productItemData in data.listProduct)
|
|
{
|
|
foreach (var kv in dict)
|
|
{
|
|
if (kv.Value.produceID == productItemData.productID)
|
|
{
|
|
kv.Value.isCanGoNext = productItemData.isCanGoNext;
|
|
kv.Key.GetComponent<Button>().interactable = productItemData.isCanGoNext;
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ReturnCallback()
|
|
{
|
|
}
|
|
|
|
private void OnClickbtnIProducttem(ProductScriptableObject product)
|
|
{
|
|
if (!product.isCanGoNext)
|
|
return;
|
|
|
|
GlobalGameData.productScriptableObject = product;
|
|
if (product.isShowTermPage)
|
|
{
|
|
OnPause();
|
|
var uiOnly = UIManager.Instance.ShowUI(nameof(TermAndConditionsUI), this);
|
|
}
|
|
else
|
|
{
|
|
OnPause();
|
|
var uiOnly = UIManager.Instance.ShowUI(nameof(ProductDesginUI), this);
|
|
EventManager.Instance.FireNow(this, new ProductEventArgs(GlobalGameData.productScriptableObject));
|
|
}
|
|
}
|
|
|
|
#region AutoGen_Method
|
|
|
|
private void OnClickbtnIProducttem()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
public override void OnDispose()
|
|
{
|
|
base.OnDispose();
|
|
goUpMenu.ReturnAction -= ReturnCallback;
|
|
LanguageManager.Instance.LanguageChange -= LanguageChange;
|
|
|
|
#region AutoGen_Dispose
|
|
|
|
goUpMenu = null;
|
|
scrParent = null;
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
} |