370 lines
11 KiB
C#
370 lines
11 KiB
C#
using BX;
|
|
using Config.config;
|
|
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// 商店UI
|
|
/// </summary>
|
|
public partial class ShopUI : UIBaseClass
|
|
{
|
|
/// <summary>
|
|
/// 条件图片
|
|
/// </summary>
|
|
public Image condition;
|
|
|
|
/// <summary>
|
|
/// 使用图片
|
|
/// </summary>
|
|
public Image use;
|
|
|
|
/// <summary>
|
|
/// 数量
|
|
/// </summary>
|
|
public TextMeshProUGUI number;
|
|
|
|
/// <summary>
|
|
/// 返回按钮
|
|
/// </summary>
|
|
public Button backBtn;
|
|
|
|
/// <summary>
|
|
/// 左按钮
|
|
/// </summary>
|
|
public Button leftBtn;
|
|
|
|
/// <summary>
|
|
/// 右按钮
|
|
/// </summary>
|
|
public Button rightBtn;
|
|
|
|
/// <summary>
|
|
/// 获得
|
|
/// </summary>
|
|
public Button acquisitionBtn;
|
|
|
|
/// <summary>
|
|
/// 使用
|
|
/// </summary>
|
|
public Button useBtn;
|
|
|
|
/// <summary>
|
|
/// 索引
|
|
/// </summary>
|
|
private int index;
|
|
|
|
/// <summary>
|
|
/// 生成血量节点
|
|
/// </summary>
|
|
public Transform bloodVolumeNode;
|
|
|
|
/// <summary>
|
|
/// 技能UI对象
|
|
/// </summary>
|
|
public List<SkillUIObj> skillUIObjs = new List<SkillUIObj>();
|
|
|
|
/// <summary>
|
|
/// 血量图标列表
|
|
/// </summary>
|
|
public List<GameObject> bloodVolume = new List<GameObject>();
|
|
|
|
/// <summary>
|
|
/// 皮肤车数据
|
|
/// </summary>
|
|
private SkinCarConfig skinCarConfig;
|
|
|
|
/// <summary>
|
|
/// 血量图片协程
|
|
/// </summary>
|
|
private Coroutine bloodVolumeCoroutine;
|
|
|
|
private void Start()
|
|
{
|
|
BackListener();
|
|
LeftBtnListener();
|
|
RigheListener();
|
|
AcquisitionBtnListener();
|
|
UseBtnListener();
|
|
AddSweepAway();
|
|
RedDot();
|
|
}
|
|
|
|
public override void OnShow()
|
|
{
|
|
base.OnShow();
|
|
BXSdk.Instance.LogEvent("ModShop_Show");
|
|
StartCoroutine(IE_SkillUIAnim());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置索引
|
|
/// </summary>
|
|
public void SetIndex(int index)
|
|
{
|
|
this.index = index;
|
|
SetCarValue(index);
|
|
SetBloodVolume(index);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置技能UI对象
|
|
/// </summary>
|
|
public void SetSkillUIObjs()
|
|
{
|
|
for (int i = 0; i < skillUIObjs.Count; i++)
|
|
{
|
|
skillUIObjs[i].Init();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 动效
|
|
/// </summary>
|
|
private IEnumerator IE_SkillUIAnim()
|
|
{
|
|
for (int i = 0; i < skillUIObjs.Count; i++)
|
|
{
|
|
skillUIObjs[i].Zoom();
|
|
yield return new WaitForSeconds(0.1f);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置血量显示
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
public void SetBloodVolume(int index)
|
|
{
|
|
if (bloodVolumeCoroutine != null)
|
|
{
|
|
StopCoroutine(bloodVolumeCoroutine);
|
|
}
|
|
int number = ConfigManager.Instance.Tables.TbSkinCarConfig.Get("Car_" + index).Hp/25;
|
|
int wide = 0;
|
|
for (int i = bloodVolumeNode.childCount-1; i >=0; i--)
|
|
{
|
|
CachePoolManager.Instance.Put(bloodVolumeNode.GetChild(i).gameObject);
|
|
}
|
|
bloodVolume.Clear();
|
|
for (int i = 0; i < number; i++)
|
|
{
|
|
GameObject bloodVolumeObj=CachePoolManager.Instance.Take(YooAssetManager.Instance.LoadAssetSync<GameObject>(PackagesName.GameData, "BloodVolumeObj"));
|
|
bloodVolumeObj.transform.SetParent(bloodVolumeNode);
|
|
bloodVolumeObj.transform.localPosition = Vector3.zero;
|
|
bloodVolumeObj.transform.localScale = Vector3.zero;
|
|
bloodVolume.Add(bloodVolumeObj);
|
|
}
|
|
for (int i = 0; i < bloodVolumeNode.childCount; i++)
|
|
{
|
|
switch (number)
|
|
{
|
|
case 4:
|
|
wide = 130;
|
|
break;
|
|
case 5:
|
|
wide = 100;
|
|
break;
|
|
case 6:
|
|
wide = 80;
|
|
break;
|
|
case 8:
|
|
wide = 55;
|
|
break;
|
|
}
|
|
(bloodVolumeNode.GetChild(i).transform as RectTransform).sizeDelta = new Vector2(wide, (bloodVolumeNode.GetChild(i).transform as RectTransform).rect.height);
|
|
}
|
|
bloodVolumeCoroutine= StartCoroutine(IE_BloodVolume());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 血量图片协程
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private IEnumerator IE_BloodVolume()
|
|
{
|
|
for (int i = 0; i < bloodVolume.Count; i++)
|
|
{
|
|
bloodVolume[i].transform.DOScale(Vector3.one * 1.2f, 0.05f).OnComplete(() =>
|
|
{
|
|
bloodVolume[i].transform.DOScale(Vector3.one, 0.05f);
|
|
});
|
|
yield return new WaitForSeconds(0.05f);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置卡车参数
|
|
/// </summary>
|
|
private void SetCarValue(int value)
|
|
{
|
|
useBtn.gameObject.SetActive(false);
|
|
acquisitionBtn.gameObject.SetActive(false);
|
|
skinCarConfig= ConfigManager.Instance.Tables.TbSkinCarConfig.Get("Car_" + value);
|
|
if (UserDataManager.Instance.userData.cars.Contains(skinCarConfig.Id))//拥有
|
|
{
|
|
useBtn.transform.DOKill();
|
|
useBtn.gameObject.SetActive(true);
|
|
useBtn.transform.localScale = Vector3.zero;
|
|
useBtn.transform.DOScale(Vector3.one * 1.1f, 0.2f).OnComplete(() =>
|
|
{
|
|
useBtn.transform.DOScale(Vector3.one,0.1f);
|
|
});
|
|
if(UserDataManager.Instance.userData.useCar==skinCarConfig.Id)
|
|
{
|
|
use.sprite= YooAssetManager.Instance.LoadAssetSync<Sprite>(PackagesName.GameData, "INUSEIcon");
|
|
}
|
|
else
|
|
{
|
|
use.sprite = YooAssetManager.Instance.LoadAssetSync<Sprite>(PackagesName.GameData, "USEIcon");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
acquisitionBtn.transform.DOKill();
|
|
acquisitionBtn.gameObject.SetActive(true);
|
|
acquisitionBtn.transform.localScale = Vector3.zero;
|
|
acquisitionBtn.transform.DOScale(Vector3.one * 1.1f, 0.2f).OnComplete(() =>
|
|
{
|
|
acquisitionBtn.transform.DOScale(Vector3.one, 0.1f);
|
|
});
|
|
if (skinCarConfig.IsAD)
|
|
{
|
|
BXSdk.Instance.LogEvent("RV_Button_Show", new System.Collections.Generic.Dictionary<string, object>()
|
|
{
|
|
{"Position","RV_GetCar"}
|
|
});
|
|
condition.sprite = YooAssetManager.Instance.LoadAssetSync<Sprite>(PackagesName.GameData, "ADIcon");
|
|
if (UserDataManager.Instance.userData.carAD.ContainsKey(skinCarConfig.Id))
|
|
{
|
|
number.text = UserDataManager.Instance.userData.carAD[skinCarConfig.Id]+"/"+skinCarConfig.ADNumber.ToString();
|
|
}
|
|
else
|
|
{
|
|
number.text =0 + "/" + skinCarConfig.ADNumber.ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
condition.sprite = YooAssetManager.Instance.LoadAssetSync<Sprite>(PackagesName.GameData, "BigMoneyIcon");
|
|
number.text = skinCarConfig.Pric.ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回按钮监听
|
|
/// </summary>
|
|
private void BackListener()
|
|
{
|
|
backBtn.onClick.AddListener(() =>
|
|
{
|
|
HideMe();
|
|
UIManager.Instance.AsynShowUI<MainUI>();
|
|
Scenes.Instance.player.TurnToHallCamear();
|
|
Scenes.Instance.player.CarInit();
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 左按钮监听
|
|
/// </summary>
|
|
private void LeftBtnListener()
|
|
{
|
|
leftBtn.onClick.AddListener(() =>
|
|
{
|
|
index--;
|
|
if(index<=0)
|
|
{
|
|
index = ConfigManager.Instance.Tables.TbSkinCarConfig.DataList.Count;
|
|
}
|
|
Scenes.Instance.player.CutCar(index);
|
|
SetBloodVolume(index);
|
|
SetCarValue(index);
|
|
DesLeftTips();
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 右按钮监听
|
|
/// </summary>
|
|
private void RigheListener()
|
|
{
|
|
rightBtn.onClick.AddListener(() =>
|
|
{
|
|
index++;
|
|
if (index > ConfigManager.Instance.Tables.TbSkinCarConfig.DataList.Count)
|
|
{
|
|
index = 1;
|
|
}
|
|
Scenes.Instance.player.CutCar(index);
|
|
SetCarValue(index);
|
|
SetBloodVolume(index);
|
|
DesRightTips();
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得按钮监听
|
|
/// </summary>
|
|
private void AcquisitionBtnListener()
|
|
{
|
|
acquisitionBtn.onClick.AddListener(() =>
|
|
{
|
|
if (skinCarConfig.IsAD)
|
|
{
|
|
SDKManager.Instance.ShowReward("RV_GetCar", () =>
|
|
{
|
|
UserDataManager.Instance.AddCarAD(skinCarConfig.Id);
|
|
if (UserDataManager.Instance.userData.carAD[skinCarConfig.Id] >= skinCarConfig.ADNumber)
|
|
{
|
|
BXSdk.Instance.LogEvent("Car_Unlock", new Dictionary<string, object>()
|
|
{
|
|
{"Car_Name",skinCarConfig.Name}
|
|
});
|
|
AudioManager.Instance.PlaySound(YooAssetManager.Instance.LoadAssetSync<AudioClip>(PackagesName.GameData, "Purchase"));
|
|
UserDataManager.Instance.AddCar(skinCarConfig.Id);
|
|
}
|
|
SetCarValue(index);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
if(UserDataManager.Instance.RemoveMoney(skinCarConfig.Pric))
|
|
{
|
|
BXSdk.Instance.LogEvent("Car_Unlock", new Dictionary<string, object>()
|
|
{
|
|
{"Car_Name",skinCarConfig.Name}
|
|
});
|
|
AudioManager.Instance.PlaySound(YooAssetManager.Instance.LoadAssetSync<AudioClip>(PackagesName.GameData, "Purchase"));
|
|
UserDataManager.Instance.AddCar(skinCarConfig.Id);
|
|
SetCarValue(index);
|
|
}
|
|
else
|
|
{
|
|
UIManager.Instance.GetUI<TopmostLayerUI>().SetTips(MyConstant.BeShortOfGoldCoins);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用按钮监听
|
|
/// </summary>
|
|
private void UseBtnListener()
|
|
{
|
|
useBtn.onClick.AddListener(() =>
|
|
{
|
|
if (UserDataManager.Instance.userData.useCar == skinCarConfig.Id) return;
|
|
AudioManager.Instance.PlaySound(YooAssetManager.Instance.LoadAssetSync<AudioClip>(PackagesName.GameData, "USECar"));
|
|
UserDataManager.Instance.SetUseCar(skinCarConfig.Id);
|
|
SetCarValue(index);
|
|
Scenes.Instance.player.skinCar.USE();
|
|
});
|
|
}
|
|
}
|