116 lines
3.4 KiB
C#
116 lines
3.4 KiB
C#
using System;
|
|
using Runtime;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using ZXL.Helper;
|
|
|
|
namespace HK
|
|
{
|
|
public class CommodityItem : UIItemBase
|
|
{
|
|
[SerializeField] private Button btnEditor;
|
|
[SerializeField] private Button btnDelete;
|
|
[SerializeField] private RawImage rawPic;
|
|
[SerializeField] private Button btnReduce;
|
|
[SerializeField] private TMP_Text txtCount;
|
|
[SerializeField] private Button btnAdd;
|
|
[SerializeField] private TMP_Text txtPrice;
|
|
[SerializeField] private TMP_Text txtProductName;
|
|
ShoppingCartData shoppingCartData;
|
|
public Action OnUpdateCallback;
|
|
|
|
public override void OnInit()
|
|
{
|
|
base.OnInit();
|
|
|
|
#region AutoGen_Init
|
|
|
|
btnEditor = GetValue<Button>("btnEditor");
|
|
btnDelete = GetValue<Button>("btnDelete");
|
|
rawPic = GetValue<RawImage>("rawPic");
|
|
btnReduce = GetValue<Button>("btnReduce");
|
|
txtCount = GetValue<TMP_Text>("txtCount");
|
|
btnAdd = GetValue<Button>("btnAdd");
|
|
txtPrice = GetValue<TMP_Text>("txtPrice");
|
|
txtProductName = GetValue<TMP_Text>("txtProductName");
|
|
|
|
btnEditor.onClick.AddListener(OnClickbtnEditor);
|
|
btnDelete.onClick.AddListener(OnClickbtnDelete);
|
|
btnReduce.onClick.AddListener(OnClickbtnReduce);
|
|
btnAdd.onClick.AddListener(OnClickbtnAdd);
|
|
|
|
#endregion
|
|
}
|
|
|
|
#region AutoGen_Method
|
|
|
|
private void OnClickbtnEditor()
|
|
{
|
|
}
|
|
|
|
private void OnClickbtnDelete()
|
|
{
|
|
ShoppingCartManager.Instance.RemoveFromCart(shoppingCartData);
|
|
GameObject.Destroy(gameObject);
|
|
}
|
|
|
|
private void OnClickbtnReduce()
|
|
{
|
|
if (shoppingCartData.count<=1)
|
|
{
|
|
return;
|
|
}
|
|
shoppingCartData.count--;
|
|
ShoppingCartManager.Instance.RefreshCart();
|
|
txtCount.text = shoppingCartData.count.ToString();
|
|
OnUpdateCallback?.Invoke();
|
|
}
|
|
|
|
private void OnClickbtnAdd()
|
|
{
|
|
if (shoppingCartData.count >= 10)
|
|
{
|
|
return;
|
|
}
|
|
shoppingCartData.count++;
|
|
ShoppingCartManager.Instance.RefreshCart();
|
|
txtCount.text = shoppingCartData.count.ToString();
|
|
OnUpdateCallback?.Invoke();
|
|
}
|
|
|
|
#endregion
|
|
|
|
public void SetData(ShoppingCartData data)
|
|
{
|
|
shoppingCartData = data;
|
|
rawPic.texture = TextureHelper.ConvertByteArrayToTexture2D(data.previewImage);
|
|
txtCount.text = data.count.ToString();
|
|
txtPrice.text = data.bookAmount.ToString("F");
|
|
txtProductName.text = data.bookName;
|
|
}
|
|
|
|
public override void OnDispose()
|
|
{
|
|
base.OnDispose();
|
|
|
|
#region AutoGen_Dispose
|
|
|
|
btnEditor.onClick.RemoveListener(OnClickbtnEditor);
|
|
btnDelete.onClick.RemoveListener(OnClickbtnDelete);
|
|
btnReduce.onClick.RemoveListener(OnClickbtnReduce);
|
|
btnAdd.onClick.RemoveListener(OnClickbtnAdd);
|
|
|
|
btnEditor = null;
|
|
btnDelete = null;
|
|
rawPic = null;
|
|
btnReduce = null;
|
|
txtCount = null;
|
|
btnAdd = null;
|
|
txtPrice = null;
|
|
txtProductName = null;
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
} |