123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- 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<MarketCock> 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;
- }
- }
|