CockUIItemComp.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Api;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class CockUIItemComp : MonoBehaviour
  8. {
  9. public RawImage RendeImage;
  10. public Camera RendeCamera;
  11. // public Camera ClearSkybox;
  12. public Transform CooksContainner;
  13. public GameObject ReadyImage;
  14. public GameObject SelectPanel;
  15. public GameObject TimesPanel;
  16. public StarComp Start1;
  17. public StarComp Start2;
  18. public StarComp Start3;
  19. public Text nameText;
  20. public Text timesText;
  21. public Text diamondText;
  22. public GameObject BuyButton;
  23. private string _sourceTimesString = null;
  24. private int _cutSelect = 0;
  25. public Action<MarketCock> ClickBuyAction;
  26. public Action OnCockChanged;
  27. private MarketCock _marketCock;
  28. private void Start()
  29. {
  30. if (_sourceTimesString == null)
  31. {
  32. _sourceTimesString = timesText.text;
  33. }
  34. var renderTexture = new RenderTexture(512, 512, 24);
  35. RendeCamera.targetTexture = renderTexture;
  36. RendeImage.texture = renderTexture;
  37. }
  38. public void ModeCockMy()
  39. {
  40. initPlayerCocks();
  41. TimesPanel.SetActive(true);
  42. BuyButton.SetActive(false);
  43. }
  44. public void ModeCockEnemy()
  45. {
  46. var r = CooksContainner.rotation.eulerAngles;
  47. CooksContainner.rotation = Quaternion.Euler(r.x, r.y + 500, r.z);
  48. BuyButton.SetActive(false);
  49. }
  50. public void ModeBuy(MarketCock marketCock)
  51. {
  52. BuyButton.SetActive(true);
  53. _marketCock = marketCock;
  54. ChangeCook(_marketCock.cockId);
  55. diamondText.text = "" + _marketCock.diamond;
  56. timesText.text = "" + _marketCock.times + " Times";
  57. }
  58. private void DisplayTimes(int times)
  59. {
  60. timesText.text = "Remaining Use : " + times;
  61. }
  62. public void A__ClickBuy()
  63. {
  64. ClickBuyAction?.Invoke(_marketCock);
  65. }
  66. private void initPlayerCocks()
  67. {
  68. ApiComp.Instance.PlayerCocks(data =>
  69. {
  70. if (data.playerCocks != null)
  71. {
  72. AccountManager.Instance.initPlayerCocks(data.playerCocks);
  73. if (data.playerCocks.Count > 0)
  74. {
  75. SelectPanel.SetActive(true);
  76. _cutSelect = data.playerCocks.Count - 1;
  77. ChangeCook(data.playerCocks[_cutSelect].cockId);
  78. }
  79. else
  80. {
  81. AccountManager.Instance.playerCocksEmpty();
  82. }
  83. }
  84. else
  85. {
  86. AccountManager.Instance.playerCocksEmpty();
  87. _cutSelect = 0;
  88. ChangeCook(1);
  89. }
  90. }, (code, err) => { });
  91. }
  92. public void ChangeCook(int cookId)
  93. {
  94. DisplayTimes(AccountManager.Instance.GetCockTimes(cookId));
  95. DisplayStars(cookId);
  96. OnCockChanged?.Invoke();
  97. for (int i = 0; i < CooksContainner.childCount; i++)
  98. {
  99. CooksContainner.GetChild(i).gameObject.SetActive(false);
  100. }
  101. for (int i = 0; i < CooksContainner.childCount; i++)
  102. {
  103. if (("prefab_cock_" + cookId).Equals(CooksContainner.GetChild(i).gameObject.name))
  104. {
  105. CooksContainner.GetChild(i).gameObject.SetActive(true);
  106. return;
  107. }
  108. }
  109. }
  110. private void DisplayStars(int cookId)
  111. {
  112. var cockType = ConfigManager.Instance.cockTypesMap[cookId];
  113. Debug.Log("cockId" + cookId + "hp" + cockType.hpStar + "atk" + cockType.atkStar);
  114. Start1.setStar(cockType.atkStar);
  115. Start2.setStar(cockType.hpStar);
  116. Start3.setStar(cockType.intervalStar);
  117. }
  118. public void DisplayReadyImage()
  119. {
  120. ReadyImage.SetActive(true);
  121. }
  122. public void HideSelectPanel()
  123. {
  124. SelectPanel.SetActive(false);
  125. }
  126. public void A__ClickLeft()
  127. {
  128. _cutSelect -= 1;
  129. if (_cutSelect < 0)
  130. {
  131. _cutSelect = AccountManager.Instance.playerCocks.Count - 1;
  132. }
  133. ChangeCook(AccountManager.Instance.playerCocks[_cutSelect].cockId);
  134. }
  135. public void A__ClickRight()
  136. {
  137. Debug.Log("index:" + _cutSelect);
  138. Debug.Log("cockId:" + AccountManager.Instance.playerCocks[_cutSelect].cockId);
  139. _cutSelect += 1;
  140. if (_cutSelect == AccountManager.Instance.playerCocks.Count)
  141. {
  142. _cutSelect = 0;
  143. }
  144. ChangeCook(AccountManager.Instance.playerCocks[_cutSelect].cockId);
  145. }
  146. public int GetSelectCockId()
  147. {
  148. return AccountManager.Instance.playerCocks[_cutSelect].cockId;
  149. }
  150. }