MarketPageComp.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Api;
  4. using Plugins.CxShine.page;
  5. using UI;
  6. using UI.Common;
  7. using Unity.VisualScripting;
  8. using UnityEngine;
  9. public class MarketPageComp : MonoBehaviour
  10. {
  11. public Transform ScrollRect;
  12. public GameObject CockItemPreafab;
  13. void Start()
  14. {
  15. ApiComp.Instance.cockMarket(data =>
  16. {
  17. foreach (var marketCock in data.market)
  18. {
  19. var itemComp=Instantiate(CockItemPreafab, ScrollRect, false).GetComponent<CockUIItemComp>();
  20. itemComp.ModeBuy(marketCock);
  21. itemComp.ClickBuyAction += BuyCock;
  22. }
  23. }, null);
  24. GetComponent<PageComp>().setOnPageCloseListener((() =>
  25. {
  26. HallComp.Instance.BackToHallAndRefreshUI();
  27. ;
  28. }));
  29. }
  30. private void BuyCock(MarketCock marketCock)
  31. {
  32. if (marketCock.diamond > AccountManager.Instance.GetDiamond())
  33. {
  34. TipsComp.ShowTips("Not enough diamonds");
  35. return;
  36. }
  37. ApiComp.Instance.BuyCock(marketCock.marketId, data =>
  38. {
  39. TipsComp.ShowTips("Success!");
  40. }, (code, err) =>
  41. {
  42. TipsComp.ShowTips(err);
  43. });
  44. }
  45. }