CockUIItemComp.cs 4.5 KB

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