using DG.Tweening; using IVDataFormat; using IVServerFormat; using Spine.Unity; using System.Collections; using TMPro; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.UI; public class GachaMgr : MonoBehaviour { #region Const private static GachaMgr curMgr = null; #endregion Const #region UI [SerializeField] private TextMeshProUGUI txtMainT; [SerializeField] private Canvas canvasUI; private ButtonIV[] btnTabs; private GameObject[] btnTabLocks; private Canvas sortingCanvas; // 가챠 버튼. private ButtonIV[] btnGachas; private TextMeshProUGUI[] txtGachaCnts; private TextMeshProUGUI[] txtGachaPrices; private Image[] imgGachaTypes; private Image imgChangeGachaTicket; private Image imgGachaBg, imgGachaBox; private SkeletonAnimation skAnimTop, skAnimBottom; private ParticleSystem skAnimRew; // 경험치. private TextMeshProUGUI txtGachaLv; private TextMeshProUGUI txtGachaExp; private Slider sldGachaExp; private GameObject goBtnGachaLv, goBtnGachaLvOff; // 소환 확률 정보. private Canvas canvasInfo; private GameObject goInfoCon; private GameObject groupInfoRate; private GameObject goInfoBtnPrev; private GameObject goInfoBtnNext; private TextMeshProUGUI txtInfoT; private TextMeshProUGUI[] txtInfoRaritys; private TextMeshProUGUI[] txtInfoGrades; private GoodsItem goodsInfoReward; private GameObject goInfoRewardEmpty, goInfoRewardLock; // 소환 결과. [SerializeField] private Canvas canvasResult; private GameObject goResultBtnClose; private GameObject groupResultBtn; [SerializeField] private GameObject prfGoodsItem; private GridLayoutGroup glgResult; private GoodsEfcItem[] goodsItems; private Toggle tglResultAuto; private TextMeshProUGUI txtResultLv; private TextMeshProUGUI txtResultExp; private Slider sldResultExp; private ButtonIV[] btnResultGachas; private TextMeshProUGUI[] txtResultGachaCnts; private TextMeshProUGUI[] txtResultGachaPrices; private Image[] imgResultGachaTypes; private GridLayoutGroup gachaResult; #endregion UI #region Variables private int iLoading = 1; private bool bReLocalize = true; private bool bReLocalizeInfo = true; private int iSelectedTab = -1; private int iGachaCount = 1; private int iGachaLvBef = 1; private bool bModeTicket = false; private int iSelectedLv = 1; private bool bInitNeedInfo = true; private bool bInitNeedResult = true; private Sequence seqBox; private AsyncOperationHandle handleBg, handleBox; private AsyncOperationHandle handleTop, handleBottom, handleRew; GameObject dust; #endregion Variables #region Base public static void SLocalize(bool bmain) { if (curMgr != null) curMgr.Localize(bmain); } // 번역. private void Localize(bool bmain) { if (bmain) { txtMainT.text = LocalizationText.GetText("gacha_title"); } else { bReLocalize = false; // 가챠 메인. canvasUI.transform.Find("txtT").GetComponent().text = LocalizationText.GetText("gacha_title"); btnTabs[0].transform.Find("txt").GetComponent().text = LocalizationText.GetText("gacha_weapon"); btnTabs[1].transform.Find("txt").GetComponent().text = LocalizationText.GetText("gacha_armor"); btnTabs[2].transform.Find("txt").GetComponent().text = LocalizationText.GetText("gacha_acce"); btnTabs[3].transform.Find("txt").GetComponent().text = LocalizationText.GetText("gacha_treasure"); tglResultAuto.transform.Find("txt").GetComponent().text = LocalizationText.GetText("gacha_auto"); } } // 설정에서 언어 변경 시 처리. public static void SReLocalize() { curMgr.Localize(true); curMgr.bReLocalize = true; curMgr.bReLocalizeInfo = true; } // 백버튼 처리. public static bool SCloseMenu() { return curMgr.CloseMenu(); } private bool CloseMenu() { // 게임 시작 후 열린적 없음. if (iSelectedTab < 0) return false; if (!bInitNeedResult && canvasResult.enabled) { if (tglResultAuto.isOn) { tglResultAuto.isOn = false; return true; } CloseGachaResult(); return true; } if (!bInitNeedInfo && canvasInfo.enabled) { CloseInfo(); return true; } if (canvasUI.enabled) { CloseGacha(); return true; } return false; } private void Awake() { curMgr = this; } void Start() { iLoading--; } private void Init() { sortingCanvas = canvasUI.transform.Find("sortingCanvas").GetComponent(); btnTabs = canvasUI.transform.Find("tabWrapLeft").GetComponentsInChildren(true); btnTabLocks = new GameObject[btnTabs.Length]; for (int i = 0; i < btnTabs.Length; i++) { btnTabLocks[i] = btnTabs[i].transform.Find("lock").gameObject; } btnGachas = canvasUI.transform.Find("gachaBtns").GetComponentsInChildren(true); txtGachaCnts = new TextMeshProUGUI[btnGachas.Length]; txtGachaPrices = new TextMeshProUGUI[btnGachas.Length]; imgGachaTypes = new Image[btnGachas.Length]; for (int i = 0; i < btnGachas.Length; i++) { txtGachaCnts[i] = btnGachas[i].transform.Find("txtCon").GetComponent(); txtGachaPrices[i] = btnGachas[i].transform.Find("txtPrice").GetComponent(); imgGachaTypes[i] = btnGachas[i].transform.Find("icon").GetComponent(); } Transform trfupbar = sortingCanvas.transform.Find("sortingCanvas2").GetChild(0); txtGachaLv = trfupbar.Find("txtGachaLv").GetComponent(); txtGachaExp = trfupbar.Find("txtGachaExp").GetComponent(); sldGachaExp = trfupbar.Find("sldGachaExp").GetComponent(); goBtnGachaLv = trfupbar.Find("btnGachaLv").gameObject; goBtnGachaLvOff = trfupbar.Find("gachaLvOff").gameObject; skAnimRew = goBtnGachaLv.transform.GetChild(0).GetComponent(); // 결과창. goResultBtnClose = canvasResult.transform.Find("btnClose").gameObject; groupResultBtn = canvasResult.transform.Find("gachaBtns").gameObject; glgResult = canvasResult.transform.Find("results").GetComponent(); tglResultAuto = canvasResult.transform.Find("toggleCanvas").transform.Find("tglAuto").GetComponent(); btnResultGachas = groupResultBtn.GetComponentsInChildren(true); txtResultGachaCnts = new TextMeshProUGUI[btnResultGachas.Length]; txtResultGachaPrices = new TextMeshProUGUI[btnResultGachas.Length]; imgResultGachaTypes = new Image[btnResultGachas.Length]; for (int i = 0; i < btnResultGachas.Length; i++) { txtResultGachaCnts[i] = btnResultGachas[i].transform.Find("txtCon").GetComponent(); txtResultGachaPrices[i] = btnResultGachas[i].transform.Find("txtPrice").GetComponent(); imgResultGachaTypes[i] = btnResultGachas[i].transform.Find("icon").GetComponent(); } Transform trfresupbar = canvasResult.transform.Find("upBar"); txtResultLv = trfresupbar.Find("txtGachaLv").GetComponent(); txtResultExp = trfresupbar.Find("txtGachaExp").GetComponent(); sldResultExp = trfresupbar.Find("sldGachaExp").GetComponent(); imgChangeGachaTicket = canvasUI.transform.Find("btnChange").GetComponent(); //imgGachaBg = canvasUI.transform.Find("imgGacha").GetComponent(); //imgGachaBg.color = Global.CLR_Trans; imgGachaBox = sortingCanvas.transform.GetChild(1).GetComponent(); imgGachaBox.color = Global.CLR_Trans; skAnimTop = sortingCanvas.transform.GetChild(0).GetComponent(); skAnimBottom = sortingCanvas.transform.GetChild(2).GetComponent(); gachaResult = canvasResult.transform.Find("results").GetComponent(); canvasInfo = canvasUI.transform.Find("popupInfo").GetComponent(); dust = canvasUI.transform.Find("all_dust").gameObject; } #endregion Base #region UI public static void SMoveGacha(eEventMoveType content) { curMgr.OpenGacha(); switch (content) { case eEventMoveType.SummonWeapon: curMgr.TabWeapon(); break; case eEventMoveType.SummonArmor: curMgr.TabArmor(); break; case eEventMoveType.SummonAcc: curMgr.TabAcce(); break; case eEventMoveType.SummonTreasure: curMgr.TabTreasure(); break; } } // 가챠 열기. public void OpenGacha() { if (iLoading > 0) return; iLoading++; GameUIMgr.SAllOffDownMenu(); if (iSelectedTab < 0) Init(); CoverCamera.Hold(); CoverCamera.Hold(); //CoverCamera.Hold(); //CoverCamera.Hold(); //Addressables.LoadAssetAsync("img/gacha_bg").Completed += ALoadBgComp; //Addressables.LoadAssetAsync("spine/gacha_main_top/gacha_main_top_SkeletonData.asset").Completed += ALoadTopComp; Addressables.LoadAssetAsync("spine/gacha_main_bottom/gacha_main_bottom_SkeletonData.asset").Completed += ALoadBottomComp; Addressables.LoadAssetAsync("spine/recall_reward/recall_reward_SkeletonData.asset").Completed += ALoadRewComp; //seqBox = DOTween.Sequence() // .SetUpdate(true) // .Append(imgGachaBox.GetComponent().DOScale(new Vector3(1.015f, 1.015f, 1f), 1f)) // .Append(imgGachaBox.GetComponent().DOScale(Vector3.one, 1f)) // .SetLoops(-1) // .Play(); if (bReLocalize) { int itab = 0; if (iSelectedTab >= 0) { itab = iSelectedTab; btnTabs[iSelectedTab].interactable = true; iSelectedTab = -1; } Localize(false); // 무기. if (itab == 0) TabWeapon(); // 방어구. else if (itab == 1) TabArmor(); // 악세. else if (itab == 2) TabAcce(); // 보물. else if (itab == 3) TabTreasure(); } else { CoverCamera.Hold(); Addressables.LoadAssetAsync(FormatString.CombineAllString("img/gacha", iSelectedTab.ToString())).Completed += ALoadBoxComp; } // 무기. if (iSelectedTab == 0) GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaWeapon); // 방어구. else if (iSelectedTab == 1) GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaArmor); // 악세. else if (iSelectedTab == 2) GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaAcc); // 보물. else if (iSelectedTab == 3) GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaTreasure); SetGachaBtnAvail(); btnTabLocks[2].SetActive(!DataHandler.IsClearStage(DataHandler.Const.gearAccOpenStage)); btnTabLocks[3].SetActive(!DataHandler.IsClearStage(DataHandler.Const.gearTreasureOpenStage)); canvasUI.enabled = true; setActiveSortingCanvas(); GameUIMgr.SRightWindowClose(); GameUIMgr.SOpenUpPanel(isUp: true, dia: true, gacha: true); GameUIMgr.SSetMainUiOn(false); BattleMgr.SSetBattleUiOn(false); BattleMgr.SSetClearFailUiOn(false); BattleMgr.SSetCameraOn(false); SoundMgr.PlaySfx(SoundName.BtnPress); dust.SetActive(true); iLoading--; } // 가챠 닫기. public void CloseGacha() { if (!canvasUI.enabled) return; if (iLoading > 0) return; iLoading++; CoverCamera.Hold(); DataHandler.CheckAchivement(eContent.Summon); canvasUI.enabled = false; setActiveSortingCanvas(); GameUIMgr.SCloseUpPanel(); GameUIMgr.SSetMainUiOn(true); BattleMgr.SSetBattleUiOn(true); BattleMgr.SSetClearFailUiOn(true); BattleMgr.SSetCameraOn(true); BattleMgr.SRefreshCharCloth(); MissionMgr.SRefreshMission(); //seqBox.Kill(); //imgGachaBg.color = Global.CLR_Trans; //imgGachaBg.sprite = null; imgGachaBox.color = Global.CLR_Trans; imgGachaBox.sprite = null; if (handleBg.IsValid()) { Addressables.Release(handleBg); AddressableMgr.SAddUnload(); } if (handleBox.IsValid()) { Addressables.Release(handleBox); AddressableMgr.SAddUnload(); } //MeshRenderer renderertop = skAnimTop.GetComponent(); //renderertop.sortingOrder = 0; //skAnimTop.skeletonDataAsset.Clear(); //skAnimTop.ClearState(); //skAnimTop.skeletonDataAsset = null; MeshRenderer rendererbot = skAnimBottom.GetComponent(); rendererbot.sortingOrder = 0; skAnimBottom.skeletonDataAsset.Clear(); skAnimBottom.ClearState(); skAnimBottom.skeletonDataAsset = null; //MeshRenderer rendererrew = skAnimRew.GetComponent(); //rendererrew.sortingOrder = 0; //skAnimRew.skeletonDataAsset.Clear(); //skAnimRew.ClearState(); //skAnimRew.skeletonDataAsset = null; if (handleTop.IsValid()) { Addressables.Release(handleTop); AddressableMgr.SAddUnload(); } if (handleBottom.IsValid()) { Addressables.Release(handleBottom); AddressableMgr.SAddUnload(); } if (handleRew.IsValid()) { Addressables.Release(handleRew); AddressableMgr.SAddUnload(); } SoundMgr.PlaySfx(SoundName.BtnPress); CoverCamera.Release(); dust.SetActive(false); iLoading--; } // 도움말 열기. public void OpenHelp() { } // sortingCanvas 활성화 비활성화 public void setActiveSortingCanvas() { sortingCanvas.gameObject.SetActive(canvasUI.enabled); if (canvasResult.enabled) sortingCanvas.gameObject.SetActive(false); } #endregion UI #region Info // 정보 열기. public void OpenInfo() { if (iLoading > 0) return; iLoading++; // 정보창 초기화. if (bInitNeedInfo) { Logger.Log("InitInfo"); bInitNeedInfo = false; canvasInfo = canvasUI.transform.Find("popupInfo").GetComponent(); txtInfoT = canvasInfo.transform.Find("txtT").GetComponent(); goInfoCon = canvasInfo.transform.Find("txtCon").gameObject; Transform trfrate = canvasInfo.transform.Find("groupRate"); groupInfoRate = trfrate.gameObject; goInfoBtnPrev = trfrate.Find("btnPrev").gameObject; goInfoBtnNext = trfrate.Find("btnNext").gameObject; TextMeshProUGUI[] txtraritys = trfrate.Find("groupRarity").GetComponentsInChildren(true); txtInfoRaritys = new TextMeshProUGUI[txtraritys.Length - 1]; for (int i = 0; i < txtInfoRaritys.Length; i++) txtInfoRaritys[i] = txtraritys[i + 1]; TextMeshProUGUI[] txtgrades = trfrate.Find("groupGrade").GetComponentsInChildren(true); txtInfoGrades = new TextMeshProUGUI[txtgrades.Length - 1]; for (int i = 0; i < txtInfoGrades.Length; i++) txtInfoGrades[i] = txtgrades[i + 1]; goodsInfoReward = trfrate.Find("groupReward").Find("GoodsItem").GetComponent(); goInfoRewardLock = trfrate.Find("groupReward").Find("lock").gameObject; goInfoRewardEmpty = trfrate.Find("groupReward").Find("txtEmpty").gameObject; goInfoRewardEmpty.GetComponent().text = "-"; } if (bReLocalizeInfo) { bReLocalizeInfo = false; goInfoCon.GetComponent().text = LocalizationText.GetText("gacha_treasuredesc"); Transform trfrate = canvasInfo.transform.Find("groupRate"); TextMeshProUGUI[] txtraritys = trfrate.Find("groupRarity").GetComponentsInChildren(true); txtraritys[0].text = LocalizationText.GetText("gacha_rarityt"); TextMeshProUGUI[] txtgrades = trfrate.Find("groupGrade").GetComponentsInChildren(true); txtgrades[0].text = LocalizationText.GetText("gacha_gradet"); trfrate.Find("groupReward").Find("txtT").GetComponent().text = LocalizationText.GetText("gacha_rewardt"); } SoundMgr.PlaySfx(SoundName.BtnPress); // 무기. if (iSelectedTab == 0) { iSelectedLv = DataHandler.PlayData.gachaWeaponLv; goInfoCon.SetActive(false); groupInfoRate.SetActive(true); } // 방어구. else if (iSelectedTab == 1) { iSelectedLv = DataHandler.PlayData.gachaArmorLv; goInfoCon.SetActive(false); groupInfoRate.SetActive(true); } // 악세. else if (iSelectedTab == 2) { iSelectedLv = DataHandler.PlayData.gachaAccLv; goInfoCon.SetActive(false); groupInfoRate.SetActive(true); } // 보물. else if (iSelectedTab == 3) { txtInfoT.text = LocalizationText.GetText("gacha_treasureinfo"); goInfoCon.SetActive(true); groupInfoRate.SetActive(false); } // 등급별 확률. int[] rategrades = DataHandler.GetGachaGrades(iSelectedTab); for (int i = 0; i < rategrades.Length; ++i) { if(i < txtInfoGrades.Length) txtInfoGrades[i].text = FormatString.StringFormat("({0})", FormatString.TextIntPer(rategrades[i])); } SetInfo(); canvasInfo.enabled = true; iLoading--; } // 정보 닫기. public void CloseInfo() { if (iLoading > 0) return; iLoading++; canvasInfo.enabled = false; SoundMgr.PlaySfx(SoundName.BtnPress); iLoading--; } // 이전 레벨. public void InfoLvPrev() { if (iLoading > 0) return; iLoading++; iSelectedLv--; SetInfo(); SoundMgr.PlaySfx(SoundName.BtnPress); iLoading--; } // 다음 레벨. public void InfoLvNext() { if (iLoading > 0) return; iLoading++; iSelectedLv++; SetInfo(); SoundMgr.PlaySfx(SoundName.BtnPress); iLoading--; } // 정보 세팅. private void SetInfo() { int icurrew; // 무기. if (iSelectedTab == 0) { icurrew = DataHandler.PlayData.gachaWeaponReward; txtInfoT.text = FormatString.StringFormat(LocalizationText.GetText("gacha_weaponinfo"), iSelectedLv.ToString()); } // 방어구. else if (iSelectedTab == 1) { icurrew = DataHandler.PlayData.gachaArmorReward; txtInfoT.text = FormatString.StringFormat(LocalizationText.GetText("gacha_armorinfo"), iSelectedLv.ToString()); } // 악세. else if (iSelectedTab == 2) { icurrew = DataHandler.PlayData.gachaAccReward; txtInfoT.text = FormatString.StringFormat(LocalizationText.GetText("gacha_acceinfo"), iSelectedLv.ToString()); } else { return; } goInfoBtnPrev.SetActive(iSelectedLv > 1); goInfoBtnNext.SetActive(iSelectedLv < DataHandler.GetGachaMaxLv(iSelectedTab)); dGachaLevel gachalv = DataHandler.GetGachaLv(iSelectedTab, iSelectedLv); if (gachalv == null) return; // 레벨-희귀도별 확률. for (int i = 0; i < txtInfoRaritys.Length; i++) { txtInfoRaritys[i].text = FormatString.CombineAllString(Global.STR_Rarity[i + 1], FormatString.S_Blank, FormatString.TextIntPerBracket(gachalv.props[i])); } // 레벨 달성 보상. if (gachalv.rewardType <= cGoods.TNone) { goInfoRewardEmpty.SetActive(true); goodsInfoReward.gameObject.SetActive(false); goInfoRewardLock.SetActive(false); } else { goInfoRewardEmpty.SetActive(false); goodsInfoReward.SetGoods(gachalv.rewardType, gachalv.rewardId, gachalv.rewardCount); goodsInfoReward.gameObject.SetActive(true); goInfoRewardLock.SetActive(icurrew >= iSelectedLv); } } #endregion Info #region Tab // 무기 탭. public void TabWeapon() { if (iSelectedTab == 0) return; if (iSelectedTab >= 0) { btnTabs[iSelectedTab].interactable = true; } SoundMgr.PlaySfx(SoundName.BtnPress); iSelectedTab = 0; btnTabs[iSelectedTab].interactable = false; GameUIMgr.SSetGachaTokenType(cGoods.CGachaTokenWeapon); GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaWeapon); imgChangeGachaTicket.sprite = AddressableMgr.GetGoodsIcon(cGoods.CGachaTokenWeapon); CoverCamera.Hold(); imgGachaBox.color = Global.CLR_Trans; Addressables.LoadAssetAsync(FormatString.CombineAllString("img/gacha", iSelectedTab.ToString())).Completed += ALoadBoxComp; txtGachaCnts[0].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try"), DataHandler.Const.firstButtonEquip.ToString()); txtGachaCnts[1].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try_bonus"), DataHandler.Const.secondButtonEquip.ToString(), (DataHandler.Const.secondButtonEquip / 10).ToString()); txtGachaCnts[2].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try_bonus"), DataHandler.Const.thirdButtonEquip.ToString(), (DataHandler.Const.thirdButtonEquip / 10).ToString()); txtGachaCnts[3].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try_bonus"), DataHandler.Const.fourthButtonEquip.ToString(), (DataHandler.Const.fourthButtonEquip / 10).ToString()); SetMode(); SetGachaBtnAvail(); SetLvExp(); txtGachaExp.gameObject.SetActive(true); sldGachaExp.gameObject.SetActive(true); } // 방어구 탭. public void TabArmor() { if (iSelectedTab == 1) return; if (iSelectedTab >= 0) { btnTabs[iSelectedTab].interactable = true; } SoundMgr.PlaySfx(SoundName.BtnPress); iSelectedTab = 1; btnTabs[iSelectedTab].interactable = false; GameUIMgr.SSetGachaTokenType(cGoods.CGachaTokenArmor); GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaArmor); imgChangeGachaTicket.sprite = AddressableMgr.GetGoodsIcon(cGoods.CGachaTokenArmor); CoverCamera.Hold(); imgGachaBox.color = Global.CLR_Trans; Addressables.LoadAssetAsync(FormatString.CombineAllString("img/gacha", iSelectedTab.ToString())).Completed += ALoadBoxComp; txtGachaCnts[0].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try"), DataHandler.Const.firstButtonEquip.ToString()); txtGachaCnts[1].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try_bonus"), DataHandler.Const.secondButtonEquip.ToString(), (DataHandler.Const.secondButtonEquip / 10).ToString()); txtGachaCnts[2].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try_bonus"), DataHandler.Const.thirdButtonEquip.ToString(), (DataHandler.Const.thirdButtonEquip / 10).ToString()); txtGachaCnts[3].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try_bonus"), DataHandler.Const.fourthButtonEquip.ToString(), (DataHandler.Const.fourthButtonEquip / 10).ToString()); SetMode(); SetGachaBtnAvail(); SetLvExp(); txtGachaExp.gameObject.SetActive(true); sldGachaExp.gameObject.SetActive(true); } // 악세 탭. public void TabAcce() { if (btnTabLocks[2].activeSelf) { GameUIMgr.SOpenToast(FormatString.TextOpenStageClear(DataHandler.Const.gearAccOpenStage)); SoundMgr.PlaySfx(SoundName.BtnPress); return; } if (iSelectedTab >= 0) { btnTabs[iSelectedTab].interactable = true; } SoundMgr.PlaySfx(SoundName.BtnPress); iSelectedTab = 2; btnTabs[iSelectedTab].interactable = false; GameUIMgr.SSetGachaTokenType(cGoods.CGachaTokenAcce); GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaAcc); imgChangeGachaTicket.sprite = AddressableMgr.GetGoodsIcon(cGoods.CGachaTokenAcce); CoverCamera.Hold(); imgGachaBox.color = Global.CLR_Trans; Addressables.LoadAssetAsync(FormatString.CombineAllString("img/gacha", iSelectedTab.ToString())).Completed += ALoadBoxComp; txtGachaCnts[0].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try"), DataHandler.Const.firstButtonEquip.ToString()); txtGachaCnts[1].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try_bonus"), DataHandler.Const.secondButtonEquip.ToString(), (DataHandler.Const.secondButtonEquip / 10).ToString()); txtGachaCnts[2].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try_bonus"), DataHandler.Const.thirdButtonEquip.ToString(), (DataHandler.Const.thirdButtonEquip / 10).ToString()); txtGachaCnts[3].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try_bonus"), DataHandler.Const.fourthButtonEquip.ToString(), (DataHandler.Const.fourthButtonEquip / 10).ToString()); SetMode(); SetGachaBtnAvail(); SetLvExp(); txtGachaExp.gameObject.SetActive(true); sldGachaExp.gameObject.SetActive(true); } // 보물 탭. public void TabTreasure() { if (btnTabLocks[3].activeSelf) { GameUIMgr.SOpenToast(FormatString.TextOpenStageClear(DataHandler.Const.gearTreasureOpenStage)); SoundMgr.PlaySfx(SoundName.BtnPress); return; } if (iSelectedTab == 3) return; if (iSelectedTab >= 0) { btnTabs[iSelectedTab].interactable = true; } SoundMgr.PlaySfx(SoundName.BtnPress); iSelectedTab = 3; btnTabs[iSelectedTab].interactable = false; GameUIMgr.SSetGachaTokenType(cGoods.CGachaTokenTreasure); GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaTreasure); imgChangeGachaTicket.sprite = AddressableMgr.GetGoodsIcon(cGoods.CGachaTokenTreasure); CoverCamera.Hold(); imgGachaBox.color = Global.CLR_Trans; Addressables.LoadAssetAsync(FormatString.CombineAllString("img/gacha", iSelectedTab.ToString())).Completed += ALoadBoxComp; txtGachaCnts[0].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try"), DataHandler.Const.firstButtonTreasure .ToString()); txtGachaCnts[1].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try"), DataHandler.Const.secondButtonTreasure .ToString()); txtGachaCnts[2].text = FormatString.StringFormat(LocalizationText.GetText("gacha_try"), DataHandler.Const.thirdButtonTreasure .ToString()); SetMode(); SetGachaBtnAvail(); txtGachaLv.text = LocalizationText.GetText("gacha_treasurelv"); txtGachaExp.gameObject.SetActive(false); sldGachaExp.gameObject.SetActive(false); goBtnGachaLv.SetActive(false); goBtnGachaLvOff.SetActive(false); } // 보석-티켓 변경. public void ChangeMode() { if (iLoading > 0) return; iLoading++; bModeTicket = !bModeTicket; SoundMgr.PlaySfx(SoundName.BtnPress); SetMode(); SetGachaBtnAvail(); iLoading--; } // 사용 재화 세팅. private void SetMode() { if (bModeTicket) { if (iSelectedTab == 3) { txtGachaPrices[0].text = FormatString.TextInt(DataHandler.Const.firstButtonTreasure); txtGachaPrices[1].text = FormatString.TextInt(DataHandler.Const.secondButtonTreasure); txtGachaPrices[2].text = FormatString.TextInt(DataHandler.Const.thirdButtonTreasure); txtGachaPrices[3].text = FormatString.TextInt(DataHandler.Const.thirdButtonTreasure); } else { txtGachaPrices[0].text = FormatString.TextInt(DataHandler.Const.firstButtonEquip); txtGachaPrices[1].text = FormatString.TextInt(DataHandler.Const.secondButtonEquip); txtGachaPrices[2].text = FormatString.TextInt(DataHandler.Const.thirdButtonEquip); txtGachaPrices[3].text = FormatString.TextInt(DataHandler.Const.fourthButtonEquip); } // 무기. if (iSelectedTab == 0) { imgGachaTypes[0].sprite = AddressableMgr.GetGoodsIcon(cGoods.CGachaTokenWeapon); } // 방어구. else if (iSelectedTab == 1) { imgGachaTypes[0].sprite = AddressableMgr.GetGoodsIcon(cGoods.CGachaTokenArmor); } // 악세. else if (iSelectedTab == 2) { imgGachaTypes[0].sprite = AddressableMgr.GetGoodsIcon(cGoods.CGachaTokenAcce); } // 보물. else if (iSelectedTab == 3) { imgGachaTypes[0].sprite = AddressableMgr.GetGoodsIcon(cGoods.CGachaTokenTreasure); } imgGachaTypes[1].sprite = imgGachaTypes[0].sprite; imgGachaTypes[2].sprite = imgGachaTypes[0].sprite; imgGachaTypes[3].sprite = imgGachaTypes[0].sprite; imgChangeGachaTicket.sprite = AddressableMgr.GetGoodsIcon(cGoods.CDia); imgChangeGachaTicket.rectTransform.sizeDelta = new Vector2(96, 96); } else { // 무기. if (iSelectedTab == 0) { txtGachaPrices[0].text = FormatString.TextInt(DataHandler.Const.gachaWeaponPrice * DataHandler.Const.firstButtonEquip); txtGachaPrices[1].text = FormatString.TextInt(DataHandler.Const.gachaWeaponPrice * DataHandler.Const.secondButtonEquip); txtGachaPrices[2].text = FormatString.TextInt(DataHandler.Const.gachaWeaponPrice * DataHandler.Const.thirdButtonEquip); txtGachaPrices[3].text = FormatString.TextInt(DataHandler.Const.gachaWeaponPrice * DataHandler.Const.fourthButtonEquip); imgChangeGachaTicket.sprite = AddressableMgr.GetGoodsIcon(cGoods.CGachaTokenWeapon); } // 방어구. else if (iSelectedTab == 1) { txtGachaPrices[0].text = FormatString.TextInt(DataHandler.Const.gachaArmorPrice * DataHandler.Const.firstButtonEquip); txtGachaPrices[1].text = FormatString.TextInt(DataHandler.Const.gachaArmorPrice * DataHandler.Const.secondButtonEquip); txtGachaPrices[2].text = FormatString.TextInt(DataHandler.Const.gachaArmorPrice * DataHandler.Const.thirdButtonEquip); txtGachaPrices[3].text = FormatString.TextInt(DataHandler.Const.gachaArmorPrice * DataHandler.Const.fourthButtonEquip); imgChangeGachaTicket.sprite = AddressableMgr.GetGoodsIcon(cGoods.CGachaTokenArmor); } // 악세. else if (iSelectedTab == 2) { txtGachaPrices[0].text = FormatString.TextInt(DataHandler.Const.gachaAccPrice * DataHandler.Const.firstButtonEquip); txtGachaPrices[1].text = FormatString.TextInt(DataHandler.Const.gachaAccPrice * DataHandler.Const.secondButtonEquip); txtGachaPrices[2].text = FormatString.TextInt(DataHandler.Const.gachaAccPrice * DataHandler.Const.thirdButtonEquip); txtGachaPrices[3].text = FormatString.TextInt(DataHandler.Const.gachaAccPrice * DataHandler.Const.fourthButtonEquip); imgChangeGachaTicket.sprite = AddressableMgr.GetGoodsIcon(cGoods.CGachaTokenAcce); } // 보물. else if (iSelectedTab == 3) { txtGachaPrices[0].text = FormatString.TextInt(DataHandler.Const.gachaTreasurePrice * DataHandler.Const.firstButtonTreasure); txtGachaPrices[1].text = FormatString.TextInt(DataHandler.Const.gachaTreasurePrice * DataHandler.Const.secondButtonTreasure); txtGachaPrices[2].text = FormatString.TextInt(DataHandler.Const.gachaTreasurePrice * DataHandler.Const.thirdButtonTreasure); imgChangeGachaTicket.sprite = AddressableMgr.GetGoodsIcon(cGoods.CGachaTokenTreasure); } imgChangeGachaTicket.rectTransform.sizeDelta = new Vector2(108, 108); imgGachaTypes[0].sprite = AddressableMgr.GetGoodsIcon(cGoods.CDia); imgGachaTypes[1].sprite = imgGachaTypes[0].sprite; imgGachaTypes[2].sprite = imgGachaTypes[0].sprite; imgGachaTypes[3].sprite = imgGachaTypes[0].sprite; } } // 결과창 버튼 세팅. private void SetGachaResultUi() { // 결과창. txtResultExp.gameObject.SetActive(txtGachaExp.gameObject.activeSelf); sldResultExp.gameObject.SetActive(sldGachaExp.gameObject.activeSelf); txtResultGachaCnts[0].text = txtGachaCnts[0].text; txtResultGachaCnts[1].text = txtGachaCnts[1].text; txtResultGachaCnts[2].text = txtGachaCnts[2].text; txtResultGachaCnts[3].text = txtGachaCnts[3].text; txtResultGachaPrices[0].text = txtGachaPrices[0].text; txtResultGachaPrices[1].text = txtGachaPrices[1].text; txtResultGachaPrices[2].text = txtGachaPrices[2].text; txtResultGachaPrices[3].text = txtGachaPrices[3].text; imgResultGachaTypes[0].sprite = imgGachaTypes[0].sprite; imgResultGachaTypes[1].sprite = imgGachaTypes[1].sprite; imgResultGachaTypes[2].sprite = imgGachaTypes[2].sprite; imgResultGachaTypes[3].sprite = imgGachaTypes[3].sprite; if (iSelectedTab == 3) { btnResultGachas[3].gameObject.SetActive(false); } else { btnResultGachas[3].gameObject.SetActive(true); } } private void SetCellPadding(int count) { switch (count) { case 11: gachaResult.spacing = new Vector2(16, 16); gachaResult.cellSize = new Vector2(120, 120); break; case 55: gachaResult.spacing = new Vector2(8, 8); gachaResult.cellSize = new Vector2(84, 84); break; default: gachaResult.spacing = new Vector2(12, 12); gachaResult.cellSize = new Vector2(120, 120); break; } } // 가챠 버튼 활성화. private void SetGachaBtnAvail() { if (bModeTicket) { // 무기. if (iSelectedTab == 0) { btnGachas[0].interactable = DataHandler.Goods.gachaWeapon >= DataHandler.Const.firstButtonEquip; btnGachas[1].interactable = DataHandler.Goods.gachaWeapon >= DataHandler.Const.secondButtonEquip; btnGachas[2].interactable = DataHandler.Goods.gachaWeapon >= DataHandler.Const.thirdButtonEquip; btnGachas[3].interactable = DataHandler.Goods.gachaWeapon >= DataHandler.Const.fourthButtonEquip; } // 방어구. else if (iSelectedTab == 1) { btnGachas[0].interactable = DataHandler.Goods.gachaArmor >= DataHandler.Const.firstButtonEquip; btnGachas[1].interactable = DataHandler.Goods.gachaArmor >= DataHandler.Const.secondButtonEquip; btnGachas[2].interactable = DataHandler.Goods.gachaArmor >= DataHandler.Const.thirdButtonEquip; btnGachas[3].interactable = DataHandler.Goods.gachaArmor >= DataHandler.Const.fourthButtonEquip; } // 악세. else if (iSelectedTab == 2) { btnGachas[0].interactable = DataHandler.Goods.gachaAcc >= DataHandler.Const.firstButtonEquip; btnGachas[1].interactable = DataHandler.Goods.gachaAcc >= DataHandler.Const.secondButtonEquip; btnGachas[2].interactable = DataHandler.Goods.gachaAcc >= DataHandler.Const.thirdButtonEquip; btnGachas[3].interactable = DataHandler.Goods.gachaAcc >= DataHandler.Const.fourthButtonEquip; } // 보물. else if (iSelectedTab == 3) { btnGachas[0].interactable = DataHandler.Goods.gachaTreasure >= DataHandler.Const.firstButtonTreasure; btnGachas[1].interactable = DataHandler.Goods.gachaTreasure >= DataHandler.Const.secondButtonTreasure; btnGachas[2].interactable = DataHandler.Goods.gachaTreasure >= DataHandler.Const.thirdButtonTreasure; } } else { // 무기. if (iSelectedTab == 0) { btnGachas[0].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaWeaponPrice * DataHandler.Const.firstButtonEquip; btnGachas[1].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaWeaponPrice * DataHandler.Const.secondButtonEquip; btnGachas[2].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaWeaponPrice * DataHandler.Const.thirdButtonEquip; btnGachas[3].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaWeaponPrice * DataHandler.Const.fourthButtonEquip; } // 방어구. else if (iSelectedTab == 1) { btnGachas[0].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaArmorPrice * DataHandler.Const.firstButtonEquip; btnGachas[1].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaArmorPrice * DataHandler.Const.secondButtonEquip; btnGachas[2].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaArmorPrice * DataHandler.Const.thirdButtonEquip; btnGachas[3].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaArmorPrice * DataHandler.Const.fourthButtonEquip; } // 악세. else if (iSelectedTab == 2) { btnGachas[0].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaAccPrice * DataHandler.Const.firstButtonEquip; btnGachas[1].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaAccPrice * DataHandler.Const.secondButtonEquip; btnGachas[2].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaAccPrice * DataHandler.Const.thirdButtonEquip; btnGachas[3].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaAccPrice * DataHandler.Const.fourthButtonEquip; } // 보물. else if (iSelectedTab == 3) { btnGachas[0].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaTreasurePrice * DataHandler.Const.firstButtonTreasure; btnGachas[1].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaTreasurePrice * DataHandler.Const.secondButtonTreasure; btnGachas[2].interactable = DataHandler.Goods.Dia >= DataHandler.Const.gachaTreasurePrice * DataHandler.Const.thirdButtonTreasure; } } btnResultGachas[0].interactable = btnGachas[0].interactable; btnResultGachas[1].interactable = btnGachas[1].interactable; btnResultGachas[2].interactable = btnGachas[2].interactable; btnResultGachas[3].interactable = btnGachas[3].interactable; } // 레벨/경험치 표시. private void SetLvExp() { // 무기. if (iSelectedTab == 0) { dGachaLevel gachalvnext = DataHandler.GetGachaLv(iSelectedTab, DataHandler.PlayData.gachaWeaponLv + 1); dGachaLevel gachalvcurrent = DataHandler.GetGachaLv(iSelectedTab, DataHandler.PlayData.gachaWeaponLv); float fexpmax = gachalvnext.cnt; float fprevmax = gachalvcurrent.cnt; txtGachaLv.text = FormatString.StringFormat(LocalizationText.GetText("gacha_weaponlv"), DataHandler.PlayData.gachaWeaponLv); txtGachaExp.text = FormatString.TextCntPer((DataHandler.PlayData.gachaWeaponExp - fprevmax).ToString(), (fexpmax - fprevmax).ToString()); if (DataHandler.PlayData.gachaWeaponLv >= DataHandler.GetGachaMaxLv(iSelectedTab)) { txtGachaExp.text = FormatString.TextCntPer((DataHandler.PlayData.gachaWeaponExp - fprevmax).ToString(), "MAX"); sldGachaExp.value = 1; } else { sldGachaExp.value = (DataHandler.PlayData.gachaWeaponExp - fprevmax) / (fexpmax - fprevmax); } goBtnGachaLv.SetActive(DataHandler.PlayData.gachaWeaponReward < DataHandler.PlayData.gachaWeaponLv); goBtnGachaLvOff.SetActive(!goBtnGachaLv.activeSelf); } // 방어구. else if (iSelectedTab == 1) { dGachaLevel gachalvnext = DataHandler.GetGachaLv(iSelectedTab, DataHandler.PlayData.gachaArmorLv + 1); dGachaLevel gachalvcurrent = DataHandler.GetGachaLv(iSelectedTab, DataHandler.PlayData.gachaArmorLv); float fexpmax = gachalvnext.cnt; float fprevmax = gachalvcurrent.cnt; txtGachaLv.text = FormatString.StringFormat(LocalizationText.GetText("gacha_armorlv"), DataHandler.PlayData.gachaArmorLv); txtGachaExp.text = FormatString.TextCntPer((DataHandler.PlayData.gachaArmorExp - fprevmax).ToString(), (fexpmax - fprevmax).ToString()); if (DataHandler.PlayData.gachaArmorLv >= DataHandler.GetGachaMaxLv(iSelectedTab)) { txtGachaExp.text = FormatString.TextCntPer((DataHandler.PlayData.gachaArmorExp - fprevmax).ToString(), "MAX"); sldGachaExp.value = 1; } else { sldGachaExp.value = (DataHandler.PlayData.gachaArmorExp - fprevmax) / (fexpmax - fprevmax); } goBtnGachaLv.SetActive(DataHandler.PlayData.gachaArmorReward < DataHandler.PlayData.gachaArmorLv); goBtnGachaLvOff.SetActive(!goBtnGachaLv.activeSelf); } // 악세. else if (iSelectedTab == 2) { dGachaLevel gachalvnext = DataHandler.GetGachaLv(iSelectedTab, DataHandler.PlayData.gachaAccLv + 1); dGachaLevel gachalvcurrent = DataHandler.GetGachaLv(iSelectedTab, DataHandler.PlayData.gachaAccLv); float fexpmax = gachalvnext.cnt; float fprevmax = gachalvcurrent.cnt; txtGachaLv.text = FormatString.StringFormat(LocalizationText.GetText("gacha_accelv"), DataHandler.PlayData.gachaAccLv); txtGachaExp.text = FormatString.TextCntPer((DataHandler.PlayData.gachaAccExp - fprevmax).ToString(), (fexpmax - fprevmax).ToString()); if (DataHandler.PlayData.gachaAccLv >= DataHandler.GetGachaMaxLv(iSelectedTab)) { txtGachaExp.text = FormatString.TextCntPer((DataHandler.PlayData.gachaAccExp - fprevmax).ToString(), "MAX"); sldGachaExp.value = 1; } else { sldGachaExp.value = (DataHandler.PlayData.gachaAccExp - fprevmax) / (fexpmax - fprevmax); } goBtnGachaLv.SetActive(DataHandler.PlayData.gachaAccReward < DataHandler.PlayData.gachaAccLv); goBtnGachaLvOff.SetActive(!goBtnGachaLv.activeSelf); } txtResultLv.text = txtGachaLv.text; txtResultExp.text = txtGachaExp.text; sldResultExp.value = sldGachaExp.value; } #endregion Tab #region Gacha // 가챠 메인 1회. public void StartGacha1() { if (iLoading > 0) return; iLoading++; CoverCamera.Hold(); SoundMgr.PlaySfx(SoundName.BtnPress); tglResultAuto.SetIsOnWithoutNotify(false); SetGachaResultUi(); SetCellPadding(11); if (iSelectedTab == 3) { if (DataHandler.allTreasureMax()) { GameUIMgr.SOpenToast(LocalizationText.GetText("all_treasure_max")); CoverCamera.Release(); iLoading--; return; } StartGacha(DataHandler.Const.firstButtonTreasure, true); } else { StartGacha(DataHandler.Const.firstButtonEquip, true); } } // 가챠 메인 10회. public void StartGacha10() { if (iLoading > 0) return; iLoading++; CoverCamera.Hold(); SoundMgr.PlaySfx(SoundName.BtnPress); tglResultAuto.SetIsOnWithoutNotify(false); SetGachaResultUi(); SetCellPadding(55); if (iSelectedTab == 3) { if (DataHandler.allTreasureMax()) { GameUIMgr.SOpenToast(LocalizationText.GetText("all_treasure_max")); CoverCamera.Release(); iLoading--; return; } StartGacha(DataHandler.Const.secondButtonTreasure, true); } else { StartGacha(DataHandler.Const.secondButtonEquip + (DataHandler.Const.secondButtonEquip / 10), true); } } // 가챠 메인 50회. public void StartGacha50() { if (iLoading > 0) return; iLoading++; CoverCamera.Hold(); SoundMgr.PlaySfx(SoundName.BtnPress); tglResultAuto.SetIsOnWithoutNotify(false); SetGachaResultUi(); SetCellPadding(55); if (iSelectedTab == 3) { if (DataHandler.allTreasureMax()) { GameUIMgr.SOpenToast(LocalizationText.GetText("all_treasure_max")); CoverCamera.Release(); iLoading--; return; } StartGacha(DataHandler.Const.thirdButtonTreasure, true); } else { StartGacha(DataHandler.Const.thirdButtonEquip + (DataHandler.Const.thirdButtonEquip / 10), true); } } // 가챠 시작. private void StartGacha(int icount, bool bmain) { string strurl = null; nGachaType data = bModeTicket ? new nGachaType(1) : new nGachaType(0); SingleMgr.ResetCount(); // 무기. if (iSelectedTab == 0) { if (bmain) iGachaLvBef = DataHandler.PlayData.gachaWeaponLv; #region Check Goods // 티켓 부족한지 체크. if (bModeTicket) { int iprice = icount; if (icount == DataHandler.Const.fourthButtonEquip + (DataHandler.Const.fourthButtonEquip / 10)) iprice = DataHandler.Const.fourthButtonEquip; else if (icount == DataHandler.Const.thirdButtonEquip + (DataHandler.Const.thirdButtonEquip / 10)) iprice = DataHandler.Const.thirdButtonEquip; else if (icount == DataHandler.Const.secondButtonEquip + (DataHandler.Const.secondButtonEquip / 10)) iprice = DataHandler.Const.secondButtonEquip; if (iprice > DataHandler.Goods.gachaWeapon) { CoverCamera.Release(); iLoading--; return; } } // 보석 부족한지 체크. else { int iprice; if (icount == DataHandler.Const.fourthButtonEquip + (DataHandler.Const.fourthButtonEquip / 10)) iprice = DataHandler.Const.gachaWeaponPrice * DataHandler.Const.fourthButtonEquip; else if (icount == DataHandler.Const.thirdButtonEquip + (DataHandler.Const.thirdButtonEquip / 10)) iprice = DataHandler.Const.gachaWeaponPrice * DataHandler.Const.thirdButtonEquip; else if (icount == DataHandler.Const.secondButtonEquip + (DataHandler.Const.secondButtonEquip / 10)) iprice = DataHandler.Const.gachaWeaponPrice * DataHandler.Const.secondButtonEquip; else iprice = DataHandler.Const.gachaWeaponPrice * DataHandler.Const.firstButtonEquip; if (iprice > DataHandler.Goods.Dia) { CoverCamera.Release(); iLoading--; return; } } #endregion Check Goods strurl = FormatString.CombineAllString(UrlApi.GachaWeapon, icount.ToString()); DataHandler.AddRecord(eCondition.GachaWeapon, icount); } // 방어구. else if (iSelectedTab == 1) { if (bmain) iGachaLvBef = DataHandler.PlayData.gachaArmorLv; #region Check Goods // 티켓 부족한지 체크. if (bModeTicket) { int iprice = icount; if (icount == DataHandler.Const.fourthButtonEquip + (DataHandler.Const.fourthButtonEquip / 10)) iprice = DataHandler.Const.fourthButtonEquip; else if (icount == DataHandler.Const.thirdButtonEquip + (DataHandler.Const.thirdButtonEquip / 10)) iprice = DataHandler.Const.thirdButtonEquip; else if (icount == DataHandler.Const.secondButtonEquip + (DataHandler.Const.secondButtonEquip / 10)) iprice = DataHandler.Const.secondButtonEquip; if (iprice > DataHandler.Goods.gachaArmor) { CoverCamera.Release(); iLoading--; return; } } // 보석 부족한지 체크. else { int iprice; if (icount == DataHandler.Const.fourthButtonEquip + (DataHandler.Const.fourthButtonEquip / 10)) iprice = DataHandler.Const.gachaArmorPrice * DataHandler.Const.fourthButtonEquip; else if (icount == DataHandler.Const.thirdButtonEquip + (DataHandler.Const.thirdButtonEquip / 10)) iprice = DataHandler.Const.gachaArmorPrice * DataHandler.Const.thirdButtonEquip; else if (icount == DataHandler.Const.secondButtonEquip + (DataHandler.Const.secondButtonEquip / 10)) iprice = DataHandler.Const.gachaArmorPrice * DataHandler.Const.secondButtonEquip; else iprice = DataHandler.Const.gachaArmorPrice * DataHandler.Const.firstButtonEquip; if (iprice > DataHandler.Goods.Dia) { CoverCamera.Release(); iLoading--; return; } } #endregion Check Goods strurl = FormatString.CombineAllString(UrlApi.GachaArmor, icount.ToString()); DataHandler.AddRecord(eCondition.GachaArmor, icount); } // 악세. else if (iSelectedTab == 2) { if (bmain) iGachaLvBef = DataHandler.PlayData.gachaAccLv; #region Check Goods // 티켓 부족한지 체크. if (bModeTicket) { int iprice = icount; if (icount == DataHandler.Const.fourthButtonEquip + (DataHandler.Const.fourthButtonEquip / 10)) iprice = DataHandler.Const.fourthButtonEquip; else if (icount == DataHandler.Const.thirdButtonEquip + (DataHandler.Const.thirdButtonEquip / 10)) iprice = DataHandler.Const.thirdButtonEquip; else if (icount == DataHandler.Const.secondButtonEquip + (DataHandler.Const.secondButtonEquip / 10)) iprice = DataHandler.Const.secondButtonEquip; if (iprice > DataHandler.Goods.gachaAcc) { CoverCamera.Release(); iLoading--; return; } } // 보석 부족한지 체크. else { int iprice; if (icount == DataHandler.Const.fourthButtonEquip + (DataHandler.Const.fourthButtonEquip / 10)) iprice = DataHandler.Const.gachaAccPrice * DataHandler.Const.fourthButtonEquip; else if (icount == DataHandler.Const.thirdButtonEquip + (DataHandler.Const.thirdButtonEquip / 10)) iprice = DataHandler.Const.gachaAccPrice * DataHandler.Const.thirdButtonEquip; else if (icount == DataHandler.Const.secondButtonEquip + (DataHandler.Const.secondButtonEquip / 10)) iprice = DataHandler.Const.gachaAccPrice * DataHandler.Const.secondButtonEquip; else iprice = DataHandler.Const.gachaAccPrice * DataHandler.Const.firstButtonEquip; if (iprice > DataHandler.Goods.Dia) { CoverCamera.Release(); iLoading--; return; } } #endregion Check Goods strurl = FormatString.CombineAllString(UrlApi.GachaAcce, icount.ToString()); DataHandler.AddRecord(eCondition.GachaAcc, icount); } // 보물. 보너스 횟수가 없음. else if (iSelectedTab == 3) { if (icount == 55) icount = 50; else if (icount == 11) icount = 10; #region Check Goods // 티켓 부족한지 체크. if (bModeTicket) { int iprice = icount; if (iprice > DataHandler.Goods.gachaTreasure) { CoverCamera.Release(); iLoading--; return; } } // 보석 부족한지 체크. else { int iprice; if (icount == DataHandler.Const.thirdButtonTreasure) iprice = DataHandler.Const.gachaTreasurePrice * DataHandler.Const.thirdButtonTreasure; else if (icount == DataHandler.Const.secondButtonEquip) iprice = DataHandler.Const.gachaTreasurePrice * DataHandler.Const.secondButtonTreasure; else iprice = DataHandler.Const.gachaTreasurePrice * DataHandler.Const.firstButtonTreasure; if (iprice > DataHandler.Goods.Dia) { CoverCamera.Release(); iLoading--; return; } } #endregion Check Goods strurl = FormatString.CombineAllString(UrlApi.GachaTreasure, icount.ToString()); DataHandler.AddRecord(eCondition.GachaTreasure, icount); } else { CoverCamera.Release(); iLoading--; return; } iGachaCount = icount; SvConnectManager.Instance.RequestSvPost(true, 0, UrlApi.GetUrl(strurl), typeof(nGoodsGet), AGachaSucc, AGachaFail, data, true); } // 가챠 통신 실패. private void AGachaFail(SvError error, object request) { CoverCamera.Release(); iLoading--; } // 가챠 통신 성공. private void AGachaSucc(object result, object request) { nGoodsGet data = result as nGoodsGet; if (data == null) { AGachaFail(new SvError(eErrorCode.NULL_OR_EMPTY), request); return; } DataHandler.AddGoods(data.result, data.playCurrency, true); // 무기. if (iSelectedTab == 0) { DataHandler.SetGachaLvExp(iSelectedTab, data.playUser.gachaWeaponLv, data.playUser.gachaWeaponExp); GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaWeapon); } // 방어구. else if (iSelectedTab == 1) { DataHandler.SetGachaLvExp(iSelectedTab, data.playUser.gachaArmorLv, data.playUser.gachaArmorExp); GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaArmor); } // 악세. else if (iSelectedTab == 2) { DataHandler.SetGachaLvExp(iSelectedTab, data.playUser.gachaAccLv, data.playUser.gachaAccExp); GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaAcc); } // 보물. else if (iSelectedTab == 3) { GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaTreasure); } SetLvExp(); // 남은 재화 판단해서 자동 토글 끄기 SetGachaBtnAvail(); if (tglResultAuto.isOn) { if (iSelectedTab == 3)//보물 { // 30회. if (iGachaCount > 29) { if (!btnResultGachas[2].interactable) { tglResultAuto.isOn = false; GameUIMgr.SOpenToast(LocalizationText.GetText(Global.STR_NoGoods)); } } // 10회. else if (iGachaCount > 9) { if (!btnResultGachas[1].interactable) { tglResultAuto.isOn = false; GameUIMgr.SOpenToast(LocalizationText.GetText(Global.STR_NoGoods)); } } // 1회. else { if (!btnResultGachas[0].interactable) { tglResultAuto.isOn = false; GameUIMgr.SOpenToast(LocalizationText.GetText(Global.STR_NoGoods)); } } } else//보물 외 { //300 회 if (iGachaCount > 299) { if (!btnResultGachas[3].interactable) { tglResultAuto.isOn = false; GameUIMgr.SOpenToast(LocalizationText.GetText(Global.STR_NoGoods)); } } // 100/110회. else if (iGachaCount > 99) { if (!btnResultGachas[2].interactable) { tglResultAuto.isOn = false; GameUIMgr.SOpenToast(LocalizationText.GetText(Global.STR_NoGoods)); } } // 30/33회. else if (iGachaCount > 29) { if (!btnResultGachas[1].interactable) { tglResultAuto.isOn = false; GameUIMgr.SOpenToast(LocalizationText.GetText(Global.STR_NoGoods)); } } // 10회. else { if (!btnResultGachas[0].interactable) { tglResultAuto.isOn = false; GameUIMgr.SOpenToast(LocalizationText.GetText(Global.STR_NoGoods)); } } } } StartCoroutine(OpenGachaResult(iGachaCount, data.result)); } #endregion Gacha #region Gacha Result // 가챠 결과 표시. private IEnumerator OpenGachaResult(int icount, nGoods[] results) { // 초기화. if (bInitNeedResult) { bInitNeedResult = false; goodsItems = new GoodsEfcItem[72]; RectTransform rtrfgrid = glgResult.GetComponent(); for (int i = 0; i < goodsItems.Length; i++) { GameObject go = Instantiate(prfGoodsItem, rtrfgrid); goodsItems[i] = go.GetComponent(); go.SetActive(false); } } if (icount == 1) { SoundMgr.PlaySfx(SoundName.OneSummon); } else { SoundMgr.PlaySfx(SoundName.MultiSummon); } // 자동 상태. bool bauto = tglResultAuto.isOn; // 1줄에 표시할 항목 수. if (icount > 11) { glgResult.constraintCount = 14; } else if (icount > 56) { glgResult.constraintCount = 16; } else { glgResult.constraintCount = 6; } canvasResult.enabled = true; setActiveSortingCanvas(); yield return null; bool blarge = icount <= 11; int irow = 0; int indexres = 0; int itemcnt = 0; for (int i = 0; i < icount; i++) { if (indexres >= results.Length) break; goodsItems[i].gameObject.SetActive(true); if (icount <= 56) { goodsItems[i].SetGoods(results[indexres].propertyType, results[indexres].propertyId, 1); } else { goodsItems[i].SetGoods(results[indexres].propertyType, results[indexres].propertyId, results[indexres].propertyCount); if (results[indexres].propertyId > 1000) { goodsItems[i].gameObject.SetActive(false); } } if (icount <= 56) { itemcnt++; if (itemcnt >= results[indexres].propertyCount) { itemcnt = 0; indexres++; } } else { indexres++; } if (bauto && icount > 11) { irow++; if (irow >= glgResult.constraintCount) { irow = 0; yield return null; } } else { yield return null; } } yield return null; //if (results.Length > indexres) //{ // nGoods[] cosresults = new nGoods[results.Length - indexres]; // for (int i = 0; i < cosresults.Length; i++) // cosresults[i] = results[i + indexres]; // GameUIMgr.SOpenPopupGoods(cosresults, ftime: (bauto ? 2f : 0f)); //} if (bauto) Invoke("AutoGachaResult", 0.5f); CoverCamera.Release(); iLoading--; } // 가챠 결과 닫기. public void CloseGachaResult() { CancelInvoke("AutoGachaResult"); canvasResult.enabled = false; for (int i = 0; i < goodsItems.Length; i++) goodsItems[i].gameObject.SetActive(false); setActiveSortingCanvas(); SoundMgr.PlaySfx(SoundName.BtnPress); } // 자동 가챠 토글. public void ToggleAuto(bool bvalue) { SoundMgr.PlaySfx(SoundName.BtnPress); if (!bvalue) { CancelInvoke("AutoGachaResult"); goResultBtnClose.SetActive(true); groupResultBtn.SetActive(true); } } // 자동 가챠 실행. private void AutoGachaResult() { if (tglResultAuto.isOn) { iLoading++; CoverCamera.Hold(); //CancelInvoke("AutoGachaResult"); for (int i = 0; i < goodsItems.Length; i++) goodsItems[i].gameObject.SetActive(false); StartGacha(iGachaCount, false); } } // 가챠 뽑기 1회. public void StartGachaResult1() { if (iLoading > 0) return; iLoading++; CoverCamera.Hold(); CancelInvoke("AutoGachaResult"); SoundMgr.PlaySfx(SoundName.BtnPress); for (int i = 0; i < goodsItems.Length; i++) goodsItems[i].gameObject.SetActive(false); if (tglResultAuto.isOn) { goResultBtnClose.SetActive(false); groupResultBtn.SetActive(false); } SetCellPadding(11); if (iSelectedTab == 3) { StartGacha(DataHandler.Const.firstButtonTreasure, true); } else { StartGacha(DataHandler.Const.firstButtonEquip, true); } } // 가챠 뽑기 10회. public void StartGachaResult10() { if (iLoading > 0) return; iLoading++; CoverCamera.Hold(); CancelInvoke("AutoGachaResult"); SoundMgr.PlaySfx(SoundName.BtnPress); for (int i = 0; i < goodsItems.Length; i++) goodsItems[i].gameObject.SetActive(false); if (tglResultAuto.isOn) { goResultBtnClose.SetActive(false); groupResultBtn.SetActive(false); } SetCellPadding(55); if (iSelectedTab == 3) { StartGacha(DataHandler.Const.secondButtonTreasure, true); } else { StartGacha(DataHandler.Const.secondButtonEquip + (DataHandler.Const.secondButtonEquip / 10), false); } } // 가챠 뽑기 50회. public void StartGachaResult50() { if (iLoading > 0) return; iLoading++; CoverCamera.Hold(); CancelInvoke("AutoGachaResult"); SoundMgr.PlaySfx(SoundName.BtnPress); for (int i = 0; i < goodsItems.Length; i++) goodsItems[i].gameObject.SetActive(false); if (tglResultAuto.isOn) { goResultBtnClose.SetActive(false); groupResultBtn.SetActive(false); } SetCellPadding(55); if (iSelectedTab == 3) { StartGacha(DataHandler.Const.thirdButtonTreasure, true); } else { StartGacha(DataHandler.Const.thirdButtonEquip + (DataHandler.Const.thirdButtonEquip / 10), false); } } public void StartGachaResult300() { if (iLoading > 0) return; iLoading++; CoverCamera.Hold(); CancelInvoke("AutoGachaResult"); SoundMgr.PlaySfx(SoundName.BtnPress); for (int i = 0; i < goodsItems.Length; i++) goodsItems[i].gameObject.SetActive(false); if (tglResultAuto.isOn) { goResultBtnClose.SetActive(false); groupResultBtn.SetActive(false); } SetCellPadding(55); StartGacha(DataHandler.Const.fourthButtonEquip + (DataHandler.Const.fourthButtonEquip / 10), false); } #endregion Gacha Result #region Reward // 가챠 레벨 보상 받기. public void BtnGetLvReward() { if (iLoading > 0) return; ++iLoading; CoverCamera.Hold(); string strurl = null; // 0: 무기. 1: 방어구. 2: 악세. if (iSelectedTab == 0) strurl = UrlApi.GachaRewardWeapon; else if (iSelectedTab == 1) strurl = UrlApi.GachaRewardArmor; else if (iSelectedTab == 2) strurl = UrlApi.GachaRewardAcce; else { CoverCamera.Release(); --iLoading; return; } SvConnectManager.Instance.RequestSvPost(true, 0, UrlApi.GetUrl(strurl), typeof(nGoodsGet), AGachaRewardSucc, AGachaRewardFail, new nIdCnt(), true); } // 가챠 레벨 보상 통신 성공. private void AGachaRewardSucc(object result, object request) { nGoodsGet data = result as nGoodsGet; if (data == null) { AGachaRewardFail(new SvError(eErrorCode.NULL_OR_EMPTY), request); return; } DataHandler.AddGoods(data.result, null, true); goBtnGachaLv.SetActive(DataHandler.GachaRewardLvUp(iSelectedTab)); goBtnGachaLvOff.SetActive(!goBtnGachaLv.activeSelf); // 0: 무기. 1: 방어구. 2: 악세. if (iSelectedTab == 0) GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaWeapon); else if (iSelectedTab == 1) GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaArmor); else if (iSelectedTab == 2) GameUIMgr.SSetGachaToken(DataHandler.Goods.gachaAcc); GameUIMgr.SOpenPopupGoods(data.result); CoverCamera.Release(); iLoading--; } // 가챠 레벨 보상 통신 실패. private void AGachaRewardFail(SvError error, object request) { CoverCamera.Release(); --iLoading; } #endregion Reward #region Addressable // 어드레서블 상자 이미지 불러왔을때 처리. private void ALoadBoxComp(AsyncOperationHandle obj) { imgGachaBox.sprite = obj.Result; imgGachaBox.color = Global.CLR_White; // 이전 리소스 해제. if (handleBox.IsValid()) { Addressables.Release(handleBox); AddressableMgr.SAddUnload(); } handleBox = obj; CoverCamera.Release(); } // 어드레서블 아래 이펙트 불러왔을때 처리. private void ALoadBottomComp(AsyncOperationHandle obj) { MeshRenderer renderer = skAnimBottom.GetComponent(); renderer.sortingLayerID = canvasUI.sortingLayerID; renderer.sortingOrder = 51; skAnimBottom.skeletonDataAsset = obj.Result; skAnimBottom.Initialize(true); skAnimBottom.AnimationState.SetAnimation(0, "idle", true); handleBottom = obj; CoverCamera.Release(); } // 어드레서블 소환 레벨 보상 연출 불러왔을때 처리. private void ALoadRewComp(AsyncOperationHandle obj) { handleBottom = obj; CoverCamera.Release(); } #endregion Addressable }