using System; using System.Collections; using System.Collections.Generic; using Api; using UnityEngine; using UnityEngine.UI; public class CockUIItemComp : MonoBehaviour { public RawImage RendeImage; public Camera RendeCamera; // public Camera ClearSkybox; public Transform CooksContainner; public GameObject ReadyImage; public GameObject SelectPanel; public GameObject TimesPanel; public StarComp Start1; public StarComp Start2; public StarComp Start3; public Text timesText; public Text diamondText; public GameObject BuyButton; private string _sourceTimesString = null; private int _cutSelect = 0; public Action ClickBuyAction; public Action OnCockChanged; private MarketCock _marketCock; private void Start() { if (_sourceTimesString == null) { _sourceTimesString = timesText.text; } var renderTexture = new RenderTexture(512, 512, 24); RendeCamera.targetTexture = renderTexture; RendeImage.texture = renderTexture; } public void ModeCockMy() { initPlayerCocks(); TimesPanel.SetActive(true); BuyButton.SetActive(false); } public void ModeCockEnemy() { var r = CooksContainner.rotation.eulerAngles; CooksContainner.rotation = Quaternion.Euler(r.x, r.y + 500, r.z); BuyButton.SetActive(false); } public void ModeBuy(MarketCock marketCock) { BuyButton.SetActive(true); _marketCock = marketCock; ChangeCook(_marketCock.cockId); diamondText.text = "" + _marketCock.diamond; timesText.text = "" + _marketCock.times + " Times"; } private void DisplayTimes(int times) { timesText.text = "Remaining Use : " + times; } public void A__ClickBuy() { ClickBuyAction?.Invoke(_marketCock); } private void initPlayerCocks() { ApiComp.Instance.PlayerCocks(data => { if (data.playerCocks != null) { AccountManager.Instance.initPlayerCocks(data.playerCocks); if (data.playerCocks.Count > 0) { SelectPanel.SetActive(true); _cutSelect = data.playerCocks.Count - 1; ChangeCook(data.playerCocks[_cutSelect].cockId); } else { AccountManager.Instance.playerCocksEmpty(); } } else { AccountManager.Instance.playerCocksEmpty(); _cutSelect = 0; ChangeCook(1); } }, (code, err) => { }); } public void ChangeCook(int cookId) { DisplayTimes(AccountManager.Instance.GetCockTimes(cookId)); DisplayStars(cookId); OnCockChanged?.Invoke(); for (int i = 0; i < CooksContainner.childCount; i++) { CooksContainner.GetChild(i).gameObject.SetActive(false); } for (int i = 0; i < CooksContainner.childCount; i++) { if (("prefab_cock_" + cookId).Equals(CooksContainner.GetChild(i).gameObject.name)) { CooksContainner.GetChild(i).gameObject.SetActive(true); return; } } } private void DisplayStars(int cookId) { var cockType = ConfigManager.Instance.cockTypesMap[cookId]; Start1.setStar(cockType.atkStar); Start2.setStar(cockType.hpStar); Start3.setStar(cockType.intervalStar); } public void DisplayReadyImage() { ReadyImage.SetActive(true); } public void HideSelectPanel() { SelectPanel.SetActive(false); } public void A__ClickLeft() { _cutSelect -= 1; if (_cutSelect < 0) { _cutSelect = AccountManager.Instance.playerCocks.Count - 1; } ChangeCook(AccountManager.Instance.playerCocks[_cutSelect].cockId); } public void A__ClickRight() { Debug.Log("index:" + _cutSelect); Debug.Log("cockId:" + AccountManager.Instance.playerCocks[_cutSelect].cockId); _cutSelect += 1; if (_cutSelect == AccountManager.Instance.playerCocks.Count) { _cutSelect = 0; } ChangeCook(AccountManager.Instance.playerCocks[_cutSelect].cockId); } public int GetSelectCockId() { return AccountManager.Instance.playerCocks[_cutSelect].cockId; } }