765 lines
25 KiB
C#
765 lines
25 KiB
C#
using asap.core;
|
||
using cfg;
|
||
using Coffee.UIExtensions;
|
||
using GameCore;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UIExtend.Component;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class ResAddEvent
|
||
{
|
||
public ResAddEvent(int id)
|
||
{
|
||
this.id = id;
|
||
}
|
||
public ResAddEvent(int id, int type, int subTyep)
|
||
{
|
||
this.id = id;
|
||
this.Type = type;
|
||
this.SubType = subTyep;
|
||
}
|
||
public int id;
|
||
public int Type;
|
||
public int SubType;
|
||
/// <summary>
|
||
/// 钞票 > 0 才使用
|
||
/// </summary>
|
||
public int addCount;
|
||
}
|
||
public class RewardItemNew : MonoBehaviour
|
||
{
|
||
private Tables _tables => GContext.container.Resolve<Tables>();
|
||
public Button btn_click;
|
||
public Animation ani;
|
||
//public Image bgLight;
|
||
public Image icon;
|
||
public Image icon_card;
|
||
public Image icon_card_logo;
|
||
public Image icon_card_num;
|
||
public Image icon_rod;
|
||
public TMP_Text text_num;
|
||
public TMP_Text text_title;
|
||
public GameObject received;
|
||
public CanvasGroup canvasGroup;
|
||
public Transform reward_show;
|
||
public Button btn_questionmark;
|
||
//活动奖励中的礼盒,手提袋等传入dropID的展示需要提前设好InflationRate
|
||
[NonSerialized]
|
||
public float InflationRate;
|
||
Transform RewardShow
|
||
{
|
||
get
|
||
{
|
||
if (reward_show == null)
|
||
{
|
||
reward_show = transform.Find("reward_show");
|
||
}
|
||
return reward_show;
|
||
}
|
||
}
|
||
public RewardItemTransfer transfer;
|
||
[NonSerialized]
|
||
public int id = 0;
|
||
private int showDropID = -1;
|
||
[NonSerialized]
|
||
public float count = 0;
|
||
cfg.Item item;
|
||
bool isEnable = true;
|
||
Coffee.UIExtensions.UIParticleAttractor uIParticleAttractor;
|
||
#if UNITY_EDITOR
|
||
private void Reset()
|
||
{
|
||
InitPanel();
|
||
}
|
||
#endif
|
||
private void Awake()
|
||
{
|
||
Transform icon_review = transform.Find("icon_review");
|
||
if (icon_review != null)
|
||
{
|
||
icon_review.gameObject.SetActive(false);
|
||
}
|
||
btn_questionmark = transform.Find("btn_questionmark")?.GetComponent<Button>();
|
||
if (btn_questionmark)
|
||
{
|
||
btn_questionmark.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
private void InitPanel()
|
||
{
|
||
canvasGroup = GetComponent<CanvasGroup>();
|
||
btn_click = GetComponent<Button>();
|
||
ani = GetComponent<Animation>();
|
||
//bgLight = transform.Find("light").GetComponent<Image>();
|
||
reward_show = transform.Find("reward_show");
|
||
icon = transform.Find("icon").GetComponent<Image>();
|
||
icon_card = transform.Find("icon_card").GetComponent<Image>();
|
||
icon_card_logo = transform.Find("icon_card/logo").GetComponent<Image>();
|
||
icon_card_num = transform.Find("icon_card/num").GetComponent<Image>();
|
||
icon_rod = transform.Find("icon_rod").GetComponent<Image>();
|
||
text_num = transform.Find("text_num").GetComponent<TMP_Text>();
|
||
received = transform.Find("received").gameObject;
|
||
text_title = transform.Find("text_title").GetComponent<TMP_Text>();
|
||
}
|
||
private void Start()
|
||
{
|
||
btn_click.onClick.AddListener(OnClick);
|
||
if (btn_questionmark)
|
||
{
|
||
btn_questionmark.onClick.AddListener(OnClickBtnQuestionMark);
|
||
}
|
||
}
|
||
public void PlayOpen(bool reward_fishturntable_open = false)
|
||
{
|
||
if (reward_fishturntable_open)
|
||
{
|
||
ani.Play("reward_fishturntable_open");
|
||
}
|
||
else
|
||
{
|
||
ani.Play("reward_common_open");
|
||
}
|
||
}
|
||
public void PlayOpen(string aniName)
|
||
{
|
||
ani.Play(aniName);
|
||
}
|
||
public async System.Threading.Tasks.Task PlayClose()
|
||
{
|
||
ani.Play("reward_common_close");
|
||
await Awaiters.Seconds(0.3f);
|
||
}
|
||
public void SetReceived(bool _isReceived)
|
||
{
|
||
received.SetActive(_isReceived);
|
||
}
|
||
|
||
void OnClick()
|
||
{
|
||
if (id > 0)
|
||
{
|
||
GContext.container.Resolve<PlayerItemData>().ShowItemTips(id, transform, count, InflationRate);
|
||
}
|
||
else if (showDropID > 0)
|
||
{
|
||
item_sanddig_tips.Show(transform.position, showDropID, InflationRate);
|
||
}
|
||
}
|
||
void OnClickBtnQuestionMark()
|
||
{
|
||
if (item.Type != 9 || item.SubType != 9)
|
||
{
|
||
return;
|
||
}
|
||
if (id > 0)
|
||
{
|
||
GContext.container.Resolve<PlayerItemData>().ShowItemTips(id, transform, count, InflationRate);
|
||
}
|
||
else if (showDropID > 0)
|
||
{
|
||
item_sanddig_tips.Show(transform.position, showDropID, InflationRate);
|
||
}
|
||
}
|
||
public void SetRewardPopupData(ItemData itemData, bool isCanClick = true)
|
||
{
|
||
if (itemData == null)
|
||
{
|
||
return;
|
||
}
|
||
SetData(itemData, isCanClick: isCanClick);
|
||
}
|
||
|
||
public async void PlayRewardFly(bool ignorePack = true)
|
||
{
|
||
Item flyItem = item;
|
||
Image curIcon = icon;
|
||
float showCount = count;
|
||
if (transfer != null && transfer.data != null)
|
||
{
|
||
curIcon = transfer.icon;
|
||
flyItem = _tables.TbItem.GetOrDefault(transfer.data.exchangeId);
|
||
showCount = transfer.data.exchangeCount;
|
||
}
|
||
if (flyItem == null || flyItem.Type == 12 || (flyItem.Type == 7 && flyItem.SubType == 1))
|
||
{
|
||
return;
|
||
}
|
||
ResAddEvent resAddEvent = new ResAddEvent(flyItem.ID, flyItem.Type, flyItem.SubType);
|
||
resAddEvent.addCount = (int)showCount;
|
||
var particleAttractorData = new ParticleAttractorData
|
||
{
|
||
Type = item.Type,
|
||
SubType = item.SubType,
|
||
Priority = -1,
|
||
IgnorePack = ignorePack
|
||
};
|
||
GContext.Publish(particleAttractorData);
|
||
if (particleAttractorData.uIParticleAttractorCenter == null)
|
||
{
|
||
Debug.LogWarning($"[ChainSlot] Type {flyItem.Type} SubType {flyItem.SubType} uIParticleAttractorCenter is null ,targetPos is null ");
|
||
return;
|
||
}
|
||
var center = particleAttractorData.uIParticleAttractorCenter;
|
||
if (center != null)
|
||
{
|
||
var targetPos = center.transform.position;
|
||
var request = new BatchedRewardFlyRequest
|
||
{
|
||
// itemID = _rewardItemDataList[idx].id,
|
||
Icon = new BatchedRewardFlyRequestIcon
|
||
{
|
||
itemID = flyItem.ID
|
||
},
|
||
Quantity = (int?)showCount,
|
||
StartPoint = new BatchedRewardFlyStartPoint(this),
|
||
EndPoint = new BatchedRewardFlyEndPoint(targetPos, 100, UIManager.Instance.transform.lossyScale.x),
|
||
IsDestinationRewardStash = false,
|
||
AnimationParamIndex = 0,
|
||
};
|
||
GContext.Publish(request);
|
||
await Awaiters.Seconds(1);
|
||
if (!isEnable)
|
||
{
|
||
return;
|
||
}
|
||
GContext.Publish(resAddEvent);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 资源粒子飞入,只是表现
|
||
/// </summary>
|
||
/// <param name="classification">钞票有一套数量转换规则</param>
|
||
/// <param name="ignorePack">有时候资源飞入要忽略 ParticleAttractorData.Type == -1 的全资源收集器,(比如 临时背包按钮) </param>
|
||
/// <returns></returns>
|
||
public async System.Threading.Tasks.Task ParticleAttractor(bool classification = false, bool ignorePack = false)
|
||
{
|
||
Item flyItem = item;
|
||
Image curIcon = icon;
|
||
float showCount = count;
|
||
if (transfer != null && transfer.data != null)
|
||
{
|
||
curIcon = transfer.icon;
|
||
flyItem = _tables.TbItem.GetOrDefault(transfer.data.exchangeId);
|
||
showCount = transfer.data.exchangeCount;
|
||
}
|
||
if (flyItem == null || flyItem.Type == 12 || (flyItem.Type == 7 && flyItem.SubType == 1))
|
||
{
|
||
return;
|
||
}
|
||
|
||
ResAddEvent resAddEvent = new ResAddEvent(flyItem.ID, flyItem.Type, flyItem.SubType);
|
||
resAddEvent.addCount = (int)showCount;
|
||
string fxName = flyItem.Fx;
|
||
|
||
if (string.IsNullOrEmpty(fxName))
|
||
{
|
||
GContext.Publish(resAddEvent);
|
||
return;
|
||
}
|
||
|
||
if (RewardShow == null)
|
||
{
|
||
GContext.Publish(resAddEvent);
|
||
return;
|
||
}
|
||
|
||
Transform fxP = null;
|
||
//1001 1002 另外一种配法
|
||
if (classification)
|
||
{
|
||
ItemShow itemShow = _tables.TbItemShow.GetOrDefault(flyItem.ID);
|
||
if (itemShow != null)
|
||
{
|
||
if (flyItem.ID == 1002)
|
||
{
|
||
showCount = (showCount / GContext.container.Resolve<PlayerItemData>().ExtraCoinMag());
|
||
}
|
||
fxName = itemShow.Fx[0];
|
||
for (int i = itemShow.Count.Count - 1; i >= 0; i--)
|
||
{
|
||
if (showCount > itemShow.Count[i])
|
||
{
|
||
fxName = itemShow.Fx[i + 1];
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
fxP = reward_show.Find(fxName);
|
||
|
||
if (fxP == null)
|
||
{
|
||
GContext.Publish(resAddEvent);
|
||
return;
|
||
}
|
||
GameObject fx = Instantiate(fxP.gameObject, reward_show);
|
||
ParticleSystem particleSystem = fx.transform.Find("Scale/quan03").GetComponent<ParticleSystem>();
|
||
if (particleSystem != null)
|
||
{
|
||
reward_show.gameObject.SetActive(true);
|
||
fx.transform.position = transform.position;
|
||
ParticleAttractorData particleAttractorData = new ParticleAttractorData()
|
||
{
|
||
IgnorePack = ignorePack,
|
||
Type = flyItem.Type,
|
||
SubType = flyItem.SubType,
|
||
Priority = -1,
|
||
};
|
||
GContext.Publish(particleAttractorData);
|
||
if (particleAttractorData.Priority > -1 && particleAttractorData.uIParticleAttractorCenter != null)
|
||
{
|
||
var particleRenderer = particleSystem.GetComponent<ParticleSystemRenderer>();
|
||
var sprite = curIcon.sprite;
|
||
if (sprite == null)
|
||
{
|
||
return;
|
||
}
|
||
//多个粒子飞向同一个target时,隐藏前一个粒子
|
||
var uIParticleAttractorCenter = particleAttractorData.uIParticleAttractorCenter;
|
||
UIParticleAttractor particleAttractor = uIParticleAttractorCenter.GetUIParticleAttractor();
|
||
particleAttractor?.Clear();
|
||
uIParticleAttractor = particleAttractor;
|
||
Texture texture = sprite.texture;// await GContext.container.Resolve<IUIService>().GetTexture(item.Icon, "RewardPopupPanel");
|
||
if (!isEnable)
|
||
{
|
||
return;
|
||
}
|
||
//_TextureSample0
|
||
particleRenderer.material.SetTexture("_TextureSample0", texture);
|
||
particleRenderer.material.SetTextureScale("_TextureSample0", new Vector2(sprite.textureRect.width / texture.width, sprite.textureRect.height / texture.height));
|
||
particleRenderer.material.SetTextureOffset("_TextureSample0", new Vector2(sprite.textureRect.x / texture.width, sprite.textureRect.y / texture.height));
|
||
particleSystem.Clear();
|
||
|
||
var main = particleSystem.main;
|
||
int maxCount = main.maxParticles;
|
||
if (showCount < maxCount)
|
||
{
|
||
int addCount = (int)showCount;
|
||
main.maxParticles = addCount;
|
||
//var emission = particleSystem.emission;
|
||
//emission.rateOverTime = 0;
|
||
//emission.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0.0f, addCount) });
|
||
}
|
||
fx.SetActive(true);
|
||
if (particleAttractor != null)
|
||
{
|
||
particleAttractor.particleSystem = particleSystem;
|
||
particleAttractor.enabled = true;
|
||
}
|
||
await Awaiters.Seconds(0.8f);
|
||
if (!isEnable)
|
||
{
|
||
return;
|
||
}
|
||
GContext.Publish(resAddEvent);
|
||
await Awaiters.Seconds(1.2f);
|
||
if (!isEnable)
|
||
{
|
||
return;
|
||
}
|
||
if (particleAttractor != null && particleAttractor.particleSystem == particleSystem)
|
||
{
|
||
particleAttractor.Clear();
|
||
particleAttractor.enabled = false;
|
||
particleAttractor = null;
|
||
}
|
||
}
|
||
}
|
||
Destroy(fx);
|
||
}
|
||
public void SetData(ItemData itemData, bool isCanClick = true, bool abbr = false, bool forceLight = false)
|
||
{
|
||
item = GContext.container.Resolve<Tables>().TbItem.GetOrDefault(itemData.id);
|
||
|
||
if (item == null)
|
||
{
|
||
GameDebug.LogWarning($"[PlayerItemData]AddItemCount: Not found id({itemData.id}) in DataMap");
|
||
return;
|
||
}
|
||
InflationRate = itemData.inflate;
|
||
//Convert Universal TargetEvent TokenItem to cur TargetEvent ToeknItem
|
||
if (item.Type == 10 && item.SubType == 11)
|
||
{
|
||
var tokenID = GContext.container.Resolve<FishingEventData>().collectingTargetInitTokenID;
|
||
item = _tables.TbItem.GetOrDefault(tokenID);
|
||
}
|
||
if (item.Type == 7 && item.SubType == 1)
|
||
{
|
||
gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
if (transfer != null)
|
||
{
|
||
transfer.data = null;
|
||
if (itemData.exchangeItemData != null
|
||
&& itemData.exchangeItemData.exchangeCount > 0)
|
||
{
|
||
transfer.gameObject.SetActive(true);
|
||
transfer.Init(itemData.exchangeItemData);
|
||
}
|
||
else
|
||
{
|
||
transfer.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
if (btn_questionmark)
|
||
{
|
||
btn_questionmark.gameObject.SetActive(item.Type == 9 && item.SubType == 9);
|
||
}
|
||
SetData(item, itemData.count, isCanClick, abbr, forceLight);
|
||
}
|
||
public void SetData(Item item, int count = 1, bool isCanClick = false, bool abbr = false, bool forceLight = false)
|
||
{
|
||
if (item == null)
|
||
{
|
||
return;
|
||
}
|
||
this.item = item;
|
||
id = item.ID;
|
||
showDropID = -1;
|
||
this.count = count;
|
||
gameObject.SetActive(true);
|
||
SetReceived(false);
|
||
canvasGroup.blocksRaycasts = isCanClick;
|
||
//btn_click.enabled = isCanClick;
|
||
icon.gameObject.SetActive(false);
|
||
icon_card.gameObject.SetActive(false);
|
||
icon_rod.gameObject.SetActive(false);
|
||
string text;
|
||
|
||
//if (forceLight == true)
|
||
//{
|
||
// bgLight.gameObject.SetActive(true);
|
||
//}
|
||
//else
|
||
//{
|
||
// bgLight.gameObject.SetActive(item.Type == 3 && (item.SubType == 1 || item.SubType == 3));
|
||
// if (item.Type == 3 && (item.SubType == 1 || item.SubType == 3))
|
||
// {
|
||
// GContext.container.Resolve<IUIService>().SetImageSprite(bgLight, $"light_event_challange_{item.Quality}", BasePanel.PanelName);
|
||
// }
|
||
// else
|
||
// {
|
||
// var lightIndex = item.Quality + 1 > 7 ? 7 : item.Quality + 1;
|
||
// GContext.container.Resolve<IUIService>().SetImageSprite(bgLight, $"light_item_{lightIndex}", BasePanel.PanelName);
|
||
// }
|
||
//}
|
||
|
||
text = FormatQuantityString(item, (int)count, abbr);
|
||
if (item.Type == 5)
|
||
{
|
||
if (item.SubType == 1 || item.SubType == 2)
|
||
{
|
||
IUIService uiService = GContext.container.Resolve<IUIService>();
|
||
List<string> BgNameList;
|
||
if (item.SubType == 1)
|
||
{
|
||
var fishCard = GContext.container.Resolve<Tables>().TbFishCardDrop.GetOrDefault(item.RedirectID);
|
||
BgNameList = fishCard.BgNameList;
|
||
}
|
||
else
|
||
{
|
||
var fishCard = GContext.container.Resolve<Tables>().TbGeneralCardWeight.GetOrDefault(item.RedirectID);
|
||
BgNameList = fishCard.BgNameList;
|
||
}
|
||
uiService.SetImageSprite(icon_card, BgNameList[0], BasePanel.PanelName);
|
||
uiService.SetImageSprite(icon_card_logo, BgNameList[1], BasePanel.PanelName);
|
||
uiService.SetImageSprite(icon_card_num, BgNameList[2], BasePanel.PanelName);
|
||
icon_card.gameObject.SetActive(true);
|
||
}
|
||
}
|
||
else if (item.Type == 3 && (item.SubType == 1 || item.SubType == 3))
|
||
{
|
||
icon_rod.gameObject.SetActive(true);
|
||
GContext.container.Resolve<IUIService>().SetImageSprite(icon_rod, item.Icon, BasePanel.PanelName);
|
||
}
|
||
else if (item.Type == 11 && item.SubType == 1)
|
||
{
|
||
SetIcon(item.Icon);
|
||
}
|
||
else
|
||
{
|
||
SetIcon(item.Icon);
|
||
text_num.gameObject.SetActive(true);
|
||
}
|
||
text_num.text = text;
|
||
if (text_title != null)
|
||
{
|
||
text_title.text = LocalizationMgr.GetText(item.Name_l10n_key);
|
||
}
|
||
}
|
||
|
||
public void SetIcon(string iconName)
|
||
{
|
||
icon.gameObject.SetActive(true);
|
||
GContext.container.Resolve<IUIService>().SetImageSprite(icon, iconName, BasePanel.PanelName);
|
||
}
|
||
|
||
public static string FormatQuantityString(int itemId, int count, bool abbr = false)
|
||
{
|
||
var res = GContext.container.Resolve<Tables>().TbItem.DataMap.TryGetValue(itemId, out var item);
|
||
if (!res)
|
||
{
|
||
Debug.LogWarning($"[RewardItemNew] Item Id ({itemId}) can not be found in TbItem.");
|
||
return $"x{ConvertTools.GetNumberString(count)}";
|
||
}
|
||
return FormatQuantityString(item, count, abbr);
|
||
}
|
||
|
||
public static string FormatQuantityString(Item item, int count, bool abbr = false)
|
||
{
|
||
string text;
|
||
Tables _tables = GContext.container.Resolve<Tables>();
|
||
|
||
if (item.Type == 12)
|
||
{
|
||
text = LocalizationMgr.GetFormatTextValue("UI_PlayerGradePanel_2", count);
|
||
}
|
||
else if (item.Type == 2 && (item.SubType == 4 || item.SubType == 6))
|
||
{
|
||
text = $"{count}%";
|
||
}
|
||
else if (item.Type == 11 && item.SubType == 1)
|
||
{
|
||
var buff = _tables.TbFishBuff.GetOrDefault(item.RedirectID);
|
||
text = LocalizationMgr.GetFormatTextValue("UI_COMMON_min", buff.CountDown / 60);
|
||
}
|
||
else if (abbr || item.ID == 1002)
|
||
{
|
||
var num = ConvertTools.KeepThreeSignificantDigits(count);
|
||
text = $"x{ConvertTools.GetNumberString(num)}";
|
||
}
|
||
else
|
||
{
|
||
text = $"x{ConvertTools.GetNumberString2(count)}";
|
||
}
|
||
|
||
return text;
|
||
}
|
||
|
||
public void SetData(int itemId, string text, bool isShowTipe = false)
|
||
{
|
||
if (transfer != null)
|
||
{
|
||
transfer.gameObject.SetActive(false);
|
||
}
|
||
|
||
id = isShowTipe ? itemId : 0;
|
||
|
||
item = GContext.container.Resolve<Tables>().GetItemData(itemId);
|
||
canvasGroup.blocksRaycasts = true;
|
||
btn_click.enabled = true;
|
||
text_num.text = text;
|
||
if (text_title != null)
|
||
{
|
||
text_title.text = LocalizationMgr.GetText(item.Name_l10n_key);
|
||
}
|
||
//GContext.container.Resolve<IUIService>().SetImageSprite(icon, curItem.Icon, BasePanel.PanelName);
|
||
icon.gameObject.SetActive(false);
|
||
icon_card.gameObject.SetActive(false);
|
||
icon_rod.gameObject.SetActive(false);
|
||
if (item.Type == 5)
|
||
{
|
||
if (item.SubType == 1 || item.SubType == 2)
|
||
{
|
||
IUIService uiService = GContext.container.Resolve<IUIService>();
|
||
List<string> BgNameList;
|
||
if (item.SubType == 1)
|
||
{
|
||
var fishCard = GContext.container.Resolve<Tables>().TbFishCardDrop.GetOrDefault(item.RedirectID);
|
||
BgNameList = fishCard.BgNameList;
|
||
}
|
||
else
|
||
{
|
||
var fishCard = GContext.container.Resolve<Tables>().TbGeneralCardWeight.GetOrDefault(item.RedirectID);
|
||
BgNameList = fishCard.BgNameList;
|
||
}
|
||
uiService.SetImageSprite(icon_card, BgNameList[0], BasePanel.PanelName);
|
||
uiService.SetImageSprite(icon_card_logo, BgNameList[1], BasePanel.PanelName);
|
||
uiService.SetImageSprite(icon_card_num, BgNameList[2], BasePanel.PanelName);
|
||
icon_card.gameObject.SetActive(true);
|
||
}
|
||
}
|
||
else if (item.Type == 3 && (item.SubType == 1 || item.SubType == 3))
|
||
{
|
||
icon_rod.gameObject.SetActive(true);
|
||
GContext.container.Resolve<IUIService>().SetImageSprite(icon_rod, item.Icon, BasePanel.PanelName);
|
||
}
|
||
else if (item.Type == 11 && item.SubType == 1)
|
||
{
|
||
SetIcon(item.Icon);
|
||
}
|
||
else
|
||
{
|
||
SetIcon(item.Icon);
|
||
}
|
||
gameObject.SetActive(true);
|
||
}
|
||
public void SetData(string iconName, string textTitle, string textNum)
|
||
{
|
||
if (transfer != null)
|
||
{
|
||
transfer.gameObject.SetActive(false);
|
||
}
|
||
gameObject.SetActive(true);
|
||
id = 0;
|
||
item = null;
|
||
if (text_num)
|
||
{
|
||
text_num.text = textNum;
|
||
}
|
||
if (text_title != null)
|
||
{
|
||
text_title.text = textTitle;
|
||
}
|
||
icon_card.gameObject.SetActive(false);
|
||
SetIcon(iconName);
|
||
}
|
||
public void SetDropIcon(string iconName, int showDropID)
|
||
{
|
||
if (transfer != null)
|
||
{
|
||
transfer.gameObject.SetActive(false);
|
||
}
|
||
gameObject.SetActive(true);
|
||
id = 0;
|
||
item = null;
|
||
if (text_num)
|
||
{
|
||
text_num.text = "";
|
||
}
|
||
if (text_title != null)
|
||
{
|
||
text_title.text = "";
|
||
}
|
||
this.showDropID = showDropID;
|
||
canvasGroup.blocksRaycasts = true;
|
||
btn_click.enabled = true;
|
||
if (icon_card)
|
||
icon_card.gameObject.SetActive(false);
|
||
SetIcon(iconName);
|
||
}
|
||
|
||
public void SetDropIcon(Sprite iconSprite, int showDropID)
|
||
{
|
||
if (transfer != null)
|
||
{
|
||
transfer.gameObject.SetActive(false);
|
||
}
|
||
gameObject.SetActive(true);
|
||
id = 0;
|
||
item = null;
|
||
if (text_num)
|
||
{
|
||
text_num.text = "";
|
||
}
|
||
if (text_title != null)
|
||
{
|
||
text_title.text = "";
|
||
}
|
||
this.showDropID = showDropID;
|
||
canvasGroup.blocksRaycasts = true;
|
||
btn_click.enabled = true;
|
||
icon_card.gameObject.SetActive(false);
|
||
icon.gameObject.SetActive(true);
|
||
icon.sprite = iconSprite;
|
||
}
|
||
|
||
|
||
private void OnDisable()
|
||
{
|
||
if (reward_show != null)
|
||
{
|
||
for (int i = reward_show.childCount - 1; i >= 0; i--)
|
||
{
|
||
Transform child = reward_show.GetChild(i);
|
||
if (child != null && child.gameObject.activeSelf)
|
||
{
|
||
child.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
if (uIParticleAttractor != null)
|
||
{
|
||
uIParticleAttractor.enabled = false;
|
||
uIParticleAttractor.particleSystem = null;
|
||
uIParticleAttractor = null;
|
||
}
|
||
isEnable = false;
|
||
if (btn_questionmark)
|
||
{
|
||
btn_questionmark.onClick.RemoveAllListeners();
|
||
}
|
||
}
|
||
|
||
public void SetColor(string colorHtmlString)
|
||
{
|
||
var res = ColorUtility.TryParseHtmlString(colorHtmlString, out Color color);
|
||
if (res)
|
||
SetColor(color);
|
||
else
|
||
Debug.LogError($"[RewardItemNew] ColorUtility.TryParseHtmlString Failed: \"{colorHtmlString}\"");
|
||
}
|
||
|
||
public void SetColor(Color color)
|
||
{
|
||
icon.color = color;
|
||
icon_card.color = color;
|
||
icon_card_logo.color = color;
|
||
icon_card_num.color = color;
|
||
icon_rod.color = color;
|
||
text_num.color = color;
|
||
}
|
||
}
|
||
public static class RewardItemNewEx
|
||
{
|
||
private static bool IsNull(this RewardItemNew[] rewardItemNews, List<ItemData> itemDatas)
|
||
{
|
||
if (itemDatas != null) return false;
|
||
foreach (var cell in rewardItemNews)
|
||
cell.gameObject.SetActive(false);
|
||
Debug.LogError($" [RewardItemNewEx] itemDatas is null");
|
||
return true;
|
||
}
|
||
|
||
public static void SetData(this RewardItemNew[] rewardItemNews, List<ItemData> itemDatas)
|
||
{
|
||
if (rewardItemNews.IsNull(itemDatas)) return;
|
||
|
||
for (int i = 0; i < rewardItemNews.Length; i++)
|
||
{
|
||
if (i >= itemDatas.Count)
|
||
rewardItemNews[i]?.SetActive(false);
|
||
else
|
||
{
|
||
rewardItemNews[i]?.SetData(itemDatas[i]);
|
||
rewardItemNews[i]?.SetActive(true);
|
||
}
|
||
}
|
||
}
|
||
public static void SetData(this RewardItemNew[] rewardItemNews, List<ItemData> itemDatas, bool isReceived)
|
||
{
|
||
if (rewardItemNews.IsNull(itemDatas)) return;
|
||
|
||
for (int i = 0; i < rewardItemNews.Length; i++)
|
||
{
|
||
if (i >= itemDatas.Count)
|
||
rewardItemNews[i]?.SetActive(false);
|
||
else
|
||
{
|
||
rewardItemNews[i]?.SetData(itemDatas[i]);
|
||
rewardItemNews[i]?.SetReceived(isReceived);
|
||
rewardItemNews[i]?.SetActive(true);
|
||
}
|
||
}
|
||
}
|
||
}
|