fix:1、添加_A表的读取方式
This commit is contained in:
@@ -1,68 +1,70 @@
|
||||
using SGModule.ConfigLoader;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
[ConfigKey("Common", false)]
|
||||
public class CommonModel
|
||||
{
|
||||
public int InitialNum;
|
||||
public int[] inlineLoginDown;
|
||||
public int inlineMin;
|
||||
public int Purchaseprops;
|
||||
public int rewardrate;
|
||||
public int RevivalCoins;
|
||||
public int[] wheelTimes;
|
||||
public float Passportgift;
|
||||
public float Passportgift2;
|
||||
public float addspace;
|
||||
public float addspace2;
|
||||
public int playtimes;
|
||||
public int interstitialtype;
|
||||
public int lobbyrewrdtime;
|
||||
public int roomrewardrate;
|
||||
public int Activetimes;
|
||||
public int adrate;
|
||||
public int roomrate;
|
||||
public float afSendLimit;
|
||||
public float afSendNum;
|
||||
public int rewardinsertion;
|
||||
public int exchangeCD = 120;
|
||||
|
||||
public int AddSpaceLevel;
|
||||
|
||||
public int RemoveADsPackDuration;
|
||||
public int RemoveADsPackPopup;
|
||||
|
||||
public string contactUs;
|
||||
public int[] UnlockSecret;
|
||||
|
||||
public int[] UnlockLive;
|
||||
public int Live;
|
||||
public int Secret;
|
||||
public int Assitant;
|
||||
public int LivePreview;
|
||||
public int SecretPreview;
|
||||
public int AssitantPreview;
|
||||
public int HomeGuideRate;
|
||||
public int roomGuideRate;
|
||||
public int VIPGuide;
|
||||
public int VIPGuideRate;
|
||||
public int HomeInterstitialAd;
|
||||
public int FreeClaims;
|
||||
public int TurnOffPackRate;
|
||||
public int TurnOffRewardsRate;
|
||||
public int TurnOffRewardsCD;
|
||||
public int TurnOffRewardslimit;
|
||||
public int PayRate;
|
||||
public int FreeMessages;
|
||||
public int[] CoinsAccess;
|
||||
public int AdAccess;
|
||||
public int UnlockAIAssistant;
|
||||
public int ClearRAM;
|
||||
public int CoinsDownload;
|
||||
public string ResVersion;
|
||||
public int MultiModal;
|
||||
public int[] eggReward;
|
||||
public int eggCD;
|
||||
}
|
||||
}
|
||||
using SGModule.ConfigLoader;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
[ConfigKey("Common", false)]
|
||||
public class CommonModel
|
||||
{
|
||||
public int InitialNum;
|
||||
public int[] inlineLoginDown;
|
||||
public int inlineMin;
|
||||
public int Purchaseprops;
|
||||
public int rewardrate;
|
||||
public int RevivalCoins;
|
||||
public int[] wheelTimes;
|
||||
public float Passportgift;
|
||||
public float Passportgift2;
|
||||
public float addspace;
|
||||
public float addspace2;
|
||||
public int playtimes;
|
||||
public int interstitialtype;
|
||||
public int lobbyrewrdtime;
|
||||
public int roomrewardrate;
|
||||
public int Activetimes;
|
||||
public int adrate;
|
||||
public int roomrate;
|
||||
public float afSendLimit;
|
||||
public float afSendNum;
|
||||
public int rewardinsertion;
|
||||
public int exchangeCD = 120;
|
||||
|
||||
public int AddSpaceLevel;
|
||||
|
||||
public int RemoveADsPackDuration;
|
||||
public int RemoveADsPackPopup;
|
||||
|
||||
public string contactUs;
|
||||
public int[] UnlockSecret;
|
||||
|
||||
public int[] UnlockLive;
|
||||
public int Live;
|
||||
public int Secret;
|
||||
public int Assitant;
|
||||
public int LivePreview;
|
||||
public int SecretPreview;
|
||||
public int AssitantPreview;
|
||||
public int HomeGuideRate;
|
||||
public int roomGuideRate;
|
||||
public int VIPGuide;
|
||||
public int VIPGuideRate;
|
||||
public int HomeInterstitialAd;
|
||||
public int FreeClaims;
|
||||
public int TurnOffPackRate;
|
||||
public int TurnOffRewardsRate;
|
||||
public int TurnOffRewardsCD;
|
||||
public int TurnOffRewardslimit;
|
||||
public int PayRate;
|
||||
public int FreeMessages;
|
||||
public int[] CoinsAccess;
|
||||
public int AdAccess;
|
||||
public int UnlockAIAssistant;
|
||||
public int ClearRAM;
|
||||
public int CoinsDownload;
|
||||
public string ResVersion;
|
||||
public int MultiModal;
|
||||
public int[] eggReward;
|
||||
public int eggCD;
|
||||
public string ResVersion1;
|
||||
public int IsOrganic;
|
||||
}
|
||||
}
|
||||
|
||||
+1011
-1011
File diff suppressed because it is too large
Load Diff
@@ -1,299 +1,299 @@
|
||||
|
||||
using FGUI.ZM_Common_01;
|
||||
using UnityEngine;
|
||||
using FairyGUI;
|
||||
using System.Collections.Generic;
|
||||
using FGUI.LG_albums;
|
||||
using FGUI.LG_Common;
|
||||
using SGModule.DataStorage;
|
||||
using DG.Tweening;
|
||||
using SGModule.Common.Extensions;
|
||||
using System.Linq;
|
||||
using SGModule.NetKit;
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class AlbumDetailUI : BaseUI
|
||||
{
|
||||
private AlbumDetailUICtrl ctrl;
|
||||
private AlbumDetailModel model;
|
||||
private FGUI.LG_albums.com_albumsDetail ui;
|
||||
|
||||
public AlbumDetailUI(AlbumDetailUICtrl ctrl) : base(ctrl)
|
||||
{
|
||||
uiName = UIConst.AlbumDetailUI;
|
||||
this.ctrl = ctrl;
|
||||
}
|
||||
|
||||
protected override void SetUIInfo(UIInfo uiInfo)
|
||||
{
|
||||
uiInfo.packageName = "LG_albums";
|
||||
uiInfo.assetName = "com_albumsDetail";
|
||||
uiInfo.layerType = UILayerType.Popup;
|
||||
uiInfo.isNeedOpenAnim = false;
|
||||
uiInfo.isNeedCloseAnim = false;
|
||||
uiInfo.isNeedUIMask = true;
|
||||
}
|
||||
|
||||
#region 生命周期
|
||||
protected override void OnInit()
|
||||
{
|
||||
//model = ModuleManager.Instance.GetModel(ModelConst.AlbumDetailModel) as AlbumDetailModel;
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
if (loader != null && !loader.isDisposed && loader.texture != null)
|
||||
{
|
||||
loader.texture.Dispose();
|
||||
loader.texture = null;
|
||||
}
|
||||
loader = null;
|
||||
|
||||
if (new_index != -1)
|
||||
{
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockAlbums, index);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnBind()
|
||||
{
|
||||
ui = baseUI as FGUI.LG_albums.com_albumsDetail;
|
||||
}
|
||||
private List<LevelUnlock> LevelData;
|
||||
private int new_index = -1;
|
||||
private int index;
|
||||
|
||||
private GLoader loader = new GLoader();
|
||||
protected override void OnOpenBefore(object args)
|
||||
{
|
||||
index = (int)args;
|
||||
Debug.Log(index);
|
||||
ui.btn_close.SetClick(() =>
|
||||
{
|
||||
CtrlCloseUI();
|
||||
});
|
||||
LevelData = ConfigSystem.GetConfig<LevelUnlock>();
|
||||
// ui.list_.SetVirtual();
|
||||
// ui.list_.itemRenderer = RendererList;
|
||||
// ui.list_.numItems = GameHelper.GetLevel() - 1;
|
||||
// ui.list_.ScrollToView(new_index);
|
||||
|
||||
RendererList();
|
||||
}
|
||||
|
||||
protected override void OnOpen(object args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisplay(object args)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
protected override void AddListener()
|
||||
{
|
||||
GameDispatcher.Instance.AddListener(GameMsg.BuyVip, refrsh);
|
||||
}
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.BuyVip, refrsh);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//初始化页面逻辑
|
||||
private void refrsh(object a = null)
|
||||
{
|
||||
DOVirtual.DelayedCall(0.5f, () =>
|
||||
{
|
||||
// ui.list_.numItems = GameHelper.GetLevel() - 1;
|
||||
RendererList();
|
||||
});
|
||||
|
||||
}
|
||||
// void RendererList(int index, GObject obj)
|
||||
void RendererList()
|
||||
{
|
||||
|
||||
item_albumsDetails item = (item_albumsDetails)ui.com_item;
|
||||
|
||||
loader = item.com_loader.GetChild("loader") as GLoader;
|
||||
|
||||
// if (GameHelper.GetVipPrivilege(Subscription.VipLevel.As<int>()))
|
||||
// {
|
||||
// (item.btn_vip as btn_claim_2).have_vip.selectedIndex = 1;
|
||||
|
||||
// }
|
||||
// if (GameHelper.GetVipPrivilege(Subscription.SLVLevel.As<int>()))
|
||||
// {
|
||||
// (item.btn_watch as btn_claim_1).have_vip.selectedIndex = 1;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
var downloadCoinNum = ConfigSystem.GetCommonConf().CoinsDownload;
|
||||
var btn_down_coin = (FGUI.LG_Common.btn_unlock_1)item.btn_download_coin;
|
||||
btn_down_coin.title = downloadCoinNum.As<string>();
|
||||
btn_down_coin.down_load.selectedIndex = GameHelper.GetVipPrivilege(Subscription.FreeDownImage.As<int>()) ? 0 : 1;
|
||||
|
||||
|
||||
if (GameHelper.GetVipPrivilege(Subscription.FreeDownImage.As<int>()))
|
||||
{
|
||||
(item.btn_download as FGUI.LG_Common.btn_claim).have_vip.selectedIndex = 1;
|
||||
item.is_vip.selectedIndex = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.is_vip.selectedIndex = 0;
|
||||
}
|
||||
if (index < GameHelper.GetCommonModel().MultiModal - 1)
|
||||
{
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, LevelData[index].Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
item.btn_download.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.GetVipPrivilege(Subscription.FreeDownImage.As<int>()))
|
||||
{
|
||||
TextureHelper.SaveImageToAlbum(LevelData[index].Name, FolderNames.AlbumName);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowVideoAd("DownloadImage", isSuccess =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
TextureHelper.SaveImageToAlbum(LevelData[index].Name, FolderNames.AlbumName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
btn_down_coin.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.Get101() >= downloadCoinNum)
|
||||
{
|
||||
GameHelper.AddGold(-downloadCoinNum);
|
||||
TextureHelper.SaveImageToAlbum(LevelData[index].Name, FolderNames.AlbumName);
|
||||
TrackKit.SendEvent(ADEventTrack.Coinsbuy, ADEventTrack.Property.download);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Levelunlock levelunlock_ = DataMgr.LevelUnlockListNew.Value.FirstOrDefault(x => x.level_ == index + 1);
|
||||
string file_name = "";
|
||||
if (levelunlock_ != null)
|
||||
{
|
||||
if (levelunlock_.type == 0)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<FreeImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<FreeImageLibrary>().Count - 1;
|
||||
FreeImageLibrary _leveldata = ConfigSystem.GetConfig<FreeImageLibrary>()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
file_name = _leveldata.Name;
|
||||
}
|
||||
else if (levelunlock_.type == 1)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<ADImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<ADImageLibrary>().Count - 1;
|
||||
ADImageLibrary _leveldata = ConfigSystem.GetConfig<ADImageLibrary>()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
file_name = _leveldata.Name;
|
||||
}
|
||||
else if (levelunlock_.type == 2)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<SpecialImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<SpecialImageLibrary>().Count - 1;
|
||||
SpecialImageLibrary _leveldata = ConfigSystem.GetConfig<SpecialImageLibrary>()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
file_name = _leveldata.Name;
|
||||
}
|
||||
else if (levelunlock_.type == 3)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<VIPImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<VIPImageLibrary>().Count - 1;
|
||||
VIPImageLibrary _leveldata = ConfigSystem.GetConfig<VIPImageLibrary>()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
file_name = _leveldata.Name;
|
||||
}
|
||||
item.btn_download.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.GetVipPrivilege(Subscription.FreeDownImage.As<int>()))
|
||||
{
|
||||
TextureHelper.SaveImageToAlbum(file_name, FolderNames.AlbumName);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowVideoAd("DownloadImage", isSuccess =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
TextureHelper.SaveImageToAlbum(file_name, FolderNames.AlbumName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
btn_down_coin.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.Get101() >= downloadCoinNum)
|
||||
{
|
||||
GameHelper.AddGold(-downloadCoinNum);
|
||||
TextureHelper.SaveImageToAlbum(file_name, FolderNames.AlbumName);
|
||||
TrackKit.SendEvent(ADEventTrack.Coinsbuy, ADEventTrack.Property.download);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, LevelData[index].Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
item.btn_download.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.GetVipPrivilege(Subscription.FreeDownImage.As<int>()))
|
||||
{
|
||||
TextureHelper.SaveImageToAlbum(LevelData[index].Name, FolderNames.AlbumName);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowVideoAd("DownloadImage", isSuccess =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
TextureHelper.SaveImageToAlbum(LevelData[index].Name, FolderNames.AlbumName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
btn_down_coin.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.Get101() >= downloadCoinNum)
|
||||
{
|
||||
GameHelper.AddGold(-downloadCoinNum);
|
||||
TextureHelper.SaveImageToAlbum(LevelData[index].Name, FolderNames.AlbumName);
|
||||
TrackKit.SendEvent(ADEventTrack.Coinsbuy, ADEventTrack.Property.download);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using FGUI.ZM_Common_01;
|
||||
using UnityEngine;
|
||||
using FairyGUI;
|
||||
using System.Collections.Generic;
|
||||
using FGUI.LG_albums;
|
||||
using FGUI.LG_Common;
|
||||
using SGModule.DataStorage;
|
||||
using DG.Tweening;
|
||||
using SGModule.Common.Extensions;
|
||||
using System.Linq;
|
||||
using SGModule.NetKit;
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class AlbumDetailUI : BaseUI
|
||||
{
|
||||
private AlbumDetailUICtrl ctrl;
|
||||
private AlbumDetailModel model;
|
||||
private FGUI.LG_albums.com_albumsDetail ui;
|
||||
|
||||
public AlbumDetailUI(AlbumDetailUICtrl ctrl) : base(ctrl)
|
||||
{
|
||||
uiName = UIConst.AlbumDetailUI;
|
||||
this.ctrl = ctrl;
|
||||
}
|
||||
|
||||
protected override void SetUIInfo(UIInfo uiInfo)
|
||||
{
|
||||
uiInfo.packageName = "LG_albums";
|
||||
uiInfo.assetName = "com_albumsDetail";
|
||||
uiInfo.layerType = UILayerType.Popup;
|
||||
uiInfo.isNeedOpenAnim = false;
|
||||
uiInfo.isNeedCloseAnim = false;
|
||||
uiInfo.isNeedUIMask = true;
|
||||
}
|
||||
|
||||
#region 生命周期
|
||||
protected override void OnInit()
|
||||
{
|
||||
//model = ModuleManager.Instance.GetModel(ModelConst.AlbumDetailModel) as AlbumDetailModel;
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
if (loader != null && !loader.isDisposed && loader.texture != null)
|
||||
{
|
||||
loader.texture.Dispose();
|
||||
loader.texture = null;
|
||||
}
|
||||
loader = null;
|
||||
|
||||
if (new_index != -1)
|
||||
{
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockAlbums, index);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnBind()
|
||||
{
|
||||
ui = baseUI as FGUI.LG_albums.com_albumsDetail;
|
||||
}
|
||||
private List<LevelUnlock> LevelData;
|
||||
private int new_index = -1;
|
||||
private int index;
|
||||
|
||||
private GLoader loader = new GLoader();
|
||||
protected override void OnOpenBefore(object args)
|
||||
{
|
||||
index = (int)args;
|
||||
Debug.Log(index);
|
||||
ui.btn_close.SetClick(() =>
|
||||
{
|
||||
CtrlCloseUI();
|
||||
});
|
||||
LevelData = ConfigSystem.GetLevelUnlockConfig();
|
||||
// ui.list_.SetVirtual();
|
||||
// ui.list_.itemRenderer = RendererList;
|
||||
// ui.list_.numItems = GameHelper.GetLevel() - 1;
|
||||
// ui.list_.ScrollToView(new_index);
|
||||
|
||||
RendererList();
|
||||
}
|
||||
|
||||
protected override void OnOpen(object args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisplay(object args)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
protected override void AddListener()
|
||||
{
|
||||
GameDispatcher.Instance.AddListener(GameMsg.BuyVip, refrsh);
|
||||
}
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.BuyVip, refrsh);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//初始化页面逻辑
|
||||
private void refrsh(object a = null)
|
||||
{
|
||||
DOVirtual.DelayedCall(0.5f, () =>
|
||||
{
|
||||
// ui.list_.numItems = GameHelper.GetLevel() - 1;
|
||||
RendererList();
|
||||
});
|
||||
|
||||
}
|
||||
// void RendererList(int index, GObject obj)
|
||||
void RendererList()
|
||||
{
|
||||
|
||||
item_albumsDetails item = (item_albumsDetails)ui.com_item;
|
||||
|
||||
loader = item.com_loader.GetChild("loader") as GLoader;
|
||||
|
||||
// if (GameHelper.GetVipPrivilege(Subscription.VipLevel.As<int>()))
|
||||
// {
|
||||
// (item.btn_vip as btn_claim_2).have_vip.selectedIndex = 1;
|
||||
|
||||
// }
|
||||
// if (GameHelper.GetVipPrivilege(Subscription.SLVLevel.As<int>()))
|
||||
// {
|
||||
// (item.btn_watch as btn_claim_1).have_vip.selectedIndex = 1;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
var downloadCoinNum = ConfigSystem.GetCommonConf().CoinsDownload;
|
||||
var btn_down_coin = (FGUI.LG_Common.btn_unlock_1)item.btn_download_coin;
|
||||
btn_down_coin.title = downloadCoinNum.As<string>();
|
||||
btn_down_coin.down_load.selectedIndex = GameHelper.GetVipPrivilege(Subscription.FreeDownImage.As<int>()) ? 0 : 1;
|
||||
|
||||
|
||||
if (GameHelper.GetVipPrivilege(Subscription.FreeDownImage.As<int>()))
|
||||
{
|
||||
(item.btn_download as FGUI.LG_Common.btn_claim).have_vip.selectedIndex = 1;
|
||||
item.is_vip.selectedIndex = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.is_vip.selectedIndex = 0;
|
||||
}
|
||||
if (index < GameHelper.GetCommonModel().MultiModal - 1)
|
||||
{
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, LevelData[index].Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
item.btn_download.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.GetVipPrivilege(Subscription.FreeDownImage.As<int>()))
|
||||
{
|
||||
TextureHelper.SaveImageToAlbum(LevelData[index].Name, FolderNames.AlbumName);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowVideoAd("DownloadImage", isSuccess =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
TextureHelper.SaveImageToAlbum(LevelData[index].Name, FolderNames.AlbumName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
btn_down_coin.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.Get101() >= downloadCoinNum)
|
||||
{
|
||||
GameHelper.AddGold(-downloadCoinNum);
|
||||
TextureHelper.SaveImageToAlbum(LevelData[index].Name, FolderNames.AlbumName);
|
||||
TrackKit.SendEvent(ADEventTrack.Coinsbuy, ADEventTrack.Property.download);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Levelunlock levelunlock_ = DataMgr.LevelUnlockListNew.Value.FirstOrDefault(x => x.level_ == index + 1);
|
||||
string file_name = "";
|
||||
if (levelunlock_ != null)
|
||||
{
|
||||
if (levelunlock_.type == 0)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetFreeImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetFreeImageConfig().Count - 1;
|
||||
FreeImageLibrary _leveldata = ConfigSystem.GetFreeImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
file_name = _leveldata.Name;
|
||||
}
|
||||
else if (levelunlock_.type == 1)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetADImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetADImageConfig().Count - 1;
|
||||
ADImageLibrary _leveldata = ConfigSystem.GetADImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
file_name = _leveldata.Name;
|
||||
}
|
||||
else if (levelunlock_.type == 2)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetSpecialImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetSpecialImageConfig().Count - 1;
|
||||
SpecialImageLibrary _leveldata = ConfigSystem.GetSpecialImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
file_name = _leveldata.Name;
|
||||
}
|
||||
else if (levelunlock_.type == 3)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetVIPImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetVIPImageConfig().Count - 1;
|
||||
VIPImageLibrary _leveldata = ConfigSystem.GetVIPImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
file_name = _leveldata.Name;
|
||||
}
|
||||
item.btn_download.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.GetVipPrivilege(Subscription.FreeDownImage.As<int>()))
|
||||
{
|
||||
TextureHelper.SaveImageToAlbum(file_name, FolderNames.AlbumName);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowVideoAd("DownloadImage", isSuccess =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
TextureHelper.SaveImageToAlbum(file_name, FolderNames.AlbumName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
btn_down_coin.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.Get101() >= downloadCoinNum)
|
||||
{
|
||||
GameHelper.AddGold(-downloadCoinNum);
|
||||
TextureHelper.SaveImageToAlbum(file_name, FolderNames.AlbumName);
|
||||
TrackKit.SendEvent(ADEventTrack.Coinsbuy, ADEventTrack.Property.download);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, LevelData[index].Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
item.btn_download.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.GetVipPrivilege(Subscription.FreeDownImage.As<int>()))
|
||||
{
|
||||
TextureHelper.SaveImageToAlbum(LevelData[index].Name, FolderNames.AlbumName);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowVideoAd("DownloadImage", isSuccess =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
TextureHelper.SaveImageToAlbum(LevelData[index].Name, FolderNames.AlbumName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
btn_down_coin.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.Get101() >= downloadCoinNum)
|
||||
{
|
||||
GameHelper.AddGold(-downloadCoinNum);
|
||||
TextureHelper.SaveImageToAlbum(LevelData[index].Name, FolderNames.AlbumName);
|
||||
TrackKit.SendEvent(ADEventTrack.Coinsbuy, ADEventTrack.Property.download);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,494 +1,494 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using DG.Tweening;
|
||||
using FairyGUI;
|
||||
using FGUI.LG_albums;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
namespace RedHotRoast
|
||||
|
||||
{
|
||||
public class AlubumUI : BaseUI
|
||||
{
|
||||
private AlubumUICtrl ctrl;
|
||||
private AlubumModel model;
|
||||
private com_albums ui;
|
||||
private long[] UpDatatime;
|
||||
|
||||
public AlubumUI(AlubumUICtrl ctrl) : base(ctrl)
|
||||
{
|
||||
uiName = UIConst.AlubumUI;
|
||||
this.ctrl = ctrl;
|
||||
}
|
||||
|
||||
protected override void SetUIInfo(UIInfo uiInfo)
|
||||
{
|
||||
uiInfo.packageName = "LG_albums";
|
||||
uiInfo.assetName = "com_albums";
|
||||
uiInfo.layerType = UILayerType.Popup;
|
||||
uiInfo.isNeedOpenAnim = false;
|
||||
uiInfo.isNeedCloseAnim = false;
|
||||
uiInfo.isNeedUIMask = true;
|
||||
}
|
||||
|
||||
//初始化页面逻辑
|
||||
private void InitView(object a = null)
|
||||
{
|
||||
UpDatatime = new long[LevelData.Count];
|
||||
ImageName = new string[LevelData.Count];
|
||||
ui.list_albums.itemRenderer = RendererList;
|
||||
ui.list_albums.numItems = LevelData.Count;
|
||||
|
||||
InitScroll();
|
||||
}
|
||||
|
||||
private void SetItemData(object obj = null)
|
||||
{
|
||||
UpDatatime[(int)obj] = 0;
|
||||
ui.list_albums.RefreshVirtualList();
|
||||
}
|
||||
|
||||
#region 生命周期
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
GLoaderPool.Instance.Init(null, 24, 312, 310);
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
foreach (var t in loader_list)
|
||||
if (t != null && !t.isDisposed && t.texture != null)
|
||||
{
|
||||
t.texture.Dispose();
|
||||
t.texture = null;
|
||||
}
|
||||
|
||||
// 1. 解除 UI 对 Loader 的引用
|
||||
for (var i = 0; i < ui.list_albums.numChildren; i++)
|
||||
{
|
||||
var item = ui.list_albums.GetChildAt(i) as item_albums;
|
||||
if (item != null && item.com_loader.loader != null) item.com_loader.loader = null; // 清掉 GLoader 引用
|
||||
}
|
||||
|
||||
activeLoaders.Clear();
|
||||
_fileIsExist.Clear();
|
||||
|
||||
GLoaderPool.Instance.DisposeAll();
|
||||
|
||||
TextureHelper.ClearMaterialPool();
|
||||
|
||||
// 强制卸载未使用的资源
|
||||
Resources.UnloadUnusedAssets();
|
||||
MemoryManager.CleanMemoryMonitor();
|
||||
}
|
||||
|
||||
protected override void OnBind()
|
||||
{
|
||||
ui = baseUI as com_albums;
|
||||
}
|
||||
|
||||
private List<LevelUnlock> LevelData;
|
||||
|
||||
private readonly List<GLoader> loader_list = new();
|
||||
public SmartInvoker invoker;
|
||||
protected override void OnOpenBefore(object args)
|
||||
{
|
||||
invoker = new SmartInvoker(() =>
|
||||
{
|
||||
for (int i = 0; i < UpDatatime.Length; i++)
|
||||
{
|
||||
UpDatatime[i] = 0;
|
||||
// ImageName[i] = "";
|
||||
}
|
||||
ui.list_albums.RefreshVirtualList();
|
||||
}, TimeSpan.FromSeconds(0.2f));
|
||||
|
||||
LevelData = ConfigSystem.GetConfig<LevelUnlock>();
|
||||
ui.list_albums.SetVirtual();
|
||||
ui.btn_close1.SetClick(() => { CtrlCloseUI(); });
|
||||
InitView();
|
||||
}
|
||||
|
||||
|
||||
private const int MaxVisibleCount = 18; // 一屏显示18个
|
||||
private const int PreloadCount = 3; // 上下各预加载一屏
|
||||
private readonly Dictionary<int, GLoader> activeLoaders = new();
|
||||
private readonly Dictionary<int, bool> _fileIsExist = new();
|
||||
|
||||
private Throttle _throttle;
|
||||
|
||||
private void InitScroll()
|
||||
{
|
||||
// ui.list_albums.scrollPane.onScroll.Add(OnScrollUpdate);
|
||||
ui.list_albums.scrollPane.onScrollEnd.Add(OnScrollEndCB); // 保留结束时的整理
|
||||
|
||||
OnScrollEnd();
|
||||
}
|
||||
|
||||
|
||||
private void OnScrollEndCB()
|
||||
{
|
||||
// UpdateVisibleAndPreload();
|
||||
|
||||
OnScrollEnd();
|
||||
|
||||
// Debug.Log("更新一次");
|
||||
}
|
||||
|
||||
private void UpdateVisibleAndPreload()
|
||||
{
|
||||
// Debug.Log("[UpdateVisibleAndPreload]--------111111--------- ");
|
||||
// if (LevelData == null || LevelData.Count == 0) return;
|
||||
|
||||
// var firstVisibleIndex = ui.list_albums.GetFirstChildInView();
|
||||
// var lastVisibleIndex = Mathf.Min(firstVisibleIndex + MaxVisibleCount - 1, ui.list_albums.numItems - 1);
|
||||
|
||||
// var startIndex = Mathf.Max(0, firstVisibleIndex - PreloadCount);
|
||||
// var endIndex = Mathf.Min(ui.list_albums.numItems - 1, lastVisibleIndex + PreloadCount);
|
||||
|
||||
// // 回收超出范围 loader
|
||||
// var keysToRemove = new List<int>();
|
||||
// foreach (var kv in activeLoaders)
|
||||
// {
|
||||
// var idx = kv.Key;
|
||||
// if (idx < startIndex || idx > endIndex)
|
||||
// {
|
||||
// GLoaderPool.Instance.ReturnLoader(kv.Value);
|
||||
// var oldItem = ui.list_albums.GetChildAt(idx) as item_albums;
|
||||
// if (oldItem != null) oldItem.com_loader.loader = null;
|
||||
// keysToRemove.Add(idx);
|
||||
// }
|
||||
// }
|
||||
|
||||
// foreach (var k in keysToRemove) activeLoaders.Remove(k);
|
||||
|
||||
|
||||
// // 分配 loader 并加载图片
|
||||
// for (var i = startIndex; i <= endIndex; i++)
|
||||
// {
|
||||
// if (activeLoaders.ContainsKey(i)) continue;
|
||||
|
||||
// var item = ui.list_albums.GetChildAt(i) as item_albums;
|
||||
// if (item == null) continue;
|
||||
|
||||
// if (item.com_loader.loader != null && !item.com_loader.loader.isDisposed)
|
||||
// GLoaderPool.Instance.ReturnLoader(item.com_loader.loader);
|
||||
|
||||
// var loader = GLoaderPool.Instance.GetLoader();
|
||||
// item.com_loader.loader = loader;
|
||||
// item.com_loader.AddChild(loader);
|
||||
// loader.SetSize(item.com_loader.loader.width, item.com_loader.loader.height);
|
||||
|
||||
// _fileIsExist.TryGetValue(i, out var value);
|
||||
// if (!value)
|
||||
// {
|
||||
// var localPath = Path.Combine(TextureHelper.getResPath(), LevelData[i].Name + ".jpg");
|
||||
|
||||
// if (File.Exists(localPath))
|
||||
// {
|
||||
// _fileIsExist[i] = true;
|
||||
// Debug.Log($"[SetImgLoader] 本地存在,直接加载 {LevelData[i].Name}");
|
||||
// CrazyAsyKit.StartCoroutine(TextureHelper.LoadTexture(LevelData[i].Name, loader, null,
|
||||
// "LevelAlbums/"));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _fileIsExist[i] = false;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// CrazyAsyKit.StartCoroutine(TextureHelper.LoadTexture(LevelData[i].Name, loader, null,
|
||||
// "LevelAlbums/"));
|
||||
// }
|
||||
|
||||
// activeLoaders[i] = loader;
|
||||
// }
|
||||
// Debug.Log($"[ScrollUpdate] active loaders={activeLoaders.Count}, pool={GLoaderPool.Instance.GetPoolCount()}, inUse={GLoaderPool.Instance.GetInUseCount()}");
|
||||
}
|
||||
|
||||
private void OnScrollEnd()
|
||||
{
|
||||
invoker.Invoke();
|
||||
// for (int i = 0; i < UpDatatime.Length; i++)
|
||||
// {
|
||||
// UpDatatime[i] = 0;
|
||||
// // ImageName[i] = "";
|
||||
// }
|
||||
|
||||
// DOVirtual.DelayedCall(0.1f, () =>
|
||||
// {
|
||||
// ui.list_albums.RefreshVirtualList();
|
||||
// });
|
||||
|
||||
// if (LevelData == null || LevelData.Count == 0) return;
|
||||
|
||||
// var firstVisibleIndex = ui.list_albums.GetFirstChildInView();
|
||||
// var lastVisibleIndex = Mathf.Min(firstVisibleIndex + MaxVisibleCount - 1, ui.list_albums.numItems - 1);
|
||||
|
||||
// var startIndex = Mathf.Max(0, firstVisibleIndex - PreloadCount);
|
||||
// var endIndex = Mathf.Min(ui.list_albums.numItems - 1, lastVisibleIndex + PreloadCount);
|
||||
|
||||
// // Debug.Log($"[ScrollEnd] start index={startIndex} end index={endIndex}");
|
||||
|
||||
|
||||
// var tasks = new List<(GLoader loader, string fileName, Action<NTexture> callback, string folder)>();
|
||||
// // 分配 loader 并加载图片
|
||||
// for (var i = startIndex; i <= endIndex; i++)
|
||||
// {
|
||||
// _fileIsExist.TryGetValue(i, out var value);
|
||||
|
||||
// if (value) continue;
|
||||
|
||||
// if (GameHelper.GetLevel() < i + 1) continue;
|
||||
|
||||
// var item = ui.list_albums.GetChildAt(i) as item_albums;
|
||||
// if (item == null) continue;
|
||||
// if (item.com_loader.loader != null && !item.com_loader.loader.isDisposed)
|
||||
// GLoaderPool.Instance.ReturnLoader(item.com_loader.loader);
|
||||
// var loader = GLoaderPool.Instance.GetLoader();
|
||||
// item.com_loader.loader = loader;
|
||||
// item.com_loader.AddChild(loader);
|
||||
// loader.SetSize(item.com_loader.loader.width, item.com_loader.loader.height);
|
||||
|
||||
// var idx = i;
|
||||
// tasks.Add((loader, LevelData[i].Name, NTexture =>
|
||||
// {
|
||||
// if (NTexture != null) _fileIsExist[idx] = true;
|
||||
// }, "LevelAlbums/"));
|
||||
|
||||
// activeLoaders[i] = loader;
|
||||
// }
|
||||
|
||||
// if (tasks.Count > 0) TextureHelper.SetImgLoaders(tasks);
|
||||
}
|
||||
|
||||
private string[] ImageName;
|
||||
|
||||
private void RendererList(int index, GObject obj)
|
||||
{
|
||||
// Debug.Log("Render list" );
|
||||
|
||||
// Debug.Log(JsonConvert.SerializeObject(LevelData[index]));
|
||||
|
||||
item_albums item = (item_albums)obj;
|
||||
item.text_num.text = (index + 1).ToString();
|
||||
if (index < GameHelper.GetCommonModel().MultiModal - 1)
|
||||
{
|
||||
item.type_.selectedIndex = 0;
|
||||
if (GameHelper.GetLevel() > index + 1)
|
||||
{
|
||||
item.SetClick(() => { uiCtrlDispatcher.Dispatch(UICtrlMsg.AlbumDetailUI_Open, index); });
|
||||
}
|
||||
else
|
||||
{
|
||||
item.SetClick(() => { GameHelper.ShowTips("lv_unlock", true); });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Levelunlock levelunlock_ = DataMgr.LevelUnlockListNew.Value.FirstOrDefault(x => x.level_ == index + 1);
|
||||
if (levelunlock_ != null)
|
||||
{
|
||||
item.type_.selectedIndex = levelunlock_.type;
|
||||
}
|
||||
else item.type_.selectedIndex = 0;
|
||||
if (GameHelper.GetLevel() > index + 1)
|
||||
{
|
||||
item.SetClick(() => { uiCtrlDispatcher.Dispatch(UICtrlMsg.AlbumDetailUI_Open, index); });
|
||||
}
|
||||
else
|
||||
{
|
||||
item.SetClick(() => { GameHelper.ShowTips("lv_unlock", true); });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (GameHelper.GetNowTime() < UpDatatime[index] + 1) return;
|
||||
UpDatatime[index] = GameHelper.GetNowTime();
|
||||
// if (!activeLoaders.ContainsValue(item.com_loader.loader)) activeLoaders[index] = item.com_loader.loader;
|
||||
if (!loader_list.Contains(item.com_loader.GetChild("loader") as GLoader))
|
||||
loader_list.Add(item.com_loader.GetChild("loader") as GLoader);
|
||||
|
||||
|
||||
if (index < GameHelper.GetCommonModel().MultiModal - 1)
|
||||
{
|
||||
if (GameHelper.GetLevel() > index + 1)
|
||||
{
|
||||
item.isUnlock.selectedIndex = 1;
|
||||
if (item.com_loader.loader.texture == null ||
|
||||
item.com_loader.loader.texture.nativeTexture.name != LevelData[index].Name)
|
||||
{
|
||||
// item.isUnlock.selectedIndex = 0;
|
||||
// if (item.com_loader.loader.texture != null)
|
||||
// {
|
||||
// item.com_loader.loader.texture.Dispose(); // 释放 GPU 资源
|
||||
// item.com_loader.loader.texture = null; // 断开引用
|
||||
// }
|
||||
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, LevelData[index].Name,
|
||||
(a) => { Debug.Log(item.com_loader.loader.texture.nativeTexture.name); }, "LevelAlbums/", FolderNames.AlbumName);
|
||||
|
||||
ImageName[index] = LevelData[index].Name;
|
||||
}
|
||||
|
||||
item.touchable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.isUnlock.selectedIndex = 0;
|
||||
// item.touchable = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Levelunlock levelunlock_ = DataMgr.LevelUnlockListNew.Value.FirstOrDefault(x => x.level_ == index + 1);
|
||||
|
||||
if (GameHelper.GetLevel() > index + 1)
|
||||
{
|
||||
if (levelunlock_ != null)
|
||||
{
|
||||
item.isUnlock.selectedIndex = 1;
|
||||
|
||||
if (item.com_loader.loader.texture == null || item.com_loader.loader.texture.nativeTexture.name != ImageName[index])
|
||||
{
|
||||
|
||||
if (levelunlock_.type == 0)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<FreeImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<FreeImageLibrary>().Count - 1;
|
||||
FreeImageLibrary _leveldata = ConfigSystem.GetConfig<FreeImageLibrary>()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
ImageName[index] = LevelData[index].Name;
|
||||
}
|
||||
else if (levelunlock_.type == 1)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<ADImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<ADImageLibrary>().Count - 1;
|
||||
ADImageLibrary _leveldata = ConfigSystem.GetConfig<ADImageLibrary>()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
ImageName[index] = LevelData[index].Name;
|
||||
}
|
||||
else if (levelunlock_.type == 2)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<SpecialImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<SpecialImageLibrary>().Count - 1;
|
||||
SpecialImageLibrary _leveldata = ConfigSystem.GetConfig<SpecialImageLibrary>()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
ImageName[index] = LevelData[index].Name;
|
||||
}
|
||||
else if (levelunlock_.type == 3)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<VIPImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<VIPImageLibrary>().Count - 1;
|
||||
VIPImageLibrary _leveldata = ConfigSystem.GetConfig<VIPImageLibrary>()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
ImageName[index] = LevelData[index].Name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
item.isUnlock.selectedIndex = 1;
|
||||
if (item.com_loader.loader.texture == null || item.com_loader.loader.texture.nativeTexture.name != LevelData[index].Name)
|
||||
{
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, LevelData[index].Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
ImageName[index] = LevelData[index].Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// item.touchable = false;
|
||||
item.isUnlock.selectedIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnOpen(object args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisplay(object args)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
|
||||
protected override void AddListener()
|
||||
{
|
||||
GameDispatcher.Instance.AddListener(GameMsg.UnlockAlbums, SetItemData);
|
||||
}
|
||||
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.UnlockAlbums, SetItemData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
public class SmartInvoker
|
||||
{
|
||||
private readonly Action _action;
|
||||
private readonly TimeSpan _delay;
|
||||
private DateTime _lastImmediateInvoke = DateTime.MinValue;
|
||||
private CancellationTokenSource _cts = null;
|
||||
private readonly object _lock = new object();
|
||||
private bool _hasPending = false;
|
||||
|
||||
public SmartInvoker(Action action, TimeSpan delay)
|
||||
{
|
||||
_action = action;
|
||||
_delay = delay;
|
||||
}
|
||||
|
||||
public void Invoke()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
var timeSinceLast = now - _lastImmediateInvoke;
|
||||
|
||||
if (timeSinceLast >= _delay)
|
||||
{
|
||||
_lastImmediateInvoke = now;
|
||||
_action();
|
||||
Debug.Log("diaoyongyiciiiiiiiiiiiiiii");
|
||||
}
|
||||
else
|
||||
{
|
||||
_hasPending = true;
|
||||
_cts?.Cancel();
|
||||
_cts = new CancellationTokenSource();
|
||||
var token = _cts.Token;
|
||||
|
||||
Task.Delay(_delay, token).ContinueWith(t =>
|
||||
{
|
||||
if (!t.IsCanceled)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_hasPending)
|
||||
{
|
||||
_lastImmediateInvoke = DateTime.UtcNow;
|
||||
_hasPending = false;
|
||||
_action();
|
||||
Debug.Log("diaoyongyiciiiiiiiiiiiiiii");
|
||||
}
|
||||
}
|
||||
}
|
||||
}, TaskScheduler.Default);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using DG.Tweening;
|
||||
using FairyGUI;
|
||||
using FGUI.LG_albums;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
namespace RedHotRoast
|
||||
|
||||
{
|
||||
public class AlubumUI : BaseUI
|
||||
{
|
||||
private AlubumUICtrl ctrl;
|
||||
private AlubumModel model;
|
||||
private com_albums ui;
|
||||
private long[] UpDatatime;
|
||||
|
||||
public AlubumUI(AlubumUICtrl ctrl) : base(ctrl)
|
||||
{
|
||||
uiName = UIConst.AlubumUI;
|
||||
this.ctrl = ctrl;
|
||||
}
|
||||
|
||||
protected override void SetUIInfo(UIInfo uiInfo)
|
||||
{
|
||||
uiInfo.packageName = "LG_albums";
|
||||
uiInfo.assetName = "com_albums";
|
||||
uiInfo.layerType = UILayerType.Popup;
|
||||
uiInfo.isNeedOpenAnim = false;
|
||||
uiInfo.isNeedCloseAnim = false;
|
||||
uiInfo.isNeedUIMask = true;
|
||||
}
|
||||
|
||||
//初始化页面逻辑
|
||||
private void InitView(object a = null)
|
||||
{
|
||||
UpDatatime = new long[LevelData.Count];
|
||||
ImageName = new string[LevelData.Count];
|
||||
ui.list_albums.itemRenderer = RendererList;
|
||||
ui.list_albums.numItems = LevelData.Count;
|
||||
|
||||
InitScroll();
|
||||
}
|
||||
|
||||
private void SetItemData(object obj = null)
|
||||
{
|
||||
UpDatatime[(int)obj] = 0;
|
||||
ui.list_albums.RefreshVirtualList();
|
||||
}
|
||||
|
||||
#region 生命周期
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
GLoaderPool.Instance.Init(null, 24, 312, 310);
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
foreach (var t in loader_list)
|
||||
if (t != null && !t.isDisposed && t.texture != null)
|
||||
{
|
||||
t.texture.Dispose();
|
||||
t.texture = null;
|
||||
}
|
||||
|
||||
// 1. 解除 UI 对 Loader 的引用
|
||||
for (var i = 0; i < ui.list_albums.numChildren; i++)
|
||||
{
|
||||
var item = ui.list_albums.GetChildAt(i) as item_albums;
|
||||
if (item != null && item.com_loader.loader != null) item.com_loader.loader = null; // 清掉 GLoader 引用
|
||||
}
|
||||
|
||||
activeLoaders.Clear();
|
||||
_fileIsExist.Clear();
|
||||
|
||||
GLoaderPool.Instance.DisposeAll();
|
||||
|
||||
TextureHelper.ClearMaterialPool();
|
||||
|
||||
// 强制卸载未使用的资源
|
||||
Resources.UnloadUnusedAssets();
|
||||
MemoryManager.CleanMemoryMonitor();
|
||||
}
|
||||
|
||||
protected override void OnBind()
|
||||
{
|
||||
ui = baseUI as com_albums;
|
||||
}
|
||||
|
||||
private List<LevelUnlock> LevelData;
|
||||
|
||||
private readonly List<GLoader> loader_list = new();
|
||||
public SmartInvoker invoker;
|
||||
protected override void OnOpenBefore(object args)
|
||||
{
|
||||
invoker = new SmartInvoker(() =>
|
||||
{
|
||||
for (int i = 0; i < UpDatatime.Length; i++)
|
||||
{
|
||||
UpDatatime[i] = 0;
|
||||
// ImageName[i] = "";
|
||||
}
|
||||
ui.list_albums.RefreshVirtualList();
|
||||
}, TimeSpan.FromSeconds(0.2f));
|
||||
|
||||
LevelData = ConfigSystem.GetLevelUnlockConfig();
|
||||
ui.list_albums.SetVirtual();
|
||||
ui.btn_close1.SetClick(() => { CtrlCloseUI(); });
|
||||
InitView();
|
||||
}
|
||||
|
||||
|
||||
private const int MaxVisibleCount = 18; // 一屏显示18个
|
||||
private const int PreloadCount = 3; // 上下各预加载一屏
|
||||
private readonly Dictionary<int, GLoader> activeLoaders = new();
|
||||
private readonly Dictionary<int, bool> _fileIsExist = new();
|
||||
|
||||
private Throttle _throttle;
|
||||
|
||||
private void InitScroll()
|
||||
{
|
||||
// ui.list_albums.scrollPane.onScroll.Add(OnScrollUpdate);
|
||||
ui.list_albums.scrollPane.onScrollEnd.Add(OnScrollEndCB); // 保留结束时的整理
|
||||
|
||||
OnScrollEnd();
|
||||
}
|
||||
|
||||
|
||||
private void OnScrollEndCB()
|
||||
{
|
||||
// UpdateVisibleAndPreload();
|
||||
|
||||
OnScrollEnd();
|
||||
|
||||
// Debug.Log("更新一次");
|
||||
}
|
||||
|
||||
private void UpdateVisibleAndPreload()
|
||||
{
|
||||
// Debug.Log("[UpdateVisibleAndPreload]--------111111--------- ");
|
||||
// if (LevelData == null || LevelData.Count == 0) return;
|
||||
|
||||
// var firstVisibleIndex = ui.list_albums.GetFirstChildInView();
|
||||
// var lastVisibleIndex = Mathf.Min(firstVisibleIndex + MaxVisibleCount - 1, ui.list_albums.numItems - 1);
|
||||
|
||||
// var startIndex = Mathf.Max(0, firstVisibleIndex - PreloadCount);
|
||||
// var endIndex = Mathf.Min(ui.list_albums.numItems - 1, lastVisibleIndex + PreloadCount);
|
||||
|
||||
// // 回收超出范围 loader
|
||||
// var keysToRemove = new List<int>();
|
||||
// foreach (var kv in activeLoaders)
|
||||
// {
|
||||
// var idx = kv.Key;
|
||||
// if (idx < startIndex || idx > endIndex)
|
||||
// {
|
||||
// GLoaderPool.Instance.ReturnLoader(kv.Value);
|
||||
// var oldItem = ui.list_albums.GetChildAt(idx) as item_albums;
|
||||
// if (oldItem != null) oldItem.com_loader.loader = null;
|
||||
// keysToRemove.Add(idx);
|
||||
// }
|
||||
// }
|
||||
|
||||
// foreach (var k in keysToRemove) activeLoaders.Remove(k);
|
||||
|
||||
|
||||
// // 分配 loader 并加载图片
|
||||
// for (var i = startIndex; i <= endIndex; i++)
|
||||
// {
|
||||
// if (activeLoaders.ContainsKey(i)) continue;
|
||||
|
||||
// var item = ui.list_albums.GetChildAt(i) as item_albums;
|
||||
// if (item == null) continue;
|
||||
|
||||
// if (item.com_loader.loader != null && !item.com_loader.loader.isDisposed)
|
||||
// GLoaderPool.Instance.ReturnLoader(item.com_loader.loader);
|
||||
|
||||
// var loader = GLoaderPool.Instance.GetLoader();
|
||||
// item.com_loader.loader = loader;
|
||||
// item.com_loader.AddChild(loader);
|
||||
// loader.SetSize(item.com_loader.loader.width, item.com_loader.loader.height);
|
||||
|
||||
// _fileIsExist.TryGetValue(i, out var value);
|
||||
// if (!value)
|
||||
// {
|
||||
// var localPath = Path.Combine(TextureHelper.getResPath(), LevelData[i].Name + ".jpg");
|
||||
|
||||
// if (File.Exists(localPath))
|
||||
// {
|
||||
// _fileIsExist[i] = true;
|
||||
// Debug.Log($"[SetImgLoader] 本地存在,直接加载 {LevelData[i].Name}");
|
||||
// CrazyAsyKit.StartCoroutine(TextureHelper.LoadTexture(LevelData[i].Name, loader, null,
|
||||
// "LevelAlbums/"));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _fileIsExist[i] = false;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// CrazyAsyKit.StartCoroutine(TextureHelper.LoadTexture(LevelData[i].Name, loader, null,
|
||||
// "LevelAlbums/"));
|
||||
// }
|
||||
|
||||
// activeLoaders[i] = loader;
|
||||
// }
|
||||
// Debug.Log($"[ScrollUpdate] active loaders={activeLoaders.Count}, pool={GLoaderPool.Instance.GetPoolCount()}, inUse={GLoaderPool.Instance.GetInUseCount()}");
|
||||
}
|
||||
|
||||
private void OnScrollEnd()
|
||||
{
|
||||
invoker.Invoke();
|
||||
// for (int i = 0; i < UpDatatime.Length; i++)
|
||||
// {
|
||||
// UpDatatime[i] = 0;
|
||||
// // ImageName[i] = "";
|
||||
// }
|
||||
|
||||
// DOVirtual.DelayedCall(0.1f, () =>
|
||||
// {
|
||||
// ui.list_albums.RefreshVirtualList();
|
||||
// });
|
||||
|
||||
// if (LevelData == null || LevelData.Count == 0) return;
|
||||
|
||||
// var firstVisibleIndex = ui.list_albums.GetFirstChildInView();
|
||||
// var lastVisibleIndex = Mathf.Min(firstVisibleIndex + MaxVisibleCount - 1, ui.list_albums.numItems - 1);
|
||||
|
||||
// var startIndex = Mathf.Max(0, firstVisibleIndex - PreloadCount);
|
||||
// var endIndex = Mathf.Min(ui.list_albums.numItems - 1, lastVisibleIndex + PreloadCount);
|
||||
|
||||
// // Debug.Log($"[ScrollEnd] start index={startIndex} end index={endIndex}");
|
||||
|
||||
|
||||
// var tasks = new List<(GLoader loader, string fileName, Action<NTexture> callback, string folder)>();
|
||||
// // 分配 loader 并加载图片
|
||||
// for (var i = startIndex; i <= endIndex; i++)
|
||||
// {
|
||||
// _fileIsExist.TryGetValue(i, out var value);
|
||||
|
||||
// if (value) continue;
|
||||
|
||||
// if (GameHelper.GetLevel() < i + 1) continue;
|
||||
|
||||
// var item = ui.list_albums.GetChildAt(i) as item_albums;
|
||||
// if (item == null) continue;
|
||||
// if (item.com_loader.loader != null && !item.com_loader.loader.isDisposed)
|
||||
// GLoaderPool.Instance.ReturnLoader(item.com_loader.loader);
|
||||
// var loader = GLoaderPool.Instance.GetLoader();
|
||||
// item.com_loader.loader = loader;
|
||||
// item.com_loader.AddChild(loader);
|
||||
// loader.SetSize(item.com_loader.loader.width, item.com_loader.loader.height);
|
||||
|
||||
// var idx = i;
|
||||
// tasks.Add((loader, LevelData[i].Name, NTexture =>
|
||||
// {
|
||||
// if (NTexture != null) _fileIsExist[idx] = true;
|
||||
// }, "LevelAlbums/"));
|
||||
|
||||
// activeLoaders[i] = loader;
|
||||
// }
|
||||
|
||||
// if (tasks.Count > 0) TextureHelper.SetImgLoaders(tasks);
|
||||
}
|
||||
|
||||
private string[] ImageName;
|
||||
|
||||
private void RendererList(int index, GObject obj)
|
||||
{
|
||||
// Debug.Log("Render list" );
|
||||
|
||||
// Debug.Log(JsonConvert.SerializeObject(LevelData[index]));
|
||||
|
||||
item_albums item = (item_albums)obj;
|
||||
item.text_num.text = (index + 1).ToString();
|
||||
if (index < GameHelper.GetCommonModel().MultiModal - 1)
|
||||
{
|
||||
item.type_.selectedIndex = 0;
|
||||
if (GameHelper.GetLevel() > index + 1)
|
||||
{
|
||||
item.SetClick(() => { uiCtrlDispatcher.Dispatch(UICtrlMsg.AlbumDetailUI_Open, index); });
|
||||
}
|
||||
else
|
||||
{
|
||||
item.SetClick(() => { GameHelper.ShowTips("lv_unlock", true); });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Levelunlock levelunlock_ = DataMgr.LevelUnlockListNew.Value.FirstOrDefault(x => x.level_ == index + 1);
|
||||
if (levelunlock_ != null)
|
||||
{
|
||||
item.type_.selectedIndex = levelunlock_.type;
|
||||
}
|
||||
else item.type_.selectedIndex = 0;
|
||||
if (GameHelper.GetLevel() > index + 1)
|
||||
{
|
||||
item.SetClick(() => { uiCtrlDispatcher.Dispatch(UICtrlMsg.AlbumDetailUI_Open, index); });
|
||||
}
|
||||
else
|
||||
{
|
||||
item.SetClick(() => { GameHelper.ShowTips("lv_unlock", true); });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (GameHelper.GetNowTime() < UpDatatime[index] + 1) return;
|
||||
UpDatatime[index] = GameHelper.GetNowTime();
|
||||
// if (!activeLoaders.ContainsValue(item.com_loader.loader)) activeLoaders[index] = item.com_loader.loader;
|
||||
if (!loader_list.Contains(item.com_loader.GetChild("loader") as GLoader))
|
||||
loader_list.Add(item.com_loader.GetChild("loader") as GLoader);
|
||||
|
||||
|
||||
if (index < GameHelper.GetCommonModel().MultiModal - 1)
|
||||
{
|
||||
if (GameHelper.GetLevel() > index + 1)
|
||||
{
|
||||
item.isUnlock.selectedIndex = 1;
|
||||
if (item.com_loader.loader.texture == null ||
|
||||
item.com_loader.loader.texture.nativeTexture.name != LevelData[index].Name)
|
||||
{
|
||||
// item.isUnlock.selectedIndex = 0;
|
||||
// if (item.com_loader.loader.texture != null)
|
||||
// {
|
||||
// item.com_loader.loader.texture.Dispose(); // 释放 GPU 资源
|
||||
// item.com_loader.loader.texture = null; // 断开引用
|
||||
// }
|
||||
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, LevelData[index].Name,
|
||||
(a) => { Debug.Log(item.com_loader.loader.texture.nativeTexture.name); }, "LevelAlbums/", FolderNames.AlbumName);
|
||||
|
||||
ImageName[index] = LevelData[index].Name;
|
||||
}
|
||||
|
||||
item.touchable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.isUnlock.selectedIndex = 0;
|
||||
// item.touchable = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Levelunlock levelunlock_ = DataMgr.LevelUnlockListNew.Value.FirstOrDefault(x => x.level_ == index + 1);
|
||||
|
||||
if (GameHelper.GetLevel() > index + 1)
|
||||
{
|
||||
if (levelunlock_ != null)
|
||||
{
|
||||
item.isUnlock.selectedIndex = 1;
|
||||
|
||||
if (item.com_loader.loader.texture == null || item.com_loader.loader.texture.nativeTexture.name != ImageName[index])
|
||||
{
|
||||
|
||||
if (levelunlock_.type == 0)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetFreeImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetFreeImageConfig().Count - 1;
|
||||
FreeImageLibrary _leveldata = ConfigSystem.GetFreeImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
ImageName[index] = LevelData[index].Name;
|
||||
}
|
||||
else if (levelunlock_.type == 1)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetADImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetADImageConfig().Count - 1;
|
||||
ADImageLibrary _leveldata = ConfigSystem.GetADImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
ImageName[index] = LevelData[index].Name;
|
||||
}
|
||||
else if (levelunlock_.type == 2)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetSpecialImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetSpecialImageConfig().Count - 1;
|
||||
SpecialImageLibrary _leveldata = ConfigSystem.GetSpecialImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
ImageName[index] = LevelData[index].Name;
|
||||
}
|
||||
else if (levelunlock_.type == 3)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetVIPImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetVIPImageConfig().Count - 1;
|
||||
VIPImageLibrary _leveldata = ConfigSystem.GetVIPImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
ImageName[index] = LevelData[index].Name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
item.isUnlock.selectedIndex = 1;
|
||||
if (item.com_loader.loader.texture == null || item.com_loader.loader.texture.nativeTexture.name != LevelData[index].Name)
|
||||
{
|
||||
TextureHelper.SetImgLoader(item.com_loader.GetChild("loader") as GLoader, LevelData[index].Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
ImageName[index] = LevelData[index].Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// item.touchable = false;
|
||||
item.isUnlock.selectedIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnOpen(object args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisplay(object args)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
|
||||
protected override void AddListener()
|
||||
{
|
||||
GameDispatcher.Instance.AddListener(GameMsg.UnlockAlbums, SetItemData);
|
||||
}
|
||||
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.UnlockAlbums, SetItemData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
public class SmartInvoker
|
||||
{
|
||||
private readonly Action _action;
|
||||
private readonly TimeSpan _delay;
|
||||
private DateTime _lastImmediateInvoke = DateTime.MinValue;
|
||||
private CancellationTokenSource _cts = null;
|
||||
private readonly object _lock = new object();
|
||||
private bool _hasPending = false;
|
||||
|
||||
public SmartInvoker(Action action, TimeSpan delay)
|
||||
{
|
||||
_action = action;
|
||||
_delay = delay;
|
||||
}
|
||||
|
||||
public void Invoke()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
var timeSinceLast = now - _lastImmediateInvoke;
|
||||
|
||||
if (timeSinceLast >= _delay)
|
||||
{
|
||||
_lastImmediateInvoke = now;
|
||||
_action();
|
||||
Debug.Log("diaoyongyiciiiiiiiiiiiiiii");
|
||||
}
|
||||
else
|
||||
{
|
||||
_hasPending = true;
|
||||
_cts?.Cancel();
|
||||
_cts = new CancellationTokenSource();
|
||||
var token = _cts.Token;
|
||||
|
||||
Task.Delay(_delay, token).ContinueWith(t =>
|
||||
{
|
||||
if (!t.IsCanceled)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_hasPending)
|
||||
{
|
||||
_lastImmediateInvoke = DateTime.UtcNow;
|
||||
_hasPending = false;
|
||||
_action();
|
||||
Debug.Log("diaoyongyiciiiiiiiiiiiiiii");
|
||||
}
|
||||
}
|
||||
}
|
||||
}, TaskScheduler.Default);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,8 +218,8 @@ namespace RedHotRoast
|
||||
{
|
||||
int level_ = GameHelper.GetLevel() - 2;
|
||||
if (level_ <= 0) level_ = 0;
|
||||
if (level_ >= ConfigSystem.GetConfig<LevelUnlock>().Count) level_ = ConfigSystem.GetConfig<LevelUnlock>().Count - 1;
|
||||
TextureHelper.SetImgLoader(ui.bg_loader, ConfigSystem.GetConfig<LevelUnlock>()[level_].Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
if (level_ >= ConfigSystem.GetLevelUnlockConfig().Count) level_ = ConfigSystem.GetLevelUnlockConfig().Count - 1;
|
||||
TextureHelper.SetImgLoader(ui.bg_loader, ConfigSystem.GetLevelUnlockConfig()[level_].Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -228,26 +228,26 @@ namespace RedHotRoast
|
||||
{
|
||||
if (levelunlock_.type == 0)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<FreeImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<FreeImageLibrary>().Count - 1;
|
||||
FreeImageLibrary _leveldata = ConfigSystem.GetConfig<FreeImageLibrary>()[levelunlock_.config_index];
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetFreeImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetFreeImageConfig().Count - 1;
|
||||
FreeImageLibrary _leveldata = ConfigSystem.GetFreeImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(ui.bg_loader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
}
|
||||
else if (levelunlock_.type == 1)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<ADImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<ADImageLibrary>().Count - 1;
|
||||
ADImageLibrary _leveldata = ConfigSystem.GetConfig<ADImageLibrary>()[levelunlock_.config_index];
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetADImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetADImageConfig().Count - 1;
|
||||
ADImageLibrary _leveldata = ConfigSystem.GetADImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(ui.bg_loader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
}
|
||||
else if (levelunlock_.type == 2)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<SpecialImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<SpecialImageLibrary>().Count - 1;
|
||||
SpecialImageLibrary _leveldata = ConfigSystem.GetConfig<SpecialImageLibrary>()[levelunlock_.config_index];
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetSpecialImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetSpecialImageConfig().Count - 1;
|
||||
SpecialImageLibrary _leveldata = ConfigSystem.GetSpecialImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(ui.bg_loader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
}
|
||||
else if (levelunlock_.type == 3)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<VIPImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<VIPImageLibrary>().Count - 1;
|
||||
VIPImageLibrary _leveldata = ConfigSystem.GetConfig<VIPImageLibrary>()[levelunlock_.config_index];
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetVIPImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetVIPImageConfig().Count - 1;
|
||||
VIPImageLibrary _leveldata = ConfigSystem.GetVIPImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.SetImgLoader(ui.bg_loader, _leveldata.Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
}
|
||||
}
|
||||
@@ -255,8 +255,8 @@ namespace RedHotRoast
|
||||
{
|
||||
int level_ = GameHelper.GetLevel() - 1;
|
||||
if (level_ < 0) level_ = 0;
|
||||
if (level_ >= ConfigSystem.GetConfig<LevelUnlock>().Count) level_ = ConfigSystem.GetConfig<LevelUnlock>().Count - 1;
|
||||
TextureHelper.SetImgLoader(ui.bg_loader, ConfigSystem.GetConfig<LevelUnlock>()[level_].Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
if (level_ >= ConfigSystem.GetLevelUnlockConfig().Count) level_ = ConfigSystem.GetLevelUnlockConfig().Count - 1;
|
||||
TextureHelper.SetImgLoader(ui.bg_loader, ConfigSystem.GetLevelUnlockConfig()[level_].Name, null, "LevelAlbums/", FolderNames.AlbumName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,419 +1,419 @@
|
||||
// using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
// using System.IO;
|
||||
|
||||
using FairyGUI;
|
||||
using FGUI.LG_Common;
|
||||
using FGUI.LG_live;
|
||||
using SGModule.Common.Extensions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Video;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class LiveUI : BaseUI
|
||||
{
|
||||
private const int MaxVisibleCount = 6; // 一屏最多6个播放器
|
||||
private const int PreloadCount = 2; // 上下各预加载一屏
|
||||
private static readonly Dictionary<item_live, VideoPlayer> dictionary_ = new();
|
||||
private readonly Dictionary<int, GLoader> activeLoaders = new();
|
||||
private readonly Dictionary<int, bool> _fileIsExist = new();
|
||||
private LiveUICtrl ctrl;
|
||||
|
||||
private float late_time = 0.1f;
|
||||
private List<Live> LiveConfig;
|
||||
private LiveModel model;
|
||||
private com_live ui;
|
||||
|
||||
|
||||
private GameObject videoParent;
|
||||
|
||||
public LiveUI(LiveUICtrl ctrl) : base(ctrl)
|
||||
{
|
||||
uiName = UIConst.LiveUI;
|
||||
this.ctrl = ctrl;
|
||||
}
|
||||
|
||||
protected override void SetUIInfo(UIInfo uiInfo)
|
||||
{
|
||||
uiInfo.packageName = "LG_live";
|
||||
uiInfo.assetName = "com_live";
|
||||
uiInfo.layerType = UILayerType.Popup;
|
||||
uiInfo.isNeedOpenAnim = false;
|
||||
uiInfo.isNeedCloseAnim = false;
|
||||
uiInfo.isNeedUIMask = true;
|
||||
}
|
||||
|
||||
private void UpdateEvent()
|
||||
{
|
||||
late_time = 0.1f;
|
||||
}
|
||||
|
||||
private void Refresh(object param = null)
|
||||
{
|
||||
var index = param.As<int>();
|
||||
// ui.list_.itemRenderer = RendererList;
|
||||
// Debug.Log($"LiveConfig.Count==2=== {LiveConfig.Count}");
|
||||
// ui.list_.numItems = LiveConfig.Count;
|
||||
|
||||
|
||||
if (ui.list_.GetChildAt(index) is item_live item)
|
||||
{
|
||||
var livedata_ = PreDownloadManager.GetLiveDataByIndex(LiveConfig[index], index);
|
||||
item.state.selectedIndex = livedata_.progress >= 100 ? 0 : 1;
|
||||
item.img_mask.fillAmount = (float)(100 - livedata_.progress) / 100;
|
||||
BindPlayerToItem(item, index);
|
||||
|
||||
if (LiveConfig[index].SubscribeUnlock == 1)
|
||||
{
|
||||
if (livedata_.progress < 100) item.vip.selectedIndex = 1;
|
||||
else item.vip.selectedIndex = 2;
|
||||
}
|
||||
else item.vip.selectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化页面逻辑
|
||||
private void InitView()
|
||||
{
|
||||
}
|
||||
|
||||
#region 生命周期
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
videoParent = new GameObject("VideoPlayerParent");
|
||||
VideoPlayerPool.Instance.Init(videoParent, MaxVisibleCount);
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
// 归还所有播放器
|
||||
foreach (var kvp in dictionary_)
|
||||
VideoPlayerPool.Instance.ReturnPlayer(kvp.Value);
|
||||
|
||||
dictionary_.Clear();
|
||||
VideoPlayerPool.Instance.DisposeAll();
|
||||
UnityEngine.Object.Destroy(videoParent);
|
||||
|
||||
foreach (var t in loader_list)
|
||||
if (t != null && !t.isDisposed && t.texture != null)
|
||||
{
|
||||
t.texture.Dispose();
|
||||
t.texture = null;
|
||||
}
|
||||
|
||||
MemoryManager.CleanMemoryMonitor();
|
||||
activeLoaders.Clear();
|
||||
_fileIsExist.Clear();
|
||||
|
||||
GLoaderPool.Instance.DisposeAll();
|
||||
}
|
||||
|
||||
protected override void OnBind()
|
||||
{
|
||||
ui = baseUI as com_live;
|
||||
}
|
||||
|
||||
private readonly List<GLoader> loader_list = new();
|
||||
|
||||
|
||||
protected override void OnOpenBefore(object args)
|
||||
{
|
||||
LiveConfig = ConfigSystem.GetConfig<Live>();
|
||||
|
||||
ui.list_.itemRenderer = RendererList;
|
||||
Debug.Log($"LiveConfig.Count==1=== {LiveConfig.Count}");
|
||||
ui.list_.numItems = LiveConfig.Count;
|
||||
|
||||
ui.btn_close.SetClick(() => { CtrlCloseUI(); });
|
||||
|
||||
InitView();
|
||||
|
||||
// 滚动过程中实时刷新可见播放器
|
||||
ui.list_.scrollPane.onScroll.Add(OnScrollUpdate);
|
||||
ui.list_.scrollPane.onScrollEnd.Add(OnScrollEnd);
|
||||
|
||||
// 打开页面时初始化一次
|
||||
OnScrollEnd();
|
||||
}
|
||||
|
||||
private void OnScrollUpdate()
|
||||
{
|
||||
if (LiveConfig == null || LiveConfig.Count == 0) return;
|
||||
var firstVisibleIndex = ui.list_.GetFirstChildInView();
|
||||
var lastVisibleIndex = Mathf.Min(firstVisibleIndex + MaxVisibleCount - 1, ui.list_.numItems - 1);
|
||||
|
||||
var startIndex = Mathf.Max(0, firstVisibleIndex - PreloadCount);
|
||||
var endIndex = Mathf.Min(ui.list_.numItems - 1, lastVisibleIndex + PreloadCount);
|
||||
|
||||
// 回收超出范围 loader
|
||||
var keysToRemove = new List<int>();
|
||||
foreach (var kv in activeLoaders)
|
||||
{
|
||||
var idx = kv.Key;
|
||||
if (idx < startIndex || idx > endIndex)
|
||||
{
|
||||
GLoaderPool.Instance.ReturnLoader(kv.Value);
|
||||
var oldItem = ui.list_.GetChildAt(idx) as item_live;
|
||||
if (oldItem != null) {
|
||||
(oldItem.img_cover as com_loaderMask_circlle).loader = null;
|
||||
}
|
||||
keysToRemove.Add(idx);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var k in keysToRemove) activeLoaders.Remove(k);
|
||||
|
||||
// 分配 loader 并加载图片
|
||||
for (var i = startIndex; i <= endIndex; i++)
|
||||
{
|
||||
if (activeLoaders.ContainsKey(i)) continue;
|
||||
|
||||
var item = ui.list_.GetChildAt(i) as item_live;
|
||||
if (item == null) continue;
|
||||
|
||||
if ((item.img_cover as com_loaderMask_circlle).loader != null && !(item.img_cover as com_loaderMask_circlle).loader.isDisposed)
|
||||
GLoaderPool.Instance.ReturnLoader((item.img_cover as com_loaderMask_circlle).loader);
|
||||
|
||||
var loader = GLoaderPool.Instance.GetLoader();
|
||||
(item.img_cover as com_loaderMask_circlle).loader = loader;
|
||||
item.img_cover.AddChild(loader);
|
||||
loader.SetSize(item.img_cover.width, item.img_cover.height);
|
||||
item.img_cover.visible = true;
|
||||
|
||||
_fileIsExist.TryGetValue(i, out var value);
|
||||
if (!value)
|
||||
{
|
||||
var localPath = Path.Combine(TextureHelper.getResPath(), "LiveVideoCovers", LiveConfig[i].Name + "_cover" + ".jpg");
|
||||
if (File.Exists(localPath))
|
||||
{
|
||||
_fileIsExist[i] = true;
|
||||
Debug.Log($"[SetImgLoader] 本地存在,直接加载 {LiveConfig[i].Name + "_cover"}");
|
||||
CrazyAsyKit.StartCoroutine(TextureHelper.LoadTexture(LiveConfig[i].Name + "_cover", loader, null,
|
||||
"LiveVideoCovers/"));
|
||||
}
|
||||
else
|
||||
{
|
||||
_fileIsExist[i] = false;
|
||||
CrazyAsyKit.StartCoroutine(LiveVideoManager.Instance.LoadCover(LiveConfig[i].Name + "_cover", tex =>
|
||||
{
|
||||
if (tex != null)
|
||||
{
|
||||
if (loader != null)
|
||||
{
|
||||
loader.texture = new NTexture(tex);
|
||||
loader.visible = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("封面获取失败");
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CrazyAsyKit.StartCoroutine(TextureHelper.LoadTexture(LiveConfig[i].Name + "_cover", loader, null,
|
||||
"LiveVideoCovers/"));
|
||||
}
|
||||
|
||||
activeLoaders[i] = loader;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private HashSet<item_live> lastVisibleItems = new();
|
||||
|
||||
private void OnScrollEnd()
|
||||
{
|
||||
var tasks = new List<(GLoader loader, string fileName, Action<NTexture> callback, string folder, string localFolder)>();
|
||||
var firstVisibleIndex = ui.list_.GetFirstChildInView();
|
||||
var lastVisibleIndex = Mathf.Min(firstVisibleIndex + MaxVisibleCount - 1, ui.list_.numItems - 1);
|
||||
|
||||
var startIndex = Mathf.Max(0, firstVisibleIndex - PreloadCount);
|
||||
var endIndex = Mathf.Min(ui.list_.numItems - 1, lastVisibleIndex + PreloadCount);
|
||||
for (var i = startIndex; i <= endIndex; i++)
|
||||
{
|
||||
_fileIsExist.TryGetValue(i, out var value);
|
||||
|
||||
if (value) continue;
|
||||
if (ui.list_.GetChildAt(i) is item_live item)
|
||||
{
|
||||
if ((item.img_cover as com_loaderMask_circlle).loader != null && !(item.img_cover as com_loaderMask_circlle).loader.isDisposed)
|
||||
GLoaderPool.Instance.ReturnLoader((item.img_cover as com_loaderMask_circlle).loader);
|
||||
var loader = GLoaderPool.Instance.GetLoader();
|
||||
(item.img_cover as com_loaderMask_circlle).loader = loader;
|
||||
item.img_cover.AddChild(loader);
|
||||
loader.SetSize(item.img_cover.width, item.img_cover.height);
|
||||
|
||||
var idx = i;
|
||||
tasks.Add((loader, LiveConfig[i].Name + "_cover", texture =>
|
||||
{
|
||||
if (texture != null) _fileIsExist[idx] = true;
|
||||
}, "LiveAlbums/", FolderNames.VideoCoversName));
|
||||
|
||||
activeLoaders[i] = loader;
|
||||
}
|
||||
}
|
||||
|
||||
TextureHelper.SetImgLoaders(tasks);
|
||||
|
||||
Debug.Log($"[OnScrollEnd]==lastVisibleItems=== {lastVisibleItems.Count}");
|
||||
VideoLoadScheduler.ClearAll();
|
||||
// 1️⃣ 回收上一次的可见播放器
|
||||
foreach (var oldItem in lastVisibleItems)
|
||||
if (dictionary_.TryGetValue(oldItem, out var player))
|
||||
{
|
||||
player.Pause();
|
||||
player.targetTexture?.Release();
|
||||
VideoPlayerPool.Instance.ReturnPlayer(player);
|
||||
dictionary_.Remove(oldItem);
|
||||
oldItem.com_loader.visible = false;
|
||||
oldItem.img_cover.visible = true;
|
||||
}
|
||||
|
||||
lastVisibleItems.Clear();
|
||||
|
||||
|
||||
// 2️⃣ 获取当前可见项
|
||||
var firstIndex = ui.list_.GetFirstChildInView();
|
||||
var lastIndex = Mathf.Min(firstIndex + MaxVisibleCount, ui.list_.numItems);
|
||||
|
||||
HashSet<item_live> newVisibleItems = new();
|
||||
for (var i = firstIndex; i < lastIndex; i++)
|
||||
{
|
||||
if (ui.list_.GetChildAt(i) is item_live item)
|
||||
{
|
||||
// 分配播放器
|
||||
newVisibleItems.Add(item);
|
||||
if (!dictionary_.ContainsKey(item))
|
||||
{
|
||||
var player = VideoPlayerPool.Instance.GetPlayer();
|
||||
if (player != null)
|
||||
{
|
||||
dictionary_[item] = player;
|
||||
BindPlayerToItem(item, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3️⃣ 保存为“上一次可见项”
|
||||
lastVisibleItems = newVisibleItems;
|
||||
}
|
||||
|
||||
private void BindPlayerToItem(item_live item, int index)
|
||||
{
|
||||
var data = PreDownloadManager.GetLiveDataByIndex(LiveConfig[index], index);
|
||||
|
||||
Debug.Log($"[绑定播放器 进度] progress==1=== {data.progress}");
|
||||
if (data.progress < 100) return;
|
||||
|
||||
var player = dictionary_[item];
|
||||
var loader = item.com_loader.GetChild("loader") as GLoader;
|
||||
item.com_loader.visible = true;
|
||||
|
||||
if (!loader_list.Contains(loader)) loader_list.Add(loader);
|
||||
|
||||
TextureHelper.SetVideoLoader(player, loader, LiveConfig[index].Name, vp =>
|
||||
{
|
||||
if (vp != null && !item.isDisposed)
|
||||
{
|
||||
if (data.progress >= 100)
|
||||
{
|
||||
item.img_cover.visible = false;
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.liveVideoLoaded);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void RendererList(int index, GObject obj)
|
||||
{
|
||||
var livedata_ = PreDownloadManager.GetLiveDataByIndex(LiveConfig[index], index);
|
||||
|
||||
var item = (item_live)obj;
|
||||
|
||||
// UI状态显示
|
||||
item.state.selectedIndex = livedata_.progress < 100 ? 1 : 0;
|
||||
|
||||
if (LiveConfig[index].SubscribeUnlock == 1)
|
||||
{
|
||||
if (livedata_.progress < 100) item.vip.selectedIndex = 1;
|
||||
else item.vip.selectedIndex = 2;
|
||||
}
|
||||
else item.vip.selectedIndex = 0;
|
||||
|
||||
item.img_mask.fillAmount = (float)(100 - livedata_.progress) / 100;
|
||||
|
||||
// 点击事件
|
||||
item.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.GetLevel() < GameHelper.GetCommonModel().UnlockLive[1])
|
||||
{
|
||||
if (DataMgr.IsUnlockLive.Value < 0 && !GameHelper.GetVipPrivilege(Subscription.UnlockLive.As<int>()))
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.SecretUnlockUI_Open, 2);
|
||||
else if (DataMgr.IsUnlockLive.Value == 0)
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.UnlockTipsUI_Open, 2);
|
||||
else
|
||||
HandleDetailOpen(item, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
HandleDetailOpen(item, index);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void HandleDetailOpen(item_live item, int index)
|
||||
{
|
||||
dictionary_.TryGetValue(item, out var player);
|
||||
// if (dictionary_.TryGetValue(item, out var player))
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.LiveDetailUI_Open, (index, player));
|
||||
}
|
||||
|
||||
protected override void OnOpen(object args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisplay(object args)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
|
||||
protected override void AddListener()
|
||||
{
|
||||
GameDispatcher.Instance.AddListener(GameMsg.LiveChange, Refresh);
|
||||
HallManager.Instance.UpdateEvent += UpdateEvent;
|
||||
}
|
||||
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.LiveChange, Refresh);
|
||||
HallManager.Instance.UpdateEvent -= UpdateEvent;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class LiveData
|
||||
{
|
||||
public int AD_num;
|
||||
public int progress;
|
||||
public int Singleprogress;
|
||||
public long LiveADTime;
|
||||
}
|
||||
// using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
// using System.IO;
|
||||
|
||||
using FairyGUI;
|
||||
using FGUI.LG_Common;
|
||||
using FGUI.LG_live;
|
||||
using SGModule.Common.Extensions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Video;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class LiveUI : BaseUI
|
||||
{
|
||||
private const int MaxVisibleCount = 6; // 一屏最多6个播放器
|
||||
private const int PreloadCount = 2; // 上下各预加载一屏
|
||||
private static readonly Dictionary<item_live, VideoPlayer> dictionary_ = new();
|
||||
private readonly Dictionary<int, GLoader> activeLoaders = new();
|
||||
private readonly Dictionary<int, bool> _fileIsExist = new();
|
||||
private LiveUICtrl ctrl;
|
||||
|
||||
private float late_time = 0.1f;
|
||||
private List<Live> LiveConfig;
|
||||
private LiveModel model;
|
||||
private com_live ui;
|
||||
|
||||
|
||||
private GameObject videoParent;
|
||||
|
||||
public LiveUI(LiveUICtrl ctrl) : base(ctrl)
|
||||
{
|
||||
uiName = UIConst.LiveUI;
|
||||
this.ctrl = ctrl;
|
||||
}
|
||||
|
||||
protected override void SetUIInfo(UIInfo uiInfo)
|
||||
{
|
||||
uiInfo.packageName = "LG_live";
|
||||
uiInfo.assetName = "com_live";
|
||||
uiInfo.layerType = UILayerType.Popup;
|
||||
uiInfo.isNeedOpenAnim = false;
|
||||
uiInfo.isNeedCloseAnim = false;
|
||||
uiInfo.isNeedUIMask = true;
|
||||
}
|
||||
|
||||
private void UpdateEvent()
|
||||
{
|
||||
late_time = 0.1f;
|
||||
}
|
||||
|
||||
private void Refresh(object param = null)
|
||||
{
|
||||
var index = param.As<int>();
|
||||
// ui.list_.itemRenderer = RendererList;
|
||||
// Debug.Log($"LiveConfig.Count==2=== {LiveConfig.Count}");
|
||||
// ui.list_.numItems = LiveConfig.Count;
|
||||
|
||||
|
||||
if (ui.list_.GetChildAt(index) is item_live item)
|
||||
{
|
||||
var livedata_ = PreDownloadManager.GetLiveDataByIndex(LiveConfig[index], index);
|
||||
item.state.selectedIndex = livedata_.progress >= 100 ? 0 : 1;
|
||||
item.img_mask.fillAmount = (float)(100 - livedata_.progress) / 100;
|
||||
BindPlayerToItem(item, index);
|
||||
|
||||
if (LiveConfig[index].SubscribeUnlock == 1)
|
||||
{
|
||||
if (livedata_.progress < 100) item.vip.selectedIndex = 1;
|
||||
else item.vip.selectedIndex = 2;
|
||||
}
|
||||
else item.vip.selectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化页面逻辑
|
||||
private void InitView()
|
||||
{
|
||||
}
|
||||
|
||||
#region 生命周期
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
videoParent = new GameObject("VideoPlayerParent");
|
||||
VideoPlayerPool.Instance.Init(videoParent, MaxVisibleCount);
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
// 归还所有播放器
|
||||
foreach (var kvp in dictionary_)
|
||||
VideoPlayerPool.Instance.ReturnPlayer(kvp.Value);
|
||||
|
||||
dictionary_.Clear();
|
||||
VideoPlayerPool.Instance.DisposeAll();
|
||||
UnityEngine.Object.Destroy(videoParent);
|
||||
|
||||
foreach (var t in loader_list)
|
||||
if (t != null && !t.isDisposed && t.texture != null)
|
||||
{
|
||||
t.texture.Dispose();
|
||||
t.texture = null;
|
||||
}
|
||||
|
||||
MemoryManager.CleanMemoryMonitor();
|
||||
activeLoaders.Clear();
|
||||
_fileIsExist.Clear();
|
||||
|
||||
GLoaderPool.Instance.DisposeAll();
|
||||
}
|
||||
|
||||
protected override void OnBind()
|
||||
{
|
||||
ui = baseUI as com_live;
|
||||
}
|
||||
|
||||
private readonly List<GLoader> loader_list = new();
|
||||
|
||||
|
||||
protected override void OnOpenBefore(object args)
|
||||
{
|
||||
LiveConfig = ConfigSystem.GetLiveConfig();
|
||||
|
||||
ui.list_.itemRenderer = RendererList;
|
||||
Debug.Log($"LiveConfig.Count==1=== {LiveConfig.Count}");
|
||||
ui.list_.numItems = LiveConfig.Count;
|
||||
|
||||
ui.btn_close.SetClick(() => { CtrlCloseUI(); });
|
||||
|
||||
InitView();
|
||||
|
||||
// 滚动过程中实时刷新可见播放器
|
||||
ui.list_.scrollPane.onScroll.Add(OnScrollUpdate);
|
||||
ui.list_.scrollPane.onScrollEnd.Add(OnScrollEnd);
|
||||
|
||||
// 打开页面时初始化一次
|
||||
OnScrollEnd();
|
||||
}
|
||||
|
||||
private void OnScrollUpdate()
|
||||
{
|
||||
if (LiveConfig == null || LiveConfig.Count == 0) return;
|
||||
var firstVisibleIndex = ui.list_.GetFirstChildInView();
|
||||
var lastVisibleIndex = Mathf.Min(firstVisibleIndex + MaxVisibleCount - 1, ui.list_.numItems - 1);
|
||||
|
||||
var startIndex = Mathf.Max(0, firstVisibleIndex - PreloadCount);
|
||||
var endIndex = Mathf.Min(ui.list_.numItems - 1, lastVisibleIndex + PreloadCount);
|
||||
|
||||
// 回收超出范围 loader
|
||||
var keysToRemove = new List<int>();
|
||||
foreach (var kv in activeLoaders)
|
||||
{
|
||||
var idx = kv.Key;
|
||||
if (idx < startIndex || idx > endIndex)
|
||||
{
|
||||
GLoaderPool.Instance.ReturnLoader(kv.Value);
|
||||
var oldItem = ui.list_.GetChildAt(idx) as item_live;
|
||||
if (oldItem != null) {
|
||||
(oldItem.img_cover as com_loaderMask_circlle).loader = null;
|
||||
}
|
||||
keysToRemove.Add(idx);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var k in keysToRemove) activeLoaders.Remove(k);
|
||||
|
||||
// 分配 loader 并加载图片
|
||||
for (var i = startIndex; i <= endIndex; i++)
|
||||
{
|
||||
if (activeLoaders.ContainsKey(i)) continue;
|
||||
|
||||
var item = ui.list_.GetChildAt(i) as item_live;
|
||||
if (item == null) continue;
|
||||
|
||||
if ((item.img_cover as com_loaderMask_circlle).loader != null && !(item.img_cover as com_loaderMask_circlle).loader.isDisposed)
|
||||
GLoaderPool.Instance.ReturnLoader((item.img_cover as com_loaderMask_circlle).loader);
|
||||
|
||||
var loader = GLoaderPool.Instance.GetLoader();
|
||||
(item.img_cover as com_loaderMask_circlle).loader = loader;
|
||||
item.img_cover.AddChild(loader);
|
||||
loader.SetSize(item.img_cover.width, item.img_cover.height);
|
||||
item.img_cover.visible = true;
|
||||
|
||||
_fileIsExist.TryGetValue(i, out var value);
|
||||
if (!value)
|
||||
{
|
||||
var localPath = Path.Combine(TextureHelper.getResPath(), "LiveVideoCovers", LiveConfig[i].Name + "_cover" + ".jpg");
|
||||
if (File.Exists(localPath))
|
||||
{
|
||||
_fileIsExist[i] = true;
|
||||
Debug.Log($"[SetImgLoader] 本地存在,直接加载 {LiveConfig[i].Name + "_cover"}");
|
||||
CrazyAsyKit.StartCoroutine(TextureHelper.LoadTexture(LiveConfig[i].Name + "_cover", loader, null,
|
||||
"LiveVideoCovers/"));
|
||||
}
|
||||
else
|
||||
{
|
||||
_fileIsExist[i] = false;
|
||||
CrazyAsyKit.StartCoroutine(LiveVideoManager.Instance.LoadCover(LiveConfig[i].Name + "_cover", tex =>
|
||||
{
|
||||
if (tex != null)
|
||||
{
|
||||
if (loader != null)
|
||||
{
|
||||
loader.texture = new NTexture(tex);
|
||||
loader.visible = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("封面获取失败");
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CrazyAsyKit.StartCoroutine(TextureHelper.LoadTexture(LiveConfig[i].Name + "_cover", loader, null,
|
||||
"LiveVideoCovers/"));
|
||||
}
|
||||
|
||||
activeLoaders[i] = loader;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private HashSet<item_live> lastVisibleItems = new();
|
||||
|
||||
private void OnScrollEnd()
|
||||
{
|
||||
var tasks = new List<(GLoader loader, string fileName, Action<NTexture> callback, string folder, string localFolder)>();
|
||||
var firstVisibleIndex = ui.list_.GetFirstChildInView();
|
||||
var lastVisibleIndex = Mathf.Min(firstVisibleIndex + MaxVisibleCount - 1, ui.list_.numItems - 1);
|
||||
|
||||
var startIndex = Mathf.Max(0, firstVisibleIndex - PreloadCount);
|
||||
var endIndex = Mathf.Min(ui.list_.numItems - 1, lastVisibleIndex + PreloadCount);
|
||||
for (var i = startIndex; i <= endIndex; i++)
|
||||
{
|
||||
_fileIsExist.TryGetValue(i, out var value);
|
||||
|
||||
if (value) continue;
|
||||
if (ui.list_.GetChildAt(i) is item_live item)
|
||||
{
|
||||
if ((item.img_cover as com_loaderMask_circlle).loader != null && !(item.img_cover as com_loaderMask_circlle).loader.isDisposed)
|
||||
GLoaderPool.Instance.ReturnLoader((item.img_cover as com_loaderMask_circlle).loader);
|
||||
var loader = GLoaderPool.Instance.GetLoader();
|
||||
(item.img_cover as com_loaderMask_circlle).loader = loader;
|
||||
item.img_cover.AddChild(loader);
|
||||
loader.SetSize(item.img_cover.width, item.img_cover.height);
|
||||
|
||||
var idx = i;
|
||||
tasks.Add((loader, LiveConfig[i].Name + "_cover", texture =>
|
||||
{
|
||||
if (texture != null) _fileIsExist[idx] = true;
|
||||
}, "LiveAlbums/", FolderNames.VideoCoversName));
|
||||
|
||||
activeLoaders[i] = loader;
|
||||
}
|
||||
}
|
||||
|
||||
TextureHelper.SetImgLoaders(tasks);
|
||||
|
||||
Debug.Log($"[OnScrollEnd]==lastVisibleItems=== {lastVisibleItems.Count}");
|
||||
VideoLoadScheduler.ClearAll();
|
||||
// 1️⃣ 回收上一次的可见播放器
|
||||
foreach (var oldItem in lastVisibleItems)
|
||||
if (dictionary_.TryGetValue(oldItem, out var player))
|
||||
{
|
||||
player.Pause();
|
||||
player.targetTexture?.Release();
|
||||
VideoPlayerPool.Instance.ReturnPlayer(player);
|
||||
dictionary_.Remove(oldItem);
|
||||
oldItem.com_loader.visible = false;
|
||||
oldItem.img_cover.visible = true;
|
||||
}
|
||||
|
||||
lastVisibleItems.Clear();
|
||||
|
||||
|
||||
// 2️⃣ 获取当前可见项
|
||||
var firstIndex = ui.list_.GetFirstChildInView();
|
||||
var lastIndex = Mathf.Min(firstIndex + MaxVisibleCount, ui.list_.numItems);
|
||||
|
||||
HashSet<item_live> newVisibleItems = new();
|
||||
for (var i = firstIndex; i < lastIndex; i++)
|
||||
{
|
||||
if (ui.list_.GetChildAt(i) is item_live item)
|
||||
{
|
||||
// 分配播放器
|
||||
newVisibleItems.Add(item);
|
||||
if (!dictionary_.ContainsKey(item))
|
||||
{
|
||||
var player = VideoPlayerPool.Instance.GetPlayer();
|
||||
if (player != null)
|
||||
{
|
||||
dictionary_[item] = player;
|
||||
BindPlayerToItem(item, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3️⃣ 保存为“上一次可见项”
|
||||
lastVisibleItems = newVisibleItems;
|
||||
}
|
||||
|
||||
private void BindPlayerToItem(item_live item, int index)
|
||||
{
|
||||
var data = PreDownloadManager.GetLiveDataByIndex(LiveConfig[index], index);
|
||||
|
||||
Debug.Log($"[绑定播放器 进度] progress==1=== {data.progress}");
|
||||
if (data.progress < 100) return;
|
||||
|
||||
var player = dictionary_[item];
|
||||
var loader = item.com_loader.GetChild("loader") as GLoader;
|
||||
item.com_loader.visible = true;
|
||||
|
||||
if (!loader_list.Contains(loader)) loader_list.Add(loader);
|
||||
|
||||
TextureHelper.SetVideoLoader(player, loader, LiveConfig[index].Name, vp =>
|
||||
{
|
||||
if (vp != null && !item.isDisposed)
|
||||
{
|
||||
if (data.progress >= 100)
|
||||
{
|
||||
item.img_cover.visible = false;
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.liveVideoLoaded);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void RendererList(int index, GObject obj)
|
||||
{
|
||||
var livedata_ = PreDownloadManager.GetLiveDataByIndex(LiveConfig[index], index);
|
||||
|
||||
var item = (item_live)obj;
|
||||
|
||||
// UI状态显示
|
||||
item.state.selectedIndex = livedata_.progress < 100 ? 1 : 0;
|
||||
|
||||
if (LiveConfig[index].SubscribeUnlock == 1)
|
||||
{
|
||||
if (livedata_.progress < 100) item.vip.selectedIndex = 1;
|
||||
else item.vip.selectedIndex = 2;
|
||||
}
|
||||
else item.vip.selectedIndex = 0;
|
||||
|
||||
item.img_mask.fillAmount = (float)(100 - livedata_.progress) / 100;
|
||||
|
||||
// 点击事件
|
||||
item.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.GetLevel() < GameHelper.GetCommonModel().UnlockLive[1])
|
||||
{
|
||||
if (DataMgr.IsUnlockLive.Value < 0 && !GameHelper.GetVipPrivilege(Subscription.UnlockLive.As<int>()))
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.SecretUnlockUI_Open, 2);
|
||||
else if (DataMgr.IsUnlockLive.Value == 0)
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.UnlockTipsUI_Open, 2);
|
||||
else
|
||||
HandleDetailOpen(item, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
HandleDetailOpen(item, index);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void HandleDetailOpen(item_live item, int index)
|
||||
{
|
||||
dictionary_.TryGetValue(item, out var player);
|
||||
// if (dictionary_.TryGetValue(item, out var player))
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.LiveDetailUI_Open, (index, player));
|
||||
}
|
||||
|
||||
protected override void OnOpen(object args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisplay(object args)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
|
||||
protected override void AddListener()
|
||||
{
|
||||
GameDispatcher.Instance.AddListener(GameMsg.LiveChange, Refresh);
|
||||
HallManager.Instance.UpdateEvent += UpdateEvent;
|
||||
}
|
||||
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.LiveChange, Refresh);
|
||||
HallManager.Instance.UpdateEvent -= UpdateEvent;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class LiveData
|
||||
{
|
||||
public int AD_num;
|
||||
public int progress;
|
||||
public int Singleprogress;
|
||||
public long LiveADTime;
|
||||
}
|
||||
}
|
||||
@@ -262,7 +262,7 @@ namespace RedHotRoast
|
||||
player.audioOutputMode = VideoAudioOutputMode.None;
|
||||
|
||||
// 从配置表取配置(这里还是 List,如果有 Id 字段可改成字典)
|
||||
LiveConfig = ConfigSystem.GetConfig<Live>()[index];
|
||||
LiveConfig = ConfigSystem.GetLiveConfig()[index];
|
||||
|
||||
livedata_ = PreDownloadManager.GetLiveDataByIndex(LiveConfig, index);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -51,9 +51,9 @@ namespace RedHotRoast
|
||||
InitView();
|
||||
// DOVirtual.DelayedCall(0.2f, () =>
|
||||
// {
|
||||
// if (GameHelper.GetLevel() - 1 < ConfigSystem.GetConfig<LevelUnlock>().Count&&GameHelper.IsGiftSwitch())
|
||||
// if (GameHelper.GetLevel() - 1 < ConfigSystem.GetLevelUnlockConfig().Count&&GameHelper.IsGiftSwitch())
|
||||
// {
|
||||
// LevelUnlock levelUnlock_ = ConfigSystem.GetConfig<LevelUnlock>()[GameHelper.GetLevel() - 1];
|
||||
// LevelUnlock levelUnlock_ = ConfigSystem.GetLevelUnlockConfig()[GameHelper.GetLevel() - 1];
|
||||
// if (levelUnlock_.LeveType != 0)
|
||||
// {
|
||||
// if (!DataMgr.LevelUnlockList.Value.Contains(GameHelper.GetLevel() - 1))
|
||||
|
||||
@@ -593,7 +593,7 @@ namespace RedHotRoast
|
||||
{
|
||||
if (GameHelper.GetLevel() < GameHelper.GetCommonModel().MultiModal)
|
||||
{
|
||||
TextureHelper.setGamebg(ConfigSystem.GetConfig<LevelUnlock>()[GameHelper.GetLevel() - 1].Name);
|
||||
TextureHelper.setGamebg(ConfigSystem.GetLevelUnlockConfig()[GameHelper.GetLevel() - 1].Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -603,27 +603,27 @@ namespace RedHotRoast
|
||||
{
|
||||
if (levelunlock_.type == 0)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<FreeImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<FreeImageLibrary>().Count - 1;
|
||||
FreeImageLibrary _leveldata = ConfigSystem.GetConfig<FreeImageLibrary>()[levelunlock_.config_index];
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetFreeImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetFreeImageConfig().Count - 1;
|
||||
FreeImageLibrary _leveldata = ConfigSystem.GetFreeImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.setGamebg(_leveldata.Name);
|
||||
|
||||
}
|
||||
else if (levelunlock_.type == 1)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<ADImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<ADImageLibrary>().Count - 1;
|
||||
ADImageLibrary _leveldata = ConfigSystem.GetConfig<ADImageLibrary>()[levelunlock_.config_index];
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetADImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetADImageConfig().Count - 1;
|
||||
ADImageLibrary _leveldata = ConfigSystem.GetADImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.setGamebg(_leveldata.Name);
|
||||
}
|
||||
else if (levelunlock_.type == 2)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<SpecialImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<SpecialImageLibrary>().Count - 1;
|
||||
SpecialImageLibrary _leveldata = ConfigSystem.GetConfig<SpecialImageLibrary>()[levelunlock_.config_index];
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetSpecialImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetSpecialImageConfig().Count - 1;
|
||||
SpecialImageLibrary _leveldata = ConfigSystem.GetSpecialImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.setGamebg(_leveldata.Name);
|
||||
}
|
||||
else if (levelunlock_.type == 3)
|
||||
{
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetConfig<VIPImageLibrary>().Count) levelunlock_.config_index = ConfigSystem.GetConfig<VIPImageLibrary>().Count - 1;
|
||||
VIPImageLibrary _leveldata = ConfigSystem.GetConfig<VIPImageLibrary>()[levelunlock_.config_index];
|
||||
if (levelunlock_.config_index >= ConfigSystem.GetVIPImageConfig().Count) levelunlock_.config_index = ConfigSystem.GetVIPImageConfig().Count - 1;
|
||||
VIPImageLibrary _leveldata = ConfigSystem.GetVIPImageConfig()[levelunlock_.config_index];
|
||||
TextureHelper.setGamebg(_leveldata.Name);
|
||||
}
|
||||
}
|
||||
@@ -633,13 +633,13 @@ namespace RedHotRoast
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (GameHelper.GetLevel() - 1 < ConfigSystem.GetConfig<LevelUnlock>().Count)
|
||||
if (GameHelper.GetLevel() - 1 < ConfigSystem.GetLevelUnlockConfig().Count)
|
||||
{
|
||||
TextureHelper.setGamebg(ConfigSystem.GetConfig<LevelUnlock>()[GameHelper.GetLevel() - 1].Name);
|
||||
TextureHelper.setGamebg(ConfigSystem.GetLevelUnlockConfig()[GameHelper.GetLevel() - 1].Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
TextureHelper.setGamebg(ConfigSystem.GetConfig<LevelUnlock>()[ConfigSystem.GetConfig<LevelUnlock>().Count - 1].Name);
|
||||
TextureHelper.setGamebg(ConfigSystem.GetLevelUnlockConfig()[ConfigSystem.GetLevelUnlockConfig().Count - 1].Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,308 +1,308 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using AppsFlyerSDK;
|
||||
using IgnoreOPS;
|
||||
using SGModule.Common.Extensions;
|
||||
using SGModule.Net;
|
||||
using SGModule.NetKit;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class RainPlayUICtrl : BaseUICtrl
|
||||
{
|
||||
private RainPlayUI ui;
|
||||
private RainPlayModel model;
|
||||
|
||||
private uint openUIMsg = UICtrlMsg.RainPlayUI_Open;
|
||||
private uint closeUIMsg = UICtrlMsg.RainPlayUI_Close;
|
||||
|
||||
#region 生命周期
|
||||
protected override void OnInit()
|
||||
{
|
||||
//model = ModuleManager.Instance.GetModel(ModelConst.RainPlayModel) as RainPlayModel;
|
||||
}
|
||||
|
||||
protected override void OnDispose()
|
||||
{
|
||||
}
|
||||
|
||||
public override void OpenUI(object args = null)
|
||||
{
|
||||
if (ui == null)
|
||||
{
|
||||
ui = new RainPlayUI(this);
|
||||
ui.Open(args);
|
||||
}
|
||||
}
|
||||
|
||||
public override void CloseUI(object args = null)
|
||||
{
|
||||
if (ui != null && !ui.isClose)
|
||||
{
|
||||
ui.Close();
|
||||
}
|
||||
ui = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
public override uint GetOpenUIMsg(string uiName)
|
||||
{
|
||||
return openUIMsg;
|
||||
}
|
||||
public override uint GetCloseUIMsg(string uiName)
|
||||
{
|
||||
return closeUIMsg;
|
||||
}
|
||||
|
||||
protected override void AddListener()
|
||||
{
|
||||
uiCtrlDispatcher.AddListener(openUIMsg, OpenUI);
|
||||
uiCtrlDispatcher.AddListener(closeUIMsg, CloseUI);
|
||||
GameDispatcher.Instance.AddListener(GameMsg.apple_pay_success, pay_success);
|
||||
|
||||
}
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
uiCtrlDispatcher.RemoveListener(openUIMsg, OpenUI);
|
||||
uiCtrlDispatcher.RemoveListener(closeUIMsg, CloseUI);
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.apple_pay_success, pay_success);
|
||||
|
||||
}
|
||||
|
||||
protected override void AddServerListener()
|
||||
{
|
||||
|
||||
}
|
||||
protected override void RemoveServerListener()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void GetPayReward(decimal goldNum)
|
||||
{
|
||||
if (goldNum == 0) return;
|
||||
|
||||
var start = new Vector2(540, 960);
|
||||
var end = new Vector2(236, 62);
|
||||
var rewardData = new RewardData();
|
||||
var rewardSingleData = new RewardSingleData(101, goldNum, RewardOrigin.AdTask)
|
||||
{
|
||||
startPosition = start,
|
||||
};
|
||||
rewardData.AddReward(rewardSingleData);
|
||||
rewardData.displayType = RewardDisplayType.RewardFly | RewardDisplayType.ValueChange;
|
||||
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData);
|
||||
}
|
||||
|
||||
void pay_success(object str)
|
||||
{
|
||||
bool is_maxPay = false; // 第三方支付
|
||||
string type = (string)str;
|
||||
string purch_number = "";
|
||||
if (type.Contains("buy_gold"))
|
||||
{
|
||||
if (type.StartsWith("buy_gold"))
|
||||
{
|
||||
int startIndex = "buy_gold".Length;
|
||||
string suffix = type[startIndex..]; // 截取 "gold" 后的所有字符
|
||||
int suffix_num = int.Parse(suffix);
|
||||
|
||||
purch_number = ConfigSystem.GetConfig<Paidcoins>()[suffix_num].Payment_amount2.ToString();
|
||||
|
||||
if (!UIManager.Instance.IsExistUI(UIConst.BuygoldUI))
|
||||
{
|
||||
List<Paidcoins> list = ConfigSystem.GetConfig<Paidcoins>();
|
||||
// GameHelper.AddGoldNumber(list[suffix_num].Actual_coins);
|
||||
int gold_num = list[suffix_num].Actual_coins;
|
||||
GetPayReward(gold_num);
|
||||
SaveData.GetSaveObject()._goldtime[suffix_num] = (int)GameHelper.GetNowTime();
|
||||
SaveData.SaveDataFunc();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (type == PurchasingManager.GetPaySku(PayType.battle_pass))
|
||||
{
|
||||
SaveData.GetSaveObject().is_get_battlepass = true;
|
||||
int gold = 0;
|
||||
int out_ = 0;
|
||||
int back_ = 0;
|
||||
int refresh_ = 0;
|
||||
List<Passportrewards> Passportrewards_list = ConfigSystem.GetConfig<Passportrewards>();
|
||||
for (int i = 0; i < Passportrewards_list.Count; i++)
|
||||
{
|
||||
if (GameHelper.GetBattleLv() > i || (GameHelper.GetGameExp() >= Passportrewards_list[Passportrewards_list.Count - 1].Eliminating_quantity))
|
||||
{
|
||||
if (Passportrewards_list[i].Paid_rewards_type == 0) gold += Passportrewards_list[i].Paid_rewards_num;
|
||||
else if (Passportrewards_list[i].Paid_rewards_type == 1) out_ += Passportrewards_list[i].Paid_rewards_num;
|
||||
else if (Passportrewards_list[i].Paid_rewards_type == 2) back_ += Passportrewards_list[i].Paid_rewards_num;
|
||||
else if (Passportrewards_list[i].Paid_rewards_type == 3) refresh_ += Passportrewards_list[i].Paid_rewards_num;
|
||||
SaveData.GetSaveObject().battle_pass_paylist.Add(i + 1);
|
||||
}
|
||||
else break;
|
||||
}
|
||||
var purch = ConfigSystem.GetCommonConf().Passportgift2;
|
||||
purch_number = purch.ToString();
|
||||
if (UIManager.Instance.IsExistUI(UIConst.PassViewUI))
|
||||
{
|
||||
GameHelper.AddItemNumber(0, out_);
|
||||
GameHelper.AddItemNumber(1, back_);
|
||||
GameHelper.AddItemNumber(2, refresh_);
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Sheep_item_refresh);
|
||||
// DataMgr.Coin.Value += gold;
|
||||
GetPayReward(gold);
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
}
|
||||
}
|
||||
else if (type == PurchasingManager.GetPaySku(PayType.buy_one))
|
||||
{
|
||||
SaveData.GetSaveObject().have_slot = true;
|
||||
SaveData.SaveDataFunc();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Slot_refresh);
|
||||
GameHelper.ShowTips("purchase_succ", true);
|
||||
|
||||
purch_number = GameHelper.GetCommonModel().addspace2.ToString();
|
||||
}
|
||||
else if (type == PurchasingManager.GetPaySku(PayType.remove_ad))
|
||||
{
|
||||
SaveData.GetSaveObject().remove_ad_time = (int)GameHelper.GetNowTime() + GameHelper.GetCommonModel().RemoveADsPackDuration * 3600;
|
||||
SaveData.GetSaveObject().is_get_removead = true;
|
||||
SaveData.SaveDataFunc();
|
||||
// GameHelper.AddGoldNumber(ConfigSystem.GetConfig<PaidgiftModel>().DataList[1].coins_quantity);
|
||||
// GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
ui?.setBtnAds();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UpdateNoads);
|
||||
GameHelper.ShowTips("purchase_succ", true);
|
||||
purch_number = ConfigSystem.GetConfig<Paidgift>()[1].Paid_price2.ToString();
|
||||
}
|
||||
else if (type == PurchasingManager.GetPaySku(PayType.pack_reward))
|
||||
{
|
||||
List<Paidgift> list = ConfigSystem.GetConfig<Paidgift>();
|
||||
int gold_num = list[0].coins_quantity;
|
||||
int back_num = list[0].props_quantity[1];
|
||||
int out_num = list[0].props_quantity[0];
|
||||
int refresh_num = list[0].props_quantity[2];
|
||||
|
||||
GameHelper.AddItemNumber(0, out_num);
|
||||
GameHelper.AddItemNumber(1, back_num);
|
||||
GameHelper.AddItemNumber(2, refresh_num);
|
||||
SaveData.GetSaveObject().is_get_packreward = true;
|
||||
SaveData.SaveDataFunc();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Sheep_item_refresh);
|
||||
ui?.setBtnAds();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UpdateNoads);
|
||||
GameHelper.ShowTips("purchase_succ", true);
|
||||
purch_number = ConfigSystem.GetConfig<Paidgift>()[0].Paid_price2.ToString();
|
||||
}
|
||||
else if (type == PurchasingManager.GetPaySku(PayType.fail_pack))
|
||||
{
|
||||
List<Paidgift> list = ConfigSystem.GetConfig<Paidgift>();
|
||||
purch_number = ConfigSystem.GetConfig<Paidgift>()[2].Paid_price2.ToString();
|
||||
//ui?.setBtnAds();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.resurgence);
|
||||
|
||||
// DataMgr.Coin.Value += ConfigSystem.GetConfig<PaidgiftModel>().DataList[1].coins_quantity;
|
||||
// GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
int back_num = list[2].props_quantity[1];
|
||||
int out_num = list[2].props_quantity[0];
|
||||
int refresh_num = list[2].props_quantity[2];
|
||||
//GameHelper.addGoldNumber(gold_num);
|
||||
int gold_num = list[2].coins_quantity;
|
||||
if (!UIManager.Instance.IsExistUI(UIConst.ResurgenceUI)) DataMgr.Coin.Value += gold_num;
|
||||
GameHelper.AddItemNumber(0, out_num);
|
||||
GameHelper.AddItemNumber(1, back_num);
|
||||
GameHelper.AddItemNumber(2, refresh_num);
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Sheep_item_refresh);
|
||||
SaveData.SaveDataFunc();
|
||||
|
||||
}
|
||||
else if (type == PurchasingManager.GetPaySku(PayType.three_days_gift))
|
||||
{
|
||||
SaveData.GetSaveObject().is_get_ThreeDaysGift = true;
|
||||
SaveData.SaveDataFunc();
|
||||
purch_number = ConfigSystem.GetConfig<Multigift>()[0].Paid_price2.ToString();
|
||||
}
|
||||
else if (type.StartsWith("vip_club"))
|
||||
{
|
||||
is_maxPay = true;
|
||||
int startIndex = "vip_club".Length;
|
||||
string suffix = type[startIndex..]; // 截取 "gold" 后的所有字符
|
||||
int suffixNum = int.Parse(suffix);
|
||||
|
||||
if (!MaxPayManager.isIOSPay)
|
||||
{
|
||||
var days = 0;
|
||||
switch (suffixNum)
|
||||
{
|
||||
case 0:
|
||||
days = (int)VipDay.Week;
|
||||
break;
|
||||
case 1:
|
||||
days = (int)VipDay.Month;
|
||||
break;
|
||||
case 2:
|
||||
days = (int)VipDay.Year;
|
||||
break;
|
||||
}
|
||||
|
||||
if (days > 0)
|
||||
{
|
||||
// 设置 VIP 到期时间(当前时间戳 + VIP 天数对应的秒数)
|
||||
if (DataMgr.VipExpirationTime.Value > ServerClock.GetCurrentServerTime())
|
||||
{
|
||||
DataMgr.VipExpirationTime.Value = DataMgr.VipExpirationTime.Value + days * 24 * 60 * 60;
|
||||
}
|
||||
else DataMgr.VipExpirationTime.Value = ServerClock.GetCurrentServerTime() + days * 24 * 60 * 60;
|
||||
}
|
||||
DataMgr.VipLevel.Value = suffixNum + 1;
|
||||
}
|
||||
purch_number = ConfigSystem.GetConfig<VipClub>()[suffixNum].DiscountPrice.ToString();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.BuyVip);
|
||||
}
|
||||
else if (type.StartsWith("secret_albnums"))
|
||||
{
|
||||
is_maxPay = true;
|
||||
int startIndex = "secret_albnums".Length;
|
||||
string suffix = type[startIndex..]; // 截取 "gold" 后的所有字符
|
||||
int suffix_num = int.Parse(suffix);
|
||||
var model = ConfigSystem.GetConfig<SecretAlbums>()[suffix_num];
|
||||
if (model.PayType == (int)UnlockPayType.Pay && !GameHelper.isVipUnlock)
|
||||
{
|
||||
purch_number = ConfigSystem.GetConfig<SecretAlbums>()[suffix_num].DiscountPrice.ToString();
|
||||
}
|
||||
GameHelper.isVipUnlock = false;
|
||||
}
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PayloadingUI_Close);
|
||||
|
||||
if ((!GameHelper.IsAdModelOfPay() || is_maxPay) && !string.IsNullOrEmpty(purch_number) && decimal.TryParse(purch_number, out decimal revenue))
|
||||
{
|
||||
var revenueNum = (int)(purch_number.As<decimal>() * 10000);
|
||||
var payType = MaxPayManager.isIOSPay ? 0 : 1;
|
||||
|
||||
// 付费上报BI
|
||||
BIManager.Instance.TrackPurchase(purch_number.As<double>(), "USD", payType.ToString(), type, "paid");
|
||||
|
||||
Debug.Log("付费收益上报AF----------- " + revenue);
|
||||
adCallbackInfo.Clear();
|
||||
adCallbackInfo.Add("appsflyer_id", AppsFlyer.getAppsFlyerId());
|
||||
adCallbackInfo.Add("customer_user_id", GameHelper.GetLoginModel().Uid.ToString());
|
||||
adCallbackInfo.Add("af_currency", "USD");
|
||||
adCallbackInfo.Add("af_revenue", revenue.ToString(CultureInfo.InvariantCulture));
|
||||
AppsFlyer.sendEvent("af_purchase", adCallbackInfo);
|
||||
|
||||
TrackKit.SendEvent(AfPurchaseTrack.Event, AfPurchaseTrack.Property.af_revenue, (int)(purch_number.As<decimal>() * 10000));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static Dictionary<string, string> adCallbackInfo = new Dictionary<string, string>();
|
||||
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using AppsFlyerSDK;
|
||||
using IgnoreOPS;
|
||||
using SGModule.Common.Extensions;
|
||||
using SGModule.Net;
|
||||
using SGModule.NetKit;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class RainPlayUICtrl : BaseUICtrl
|
||||
{
|
||||
private RainPlayUI ui;
|
||||
private RainPlayModel model;
|
||||
|
||||
private uint openUIMsg = UICtrlMsg.RainPlayUI_Open;
|
||||
private uint closeUIMsg = UICtrlMsg.RainPlayUI_Close;
|
||||
|
||||
#region 生命周期
|
||||
protected override void OnInit()
|
||||
{
|
||||
//model = ModuleManager.Instance.GetModel(ModelConst.RainPlayModel) as RainPlayModel;
|
||||
}
|
||||
|
||||
protected override void OnDispose()
|
||||
{
|
||||
}
|
||||
|
||||
public override void OpenUI(object args = null)
|
||||
{
|
||||
if (ui == null)
|
||||
{
|
||||
ui = new RainPlayUI(this);
|
||||
ui.Open(args);
|
||||
}
|
||||
}
|
||||
|
||||
public override void CloseUI(object args = null)
|
||||
{
|
||||
if (ui != null && !ui.isClose)
|
||||
{
|
||||
ui.Close();
|
||||
}
|
||||
ui = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
public override uint GetOpenUIMsg(string uiName)
|
||||
{
|
||||
return openUIMsg;
|
||||
}
|
||||
public override uint GetCloseUIMsg(string uiName)
|
||||
{
|
||||
return closeUIMsg;
|
||||
}
|
||||
|
||||
protected override void AddListener()
|
||||
{
|
||||
uiCtrlDispatcher.AddListener(openUIMsg, OpenUI);
|
||||
uiCtrlDispatcher.AddListener(closeUIMsg, CloseUI);
|
||||
GameDispatcher.Instance.AddListener(GameMsg.apple_pay_success, pay_success);
|
||||
|
||||
}
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
uiCtrlDispatcher.RemoveListener(openUIMsg, OpenUI);
|
||||
uiCtrlDispatcher.RemoveListener(closeUIMsg, CloseUI);
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.apple_pay_success, pay_success);
|
||||
|
||||
}
|
||||
|
||||
protected override void AddServerListener()
|
||||
{
|
||||
|
||||
}
|
||||
protected override void RemoveServerListener()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void GetPayReward(decimal goldNum)
|
||||
{
|
||||
if (goldNum == 0) return;
|
||||
|
||||
var start = new Vector2(540, 960);
|
||||
var end = new Vector2(236, 62);
|
||||
var rewardData = new RewardData();
|
||||
var rewardSingleData = new RewardSingleData(101, goldNum, RewardOrigin.AdTask)
|
||||
{
|
||||
startPosition = start,
|
||||
};
|
||||
rewardData.AddReward(rewardSingleData);
|
||||
rewardData.displayType = RewardDisplayType.RewardFly | RewardDisplayType.ValueChange;
|
||||
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData);
|
||||
}
|
||||
|
||||
void pay_success(object str)
|
||||
{
|
||||
bool is_maxPay = false; // 第三方支付
|
||||
string type = (string)str;
|
||||
string purch_number = "";
|
||||
if (type.Contains("buy_gold"))
|
||||
{
|
||||
if (type.StartsWith("buy_gold"))
|
||||
{
|
||||
int startIndex = "buy_gold".Length;
|
||||
string suffix = type[startIndex..]; // 截取 "gold" 后的所有字符
|
||||
int suffix_num = int.Parse(suffix);
|
||||
|
||||
purch_number = ConfigSystem.GetConfig<Paidcoins>()[suffix_num].Payment_amount2.ToString();
|
||||
|
||||
if (!UIManager.Instance.IsExistUI(UIConst.BuygoldUI))
|
||||
{
|
||||
List<Paidcoins> list = ConfigSystem.GetConfig<Paidcoins>();
|
||||
// GameHelper.AddGoldNumber(list[suffix_num].Actual_coins);
|
||||
int gold_num = list[suffix_num].Actual_coins;
|
||||
GetPayReward(gold_num);
|
||||
SaveData.GetSaveObject()._goldtime[suffix_num] = (int)GameHelper.GetNowTime();
|
||||
SaveData.SaveDataFunc();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (type == PurchasingManager.GetPaySku(PayType.battle_pass))
|
||||
{
|
||||
SaveData.GetSaveObject().is_get_battlepass = true;
|
||||
int gold = 0;
|
||||
int out_ = 0;
|
||||
int back_ = 0;
|
||||
int refresh_ = 0;
|
||||
List<Passportrewards> Passportrewards_list = ConfigSystem.GetConfig<Passportrewards>();
|
||||
for (int i = 0; i < Passportrewards_list.Count; i++)
|
||||
{
|
||||
if (GameHelper.GetBattleLv() > i || (GameHelper.GetGameExp() >= Passportrewards_list[Passportrewards_list.Count - 1].Eliminating_quantity))
|
||||
{
|
||||
if (Passportrewards_list[i].Paid_rewards_type == 0) gold += Passportrewards_list[i].Paid_rewards_num;
|
||||
else if (Passportrewards_list[i].Paid_rewards_type == 1) out_ += Passportrewards_list[i].Paid_rewards_num;
|
||||
else if (Passportrewards_list[i].Paid_rewards_type == 2) back_ += Passportrewards_list[i].Paid_rewards_num;
|
||||
else if (Passportrewards_list[i].Paid_rewards_type == 3) refresh_ += Passportrewards_list[i].Paid_rewards_num;
|
||||
SaveData.GetSaveObject().battle_pass_paylist.Add(i + 1);
|
||||
}
|
||||
else break;
|
||||
}
|
||||
var purch = ConfigSystem.GetCommonConf().Passportgift2;
|
||||
purch_number = purch.ToString();
|
||||
if (UIManager.Instance.IsExistUI(UIConst.PassViewUI))
|
||||
{
|
||||
GameHelper.AddItemNumber(0, out_);
|
||||
GameHelper.AddItemNumber(1, back_);
|
||||
GameHelper.AddItemNumber(2, refresh_);
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Sheep_item_refresh);
|
||||
// DataMgr.Coin.Value += gold;
|
||||
GetPayReward(gold);
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
}
|
||||
}
|
||||
else if (type == PurchasingManager.GetPaySku(PayType.buy_one))
|
||||
{
|
||||
SaveData.GetSaveObject().have_slot = true;
|
||||
SaveData.SaveDataFunc();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Slot_refresh);
|
||||
GameHelper.ShowTips("purchase_succ", true);
|
||||
|
||||
purch_number = GameHelper.GetCommonModel().addspace2.ToString();
|
||||
}
|
||||
else if (type == PurchasingManager.GetPaySku(PayType.remove_ad))
|
||||
{
|
||||
SaveData.GetSaveObject().remove_ad_time = (int)GameHelper.GetNowTime() + GameHelper.GetCommonModel().RemoveADsPackDuration * 3600;
|
||||
SaveData.GetSaveObject().is_get_removead = true;
|
||||
SaveData.SaveDataFunc();
|
||||
// GameHelper.AddGoldNumber(ConfigSystem.GetConfig<PaidgiftModel>().DataList[1].coins_quantity);
|
||||
// GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
ui?.setBtnAds();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UpdateNoads);
|
||||
GameHelper.ShowTips("purchase_succ", true);
|
||||
purch_number = ConfigSystem.GetConfig<Paidgift>()[1].Paid_price2.ToString();
|
||||
}
|
||||
else if (type == PurchasingManager.GetPaySku(PayType.pack_reward))
|
||||
{
|
||||
List<Paidgift> list = ConfigSystem.GetConfig<Paidgift>();
|
||||
int gold_num = list[0].coins_quantity;
|
||||
int back_num = list[0].props_quantity[1];
|
||||
int out_num = list[0].props_quantity[0];
|
||||
int refresh_num = list[0].props_quantity[2];
|
||||
|
||||
GameHelper.AddItemNumber(0, out_num);
|
||||
GameHelper.AddItemNumber(1, back_num);
|
||||
GameHelper.AddItemNumber(2, refresh_num);
|
||||
SaveData.GetSaveObject().is_get_packreward = true;
|
||||
SaveData.SaveDataFunc();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Sheep_item_refresh);
|
||||
ui?.setBtnAds();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UpdateNoads);
|
||||
GameHelper.ShowTips("purchase_succ", true);
|
||||
purch_number = ConfigSystem.GetConfig<Paidgift>()[0].Paid_price2.ToString();
|
||||
}
|
||||
else if (type == PurchasingManager.GetPaySku(PayType.fail_pack))
|
||||
{
|
||||
List<Paidgift> list = ConfigSystem.GetConfig<Paidgift>();
|
||||
purch_number = ConfigSystem.GetConfig<Paidgift>()[2].Paid_price2.ToString();
|
||||
//ui?.setBtnAds();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.resurgence);
|
||||
|
||||
// DataMgr.Coin.Value += ConfigSystem.GetConfig<PaidgiftModel>().DataList[1].coins_quantity;
|
||||
// GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
int back_num = list[2].props_quantity[1];
|
||||
int out_num = list[2].props_quantity[0];
|
||||
int refresh_num = list[2].props_quantity[2];
|
||||
//GameHelper.addGoldNumber(gold_num);
|
||||
int gold_num = list[2].coins_quantity;
|
||||
if (!UIManager.Instance.IsExistUI(UIConst.ResurgenceUI)) DataMgr.Coin.Value += gold_num;
|
||||
GameHelper.AddItemNumber(0, out_num);
|
||||
GameHelper.AddItemNumber(1, back_num);
|
||||
GameHelper.AddItemNumber(2, refresh_num);
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Sheep_item_refresh);
|
||||
SaveData.SaveDataFunc();
|
||||
|
||||
}
|
||||
else if (type == PurchasingManager.GetPaySku(PayType.three_days_gift))
|
||||
{
|
||||
SaveData.GetSaveObject().is_get_ThreeDaysGift = true;
|
||||
SaveData.SaveDataFunc();
|
||||
purch_number = ConfigSystem.GetConfig<Multigift>()[0].Paid_price2.ToString();
|
||||
}
|
||||
else if (type.StartsWith("vip_club"))
|
||||
{
|
||||
is_maxPay = true;
|
||||
int startIndex = "vip_club".Length;
|
||||
string suffix = type[startIndex..]; // 截取 "gold" 后的所有字符
|
||||
int suffixNum = int.Parse(suffix);
|
||||
|
||||
if (!MaxPayManager.isIOSPay)
|
||||
{
|
||||
var days = 0;
|
||||
switch (suffixNum)
|
||||
{
|
||||
case 0:
|
||||
days = (int)VipDay.Week;
|
||||
break;
|
||||
case 1:
|
||||
days = (int)VipDay.Month;
|
||||
break;
|
||||
case 2:
|
||||
days = (int)VipDay.Year;
|
||||
break;
|
||||
}
|
||||
|
||||
if (days > 0)
|
||||
{
|
||||
// 设置 VIP 到期时间(当前时间戳 + VIP 天数对应的秒数)
|
||||
if (DataMgr.VipExpirationTime.Value > ServerClock.GetCurrentServerTime())
|
||||
{
|
||||
DataMgr.VipExpirationTime.Value = DataMgr.VipExpirationTime.Value + days * 24 * 60 * 60;
|
||||
}
|
||||
else DataMgr.VipExpirationTime.Value = ServerClock.GetCurrentServerTime() + days * 24 * 60 * 60;
|
||||
}
|
||||
DataMgr.VipLevel.Value = suffixNum + 1;
|
||||
}
|
||||
purch_number = ConfigSystem.GetConfig<VipClub>()[suffixNum].DiscountPrice.ToString();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.BuyVip);
|
||||
}
|
||||
else if (type.StartsWith("secret_albnums"))
|
||||
{
|
||||
is_maxPay = true;
|
||||
int startIndex = "secret_albnums".Length;
|
||||
string suffix = type[startIndex..]; // 截取 "gold" 后的所有字符
|
||||
int suffix_num = int.Parse(suffix);
|
||||
var model = ConfigSystem.GetSecretAlbumsConfig()[suffix_num];
|
||||
if (model.PayType == (int)UnlockPayType.Pay && !GameHelper.isVipUnlock)
|
||||
{
|
||||
purch_number = ConfigSystem.GetSecretAlbumsConfig()[suffix_num].DiscountPrice.ToString();
|
||||
}
|
||||
GameHelper.isVipUnlock = false;
|
||||
}
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PayloadingUI_Close);
|
||||
|
||||
if ((!GameHelper.IsAdModelOfPay() || is_maxPay) && !string.IsNullOrEmpty(purch_number) && decimal.TryParse(purch_number, out decimal revenue))
|
||||
{
|
||||
var revenueNum = (int)(purch_number.As<decimal>() * 10000);
|
||||
var payType = MaxPayManager.isIOSPay ? 0 : 1;
|
||||
|
||||
// 付费上报BI
|
||||
BIManager.Instance.TrackPurchase(purch_number.As<double>(), "USD", payType.ToString(), type, "paid");
|
||||
|
||||
Debug.Log("付费收益上报AF----------- " + revenue);
|
||||
adCallbackInfo.Clear();
|
||||
adCallbackInfo.Add("appsflyer_id", AppsFlyer.getAppsFlyerId());
|
||||
adCallbackInfo.Add("customer_user_id", GameHelper.GetLoginModel().Uid.ToString());
|
||||
adCallbackInfo.Add("af_currency", "USD");
|
||||
adCallbackInfo.Add("af_revenue", revenue.ToString(CultureInfo.InvariantCulture));
|
||||
AppsFlyer.sendEvent("af_purchase", adCallbackInfo);
|
||||
|
||||
TrackKit.SendEvent(AfPurchaseTrack.Event, AfPurchaseTrack.Property.af_revenue, (int)(purch_number.As<decimal>() * 10000));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static Dictionary<string, string> adCallbackInfo = new Dictionary<string, string>();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,378 +1,378 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using FairyGUI;
|
||||
using FGUI.LG_secretAlbums;
|
||||
using SGModule.NetKit;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class SecretAlbumsUI : BaseUI
|
||||
{
|
||||
private const int MaxVisibleCount = 6; // 一屏显示6个
|
||||
private const int PreloadCount = 2; // 上下各预加载一屏
|
||||
|
||||
private readonly Dictionary<int, bool> _fileIsExist = new();
|
||||
private readonly Dictionary<int, GLoader> activeLoaders = new();
|
||||
private SecretAlbumsUICtrl ctrl;
|
||||
private SecretAlbumsModel model;
|
||||
private com_scAlbums ui;
|
||||
|
||||
public SecretAlbumsUI(SecretAlbumsUICtrl ctrl) : base(ctrl)
|
||||
{
|
||||
uiName = UIConst.SecretAlbumsUI;
|
||||
this.ctrl = ctrl;
|
||||
}
|
||||
|
||||
protected override void SetUIInfo(UIInfo uiInfo)
|
||||
{
|
||||
uiInfo.packageName = "LG_secretAlbums";
|
||||
uiInfo.assetName = "com_scAlbums";
|
||||
uiInfo.layerType = UILayerType.Popup;
|
||||
uiInfo.isNeedOpenAnim = false;
|
||||
uiInfo.isNeedCloseAnim = false;
|
||||
uiInfo.isNeedUIMask = true;
|
||||
}
|
||||
|
||||
private void UnlockSuccess(object str = null)
|
||||
{
|
||||
ui.sc_list.itemRenderer = ItemRender;
|
||||
ui.sc_list.numItems = _secretData.Count;
|
||||
}
|
||||
|
||||
|
||||
// 初始化页面逻辑
|
||||
private void InitView()
|
||||
{
|
||||
ui.btn_gold.GetChild("text_gold").text = GameHelper.Get101Str();
|
||||
ui.btn_close.SetClick(CtrlCloseUI);
|
||||
|
||||
UnlockSuccess();
|
||||
|
||||
|
||||
// 滚动过程中实时刷新可见播放器
|
||||
// ui.sc_list.scrollPane.onScrollEnd.Add(OnScrollEnd);
|
||||
|
||||
// 打开页面时初始化一次
|
||||
// OnScrollEnd();
|
||||
InitScroll();
|
||||
}
|
||||
|
||||
private void InitScroll()
|
||||
{
|
||||
ui.sc_list.scrollPane.onScroll.Add(OnScrollUpdate);
|
||||
ui.sc_list.scrollPane.onScrollEnd.Add(OnScrollEnd); // 保留结束时的整理
|
||||
|
||||
OnScrollEnd();
|
||||
}
|
||||
|
||||
// 滑动过程中实时更新
|
||||
private void OnScrollUpdate()
|
||||
{
|
||||
UpdateVisibleAndPreload();
|
||||
}
|
||||
|
||||
// 核心刷新逻辑
|
||||
private void UpdateVisibleAndPreload()
|
||||
{
|
||||
if (_secretData == null || _secretData.Count == 0) return;
|
||||
|
||||
var firstVisibleIndex = ui.sc_list.GetFirstChildInView();
|
||||
var lastVisibleIndex = Mathf.Min(firstVisibleIndex + MaxVisibleCount - 1, ui.sc_list.numItems - 1);
|
||||
|
||||
var startIndex = Mathf.Max(0, firstVisibleIndex - PreloadCount);
|
||||
var endIndex = Mathf.Min(ui.sc_list.numItems - 1, lastVisibleIndex + PreloadCount);
|
||||
|
||||
// 回收超出范围 loader
|
||||
var keysToRemove = new List<int>();
|
||||
foreach (var kv in activeLoaders)
|
||||
{
|
||||
var idx = kv.Key;
|
||||
if (idx < startIndex || idx > endIndex)
|
||||
{
|
||||
GLoaderPool.Instance.ReturnLoader(kv.Value);
|
||||
var oldItem = ui.sc_list.GetChildAt(idx) as item_scalnums;
|
||||
if (oldItem != null) oldItem.com_pic.picture = null;
|
||||
keysToRemove.Add(idx);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var k in keysToRemove) activeLoaders.Remove(k);
|
||||
|
||||
|
||||
// 分配 loader 并加载图片
|
||||
for (var i = startIndex; i <= endIndex; i++)
|
||||
{
|
||||
if (activeLoaders.ContainsKey(i)) continue;
|
||||
|
||||
var item = ui.sc_list.GetChildAt(i) as item_scalnums;
|
||||
if (item == null) continue;
|
||||
|
||||
if (item.com_pic.picture != null && !item.com_pic.picture.isDisposed)
|
||||
GLoaderPool.Instance.ReturnLoader(item.com_pic.picture);
|
||||
|
||||
var loader = GLoaderPool.Instance.GetLoader();
|
||||
item.com_pic.picture = loader;
|
||||
item.com_pic.AddChild(loader);
|
||||
loader.SetSize(item.com_pic.width, item.com_pic.height);
|
||||
|
||||
_fileIsExist.TryGetValue(i, out var value);
|
||||
if (!value)
|
||||
{
|
||||
var localPath = Path.Combine(TextureHelper.getResPath(), _secretData[i].Name + ".jpg");
|
||||
|
||||
if (File.Exists(localPath))
|
||||
{
|
||||
_fileIsExist[i] = true;
|
||||
Debug.Log($"[SetImgLoader] 本地存在,直接加载 {_secretData[i].Name}");
|
||||
CrazyAsyKit.StartCoroutine(TextureHelper.LoadTexture(_secretData[i].Name, loader, null,
|
||||
"SecretAlbums/"));
|
||||
}
|
||||
else
|
||||
{
|
||||
_fileIsExist[i] = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CrazyAsyKit.StartCoroutine(TextureHelper.LoadTexture(_secretData[i].Name, loader, null,
|
||||
"SecretAlbums/"));
|
||||
}
|
||||
|
||||
activeLoaders[i] = loader;
|
||||
}
|
||||
|
||||
// Debug.Log($"[ScrollUpdate] active loaders={activeLoaders.Count}, pool={GLoaderPool.Instance.GetPoolCount()}, inUse={GLoaderPool.Instance.GetInUseCount()}");
|
||||
}
|
||||
|
||||
private void OnScrollEnd()
|
||||
{
|
||||
if (_secretData == null || _secretData.Count == 0) return;
|
||||
|
||||
var firstVisibleIndex = ui.sc_list.GetFirstChildInView();
|
||||
var lastVisibleIndex = Mathf.Min(firstVisibleIndex + MaxVisibleCount - 1, ui.sc_list.numItems - 1);
|
||||
|
||||
var startIndex = Mathf.Max(0, firstVisibleIndex - PreloadCount);
|
||||
var endIndex = Mathf.Min(ui.sc_list.numItems - 1, lastVisibleIndex + PreloadCount);
|
||||
|
||||
// Debug.Log($"[ScrollEnd] start index={startIndex} end index={endIndex}");
|
||||
|
||||
|
||||
var tasks = new List<(GLoader loader, string fileName, Action<NTexture> callback, string folder, string localFolder)>();
|
||||
// 分配 loader 并加载图片
|
||||
for (var i = startIndex; i <= endIndex; i++)
|
||||
{
|
||||
_fileIsExist.TryGetValue(i, out var value);
|
||||
|
||||
if (value) continue;
|
||||
var item = ui.sc_list.GetChildAt(i) as item_scalnums;
|
||||
if (item == null) continue;
|
||||
if (item.com_pic.picture != null && !item.com_pic.picture.isDisposed)
|
||||
GLoaderPool.Instance.ReturnLoader(item.com_pic.picture);
|
||||
var loader = GLoaderPool.Instance.GetLoader();
|
||||
item.com_pic.picture = loader;
|
||||
item.com_pic.AddChild(loader);
|
||||
loader.SetSize(item.com_pic.width, item.com_pic.height);
|
||||
|
||||
var idx = i;
|
||||
tasks.Add((loader, _secretData[i].Name, texture =>
|
||||
{
|
||||
if (texture != null) _fileIsExist[idx] = true;
|
||||
}, "SecretAlbums/", FolderNames.SecretName));
|
||||
|
||||
activeLoaders[i] = loader;
|
||||
}
|
||||
|
||||
TextureHelper.SetImgLoaders(tasks);
|
||||
}
|
||||
|
||||
|
||||
private void ItemRender(int index, GObject obj)
|
||||
{
|
||||
var item = (item_scalnums)obj;
|
||||
|
||||
item.text_id.text = _secretData[index].id.ToString();
|
||||
|
||||
var isUnlock = DataMgr.SecretUnlockList.Value.Contains(index);
|
||||
|
||||
item.btn_unlock.pay_type.selectedIndex = _secretData[index].PayType;
|
||||
|
||||
if (_secretData[index].PayType == 0)
|
||||
item.btn_unlock.title = GameHelper.getPrice((decimal)_secretData[index].DiscountPrice);
|
||||
else if (_secretData[index].PayType == 1)
|
||||
item.btn_unlock.title = _secretData[index].GoldCoins.ToString();
|
||||
else if (_secretData[index].PayType == 2) item.btn_unlock.title = _secretData[index].AD + "AD";
|
||||
|
||||
if (isUnlock)
|
||||
{
|
||||
item.btn_unlock.pay_type.selectedIndex = 3;
|
||||
if (_secretData[index].SubscribeUnlock == 1)
|
||||
{
|
||||
item.vip.selectedIndex = 1;
|
||||
item.btn_unlock.pay_type.selectedIndex = 5;
|
||||
}
|
||||
item.btn_unlock.title = Language.GetContent("go");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_secretData[index].SubscribeUnlock == 1)
|
||||
{
|
||||
item.vip.selectedIndex = 1;
|
||||
item.btn_unlock.pay_type.selectedIndex = 4;
|
||||
}
|
||||
}
|
||||
|
||||
item.btn_null.SetClick(GotoNext);
|
||||
|
||||
item.un_lock.selectedIndex = isUnlock ? 1 : 0;
|
||||
|
||||
item.btn_unlock.SetClick(GotoNext);
|
||||
|
||||
item.peple_num.text = GetPepleNum(_secretData[index].Quantity).ToString();
|
||||
|
||||
item.hot.selectedIndex = _secretData[index].HotType;
|
||||
|
||||
void GotoNext()
|
||||
{
|
||||
var data = new AlbumPreviewData
|
||||
{
|
||||
Index = index,
|
||||
State = _secretData[index].State,
|
||||
Price = _secretData[index].Price,
|
||||
PayType = _secretData[index].PayType,
|
||||
SubscribeUnlock = _secretData[index].SubscribeUnlock,
|
||||
DiscountPrice = _secretData[index].DiscountPrice,
|
||||
Name = _secretData[index].Name,
|
||||
Name2 = _secretData[index].Name2,
|
||||
GoldCoins = _secretData[index].GoldCoins,
|
||||
AD = _secretData[index].AD,
|
||||
CD = _secretData[index].CD
|
||||
};
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.SecretAlbumsNextUI_Open, data);
|
||||
}
|
||||
}
|
||||
|
||||
private int GetPepleNum(float quantity)
|
||||
{
|
||||
// 获取当前时间
|
||||
var now = DateTime.Now;
|
||||
|
||||
// 计算当天已经过去的分钟数(从凌晨 0 点开始算)
|
||||
var minutesPassedToday = now.Hour * 60 + now.Minute;
|
||||
|
||||
// 计算人数
|
||||
var num = Mathf.FloorToInt(quantity * minutesPassedToday);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
#region 生命周期
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
// 初始化GLoader池,设置最大缓存数
|
||||
GLoaderPool.Instance.Init(null, 10, 464, 642);
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
// 1. 解除 UI 对 Loader 的引用
|
||||
for (var i = 0; i < ui.sc_list.numChildren; i++)
|
||||
{
|
||||
var item = ui.sc_list.GetChildAt(i) as item_scalnums;
|
||||
if (item != null && item.com_pic.picture != null) item.com_pic.picture = null; // 清掉 GLoader 引用
|
||||
}
|
||||
|
||||
activeLoaders.Clear();
|
||||
_fileIsExist.Clear();
|
||||
|
||||
GLoaderPool.Instance.DisposeAll();
|
||||
|
||||
TextureHelper.ClearMaterialPool();
|
||||
|
||||
// 强制卸载未使用的资源
|
||||
Resources.UnloadUnusedAssets();
|
||||
MemoryManager.CleanMemoryMonitor();
|
||||
}
|
||||
|
||||
protected override void OnBind()
|
||||
{
|
||||
ui = baseUI as com_scAlbums;
|
||||
}
|
||||
|
||||
private List<SecretAlbums> _secretData = new();
|
||||
|
||||
protected override void OnOpenBefore(object args)
|
||||
{
|
||||
if (Screen.safeArea.y != 0)
|
||||
{
|
||||
ui.btn_gold.y += 68;
|
||||
ui.btn_close.y += 68;
|
||||
ui.sc_list.y += 68;
|
||||
}
|
||||
|
||||
var eventName = GameHelper.IsAdModelOfPay() ? ADEventTrack.Event : ADEventTrack.MaxPayEvent;
|
||||
TrackKit.SendEvent(eventName, ADEventTrack.Property.shop_show);
|
||||
|
||||
_secretData = ConfigSystem.GetConfig<SecretAlbums>();
|
||||
InitView();
|
||||
}
|
||||
|
||||
protected override void OnOpen(object args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisplay(object args)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
public void SetTopCurr(object a = null)
|
||||
{
|
||||
ui.btn_gold.GetChild("text_gold").text = GameHelper.Get101Str();
|
||||
}
|
||||
protected override void AddListener()
|
||||
{
|
||||
GameDispatcher.Instance.AddListener(GameMsg.UnlockSecretSuccess, UnlockSuccess);
|
||||
GameDispatcher.Instance.AddListener(GameMsg.Update101, SetTopCurr);
|
||||
}
|
||||
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.UnlockSecretSuccess, UnlockSuccess);
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.Update101, SetTopCurr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class AlbumPreviewData
|
||||
{
|
||||
public int AD;
|
||||
public int CD;
|
||||
public float DiscountPrice;
|
||||
public int GoldCoins;
|
||||
public int Index;
|
||||
public string Name;
|
||||
public string Name2;
|
||||
public int PayType;
|
||||
public float Price;
|
||||
public int[] State;
|
||||
public int SubscribeUnlock;
|
||||
}
|
||||
|
||||
public enum UnlockPayType
|
||||
{
|
||||
Pay = 0,
|
||||
Coin = 1,
|
||||
Ad = 2,
|
||||
None = 3
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using FairyGUI;
|
||||
using FGUI.LG_secretAlbums;
|
||||
using SGModule.NetKit;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class SecretAlbumsUI : BaseUI
|
||||
{
|
||||
private const int MaxVisibleCount = 6; // 一屏显示6个
|
||||
private const int PreloadCount = 2; // 上下各预加载一屏
|
||||
|
||||
private readonly Dictionary<int, bool> _fileIsExist = new();
|
||||
private readonly Dictionary<int, GLoader> activeLoaders = new();
|
||||
private SecretAlbumsUICtrl ctrl;
|
||||
private SecretAlbumsModel model;
|
||||
private com_scAlbums ui;
|
||||
|
||||
public SecretAlbumsUI(SecretAlbumsUICtrl ctrl) : base(ctrl)
|
||||
{
|
||||
uiName = UIConst.SecretAlbumsUI;
|
||||
this.ctrl = ctrl;
|
||||
}
|
||||
|
||||
protected override void SetUIInfo(UIInfo uiInfo)
|
||||
{
|
||||
uiInfo.packageName = "LG_secretAlbums";
|
||||
uiInfo.assetName = "com_scAlbums";
|
||||
uiInfo.layerType = UILayerType.Popup;
|
||||
uiInfo.isNeedOpenAnim = false;
|
||||
uiInfo.isNeedCloseAnim = false;
|
||||
uiInfo.isNeedUIMask = true;
|
||||
}
|
||||
|
||||
private void UnlockSuccess(object str = null)
|
||||
{
|
||||
ui.sc_list.itemRenderer = ItemRender;
|
||||
ui.sc_list.numItems = _secretData.Count;
|
||||
}
|
||||
|
||||
|
||||
// 初始化页面逻辑
|
||||
private void InitView()
|
||||
{
|
||||
ui.btn_gold.GetChild("text_gold").text = GameHelper.Get101Str();
|
||||
ui.btn_close.SetClick(CtrlCloseUI);
|
||||
|
||||
UnlockSuccess();
|
||||
|
||||
|
||||
// 滚动过程中实时刷新可见播放器
|
||||
// ui.sc_list.scrollPane.onScrollEnd.Add(OnScrollEnd);
|
||||
|
||||
// 打开页面时初始化一次
|
||||
// OnScrollEnd();
|
||||
InitScroll();
|
||||
}
|
||||
|
||||
private void InitScroll()
|
||||
{
|
||||
ui.sc_list.scrollPane.onScroll.Add(OnScrollUpdate);
|
||||
ui.sc_list.scrollPane.onScrollEnd.Add(OnScrollEnd); // 保留结束时的整理
|
||||
|
||||
OnScrollEnd();
|
||||
}
|
||||
|
||||
// 滑动过程中实时更新
|
||||
private void OnScrollUpdate()
|
||||
{
|
||||
UpdateVisibleAndPreload();
|
||||
}
|
||||
|
||||
// 核心刷新逻辑
|
||||
private void UpdateVisibleAndPreload()
|
||||
{
|
||||
if (_secretData == null || _secretData.Count == 0) return;
|
||||
|
||||
var firstVisibleIndex = ui.sc_list.GetFirstChildInView();
|
||||
var lastVisibleIndex = Mathf.Min(firstVisibleIndex + MaxVisibleCount - 1, ui.sc_list.numItems - 1);
|
||||
|
||||
var startIndex = Mathf.Max(0, firstVisibleIndex - PreloadCount);
|
||||
var endIndex = Mathf.Min(ui.sc_list.numItems - 1, lastVisibleIndex + PreloadCount);
|
||||
|
||||
// 回收超出范围 loader
|
||||
var keysToRemove = new List<int>();
|
||||
foreach (var kv in activeLoaders)
|
||||
{
|
||||
var idx = kv.Key;
|
||||
if (idx < startIndex || idx > endIndex)
|
||||
{
|
||||
GLoaderPool.Instance.ReturnLoader(kv.Value);
|
||||
var oldItem = ui.sc_list.GetChildAt(idx) as item_scalnums;
|
||||
if (oldItem != null) oldItem.com_pic.picture = null;
|
||||
keysToRemove.Add(idx);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var k in keysToRemove) activeLoaders.Remove(k);
|
||||
|
||||
|
||||
// 分配 loader 并加载图片
|
||||
for (var i = startIndex; i <= endIndex; i++)
|
||||
{
|
||||
if (activeLoaders.ContainsKey(i)) continue;
|
||||
|
||||
var item = ui.sc_list.GetChildAt(i) as item_scalnums;
|
||||
if (item == null) continue;
|
||||
|
||||
if (item.com_pic.picture != null && !item.com_pic.picture.isDisposed)
|
||||
GLoaderPool.Instance.ReturnLoader(item.com_pic.picture);
|
||||
|
||||
var loader = GLoaderPool.Instance.GetLoader();
|
||||
item.com_pic.picture = loader;
|
||||
item.com_pic.AddChild(loader);
|
||||
loader.SetSize(item.com_pic.width, item.com_pic.height);
|
||||
|
||||
_fileIsExist.TryGetValue(i, out var value);
|
||||
if (!value)
|
||||
{
|
||||
var localPath = Path.Combine(TextureHelper.getResPath(), _secretData[i].Name + ".jpg");
|
||||
|
||||
if (File.Exists(localPath))
|
||||
{
|
||||
_fileIsExist[i] = true;
|
||||
Debug.Log($"[SetImgLoader] 本地存在,直接加载 {_secretData[i].Name}");
|
||||
CrazyAsyKit.StartCoroutine(TextureHelper.LoadTexture(_secretData[i].Name, loader, null,
|
||||
"SecretAlbums/"));
|
||||
}
|
||||
else
|
||||
{
|
||||
_fileIsExist[i] = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CrazyAsyKit.StartCoroutine(TextureHelper.LoadTexture(_secretData[i].Name, loader, null,
|
||||
"SecretAlbums/"));
|
||||
}
|
||||
|
||||
activeLoaders[i] = loader;
|
||||
}
|
||||
|
||||
// Debug.Log($"[ScrollUpdate] active loaders={activeLoaders.Count}, pool={GLoaderPool.Instance.GetPoolCount()}, inUse={GLoaderPool.Instance.GetInUseCount()}");
|
||||
}
|
||||
|
||||
private void OnScrollEnd()
|
||||
{
|
||||
if (_secretData == null || _secretData.Count == 0) return;
|
||||
|
||||
var firstVisibleIndex = ui.sc_list.GetFirstChildInView();
|
||||
var lastVisibleIndex = Mathf.Min(firstVisibleIndex + MaxVisibleCount - 1, ui.sc_list.numItems - 1);
|
||||
|
||||
var startIndex = Mathf.Max(0, firstVisibleIndex - PreloadCount);
|
||||
var endIndex = Mathf.Min(ui.sc_list.numItems - 1, lastVisibleIndex + PreloadCount);
|
||||
|
||||
// Debug.Log($"[ScrollEnd] start index={startIndex} end index={endIndex}");
|
||||
|
||||
|
||||
var tasks = new List<(GLoader loader, string fileName, Action<NTexture> callback, string folder, string localFolder)>();
|
||||
// 分配 loader 并加载图片
|
||||
for (var i = startIndex; i <= endIndex; i++)
|
||||
{
|
||||
_fileIsExist.TryGetValue(i, out var value);
|
||||
|
||||
if (value) continue;
|
||||
var item = ui.sc_list.GetChildAt(i) as item_scalnums;
|
||||
if (item == null) continue;
|
||||
if (item.com_pic.picture != null && !item.com_pic.picture.isDisposed)
|
||||
GLoaderPool.Instance.ReturnLoader(item.com_pic.picture);
|
||||
var loader = GLoaderPool.Instance.GetLoader();
|
||||
item.com_pic.picture = loader;
|
||||
item.com_pic.AddChild(loader);
|
||||
loader.SetSize(item.com_pic.width, item.com_pic.height);
|
||||
|
||||
var idx = i;
|
||||
tasks.Add((loader, _secretData[i].Name, texture =>
|
||||
{
|
||||
if (texture != null) _fileIsExist[idx] = true;
|
||||
}, "SecretAlbums/", FolderNames.SecretName));
|
||||
|
||||
activeLoaders[i] = loader;
|
||||
}
|
||||
|
||||
TextureHelper.SetImgLoaders(tasks);
|
||||
}
|
||||
|
||||
|
||||
private void ItemRender(int index, GObject obj)
|
||||
{
|
||||
var item = (item_scalnums)obj;
|
||||
|
||||
item.text_id.text = _secretData[index].id.ToString();
|
||||
|
||||
var isUnlock = DataMgr.SecretUnlockList.Value.Contains(index);
|
||||
|
||||
item.btn_unlock.pay_type.selectedIndex = _secretData[index].PayType;
|
||||
|
||||
if (_secretData[index].PayType == 0)
|
||||
item.btn_unlock.title = GameHelper.getPrice((decimal)_secretData[index].DiscountPrice);
|
||||
else if (_secretData[index].PayType == 1)
|
||||
item.btn_unlock.title = _secretData[index].GoldCoins.ToString();
|
||||
else if (_secretData[index].PayType == 2) item.btn_unlock.title = _secretData[index].AD + "AD";
|
||||
|
||||
if (isUnlock)
|
||||
{
|
||||
item.btn_unlock.pay_type.selectedIndex = 3;
|
||||
if (_secretData[index].SubscribeUnlock == 1)
|
||||
{
|
||||
item.vip.selectedIndex = 1;
|
||||
item.btn_unlock.pay_type.selectedIndex = 5;
|
||||
}
|
||||
item.btn_unlock.title = Language.GetContent("go");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_secretData[index].SubscribeUnlock == 1)
|
||||
{
|
||||
item.vip.selectedIndex = 1;
|
||||
item.btn_unlock.pay_type.selectedIndex = 4;
|
||||
}
|
||||
}
|
||||
|
||||
item.btn_null.SetClick(GotoNext);
|
||||
|
||||
item.un_lock.selectedIndex = isUnlock ? 1 : 0;
|
||||
|
||||
item.btn_unlock.SetClick(GotoNext);
|
||||
|
||||
item.peple_num.text = GetPepleNum(_secretData[index].Quantity).ToString();
|
||||
|
||||
item.hot.selectedIndex = _secretData[index].HotType;
|
||||
|
||||
void GotoNext()
|
||||
{
|
||||
var data = new AlbumPreviewData
|
||||
{
|
||||
Index = index,
|
||||
State = _secretData[index].State,
|
||||
Price = _secretData[index].Price,
|
||||
PayType = _secretData[index].PayType,
|
||||
SubscribeUnlock = _secretData[index].SubscribeUnlock,
|
||||
DiscountPrice = _secretData[index].DiscountPrice,
|
||||
Name = _secretData[index].Name,
|
||||
Name2 = _secretData[index].Name2,
|
||||
GoldCoins = _secretData[index].GoldCoins,
|
||||
AD = _secretData[index].AD,
|
||||
CD = _secretData[index].CD
|
||||
};
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.SecretAlbumsNextUI_Open, data);
|
||||
}
|
||||
}
|
||||
|
||||
private int GetPepleNum(float quantity)
|
||||
{
|
||||
// 获取当前时间
|
||||
var now = DateTime.Now;
|
||||
|
||||
// 计算当天已经过去的分钟数(从凌晨 0 点开始算)
|
||||
var minutesPassedToday = now.Hour * 60 + now.Minute;
|
||||
|
||||
// 计算人数
|
||||
var num = Mathf.FloorToInt(quantity * minutesPassedToday);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
#region 生命周期
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
// 初始化GLoader池,设置最大缓存数
|
||||
GLoaderPool.Instance.Init(null, 10, 464, 642);
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
// 1. 解除 UI 对 Loader 的引用
|
||||
for (var i = 0; i < ui.sc_list.numChildren; i++)
|
||||
{
|
||||
var item = ui.sc_list.GetChildAt(i) as item_scalnums;
|
||||
if (item != null && item.com_pic.picture != null) item.com_pic.picture = null; // 清掉 GLoader 引用
|
||||
}
|
||||
|
||||
activeLoaders.Clear();
|
||||
_fileIsExist.Clear();
|
||||
|
||||
GLoaderPool.Instance.DisposeAll();
|
||||
|
||||
TextureHelper.ClearMaterialPool();
|
||||
|
||||
// 强制卸载未使用的资源
|
||||
Resources.UnloadUnusedAssets();
|
||||
MemoryManager.CleanMemoryMonitor();
|
||||
}
|
||||
|
||||
protected override void OnBind()
|
||||
{
|
||||
ui = baseUI as com_scAlbums;
|
||||
}
|
||||
|
||||
private List<SecretAlbums> _secretData = new();
|
||||
|
||||
protected override void OnOpenBefore(object args)
|
||||
{
|
||||
if (Screen.safeArea.y != 0)
|
||||
{
|
||||
ui.btn_gold.y += 68;
|
||||
ui.btn_close.y += 68;
|
||||
ui.sc_list.y += 68;
|
||||
}
|
||||
|
||||
var eventName = GameHelper.IsAdModelOfPay() ? ADEventTrack.Event : ADEventTrack.MaxPayEvent;
|
||||
TrackKit.SendEvent(eventName, ADEventTrack.Property.shop_show);
|
||||
|
||||
_secretData = ConfigSystem.GetSecretAlbumsConfig();
|
||||
InitView();
|
||||
}
|
||||
|
||||
protected override void OnOpen(object args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisplay(object args)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
public void SetTopCurr(object a = null)
|
||||
{
|
||||
ui.btn_gold.GetChild("text_gold").text = GameHelper.Get101Str();
|
||||
}
|
||||
protected override void AddListener()
|
||||
{
|
||||
GameDispatcher.Instance.AddListener(GameMsg.UnlockSecretSuccess, UnlockSuccess);
|
||||
GameDispatcher.Instance.AddListener(GameMsg.Update101, SetTopCurr);
|
||||
}
|
||||
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.UnlockSecretSuccess, UnlockSuccess);
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.Update101, SetTopCurr);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class AlbumPreviewData
|
||||
{
|
||||
public int AD;
|
||||
public int CD;
|
||||
public float DiscountPrice;
|
||||
public int GoldCoins;
|
||||
public int Index;
|
||||
public string Name;
|
||||
public string Name2;
|
||||
public int PayType;
|
||||
public float Price;
|
||||
public int[] State;
|
||||
public int SubscribeUnlock;
|
||||
}
|
||||
|
||||
public enum UnlockPayType
|
||||
{
|
||||
Pay = 0,
|
||||
Coin = 1,
|
||||
Ad = 2,
|
||||
None = 3
|
||||
}
|
||||
}
|
||||
@@ -1,248 +1,248 @@
|
||||
|
||||
using FGUI.ZM_Common_01;
|
||||
using UnityEngine;
|
||||
using FairyGUI;
|
||||
using FGUI.LG_Common;
|
||||
using DG.Tweening;
|
||||
using SGModule.NetKit;
|
||||
using System.Collections.Generic;
|
||||
using SGModule.Common.Extensions;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class UnlockLevelUI : BaseUI
|
||||
{
|
||||
private UnlockLevelUICtrl ctrl;
|
||||
private UnlockLevelModel model;
|
||||
private FGUI.LG_End.com_unlockLevel ui;
|
||||
|
||||
public UnlockLevelUI(UnlockLevelUICtrl ctrl) : base(ctrl)
|
||||
{
|
||||
uiName = UIConst.UnlockLevelUI;
|
||||
this.ctrl = ctrl;
|
||||
}
|
||||
|
||||
protected override void SetUIInfo(UIInfo uiInfo)
|
||||
{
|
||||
uiInfo.packageName = "LG_End";
|
||||
uiInfo.assetName = "com_unlockLevel";
|
||||
uiInfo.layerType = UILayerType.Popup;
|
||||
uiInfo.isNeedOpenAnim = false;
|
||||
uiInfo.isNeedCloseAnim = false;
|
||||
uiInfo.isNeedUIMask = true;
|
||||
}
|
||||
|
||||
#region 生命周期
|
||||
protected override void OnInit()
|
||||
{
|
||||
//model = ModuleManager.Instance.GetModel(ModelConst.UnlockLevelModel) as UnlockLevelModel;
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
for (int i = 0; i < loader_list.Count; i++)
|
||||
{
|
||||
if (loader_list[i] != null && !loader_list[i].isDisposed && loader_list[i].texture != null)
|
||||
{
|
||||
loader_list[i].texture.Dispose();
|
||||
loader_list[i].texture = null;
|
||||
}
|
||||
}
|
||||
loader_list.Clear();
|
||||
}
|
||||
|
||||
protected override void OnBind()
|
||||
{
|
||||
ui = baseUI as FGUI.LG_End.com_unlockLevel;
|
||||
}
|
||||
private LevelUnlock levelUnlock_;
|
||||
private int level_;
|
||||
protected override void OnOpenBefore(object args)
|
||||
{
|
||||
level_ = (int)args;
|
||||
Debug.Log(level_);
|
||||
|
||||
if (!loader_list.Contains(ui.com_loader.GetChild("loader") as GLoader))
|
||||
{
|
||||
loader_list.Add(ui.com_loader.GetChild("loader") as GLoader);
|
||||
}
|
||||
|
||||
levelUnlock_ = ConfigSystem.GetConfig<LevelUnlock>()[level_];
|
||||
TextureHelper.SetImgLoader(ui.com_loader.GetChild("loader") as GLoader, levelUnlock_.Name, (s) =>
|
||||
{
|
||||
TextureHelper.SetImageBlur(ui.com_loader.GetChild("loader") as GLoader);
|
||||
}, "LevelAlbums/", FolderNames.AlbumName);
|
||||
InitView();
|
||||
if (levelUnlock_.LeveType == 1)
|
||||
{
|
||||
TrackKit.SendEvent(ADEventTrack.Special, ADEventTrack.Property.speciallevel);
|
||||
}
|
||||
else if (levelUnlock_.LeveType == 2)
|
||||
{
|
||||
TrackKit.SendEvent(ADEventTrack.VipLevel, ADEventTrack.Property.viplevel);
|
||||
}
|
||||
|
||||
}
|
||||
private List<GLoader> loader_list = new List<GLoader>();
|
||||
protected override void OnOpen(object args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisplay(object args)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
protected override void AddListener()
|
||||
{
|
||||
GameDispatcher.Instance.AddListener(GameMsg.BuyVip, refrsh);
|
||||
}
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.BuyVip, refrsh);
|
||||
}
|
||||
#endregion
|
||||
private void refrsh(object a = null)
|
||||
{
|
||||
DOVirtual.DelayedCall(0.5f, () =>
|
||||
{
|
||||
InitView();
|
||||
});
|
||||
|
||||
}
|
||||
//初始化页面逻辑
|
||||
private void InitView()
|
||||
{
|
||||
|
||||
|
||||
if (GameHelper.GetVipPrivilege(Subscription.VipLevel.As<int>()))
|
||||
{
|
||||
(ui.btn_vip as btn_claim_2).have_vip.selectedIndex = 1;
|
||||
}
|
||||
if (GameHelper.GetVipPrivilege(Subscription.SLVLevel.As<int>()))
|
||||
{
|
||||
(ui.btn_watch as btn_claim_1).have_vip.selectedIndex = 1;
|
||||
}
|
||||
|
||||
if (levelUnlock_.LeveType == 1) //特殊关
|
||||
{
|
||||
ui.type.selectedIndex = 0;
|
||||
ui.btn_pay.title = levelUnlock_.GoldCoins.ToString();
|
||||
|
||||
ui.btn_pay.SetClick(() =>
|
||||
{
|
||||
if (DataMgr.Coin.Value >= levelUnlock_.GoldCoins)
|
||||
{
|
||||
DataMgr.Coin.Value -= levelUnlock_.GoldCoins;
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
DataMgr.LevelUnlockList.Value.Add(level_);
|
||||
GameHelper.ShowTips("unlocked", true);
|
||||
DataMgr.LevelUnlockList.Save();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockLevelsuccess);
|
||||
CtrlCloseUI();
|
||||
TrackKit.SendEvent(ADEventTrack.Special, ADEventTrack.Property.speciallevelcoin);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
}
|
||||
});
|
||||
|
||||
ui.btn_watch.SetClick(() => //7天都不包含。30天包含特殊,365全部包含
|
||||
{
|
||||
if (GameHelper.GetVipPrivilege(Subscription.SLVLevel.As<int>()))
|
||||
{
|
||||
DataMgr.LevelUnlockList.Value.Add(level_);
|
||||
GameHelper.ShowTips("unlocked", true);
|
||||
DataMgr.LevelUnlockList.Save();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockLevelsuccess);
|
||||
CtrlCloseUI();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowVideoAd("UnlockSpecialLevel", isSuccess =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
DataMgr.LevelUnlockList.Value.Add(level_);
|
||||
GameHelper.ShowTips("unlocked", true);
|
||||
DataMgr.LevelUnlockList.Save();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockLevelsuccess);
|
||||
CtrlCloseUI();
|
||||
}
|
||||
TrackKit.SendEvent(ADEventTrack.Special, ADEventTrack.Property.speciallevelvideo);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
else if (levelUnlock_.LeveType == 2)//vip关
|
||||
{
|
||||
ui.type.selectedIndex = 1;
|
||||
ui.btn_pay.title = levelUnlock_.GoldCoins.ToString();
|
||||
|
||||
ui.btn_pay.SetClick(() =>
|
||||
{
|
||||
if (DataMgr.Coin.Value >= levelUnlock_.GoldCoins)
|
||||
{
|
||||
DataMgr.Coin.Value -= levelUnlock_.GoldCoins;
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
DataMgr.LevelUnlockList.Value.Add(level_);
|
||||
GameHelper.ShowTips("unlocked", true);
|
||||
DataMgr.LevelUnlockList.Save();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockLevelsuccess);
|
||||
TrackKit.SendEvent(ADEventTrack.VipLevel, ADEventTrack.Property.viplevelcoin);
|
||||
CtrlCloseUI();
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
}
|
||||
});
|
||||
ui.btn_vip.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.GetVipPrivilege(Subscription.VipLevel.As<int>()))
|
||||
{
|
||||
DataMgr.LevelUnlockList.Value.Add(level_);
|
||||
GameHelper.ShowTips("unlocked", true);
|
||||
DataMgr.LevelUnlockList.Save();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockLevelsuccess);
|
||||
CtrlCloseUI();
|
||||
}
|
||||
else
|
||||
{
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.VipClubViewUI_Open, 2);
|
||||
TrackKit.SendEvent(ADEventTrack.VipLevel, ADEventTrack.Property.viplevelsub);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
ui.btn_close.SetClick(() =>
|
||||
{
|
||||
GameHelper.SetLevel(GameHelper.GetLevel() + 1);
|
||||
if (UIManager.Instance.IsExistUI(UIConst.NewEndUI))
|
||||
{
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.NewEndUI_Close);
|
||||
}
|
||||
else
|
||||
{
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenGameUI_Open);
|
||||
}
|
||||
|
||||
CtrlCloseUI();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using FGUI.ZM_Common_01;
|
||||
using UnityEngine;
|
||||
using FairyGUI;
|
||||
using FGUI.LG_Common;
|
||||
using DG.Tweening;
|
||||
using SGModule.NetKit;
|
||||
using System.Collections.Generic;
|
||||
using SGModule.Common.Extensions;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class UnlockLevelUI : BaseUI
|
||||
{
|
||||
private UnlockLevelUICtrl ctrl;
|
||||
private UnlockLevelModel model;
|
||||
private FGUI.LG_End.com_unlockLevel ui;
|
||||
|
||||
public UnlockLevelUI(UnlockLevelUICtrl ctrl) : base(ctrl)
|
||||
{
|
||||
uiName = UIConst.UnlockLevelUI;
|
||||
this.ctrl = ctrl;
|
||||
}
|
||||
|
||||
protected override void SetUIInfo(UIInfo uiInfo)
|
||||
{
|
||||
uiInfo.packageName = "LG_End";
|
||||
uiInfo.assetName = "com_unlockLevel";
|
||||
uiInfo.layerType = UILayerType.Popup;
|
||||
uiInfo.isNeedOpenAnim = false;
|
||||
uiInfo.isNeedCloseAnim = false;
|
||||
uiInfo.isNeedUIMask = true;
|
||||
}
|
||||
|
||||
#region 生命周期
|
||||
protected override void OnInit()
|
||||
{
|
||||
//model = ModuleManager.Instance.GetModel(ModelConst.UnlockLevelModel) as UnlockLevelModel;
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
for (int i = 0; i < loader_list.Count; i++)
|
||||
{
|
||||
if (loader_list[i] != null && !loader_list[i].isDisposed && loader_list[i].texture != null)
|
||||
{
|
||||
loader_list[i].texture.Dispose();
|
||||
loader_list[i].texture = null;
|
||||
}
|
||||
}
|
||||
loader_list.Clear();
|
||||
}
|
||||
|
||||
protected override void OnBind()
|
||||
{
|
||||
ui = baseUI as FGUI.LG_End.com_unlockLevel;
|
||||
}
|
||||
private LevelUnlock levelUnlock_;
|
||||
private int level_;
|
||||
protected override void OnOpenBefore(object args)
|
||||
{
|
||||
level_ = (int)args;
|
||||
Debug.Log(level_);
|
||||
|
||||
if (!loader_list.Contains(ui.com_loader.GetChild("loader") as GLoader))
|
||||
{
|
||||
loader_list.Add(ui.com_loader.GetChild("loader") as GLoader);
|
||||
}
|
||||
|
||||
levelUnlock_ = ConfigSystem.GetLevelUnlockConfig()[level_];
|
||||
TextureHelper.SetImgLoader(ui.com_loader.GetChild("loader") as GLoader, levelUnlock_.Name, (s) =>
|
||||
{
|
||||
TextureHelper.SetImageBlur(ui.com_loader.GetChild("loader") as GLoader);
|
||||
}, "LevelAlbums/", FolderNames.AlbumName);
|
||||
InitView();
|
||||
if (levelUnlock_.LeveType == 1)
|
||||
{
|
||||
TrackKit.SendEvent(ADEventTrack.Special, ADEventTrack.Property.speciallevel);
|
||||
}
|
||||
else if (levelUnlock_.LeveType == 2)
|
||||
{
|
||||
TrackKit.SendEvent(ADEventTrack.VipLevel, ADEventTrack.Property.viplevel);
|
||||
}
|
||||
|
||||
}
|
||||
private List<GLoader> loader_list = new List<GLoader>();
|
||||
protected override void OnOpen(object args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisplay(object args)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
protected override void AddListener()
|
||||
{
|
||||
GameDispatcher.Instance.AddListener(GameMsg.BuyVip, refrsh);
|
||||
}
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.BuyVip, refrsh);
|
||||
}
|
||||
#endregion
|
||||
private void refrsh(object a = null)
|
||||
{
|
||||
DOVirtual.DelayedCall(0.5f, () =>
|
||||
{
|
||||
InitView();
|
||||
});
|
||||
|
||||
}
|
||||
//初始化页面逻辑
|
||||
private void InitView()
|
||||
{
|
||||
|
||||
|
||||
if (GameHelper.GetVipPrivilege(Subscription.VipLevel.As<int>()))
|
||||
{
|
||||
(ui.btn_vip as btn_claim_2).have_vip.selectedIndex = 1;
|
||||
}
|
||||
if (GameHelper.GetVipPrivilege(Subscription.SLVLevel.As<int>()))
|
||||
{
|
||||
(ui.btn_watch as btn_claim_1).have_vip.selectedIndex = 1;
|
||||
}
|
||||
|
||||
if (levelUnlock_.LeveType == 1) //特殊关
|
||||
{
|
||||
ui.type.selectedIndex = 0;
|
||||
ui.btn_pay.title = levelUnlock_.GoldCoins.ToString();
|
||||
|
||||
ui.btn_pay.SetClick(() =>
|
||||
{
|
||||
if (DataMgr.Coin.Value >= levelUnlock_.GoldCoins)
|
||||
{
|
||||
DataMgr.Coin.Value -= levelUnlock_.GoldCoins;
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
DataMgr.LevelUnlockList.Value.Add(level_);
|
||||
GameHelper.ShowTips("unlocked", true);
|
||||
DataMgr.LevelUnlockList.Save();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockLevelsuccess);
|
||||
CtrlCloseUI();
|
||||
TrackKit.SendEvent(ADEventTrack.Special, ADEventTrack.Property.speciallevelcoin);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
}
|
||||
});
|
||||
|
||||
ui.btn_watch.SetClick(() => //7天都不包含。30天包含特殊,365全部包含
|
||||
{
|
||||
if (GameHelper.GetVipPrivilege(Subscription.SLVLevel.As<int>()))
|
||||
{
|
||||
DataMgr.LevelUnlockList.Value.Add(level_);
|
||||
GameHelper.ShowTips("unlocked", true);
|
||||
DataMgr.LevelUnlockList.Save();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockLevelsuccess);
|
||||
CtrlCloseUI();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowVideoAd("UnlockSpecialLevel", isSuccess =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
DataMgr.LevelUnlockList.Value.Add(level_);
|
||||
GameHelper.ShowTips("unlocked", true);
|
||||
DataMgr.LevelUnlockList.Save();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockLevelsuccess);
|
||||
CtrlCloseUI();
|
||||
}
|
||||
TrackKit.SendEvent(ADEventTrack.Special, ADEventTrack.Property.speciallevelvideo);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
else if (levelUnlock_.LeveType == 2)//vip关
|
||||
{
|
||||
ui.type.selectedIndex = 1;
|
||||
ui.btn_pay.title = levelUnlock_.GoldCoins.ToString();
|
||||
|
||||
ui.btn_pay.SetClick(() =>
|
||||
{
|
||||
if (DataMgr.Coin.Value >= levelUnlock_.GoldCoins)
|
||||
{
|
||||
DataMgr.Coin.Value -= levelUnlock_.GoldCoins;
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
|
||||
DataMgr.LevelUnlockList.Value.Add(level_);
|
||||
GameHelper.ShowTips("unlocked", true);
|
||||
DataMgr.LevelUnlockList.Save();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockLevelsuccess);
|
||||
TrackKit.SendEvent(ADEventTrack.VipLevel, ADEventTrack.Property.viplevelcoin);
|
||||
CtrlCloseUI();
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
}
|
||||
});
|
||||
ui.btn_vip.SetClick(() =>
|
||||
{
|
||||
if (GameHelper.GetVipPrivilege(Subscription.VipLevel.As<int>()))
|
||||
{
|
||||
DataMgr.LevelUnlockList.Value.Add(level_);
|
||||
GameHelper.ShowTips("unlocked", true);
|
||||
DataMgr.LevelUnlockList.Save();
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockLevelsuccess);
|
||||
CtrlCloseUI();
|
||||
}
|
||||
else
|
||||
{
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.VipClubViewUI_Open, 2);
|
||||
TrackKit.SendEvent(ADEventTrack.VipLevel, ADEventTrack.Property.viplevelsub);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
ui.btn_close.SetClick(() =>
|
||||
{
|
||||
GameHelper.SetLevel(GameHelper.GetLevel() + 1);
|
||||
if (UIManager.Instance.IsExistUI(UIConst.NewEndUI))
|
||||
{
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.NewEndUI_Close);
|
||||
}
|
||||
else
|
||||
{
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenGameUI_Open);
|
||||
}
|
||||
|
||||
CtrlCloseUI();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,490 +1,490 @@
|
||||
|
||||
using FGUI.ZM_Common_01;
|
||||
using UnityEngine;
|
||||
using FairyGUI;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SGModule.Common.Extensions;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.UIElements;
|
||||
using SGModule.NetKit;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class UnlockLevelNewUI : BaseUI
|
||||
{
|
||||
private UnlockLevelNewUICtrl ctrl;
|
||||
private UnlockLevelNewModel model;
|
||||
private FGUI.LG_End.com_unlockLevelNew ui;
|
||||
|
||||
public UnlockLevelNewUI(UnlockLevelNewUICtrl ctrl) : base(ctrl)
|
||||
{
|
||||
uiName = UIConst.UnlockLevelNewUI;
|
||||
this.ctrl = ctrl;
|
||||
}
|
||||
|
||||
protected override void SetUIInfo(UIInfo uiInfo)
|
||||
{
|
||||
uiInfo.packageName = "LG_End";
|
||||
uiInfo.assetName = "com_unlockLevelNew";
|
||||
uiInfo.layerType = UILayerType.Popup;
|
||||
uiInfo.isNeedOpenAnim = false;
|
||||
uiInfo.isNeedCloseAnim = false;
|
||||
uiInfo.isNeedUIMask = true;
|
||||
}
|
||||
|
||||
#region 生命周期
|
||||
protected override void OnInit()
|
||||
{
|
||||
//model = ModuleManager.Instance.GetModel(ModelConst.UnlockLevelNewModel) as UnlockLevelNewModel;
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
// for (int i = 0; i < loader_list.Count; i++)
|
||||
// {
|
||||
// if (loader_list[i] != null && !loader_list[i].isDisposed && loader_list[i].texture != null)
|
||||
// {
|
||||
// loader_list[i].texture = null;
|
||||
// }
|
||||
// }
|
||||
// loader_list.Clear();
|
||||
foreach (var loader in loader_list)
|
||||
{
|
||||
if (loader == null || loader.isDisposed) continue;
|
||||
|
||||
// 释放材质到材质池
|
||||
if (loader.material != null)
|
||||
{
|
||||
TextureHelper.CancelImageBlur(loader); // 自动返回材质池
|
||||
loader.material = null;
|
||||
}
|
||||
|
||||
// 清理 NTexture
|
||||
if (loader.texture != null)
|
||||
{
|
||||
loader.texture.Dispose(); // 销毁 NTexture 对象
|
||||
loader.texture = null;
|
||||
}
|
||||
}
|
||||
loader_list.Clear();
|
||||
}
|
||||
private List<GLoader> loader_list = new List<GLoader>();
|
||||
protected override void OnBind()
|
||||
{
|
||||
ui = baseUI as FGUI.LG_End.com_unlockLevelNew;
|
||||
}
|
||||
|
||||
private bool isHallEnter = false;
|
||||
protected override void OnOpenBefore(object args)
|
||||
{
|
||||
if (args != null)
|
||||
{
|
||||
isHallEnter = (bool)args;
|
||||
}
|
||||
InitView();
|
||||
ui.btn_close.SetClick(() =>
|
||||
{
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.ExitGame);
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.NewEndUI_Close);
|
||||
CtrlCloseUI();
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnOpen(object args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisplay(object args)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
protected override void AddListener()
|
||||
{
|
||||
GameDispatcher.Instance.AddListener(GameMsg.BuyVip, RefreshVip);
|
||||
}
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.BuyVip, RefreshVip);
|
||||
}
|
||||
#endregion
|
||||
private void RefreshVip(object a = null)
|
||||
{
|
||||
bool have_special = GameHelper.GetVipPrivilege(Subscription.SLVLevel.As<int>());
|
||||
SpecialImageLibrary special_ImageLibrary = ConfigSystem.GetConfig<SpecialImageLibrary>()[DataMgr.LevelUnlockSpecial.Value];
|
||||
if (special_ImageLibrary.State == 1 && !have_special) TextureHelper.SetImageBlur(ui.item_2.com_pic.picture);
|
||||
else TextureHelper.CancelImageBlur(ui.item_2.com_pic.picture);
|
||||
|
||||
if (have_special)
|
||||
{
|
||||
ui.item_2.btn_unlock.visible = false;
|
||||
ui.item_2.type.selectedIndex = 0;
|
||||
ui.item_2.btn_skip.SetClick(() =>
|
||||
{
|
||||
SelectLevel(2, DataMgr.LevelUnlockSpecial.Value);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_2.type.selectedIndex = 2;
|
||||
ui.item_2.btn_unlock.visible = true;
|
||||
ui.item_2.btn_skip.SetClick(() =>
|
||||
{
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.VipClubViewUI_Open);
|
||||
});
|
||||
|
||||
if (special_ImageLibrary.GoldCoins > 0)
|
||||
{
|
||||
ui.item_2.btn_unlock.pay_type.selectedIndex = 1;
|
||||
ui.item_2.btn_unlock.title = special_ImageLibrary.GoldCoins.ToString();
|
||||
ui.item_2.btn_unlock.SetClick(() =>
|
||||
{
|
||||
if (DataMgr.Coin.Value >= special_ImageLibrary.GoldCoins)
|
||||
{
|
||||
GameHelper.AddGold(-special_ImageLibrary.GoldCoins);
|
||||
SelectLevel(2, DataMgr.LevelUnlockSpecial.Value);
|
||||
Debug.Log("///////金币解锁");
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_2.btn_unlock.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool have_vip = GameHelper.GetVipPrivilege(Subscription.VipLevel.As<int>());
|
||||
VIPImageLibrary vip_ImageLibrary = ConfigSystem.GetConfig<VIPImageLibrary>()[DataMgr.LevelUnlockVIP.Value];
|
||||
if (vip_ImageLibrary.State == 1 && !have_vip) TextureHelper.SetImageBlur(ui.item_3.com_pic.picture);
|
||||
else TextureHelper.CancelImageBlur(ui.item_3.com_pic.picture);
|
||||
if (have_vip)
|
||||
{
|
||||
ui.item_3.btn_unlock.visible = false;
|
||||
ui.item_3.type.selectedIndex = 0;
|
||||
ui.item_3.btn_skip.SetClick(() =>
|
||||
{
|
||||
SelectLevel(3, DataMgr.LevelUnlockVIP.Value);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_3.type.selectedIndex = 3;
|
||||
ui.item_3.btn_unlock.visible = true;
|
||||
ui.item_3.btn_skip.SetClick(() =>
|
||||
{
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.VipClubViewUI_Open);
|
||||
});
|
||||
|
||||
if (vip_ImageLibrary.GoldCoins > 0)
|
||||
{
|
||||
ui.item_3.btn_unlock.pay_type.selectedIndex = 1;
|
||||
ui.item_3.btn_unlock.title = vip_ImageLibrary.GoldCoins.ToString();
|
||||
ui.item_3.btn_unlock.SetClick(() =>
|
||||
{
|
||||
if (DataMgr.Coin.Value >= vip_ImageLibrary.GoldCoins)
|
||||
{
|
||||
GameHelper.AddGold(-vip_ImageLibrary.GoldCoins);
|
||||
SelectLevel(3, DataMgr.LevelUnlockVIP.Value);
|
||||
Debug.Log("///////金币解锁");
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_3.btn_unlock.visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//初始化页面逻辑
|
||||
private void InitView()
|
||||
{
|
||||
Debug.Log(JsonConvert.SerializeObject(ConfigSystem.GetConfig<FreeImageLibrary>()) + "..................");
|
||||
Debug.Log(JsonConvert.SerializeObject(ConfigSystem.GetConfig<ADImageLibrary>()) + "..................");
|
||||
Debug.Log(JsonConvert.SerializeObject(ConfigSystem.GetConfig<SpecialImageLibrary>()) + "..................");
|
||||
Debug.Log(JsonConvert.SerializeObject(ConfigSystem.GetConfig<VIPImageLibrary>()) + "..................");
|
||||
|
||||
ConfigSystem.GetConfig<VIPImageLibrary>();
|
||||
|
||||
loader_list.Add(ui.item_0.com_pic.picture);
|
||||
loader_list.Add(ui.item_1.com_pic.picture);
|
||||
loader_list.Add(ui.item_2.com_pic.picture);
|
||||
loader_list.Add(ui.item_3.com_pic.picture);
|
||||
|
||||
// List<int> free_level_list = new List<int>();
|
||||
// List<int> ad_level_list = new List<int>();
|
||||
// List<int> special_level_list = new List<int>();
|
||||
// List<int> vip_level_list = new List<int>();
|
||||
// for (int i = 0; i < DataMgr.LevelUnlockListNew.Value.Count; i++)
|
||||
// {
|
||||
// if (DataMgr.LevelUnlockListNew.Value[i].type == 0) free_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
// else if (DataMgr.LevelUnlockListNew.Value[i].type == 1) ad_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
// else if (DataMgr.LevelUnlockListNew.Value[i].type == 2) special_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
// else if (DataMgr.LevelUnlockListNew.Value[i].type == 3) vip_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
// }
|
||||
int Free_Alubum_0 = PlayerPrefs.GetInt("Free_Alubum_0", -1);
|
||||
|
||||
int AD_Alubum = PlayerPrefs.GetInt("AD_Alubum", -1);
|
||||
int Spec_Alubum = PlayerPrefs.GetInt("Spec_Alubum", -1);
|
||||
int Vip_Alubum = PlayerPrefs.GetInt("Vip_Alubum", -1);
|
||||
|
||||
if (DataMgr.LevelUnlockFree.Value < 0)
|
||||
{
|
||||
DataMgr.LevelUnlockFree.Value = Free_Alubum_0;
|
||||
}
|
||||
|
||||
if (DataMgr.LevelUnlockAD.Value < 0)
|
||||
{
|
||||
DataMgr.LevelUnlockAD.Value = AD_Alubum;
|
||||
}
|
||||
|
||||
if (DataMgr.LevelUnlockSpecial.Value < 0)
|
||||
{
|
||||
DataMgr.LevelUnlockSpecial.Value = Spec_Alubum;
|
||||
}
|
||||
|
||||
if (DataMgr.LevelUnlockVIP.Value < 0)
|
||||
{
|
||||
DataMgr.LevelUnlockVIP.Value = Vip_Alubum;
|
||||
}
|
||||
|
||||
|
||||
FreeImageLibrary free_ImageLibrary = ConfigSystem.GetConfig<FreeImageLibrary>()[DataMgr.LevelUnlockFree.Value];
|
||||
ui.item_0.btn_unlock.pay_type.selectedIndex = 2;
|
||||
ui.item_0_re.btn_unlock.visible = false;
|
||||
TextureHelper.SetImgLoader(ui.item_0.com_pic.picture, free_ImageLibrary.Name, (s) =>
|
||||
{
|
||||
if (free_ImageLibrary.State == 1) TextureHelper.SetImageBlur(ui.item_0.com_pic.picture);
|
||||
}, "LevelAlbums/", FolderNames.AlbumName);
|
||||
|
||||
int Free_Alubum_1 = PlayerPrefs.GetInt("Free_Alubum_1", -1);
|
||||
FreeImageLibrary free_ImageLibrary_re = ConfigSystem.GetConfig<FreeImageLibrary>()[Free_Alubum_1];
|
||||
TextureHelper.SetImgLoader(ui.item_0_re.com_pic.picture, free_ImageLibrary_re.Name, (s) =>
|
||||
{
|
||||
if (free_ImageLibrary_re.State == 1) TextureHelper.SetImageBlur(ui.item_0_re.com_pic.picture);
|
||||
}, "LevelAlbums/", FolderNames.AlbumName);
|
||||
|
||||
ui.item_0.btn_unlock.SetClick(() =>
|
||||
{
|
||||
PlayerPrefs.SetInt("unlock_refresh", 0);
|
||||
DataMgr.LevelUnlockFree.Value = Free_Alubum_1;
|
||||
ui.item_0.visible = false;
|
||||
ui.item_0_re.visible = true;
|
||||
});
|
||||
|
||||
if (PlayerPrefs.GetInt("unlock_refresh", 1) == 1)
|
||||
{
|
||||
ui.item_0.visible = true;
|
||||
ui.item_0_re.visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_0.visible = false;
|
||||
ui.item_0_re.visible = true;
|
||||
}
|
||||
|
||||
ui.item_0.btn_skip.SetClick(() =>
|
||||
{
|
||||
SelectLevel(0, DataMgr.LevelUnlockFree.Value);
|
||||
});
|
||||
ui.item_0_re.btn_skip.SetClick(() =>
|
||||
{
|
||||
SelectLevel(0, DataMgr.LevelUnlockFree.Value);
|
||||
});
|
||||
|
||||
|
||||
|
||||
ADImageLibrary ad_ImageLibrary = ConfigSystem.GetConfig<ADImageLibrary>()[DataMgr.LevelUnlockAD.Value];
|
||||
TextureHelper.SetImgLoader(ui.item_1.com_pic.picture, ad_ImageLibrary.Name, (s) =>
|
||||
{
|
||||
if (ad_ImageLibrary.State == 1) TextureHelper.SetImageBlur(ui.item_1.com_pic.picture);
|
||||
}, "LevelAlbums/", FolderNames.AlbumName);
|
||||
|
||||
ui.item_1.btn_unlock.pay_type.selectedIndex = 3;
|
||||
|
||||
ui.item_1.btn_skip.SetClick(() =>
|
||||
{
|
||||
Debug.Log("///////播放广告解锁");
|
||||
GameHelper.ShowVideoAd("UnlockLevel", isSuccess =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
SelectLevel(1, DataMgr.LevelUnlockAD.Value);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
bool have_special = GameHelper.GetVipPrivilege(Subscription.SLVLevel.As<int>());
|
||||
SpecialImageLibrary special_ImageLibrary = ConfigSystem.GetConfig<SpecialImageLibrary>()[DataMgr.LevelUnlockSpecial.Value];
|
||||
TextureHelper.SetImgLoader(ui.item_2.com_pic.picture, special_ImageLibrary.Name, (s) =>
|
||||
{
|
||||
if (special_ImageLibrary.State == 1 && !have_special) TextureHelper.SetImageBlur(ui.item_2.com_pic.picture);
|
||||
}, "LevelAlbums/", FolderNames.AlbumName);
|
||||
if (have_special)
|
||||
{
|
||||
ui.item_2.btn_unlock.visible = false;
|
||||
ui.item_2.type.selectedIndex = 0;
|
||||
ui.item_2.btn_skip.SetClick(() =>
|
||||
{
|
||||
SelectLevel(2, DataMgr.LevelUnlockSpecial.Value);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_2.type.selectedIndex = 2;
|
||||
ui.item_2.btn_unlock.visible = true;
|
||||
ui.item_2.btn_skip.SetClick(() =>
|
||||
{
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.VipClubViewUI_Open);
|
||||
});
|
||||
|
||||
if (special_ImageLibrary.GoldCoins > 0)
|
||||
{
|
||||
ui.item_2.btn_unlock.pay_type.selectedIndex = 1;
|
||||
ui.item_2.btn_unlock.title = special_ImageLibrary.GoldCoins.ToString();
|
||||
ui.item_2.btn_unlock.SetClick(() =>
|
||||
{
|
||||
if (DataMgr.Coin.Value >= special_ImageLibrary.GoldCoins)
|
||||
{
|
||||
GameHelper.AddGold(-special_ImageLibrary.GoldCoins);
|
||||
SelectLevel(2, DataMgr.LevelUnlockSpecial.Value);
|
||||
TrackKit.SendEvent(ADEventTrack.Coinsbuy, ADEventTrack.Property.unlock_svip);
|
||||
Debug.Log("///////金币解锁");
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_2.btn_unlock.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool have_vip = GameHelper.GetVipPrivilege(Subscription.VipLevel.As<int>());
|
||||
VIPImageLibrary vip_ImageLibrary = ConfigSystem.GetConfig<VIPImageLibrary>()[DataMgr.LevelUnlockVIP.Value];
|
||||
|
||||
TextureHelper.SetImgLoader(ui.item_3.com_pic.picture, vip_ImageLibrary.Name, (s) =>
|
||||
{
|
||||
if (vip_ImageLibrary.State == 1 && !have_vip) TextureHelper.SetImageBlur(ui.item_3.com_pic.picture);
|
||||
}, "LevelAlbums/", FolderNames.AlbumName);
|
||||
if (have_vip)
|
||||
{
|
||||
ui.item_3.btn_unlock.visible = false;
|
||||
ui.item_3.type.selectedIndex = 0;
|
||||
ui.item_3.btn_skip.SetClick(() =>
|
||||
{
|
||||
SelectLevel(3, DataMgr.LevelUnlockVIP.Value);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_3.type.selectedIndex = 3;
|
||||
ui.item_3.btn_unlock.visible = true;
|
||||
ui.item_3.btn_skip.SetClick(() =>
|
||||
{
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.VipClubViewUI_Open);
|
||||
});
|
||||
|
||||
if (vip_ImageLibrary.GoldCoins > 0)
|
||||
{
|
||||
ui.item_3.btn_unlock.pay_type.selectedIndex = 1;
|
||||
ui.item_3.btn_unlock.title = vip_ImageLibrary.GoldCoins.ToString();
|
||||
ui.item_3.btn_unlock.SetClick(() =>
|
||||
{
|
||||
if (DataMgr.Coin.Value >= vip_ImageLibrary.GoldCoins)
|
||||
{
|
||||
GameHelper.AddGold(-vip_ImageLibrary.GoldCoins);
|
||||
SelectLevel(3, DataMgr.LevelUnlockVIP.Value);
|
||||
Debug.Log("///////金币解锁");
|
||||
TrackKit.SendEvent(ADEventTrack.Coinsbuy, ADEventTrack.Property.unlock_vip);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_3.btn_unlock.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void SelectLevel(int type_, int id)
|
||||
{
|
||||
|
||||
DataMgr.LevelUnlockListNew.Value.Add(new Levelunlock()
|
||||
{
|
||||
level_ = GameHelper.GetLevel(),
|
||||
type = type_,
|
||||
config_index = id
|
||||
});
|
||||
DataMgr.LevelUnlockListNew.Save();
|
||||
DataMgr.LevelUnlockFree.Value = -1;
|
||||
DataMgr.LevelUnlockAD.Value = -1;
|
||||
DataMgr.LevelUnlockSpecial.Value = -1;
|
||||
DataMgr.LevelUnlockVIP.Value = -1;
|
||||
|
||||
PlayerPrefs.SetInt("Free_Alubum_0", -1);
|
||||
PlayerPrefs.SetInt("Free_Alubum_1", -1);
|
||||
PlayerPrefs.SetInt("AD_Alubum", -1);
|
||||
PlayerPrefs.SetInt("Spec_Alubum", -1);
|
||||
PlayerPrefs.SetInt("Vip_Alubum", -1);
|
||||
|
||||
PlayerPrefs.SetInt("unlock_refresh", 1);
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockLevelsuccess);
|
||||
CtrlCloseUI();
|
||||
PreDownloadManager.StartDownloadAlbumsPicture();
|
||||
|
||||
if (isHallEnter)
|
||||
{
|
||||
GameHelper.gameType = 0;
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.OpenGame, false);
|
||||
} else
|
||||
{
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenGameUI_Open, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public class Levelunlock
|
||||
{
|
||||
public int level_;
|
||||
public int type;
|
||||
public int config_index;
|
||||
}
|
||||
}
|
||||
|
||||
using FGUI.ZM_Common_01;
|
||||
using UnityEngine;
|
||||
using FairyGUI;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SGModule.Common.Extensions;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.UIElements;
|
||||
using SGModule.NetKit;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public class UnlockLevelNewUI : BaseUI
|
||||
{
|
||||
private UnlockLevelNewUICtrl ctrl;
|
||||
private UnlockLevelNewModel model;
|
||||
private FGUI.LG_End.com_unlockLevelNew ui;
|
||||
|
||||
public UnlockLevelNewUI(UnlockLevelNewUICtrl ctrl) : base(ctrl)
|
||||
{
|
||||
uiName = UIConst.UnlockLevelNewUI;
|
||||
this.ctrl = ctrl;
|
||||
}
|
||||
|
||||
protected override void SetUIInfo(UIInfo uiInfo)
|
||||
{
|
||||
uiInfo.packageName = "LG_End";
|
||||
uiInfo.assetName = "com_unlockLevelNew";
|
||||
uiInfo.layerType = UILayerType.Popup;
|
||||
uiInfo.isNeedOpenAnim = false;
|
||||
uiInfo.isNeedCloseAnim = false;
|
||||
uiInfo.isNeedUIMask = true;
|
||||
}
|
||||
|
||||
#region 生命周期
|
||||
protected override void OnInit()
|
||||
{
|
||||
//model = ModuleManager.Instance.GetModel(ModelConst.UnlockLevelNewModel) as UnlockLevelNewModel;
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
// for (int i = 0; i < loader_list.Count; i++)
|
||||
// {
|
||||
// if (loader_list[i] != null && !loader_list[i].isDisposed && loader_list[i].texture != null)
|
||||
// {
|
||||
// loader_list[i].texture = null;
|
||||
// }
|
||||
// }
|
||||
// loader_list.Clear();
|
||||
foreach (var loader in loader_list)
|
||||
{
|
||||
if (loader == null || loader.isDisposed) continue;
|
||||
|
||||
// 释放材质到材质池
|
||||
if (loader.material != null)
|
||||
{
|
||||
TextureHelper.CancelImageBlur(loader); // 自动返回材质池
|
||||
loader.material = null;
|
||||
}
|
||||
|
||||
// 清理 NTexture
|
||||
if (loader.texture != null)
|
||||
{
|
||||
loader.texture.Dispose(); // 销毁 NTexture 对象
|
||||
loader.texture = null;
|
||||
}
|
||||
}
|
||||
loader_list.Clear();
|
||||
}
|
||||
private List<GLoader> loader_list = new List<GLoader>();
|
||||
protected override void OnBind()
|
||||
{
|
||||
ui = baseUI as FGUI.LG_End.com_unlockLevelNew;
|
||||
}
|
||||
|
||||
private bool isHallEnter = false;
|
||||
protected override void OnOpenBefore(object args)
|
||||
{
|
||||
if (args != null)
|
||||
{
|
||||
isHallEnter = (bool)args;
|
||||
}
|
||||
InitView();
|
||||
ui.btn_close.SetClick(() =>
|
||||
{
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.ExitGame);
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.NewEndUI_Close);
|
||||
CtrlCloseUI();
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnOpen(object args)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnDisplay(object args)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
protected override void AddListener()
|
||||
{
|
||||
GameDispatcher.Instance.AddListener(GameMsg.BuyVip, RefreshVip);
|
||||
}
|
||||
protected override void RemoveListener()
|
||||
{
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.BuyVip, RefreshVip);
|
||||
}
|
||||
#endregion
|
||||
private void RefreshVip(object a = null)
|
||||
{
|
||||
bool have_special = GameHelper.GetVipPrivilege(Subscription.SLVLevel.As<int>());
|
||||
SpecialImageLibrary special_ImageLibrary = ConfigSystem.GetSpecialImageConfig()[DataMgr.LevelUnlockSpecial.Value];
|
||||
if (special_ImageLibrary.State == 1 && !have_special) TextureHelper.SetImageBlur(ui.item_2.com_pic.picture);
|
||||
else TextureHelper.CancelImageBlur(ui.item_2.com_pic.picture);
|
||||
|
||||
if (have_special)
|
||||
{
|
||||
ui.item_2.btn_unlock.visible = false;
|
||||
ui.item_2.type.selectedIndex = 0;
|
||||
ui.item_2.btn_skip.SetClick(() =>
|
||||
{
|
||||
SelectLevel(2, DataMgr.LevelUnlockSpecial.Value);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_2.type.selectedIndex = 2;
|
||||
ui.item_2.btn_unlock.visible = true;
|
||||
ui.item_2.btn_skip.SetClick(() =>
|
||||
{
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.VipClubViewUI_Open);
|
||||
});
|
||||
|
||||
if (special_ImageLibrary.GoldCoins > 0)
|
||||
{
|
||||
ui.item_2.btn_unlock.pay_type.selectedIndex = 1;
|
||||
ui.item_2.btn_unlock.title = special_ImageLibrary.GoldCoins.ToString();
|
||||
ui.item_2.btn_unlock.SetClick(() =>
|
||||
{
|
||||
if (DataMgr.Coin.Value >= special_ImageLibrary.GoldCoins)
|
||||
{
|
||||
GameHelper.AddGold(-special_ImageLibrary.GoldCoins);
|
||||
SelectLevel(2, DataMgr.LevelUnlockSpecial.Value);
|
||||
Debug.Log("///////金币解锁");
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_2.btn_unlock.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool have_vip = GameHelper.GetVipPrivilege(Subscription.VipLevel.As<int>());
|
||||
VIPImageLibrary vip_ImageLibrary = ConfigSystem.GetVIPImageConfig()[DataMgr.LevelUnlockVIP.Value];
|
||||
if (vip_ImageLibrary.State == 1 && !have_vip) TextureHelper.SetImageBlur(ui.item_3.com_pic.picture);
|
||||
else TextureHelper.CancelImageBlur(ui.item_3.com_pic.picture);
|
||||
if (have_vip)
|
||||
{
|
||||
ui.item_3.btn_unlock.visible = false;
|
||||
ui.item_3.type.selectedIndex = 0;
|
||||
ui.item_3.btn_skip.SetClick(() =>
|
||||
{
|
||||
SelectLevel(3, DataMgr.LevelUnlockVIP.Value);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_3.type.selectedIndex = 3;
|
||||
ui.item_3.btn_unlock.visible = true;
|
||||
ui.item_3.btn_skip.SetClick(() =>
|
||||
{
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.VipClubViewUI_Open);
|
||||
});
|
||||
|
||||
if (vip_ImageLibrary.GoldCoins > 0)
|
||||
{
|
||||
ui.item_3.btn_unlock.pay_type.selectedIndex = 1;
|
||||
ui.item_3.btn_unlock.title = vip_ImageLibrary.GoldCoins.ToString();
|
||||
ui.item_3.btn_unlock.SetClick(() =>
|
||||
{
|
||||
if (DataMgr.Coin.Value >= vip_ImageLibrary.GoldCoins)
|
||||
{
|
||||
GameHelper.AddGold(-vip_ImageLibrary.GoldCoins);
|
||||
SelectLevel(3, DataMgr.LevelUnlockVIP.Value);
|
||||
Debug.Log("///////金币解锁");
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_3.btn_unlock.visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//初始化页面逻辑
|
||||
private void InitView()
|
||||
{
|
||||
Debug.Log(JsonConvert.SerializeObject(ConfigSystem.GetConfig<FreeImageLibrary>()) + "..................");
|
||||
Debug.Log(JsonConvert.SerializeObject(ConfigSystem.GetConfig<ADImageLibrary>()) + "..................");
|
||||
Debug.Log(JsonConvert.SerializeObject(ConfigSystem.GetConfig<SpecialImageLibrary>()) + "..................");
|
||||
Debug.Log(JsonConvert.SerializeObject(ConfigSystem.GetConfig<VIPImageLibrary>()) + "..................");
|
||||
|
||||
ConfigSystem.GetVIPImageConfig();
|
||||
|
||||
loader_list.Add(ui.item_0.com_pic.picture);
|
||||
loader_list.Add(ui.item_1.com_pic.picture);
|
||||
loader_list.Add(ui.item_2.com_pic.picture);
|
||||
loader_list.Add(ui.item_3.com_pic.picture);
|
||||
|
||||
// List<int> free_level_list = new List<int>();
|
||||
// List<int> ad_level_list = new List<int>();
|
||||
// List<int> special_level_list = new List<int>();
|
||||
// List<int> vip_level_list = new List<int>();
|
||||
// for (int i = 0; i < DataMgr.LevelUnlockListNew.Value.Count; i++)
|
||||
// {
|
||||
// if (DataMgr.LevelUnlockListNew.Value[i].type == 0) free_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
// else if (DataMgr.LevelUnlockListNew.Value[i].type == 1) ad_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
// else if (DataMgr.LevelUnlockListNew.Value[i].type == 2) special_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
// else if (DataMgr.LevelUnlockListNew.Value[i].type == 3) vip_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
// }
|
||||
int Free_Alubum_0 = PlayerPrefs.GetInt("Free_Alubum_0", -1);
|
||||
|
||||
int AD_Alubum = PlayerPrefs.GetInt("AD_Alubum", -1);
|
||||
int Spec_Alubum = PlayerPrefs.GetInt("Spec_Alubum", -1);
|
||||
int Vip_Alubum = PlayerPrefs.GetInt("Vip_Alubum", -1);
|
||||
|
||||
if (DataMgr.LevelUnlockFree.Value < 0)
|
||||
{
|
||||
DataMgr.LevelUnlockFree.Value = Free_Alubum_0;
|
||||
}
|
||||
|
||||
if (DataMgr.LevelUnlockAD.Value < 0)
|
||||
{
|
||||
DataMgr.LevelUnlockAD.Value = AD_Alubum;
|
||||
}
|
||||
|
||||
if (DataMgr.LevelUnlockSpecial.Value < 0)
|
||||
{
|
||||
DataMgr.LevelUnlockSpecial.Value = Spec_Alubum;
|
||||
}
|
||||
|
||||
if (DataMgr.LevelUnlockVIP.Value < 0)
|
||||
{
|
||||
DataMgr.LevelUnlockVIP.Value = Vip_Alubum;
|
||||
}
|
||||
|
||||
|
||||
FreeImageLibrary free_ImageLibrary = ConfigSystem.GetFreeImageConfig()[DataMgr.LevelUnlockFree.Value];
|
||||
ui.item_0.btn_unlock.pay_type.selectedIndex = 2;
|
||||
ui.item_0_re.btn_unlock.visible = false;
|
||||
TextureHelper.SetImgLoader(ui.item_0.com_pic.picture, free_ImageLibrary.Name, (s) =>
|
||||
{
|
||||
if (free_ImageLibrary.State == 1) TextureHelper.SetImageBlur(ui.item_0.com_pic.picture);
|
||||
}, "LevelAlbums/", FolderNames.AlbumName);
|
||||
|
||||
int Free_Alubum_1 = PlayerPrefs.GetInt("Free_Alubum_1", -1);
|
||||
FreeImageLibrary free_ImageLibrary_re = ConfigSystem.GetFreeImageConfig()[Free_Alubum_1];
|
||||
TextureHelper.SetImgLoader(ui.item_0_re.com_pic.picture, free_ImageLibrary_re.Name, (s) =>
|
||||
{
|
||||
if (free_ImageLibrary_re.State == 1) TextureHelper.SetImageBlur(ui.item_0_re.com_pic.picture);
|
||||
}, "LevelAlbums/", FolderNames.AlbumName);
|
||||
|
||||
ui.item_0.btn_unlock.SetClick(() =>
|
||||
{
|
||||
PlayerPrefs.SetInt("unlock_refresh", 0);
|
||||
DataMgr.LevelUnlockFree.Value = Free_Alubum_1;
|
||||
ui.item_0.visible = false;
|
||||
ui.item_0_re.visible = true;
|
||||
});
|
||||
|
||||
if (PlayerPrefs.GetInt("unlock_refresh", 1) == 1)
|
||||
{
|
||||
ui.item_0.visible = true;
|
||||
ui.item_0_re.visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_0.visible = false;
|
||||
ui.item_0_re.visible = true;
|
||||
}
|
||||
|
||||
ui.item_0.btn_skip.SetClick(() =>
|
||||
{
|
||||
SelectLevel(0, DataMgr.LevelUnlockFree.Value);
|
||||
});
|
||||
ui.item_0_re.btn_skip.SetClick(() =>
|
||||
{
|
||||
SelectLevel(0, DataMgr.LevelUnlockFree.Value);
|
||||
});
|
||||
|
||||
|
||||
|
||||
ADImageLibrary ad_ImageLibrary = ConfigSystem.GetADImageConfig()[DataMgr.LevelUnlockAD.Value];
|
||||
TextureHelper.SetImgLoader(ui.item_1.com_pic.picture, ad_ImageLibrary.Name, (s) =>
|
||||
{
|
||||
if (ad_ImageLibrary.State == 1) TextureHelper.SetImageBlur(ui.item_1.com_pic.picture);
|
||||
}, "LevelAlbums/", FolderNames.AlbumName);
|
||||
|
||||
ui.item_1.btn_unlock.pay_type.selectedIndex = 3;
|
||||
|
||||
ui.item_1.btn_skip.SetClick(() =>
|
||||
{
|
||||
Debug.Log("///////播放广告解锁");
|
||||
GameHelper.ShowVideoAd("UnlockLevel", isSuccess =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
SelectLevel(1, DataMgr.LevelUnlockAD.Value);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
bool have_special = GameHelper.GetVipPrivilege(Subscription.SLVLevel.As<int>());
|
||||
SpecialImageLibrary special_ImageLibrary = ConfigSystem.GetSpecialImageConfig()[DataMgr.LevelUnlockSpecial.Value];
|
||||
TextureHelper.SetImgLoader(ui.item_2.com_pic.picture, special_ImageLibrary.Name, (s) =>
|
||||
{
|
||||
if (special_ImageLibrary.State == 1 && !have_special) TextureHelper.SetImageBlur(ui.item_2.com_pic.picture);
|
||||
}, "LevelAlbums/", FolderNames.AlbumName);
|
||||
if (have_special)
|
||||
{
|
||||
ui.item_2.btn_unlock.visible = false;
|
||||
ui.item_2.type.selectedIndex = 0;
|
||||
ui.item_2.btn_skip.SetClick(() =>
|
||||
{
|
||||
SelectLevel(2, DataMgr.LevelUnlockSpecial.Value);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_2.type.selectedIndex = 2;
|
||||
ui.item_2.btn_unlock.visible = true;
|
||||
ui.item_2.btn_skip.SetClick(() =>
|
||||
{
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.VipClubViewUI_Open);
|
||||
});
|
||||
|
||||
if (special_ImageLibrary.GoldCoins > 0)
|
||||
{
|
||||
ui.item_2.btn_unlock.pay_type.selectedIndex = 1;
|
||||
ui.item_2.btn_unlock.title = special_ImageLibrary.GoldCoins.ToString();
|
||||
ui.item_2.btn_unlock.SetClick(() =>
|
||||
{
|
||||
if (DataMgr.Coin.Value >= special_ImageLibrary.GoldCoins)
|
||||
{
|
||||
GameHelper.AddGold(-special_ImageLibrary.GoldCoins);
|
||||
SelectLevel(2, DataMgr.LevelUnlockSpecial.Value);
|
||||
TrackKit.SendEvent(ADEventTrack.Coinsbuy, ADEventTrack.Property.unlock_svip);
|
||||
Debug.Log("///////金币解锁");
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_2.btn_unlock.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool have_vip = GameHelper.GetVipPrivilege(Subscription.VipLevel.As<int>());
|
||||
VIPImageLibrary vip_ImageLibrary = ConfigSystem.GetVIPImageConfig()[DataMgr.LevelUnlockVIP.Value];
|
||||
|
||||
TextureHelper.SetImgLoader(ui.item_3.com_pic.picture, vip_ImageLibrary.Name, (s) =>
|
||||
{
|
||||
if (vip_ImageLibrary.State == 1 && !have_vip) TextureHelper.SetImageBlur(ui.item_3.com_pic.picture);
|
||||
}, "LevelAlbums/", FolderNames.AlbumName);
|
||||
if (have_vip)
|
||||
{
|
||||
ui.item_3.btn_unlock.visible = false;
|
||||
ui.item_3.type.selectedIndex = 0;
|
||||
ui.item_3.btn_skip.SetClick(() =>
|
||||
{
|
||||
SelectLevel(3, DataMgr.LevelUnlockVIP.Value);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_3.type.selectedIndex = 3;
|
||||
ui.item_3.btn_unlock.visible = true;
|
||||
ui.item_3.btn_skip.SetClick(() =>
|
||||
{
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.VipClubViewUI_Open);
|
||||
});
|
||||
|
||||
if (vip_ImageLibrary.GoldCoins > 0)
|
||||
{
|
||||
ui.item_3.btn_unlock.pay_type.selectedIndex = 1;
|
||||
ui.item_3.btn_unlock.title = vip_ImageLibrary.GoldCoins.ToString();
|
||||
ui.item_3.btn_unlock.SetClick(() =>
|
||||
{
|
||||
if (DataMgr.Coin.Value >= vip_ImageLibrary.GoldCoins)
|
||||
{
|
||||
GameHelper.AddGold(-vip_ImageLibrary.GoldCoins);
|
||||
SelectLevel(3, DataMgr.LevelUnlockVIP.Value);
|
||||
Debug.Log("///////金币解锁");
|
||||
TrackKit.SendEvent(ADEventTrack.Coinsbuy, ADEventTrack.Property.unlock_vip);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameHelper.ShowTips("no_enough_gold", true);
|
||||
|
||||
uiCtrlDispatcher.Dispatch(UICtrlMsg.BuygoldUI_Open);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.item_3.btn_unlock.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void SelectLevel(int type_, int id)
|
||||
{
|
||||
|
||||
DataMgr.LevelUnlockListNew.Value.Add(new Levelunlock()
|
||||
{
|
||||
level_ = GameHelper.GetLevel(),
|
||||
type = type_,
|
||||
config_index = id
|
||||
});
|
||||
DataMgr.LevelUnlockListNew.Save();
|
||||
DataMgr.LevelUnlockFree.Value = -1;
|
||||
DataMgr.LevelUnlockAD.Value = -1;
|
||||
DataMgr.LevelUnlockSpecial.Value = -1;
|
||||
DataMgr.LevelUnlockVIP.Value = -1;
|
||||
|
||||
PlayerPrefs.SetInt("Free_Alubum_0", -1);
|
||||
PlayerPrefs.SetInt("Free_Alubum_1", -1);
|
||||
PlayerPrefs.SetInt("AD_Alubum", -1);
|
||||
PlayerPrefs.SetInt("Spec_Alubum", -1);
|
||||
PlayerPrefs.SetInt("Vip_Alubum", -1);
|
||||
|
||||
PlayerPrefs.SetInt("unlock_refresh", 1);
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.UnlockLevelsuccess);
|
||||
CtrlCloseUI();
|
||||
PreDownloadManager.StartDownloadAlbumsPicture();
|
||||
|
||||
if (isHallEnter)
|
||||
{
|
||||
GameHelper.gameType = 0;
|
||||
GameDispatcher.Instance.Dispatch(GameMsg.OpenGame, false);
|
||||
} else
|
||||
{
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenGameUI_Open, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public class Levelunlock
|
||||
{
|
||||
public int level_;
|
||||
public int type;
|
||||
public int config_index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ namespace RedHotRoast {
|
||||
|
||||
TrackKit.TrackLoginFunnel(LoginFunnelEventType.LoadFinish); //加载完成打点
|
||||
|
||||
TextureHelper.imgUrl = CdnURL + "/" + ConfigSystem.GetCommonConf().ResVersion + "/";
|
||||
LiveVideoManager.videoBaseUrl = CdnURL + "/" + ConfigSystem.GetCommonConf().ResVersion + "/";
|
||||
TextureHelper.imgUrl = CdnURL + "/" + (IsOrganic() ? GetCommonConf().ResVersion : GetCommonConf().ResVersion1) + "/";
|
||||
LiveVideoManager.videoBaseUrl = CdnURL + "/" + (IsOrganic() ? GetCommonConf().ResVersion : GetCommonConf().ResVersion1) + "/";
|
||||
|
||||
// ParseGameConfig();
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.NetLoadingUI_Close);
|
||||
@@ -116,6 +116,66 @@ namespace RedHotRoast {
|
||||
return ConfigLoader.Instance.GetConfig<List<T>>() ?? new List<T>();
|
||||
}
|
||||
|
||||
private static bool IsOrganic()
|
||||
{
|
||||
bool b = false;
|
||||
|
||||
if (GameHelper.IsGiftSwitch() && SuperApplication.Instance.attribution == "organic")
|
||||
{
|
||||
b = GetCommonConf().IsOrganic == 1;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
private static List<T> GetConfigWithOrganicFallback<T, TOrganic>() where T : class
|
||||
{
|
||||
if (IsOrganic())
|
||||
{
|
||||
var organicConfig = ConfigLoader.Instance.GetConfig<List<TOrganic>>();
|
||||
if (organicConfig != null)
|
||||
{
|
||||
var json = Newtonsoft.Json.JsonConvert.SerializeObject(organicConfig);
|
||||
return Newtonsoft.Json.JsonConvert.DeserializeObject<List<T>>(json);
|
||||
}
|
||||
}
|
||||
|
||||
return GetConfig<T>();
|
||||
}
|
||||
|
||||
public static List<Live> GetLiveConfig()
|
||||
{
|
||||
return GetConfigWithOrganicFallback<Live, Live_A>();
|
||||
}
|
||||
|
||||
public static List<SecretAlbums> GetSecretAlbumsConfig()
|
||||
{
|
||||
return GetConfigWithOrganicFallback<SecretAlbums, SecretAlbums_A>();
|
||||
}
|
||||
public static List<FreeImageLibrary> GetFreeImageConfig()
|
||||
{
|
||||
return GetConfigWithOrganicFallback<FreeImageLibrary, FreeImageLibrary_A>();
|
||||
}
|
||||
public static List<ADImageLibrary> GetADImageConfig()
|
||||
{
|
||||
return GetConfigWithOrganicFallback<ADImageLibrary, ADImageLibrary_A>();
|
||||
}
|
||||
|
||||
public static List<SpecialImageLibrary> GetSpecialImageConfig()
|
||||
{
|
||||
return GetConfigWithOrganicFallback<SpecialImageLibrary, SpecialImageLibrary_A>();
|
||||
}
|
||||
|
||||
public static List<VIPImageLibrary> GetVIPImageConfig()
|
||||
{
|
||||
return GetConfigWithOrganicFallback<VIPImageLibrary, VIPImageLibrary_A>();
|
||||
}
|
||||
|
||||
public static List<LevelUnlock> GetLevelUnlockConfig()
|
||||
{
|
||||
return GetConfigWithOrganicFallback<LevelUnlock, LevelUnlock_A>();
|
||||
}
|
||||
|
||||
|
||||
public override void Dispose() {
|
||||
base.Dispose();
|
||||
RemoveListener();
|
||||
|
||||
@@ -1,382 +1,382 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public static class PreDownloadManager
|
||||
{
|
||||
#region Live
|
||||
|
||||
public static void InitializeLiveData()
|
||||
{
|
||||
var liveConfigList = ConfigSystem.GetConfig<Live>();
|
||||
|
||||
Debug.Log($"[预下载视频 数据初始化]-0-----{DataMgr.LiveDataDic.Value.Count}");
|
||||
|
||||
var newData = new Dictionary<int, LiveData>();
|
||||
|
||||
for (var i = 0; i < liveConfigList.Count; i++)
|
||||
{
|
||||
var oldData = GetLiveDataByIndex(liveConfigList[i], i);
|
||||
|
||||
if (oldData.progress > 0) newData[i] = oldData;
|
||||
}
|
||||
|
||||
Debug.Log($"[预下载视频 数据初始化]--1----- {newData.Count}");
|
||||
DataMgr.LiveDataDic.Value = newData;
|
||||
}
|
||||
|
||||
public static LiveData GetLiveDataByIndex(Live liveConfig, int i)
|
||||
{
|
||||
DataMgr.LiveDataDic.Value.TryGetValue(i, out var oldData);
|
||||
|
||||
oldData ??= new LiveData
|
||||
{
|
||||
progress = liveConfig.Progress,
|
||||
AD_num = 0,
|
||||
Singleprogress = (100 - liveConfig.Progress) / liveConfig.AD
|
||||
};
|
||||
|
||||
if (oldData.progress < liveConfig.Progress) oldData.progress = liveConfig.Progress;
|
||||
|
||||
return oldData;
|
||||
}
|
||||
|
||||
// 最大同时下载数量
|
||||
private const int MaxConcurrentDownloads = 1;
|
||||
|
||||
public static void StartDownload()
|
||||
{
|
||||
CrazyAsyKit.StartCoroutine(DownloadVideosCoroutine());
|
||||
}
|
||||
|
||||
private static IEnumerator DownloadVideosCoroutine()
|
||||
{
|
||||
var liveConfigList = ConfigSystem.GetConfig<Live>();
|
||||
var liveDic = DataMgr.LiveDataDic.Value;
|
||||
|
||||
var downloadNameList = new List<string>();
|
||||
|
||||
// 先加入已有进度的视频
|
||||
foreach (var kvp in liveDic)
|
||||
{
|
||||
var index = kvp.Key;
|
||||
var data = kvp.Value;
|
||||
|
||||
if (data.progress > 0 && index < liveConfigList.Count) downloadNameList.Add(liveConfigList[index].Name);
|
||||
}
|
||||
|
||||
Debug.Log($"[init down video]---1---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
// 添加不在downloadNameList中的项,最多添加6个
|
||||
var addedCount = 0;
|
||||
for (var i = 0; i < liveConfigList.Count && addedCount < 6; i++)
|
||||
if (!downloadNameList.Contains(liveConfigList[i].Name))
|
||||
{
|
||||
downloadNameList.Add(liveConfigList[i].Name);
|
||||
addedCount++;
|
||||
}
|
||||
|
||||
Debug.Log($"[init down video]---2---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
// 当前正在下载的协程数量
|
||||
var runningCount = 0;
|
||||
var currentIndex = 0;
|
||||
|
||||
if (downloadNameList.Count > 0)
|
||||
{
|
||||
var name = downloadNameList[currentIndex];
|
||||
|
||||
var localPath = Path.Combine(TextureHelper.getResPath(), FolderNames.VideoName, name + ".enc");
|
||||
Debug.Log($"[预下载 视频 路径]-------localPath===={localPath}");
|
||||
|
||||
if (!File.Exists(localPath))
|
||||
{
|
||||
Debug.Log("[开始预下载 视频 ]---------------");
|
||||
runningCount++;
|
||||
CrazyAsyKit.StartCoroutine(DownloadSingleVideoCoroutine(name, () => { runningCount--; }));
|
||||
}
|
||||
}
|
||||
|
||||
// 等待下一帧再检查
|
||||
yield return null;
|
||||
Debug.Log("[init down video]---All downloads finished---");
|
||||
}
|
||||
|
||||
|
||||
private static IEnumerator DownloadSingleVideoCoroutine(string name, Action onComplete)
|
||||
{
|
||||
var isDone = false;
|
||||
|
||||
LiveVideoManager.Instance.GetVideoLocalPath(name, tex =>
|
||||
{
|
||||
Debug.Log($"[init down video]----------------{name}");
|
||||
isDone = true;
|
||||
}, false);
|
||||
|
||||
// 等待下载完成
|
||||
while (!isDone) yield return null;
|
||||
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Picture
|
||||
|
||||
public static void StartDownloadSecretPicture()
|
||||
{
|
||||
var liveConfigList = ConfigSystem.GetConfig<SecretAlbums>();
|
||||
var liveList = DataMgr.SecretUnlockList.Value;
|
||||
|
||||
var downloadNameList = new List<string>();
|
||||
|
||||
// 先加入所有可用的图片
|
||||
for (var i = 0; i < liveList.Count; i++)
|
||||
if (liveConfigList[i] != null && !downloadNameList.Contains(liveConfigList[i].Name))
|
||||
downloadNameList.Add(liveConfigList[i].Name);
|
||||
|
||||
Debug.Log(
|
||||
$"[init down picture Secret]---1---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
// 添加不在downloadNameList中的项,最多添加6个
|
||||
var addedCount = 0;
|
||||
for (var i = 0; i < liveConfigList.Count && addedCount < 6; i++)
|
||||
if (!downloadNameList.Contains(liveConfigList[i].Name))
|
||||
{
|
||||
downloadNameList.Add(liveConfigList[i].Name);
|
||||
addedCount++;
|
||||
}
|
||||
|
||||
Debug.Log(
|
||||
$"[init down picture Secret]---2---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
foreach (var name in downloadNameList)
|
||||
{
|
||||
var localPath = Path.Combine(TextureHelper.getResPath(), FolderNames.SecretName, name + ".jpg");
|
||||
Debug.Log($"[预下载 Secret 路径]-------localPath===={localPath}");
|
||||
if (!File.Exists(localPath))
|
||||
{
|
||||
Debug.Log("[开始预下载 Secret ]---------------");
|
||||
TextureHelper.SetImgLoader(null, name,
|
||||
s =>
|
||||
{
|
||||
Debug.Log($"[init down Secret picture]----------------{name}");
|
||||
}, "SecretAlbums/", FolderNames.SecretName, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void StartDownloadAlbumsPicture()
|
||||
{
|
||||
int Free_Alubum_0 = PlayerPrefs.GetInt("Free_Alubum_0", -1);
|
||||
int Free_Alubum_1 = PlayerPrefs.GetInt("Free_Alubum_1", -1);
|
||||
int AD_Alubum = PlayerPrefs.GetInt("AD_Alubum", -1);
|
||||
int Spec_Alubum = PlayerPrefs.GetInt("Spec_Alubum", -1);
|
||||
int Vip_Alubum = PlayerPrefs.GetInt("Vip_Alubum", -1);
|
||||
|
||||
if (Free_Alubum_0 >= 0) return;
|
||||
|
||||
var FreeImageLibrary_ = ConfigSystem.GetConfig<FreeImageLibrary>();
|
||||
var ADImageLibrary_ = ConfigSystem.GetConfig<ADImageLibrary>();
|
||||
var SpecialImageLibrary_ = ConfigSystem.GetConfig<SpecialImageLibrary>();
|
||||
var VIPImageLibrary_ = ConfigSystem.GetConfig<VIPImageLibrary>();
|
||||
|
||||
List<int> free_level_list = new List<int>();
|
||||
List<int> ad_level_list = new List<int>();
|
||||
List<int> special_level_list = new List<int>();
|
||||
List<int> vip_level_list = new List<int>();
|
||||
for (int i = 0; i < DataMgr.LevelUnlockListNew.Value.Count; i++)
|
||||
{
|
||||
if (DataMgr.LevelUnlockListNew.Value[i].type == 0) free_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
else if (DataMgr.LevelUnlockListNew.Value[i].type == 1) ad_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
else if (DataMgr.LevelUnlockListNew.Value[i].type == 2) special_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
else if (DataMgr.LevelUnlockListNew.Value[i].type == 3) vip_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
}
|
||||
|
||||
|
||||
if (Free_Alubum_0 < 0)
|
||||
{
|
||||
HashSet<int> levelIds = new HashSet<int>(free_level_list);
|
||||
List<FreeImageLibrary> filtered = ConfigSystem.GetConfig<FreeImageLibrary>().Where(x => !levelIds.Contains(x.id)).ToList();
|
||||
if (filtered.Count > 0)
|
||||
{
|
||||
Free_Alubum_0 = filtered[UnityEngine.Random.Range(0, filtered.Count)].id;
|
||||
}
|
||||
else
|
||||
{
|
||||
Free_Alubum_0 = ConfigSystem.GetConfig<FreeImageLibrary>()[UnityEngine.Random.Range(0, ConfigSystem.GetConfig<FreeImageLibrary>().Count)].id;
|
||||
}
|
||||
free_level_list.Add(Free_Alubum_0);
|
||||
Debug.Log(JsonConvert.SerializeObject(filtered) + ",,,,,,,,,,,,,,,,,,,,");
|
||||
}
|
||||
if (Free_Alubum_1 < 0)
|
||||
{
|
||||
HashSet<int> levelIds = new HashSet<int>(free_level_list);
|
||||
List<FreeImageLibrary> filtered = ConfigSystem.GetConfig<FreeImageLibrary>().Where(x => !levelIds.Contains(x.id)).ToList();
|
||||
if (filtered.Count > 0)
|
||||
{
|
||||
Free_Alubum_1 = filtered[UnityEngine.Random.Range(0, filtered.Count)].id;
|
||||
}
|
||||
else
|
||||
{
|
||||
Free_Alubum_1 = ConfigSystem.GetConfig<FreeImageLibrary>()[UnityEngine.Random.Range(0, ConfigSystem.GetConfig<FreeImageLibrary>().Count)].id;
|
||||
}
|
||||
Debug.Log(JsonConvert.SerializeObject(filtered) + ",,,,,,,,,,,,,,,,,,,,");
|
||||
}
|
||||
|
||||
|
||||
if (AD_Alubum < 0)
|
||||
{
|
||||
HashSet<int> levelIds = new HashSet<int>(ad_level_list);
|
||||
List<ADImageLibrary> filtered = ConfigSystem.GetConfig<ADImageLibrary>().Where(x => !levelIds.Contains(x.id)).ToList();
|
||||
if (filtered.Count > 0)
|
||||
{
|
||||
AD_Alubum = filtered[UnityEngine.Random.Range(0, filtered.Count)].id;
|
||||
}
|
||||
else
|
||||
{
|
||||
AD_Alubum = ConfigSystem.GetConfig<ADImageLibrary>()[UnityEngine.Random.Range(0, ConfigSystem.GetConfig<ADImageLibrary>().Count)].id;
|
||||
}
|
||||
Debug.Log(JsonConvert.SerializeObject(filtered) + ",,,,,,,,,,,,,,,,,,,,");
|
||||
}
|
||||
|
||||
if (Spec_Alubum < 0)
|
||||
{
|
||||
HashSet<int> levelIds = new HashSet<int>(special_level_list);
|
||||
List<SpecialImageLibrary> filtered = ConfigSystem.GetConfig<SpecialImageLibrary>().Where(x => !levelIds.Contains(x.id)).ToList();
|
||||
if (filtered.Count > 0)
|
||||
{
|
||||
Spec_Alubum = filtered[UnityEngine.Random.Range(0, filtered.Count)].id;
|
||||
}
|
||||
else
|
||||
{
|
||||
Spec_Alubum = ConfigSystem.GetConfig<SpecialImageLibrary>()[UnityEngine.Random.Range(0, ConfigSystem.GetConfig<SpecialImageLibrary>().Count)].id;
|
||||
}
|
||||
Debug.Log(JsonConvert.SerializeObject(filtered) + ",,,,,,,,,,,,,,,,,,,,");
|
||||
}
|
||||
|
||||
if (Vip_Alubum < 0)
|
||||
{
|
||||
HashSet<int> levelIds = new HashSet<int>(vip_level_list);
|
||||
List<VIPImageLibrary> filtered = ConfigSystem.GetConfig<VIPImageLibrary>().Where(x => !levelIds.Contains(x.id)).ToList();
|
||||
if (filtered.Count > 0)
|
||||
{
|
||||
Vip_Alubum = filtered[UnityEngine.Random.Range(0, filtered.Count)].id;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vip_Alubum = ConfigSystem.GetConfig<VIPImageLibrary>()[UnityEngine.Random.Range(0, ConfigSystem.GetConfig<VIPImageLibrary>().Count)].id;
|
||||
}
|
||||
Debug.Log(JsonConvert.SerializeObject(filtered) + ",,,,,,,,,,,,,,,,,,,,");
|
||||
}
|
||||
PlayerPrefs.SetInt("Free_Alubum_0", Free_Alubum_0);
|
||||
PlayerPrefs.SetInt("Free_Alubum_1", Free_Alubum_1);
|
||||
PlayerPrefs.SetInt("AD_Alubum", AD_Alubum);
|
||||
PlayerPrefs.SetInt("Spec_Alubum", Spec_Alubum);
|
||||
PlayerPrefs.SetInt("Vip_Alubum", Vip_Alubum);
|
||||
|
||||
var downloadNameList = new List<string>
|
||||
{
|
||||
FreeImageLibrary_[Free_Alubum_0].Name,
|
||||
FreeImageLibrary_[Free_Alubum_1].Name,
|
||||
ADImageLibrary_[AD_Alubum].Name,
|
||||
SpecialImageLibrary_[Spec_Alubum].Name,
|
||||
VIPImageLibrary_[Vip_Alubum].Name
|
||||
};
|
||||
|
||||
Debug.Log(
|
||||
$"[init down picture Album]---1---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
// 添加不在downloadNameList中的项,最多添加12个
|
||||
// var addedCount = 0;
|
||||
// for (var i = 0; i < liveConfigList.Count && addedCount < 6; i++)
|
||||
// if (!downloadNameList.Contains(liveConfigList[i].Name))
|
||||
// {
|
||||
// downloadNameList.Add(liveConfigList[i].Name);
|
||||
// addedCount++;
|
||||
// }
|
||||
|
||||
Debug.Log(
|
||||
$"[init down picture Album]---2---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
// int centerIndex = GameHelper.GetLevel();
|
||||
// int totalCount = downloadNameList.Count;
|
||||
|
||||
// // 计算起始索引和实际要取的数量
|
||||
// int rangeStart = Math.Max(0, centerIndex - 5);
|
||||
// int rangeEnd = Math.Min(totalCount, centerIndex + 5);
|
||||
// int rangeCount = rangeEnd - rangeStart;
|
||||
|
||||
// // 获取范围内元素并反转
|
||||
// var segment = downloadNameList.GetRange(rangeStart, rangeCount);
|
||||
// segment.Reverse();
|
||||
|
||||
// // 移除原始位置的元素
|
||||
// downloadNameList.RemoveRange(rangeStart, rangeCount);
|
||||
|
||||
// // 插入反转后的元素到最前面
|
||||
// downloadNameList.InsertRange(0, segment);
|
||||
|
||||
|
||||
Debug.Log(
|
||||
$"[init down picture Album]---3---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
foreach (var name in downloadNameList)
|
||||
{
|
||||
var localPath = Path.Combine(TextureHelper.getResPath(), FolderNames.AlbumName, name + ".jpg");
|
||||
Debug.Log($"[预下载 Albums 路径]-------localPath===={localPath}");
|
||||
if (!File.Exists(localPath))
|
||||
{
|
||||
Debug.Log($"[开始预下载 Albums ]--------------name-{name}");
|
||||
TextureHelper.SetImgLoader(null, name,
|
||||
s =>
|
||||
{
|
||||
Debug.Log($"[init down Album picture]----------------{name}");
|
||||
}, "LevelAlbums/", FolderNames.AlbumName, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void StartDownloadLivePicture()
|
||||
{
|
||||
var liveConfigList = ConfigSystem.GetConfig<Live>();
|
||||
var liveList = DataMgr.SecretUnlockList.Value;
|
||||
|
||||
var downloadNameList = new List<string>();
|
||||
|
||||
// 先加入所有可用的图片
|
||||
for (var i = 0; i < liveConfigList.Count; i++)
|
||||
if (liveConfigList[i] != null && !downloadNameList.Contains(liveConfigList[i].Name))
|
||||
downloadNameList.Add(liveConfigList[i].Name);
|
||||
|
||||
Debug.Log(
|
||||
$"[init down picture LiveCover]---1---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
// 添加不在downloadNameList中的项,最多添加6个
|
||||
|
||||
foreach (var name in downloadNameList)
|
||||
{
|
||||
var localPath = Path.Combine(TextureHelper.getResPath(), FolderNames.VideoCoversName, name + "_cover" + ".jpg");
|
||||
Debug.Log($"[预下载 Secret 路径]-------localPath===={localPath}");
|
||||
if (!File.Exists(localPath))
|
||||
{
|
||||
Debug.Log("[开始预下载 Secret ]---------------");
|
||||
TextureHelper.SetImgLoader(null, name + "_cover",
|
||||
s =>
|
||||
{
|
||||
Debug.Log($"[init down VideoCovers picture]----------------{name}");
|
||||
}, "LiveAlbums/", FolderNames.VideoCoversName, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RedHotRoast
|
||||
{
|
||||
public static class PreDownloadManager
|
||||
{
|
||||
#region Live
|
||||
|
||||
public static void InitializeLiveData()
|
||||
{
|
||||
var liveConfigList = ConfigSystem.GetLiveConfig();
|
||||
|
||||
Debug.Log($"[预下载视频 数据初始化]-0-----{DataMgr.LiveDataDic.Value.Count}");
|
||||
|
||||
var newData = new Dictionary<int, LiveData>();
|
||||
|
||||
for (var i = 0; i < liveConfigList.Count; i++)
|
||||
{
|
||||
var oldData = GetLiveDataByIndex(liveConfigList[i], i);
|
||||
|
||||
if (oldData.progress > 0) newData[i] = oldData;
|
||||
}
|
||||
|
||||
Debug.Log($"[预下载视频 数据初始化]--1----- {newData.Count}");
|
||||
DataMgr.LiveDataDic.Value = newData;
|
||||
}
|
||||
|
||||
public static LiveData GetLiveDataByIndex(Live liveConfig, int i)
|
||||
{
|
||||
DataMgr.LiveDataDic.Value.TryGetValue(i, out var oldData);
|
||||
|
||||
oldData ??= new LiveData
|
||||
{
|
||||
progress = liveConfig.Progress,
|
||||
AD_num = 0,
|
||||
Singleprogress = (100 - liveConfig.Progress) / liveConfig.AD
|
||||
};
|
||||
|
||||
if (oldData.progress < liveConfig.Progress) oldData.progress = liveConfig.Progress;
|
||||
|
||||
return oldData;
|
||||
}
|
||||
|
||||
// 最大同时下载数量
|
||||
private const int MaxConcurrentDownloads = 1;
|
||||
|
||||
public static void StartDownload()
|
||||
{
|
||||
CrazyAsyKit.StartCoroutine(DownloadVideosCoroutine());
|
||||
}
|
||||
|
||||
private static IEnumerator DownloadVideosCoroutine()
|
||||
{
|
||||
var liveConfigList = ConfigSystem.GetLiveConfig();
|
||||
var liveDic = DataMgr.LiveDataDic.Value;
|
||||
|
||||
var downloadNameList = new List<string>();
|
||||
|
||||
// 先加入已有进度的视频
|
||||
foreach (var kvp in liveDic)
|
||||
{
|
||||
var index = kvp.Key;
|
||||
var data = kvp.Value;
|
||||
|
||||
if (data.progress > 0 && index < liveConfigList.Count) downloadNameList.Add(liveConfigList[index].Name);
|
||||
}
|
||||
|
||||
Debug.Log($"[init down video]---1---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
// 添加不在downloadNameList中的项,最多添加6个
|
||||
var addedCount = 0;
|
||||
for (var i = 0; i < liveConfigList.Count && addedCount < 6; i++)
|
||||
if (!downloadNameList.Contains(liveConfigList[i].Name))
|
||||
{
|
||||
downloadNameList.Add(liveConfigList[i].Name);
|
||||
addedCount++;
|
||||
}
|
||||
|
||||
Debug.Log($"[init down video]---2---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
// 当前正在下载的协程数量
|
||||
var runningCount = 0;
|
||||
var currentIndex = 0;
|
||||
|
||||
if (downloadNameList.Count > 0)
|
||||
{
|
||||
var name = downloadNameList[currentIndex];
|
||||
|
||||
var localPath = Path.Combine(TextureHelper.getResPath(), FolderNames.VideoName, name + ".enc");
|
||||
Debug.Log($"[预下载 视频 路径]-------localPath===={localPath}");
|
||||
|
||||
if (!File.Exists(localPath))
|
||||
{
|
||||
Debug.Log("[开始预下载 视频 ]---------------");
|
||||
runningCount++;
|
||||
CrazyAsyKit.StartCoroutine(DownloadSingleVideoCoroutine(name, () => { runningCount--; }));
|
||||
}
|
||||
}
|
||||
|
||||
// 等待下一帧再检查
|
||||
yield return null;
|
||||
Debug.Log("[init down video]---All downloads finished---");
|
||||
}
|
||||
|
||||
|
||||
private static IEnumerator DownloadSingleVideoCoroutine(string name, Action onComplete)
|
||||
{
|
||||
var isDone = false;
|
||||
|
||||
LiveVideoManager.Instance.GetVideoLocalPath(name, tex =>
|
||||
{
|
||||
Debug.Log($"[init down video]----------------{name}");
|
||||
isDone = true;
|
||||
}, false);
|
||||
|
||||
// 等待下载完成
|
||||
while (!isDone) yield return null;
|
||||
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Picture
|
||||
|
||||
public static void StartDownloadSecretPicture()
|
||||
{
|
||||
var liveConfigList = ConfigSystem.GetSecretAlbumsConfig();
|
||||
var liveList = DataMgr.SecretUnlockList.Value;
|
||||
|
||||
var downloadNameList = new List<string>();
|
||||
|
||||
// 先加入所有可用的图片
|
||||
for (var i = 0; i < liveList.Count; i++)
|
||||
if (liveConfigList[i] != null && !downloadNameList.Contains(liveConfigList[i].Name))
|
||||
downloadNameList.Add(liveConfigList[i].Name);
|
||||
|
||||
Debug.Log(
|
||||
$"[init down picture Secret]---1---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
// 添加不在downloadNameList中的项,最多添加6个
|
||||
var addedCount = 0;
|
||||
for (var i = 0; i < liveConfigList.Count && addedCount < 6; i++)
|
||||
if (!downloadNameList.Contains(liveConfigList[i].Name))
|
||||
{
|
||||
downloadNameList.Add(liveConfigList[i].Name);
|
||||
addedCount++;
|
||||
}
|
||||
|
||||
Debug.Log(
|
||||
$"[init down picture Secret]---2---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
foreach (var name in downloadNameList)
|
||||
{
|
||||
var localPath = Path.Combine(TextureHelper.getResPath(), FolderNames.SecretName, name + ".jpg");
|
||||
Debug.Log($"[预下载 Secret 路径]-------localPath===={localPath}");
|
||||
if (!File.Exists(localPath))
|
||||
{
|
||||
Debug.Log("[开始预下载 Secret ]---------------");
|
||||
TextureHelper.SetImgLoader(null, name,
|
||||
s =>
|
||||
{
|
||||
Debug.Log($"[init down Secret picture]----------------{name}");
|
||||
}, "SecretAlbums/", FolderNames.SecretName, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void StartDownloadAlbumsPicture()
|
||||
{
|
||||
int Free_Alubum_0 = PlayerPrefs.GetInt("Free_Alubum_0", -1);
|
||||
int Free_Alubum_1 = PlayerPrefs.GetInt("Free_Alubum_1", -1);
|
||||
int AD_Alubum = PlayerPrefs.GetInt("AD_Alubum", -1);
|
||||
int Spec_Alubum = PlayerPrefs.GetInt("Spec_Alubum", -1);
|
||||
int Vip_Alubum = PlayerPrefs.GetInt("Vip_Alubum", -1);
|
||||
|
||||
if (Free_Alubum_0 >= 0) return;
|
||||
|
||||
var FreeImageLibrary_ = ConfigSystem.GetFreeImageConfig();
|
||||
var ADImageLibrary_ = ConfigSystem.GetADImageConfig();
|
||||
var SpecialImageLibrary_ = ConfigSystem.GetSpecialImageConfig();
|
||||
var VIPImageLibrary_ = ConfigSystem.GetVIPImageConfig();
|
||||
|
||||
List<int> free_level_list = new List<int>();
|
||||
List<int> ad_level_list = new List<int>();
|
||||
List<int> special_level_list = new List<int>();
|
||||
List<int> vip_level_list = new List<int>();
|
||||
for (int i = 0; i < DataMgr.LevelUnlockListNew.Value.Count; i++)
|
||||
{
|
||||
if (DataMgr.LevelUnlockListNew.Value[i].type == 0) free_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
else if (DataMgr.LevelUnlockListNew.Value[i].type == 1) ad_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
else if (DataMgr.LevelUnlockListNew.Value[i].type == 2) special_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
else if (DataMgr.LevelUnlockListNew.Value[i].type == 3) vip_level_list.Add(DataMgr.LevelUnlockListNew.Value[i].config_index);
|
||||
}
|
||||
|
||||
|
||||
if (Free_Alubum_0 < 0)
|
||||
{
|
||||
HashSet<int> levelIds = new HashSet<int>(free_level_list);
|
||||
List<FreeImageLibrary> filtered = ConfigSystem.GetFreeImageConfig().Where(x => !levelIds.Contains(x.id)).ToList();
|
||||
if (filtered.Count > 0)
|
||||
{
|
||||
Free_Alubum_0 = filtered[UnityEngine.Random.Range(0, filtered.Count)].id;
|
||||
}
|
||||
else
|
||||
{
|
||||
Free_Alubum_0 = ConfigSystem.GetFreeImageConfig()[UnityEngine.Random.Range(0, ConfigSystem.GetFreeImageConfig().Count)].id;
|
||||
}
|
||||
free_level_list.Add(Free_Alubum_0);
|
||||
Debug.Log(JsonConvert.SerializeObject(filtered) + ",,,,,,,,,,,,,,,,,,,,");
|
||||
}
|
||||
if (Free_Alubum_1 < 0)
|
||||
{
|
||||
HashSet<int> levelIds = new HashSet<int>(free_level_list);
|
||||
List<FreeImageLibrary> filtered = ConfigSystem.GetFreeImageConfig().Where(x => !levelIds.Contains(x.id)).ToList();
|
||||
if (filtered.Count > 0)
|
||||
{
|
||||
Free_Alubum_1 = filtered[UnityEngine.Random.Range(0, filtered.Count)].id;
|
||||
}
|
||||
else
|
||||
{
|
||||
Free_Alubum_1 = ConfigSystem.GetFreeImageConfig()[UnityEngine.Random.Range(0, ConfigSystem.GetFreeImageConfig().Count)].id;
|
||||
}
|
||||
Debug.Log(JsonConvert.SerializeObject(filtered) + ",,,,,,,,,,,,,,,,,,,,");
|
||||
}
|
||||
|
||||
|
||||
if (AD_Alubum < 0)
|
||||
{
|
||||
HashSet<int> levelIds = new HashSet<int>(ad_level_list);
|
||||
List<ADImageLibrary> filtered = ConfigSystem.GetADImageConfig().Where(x => !levelIds.Contains(x.id)).ToList();
|
||||
if (filtered.Count > 0)
|
||||
{
|
||||
AD_Alubum = filtered[UnityEngine.Random.Range(0, filtered.Count)].id;
|
||||
}
|
||||
else
|
||||
{
|
||||
AD_Alubum = ConfigSystem.GetADImageConfig()[UnityEngine.Random.Range(0, ConfigSystem.GetADImageConfig().Count)].id;
|
||||
}
|
||||
Debug.Log(JsonConvert.SerializeObject(filtered) + ",,,,,,,,,,,,,,,,,,,,");
|
||||
}
|
||||
|
||||
if (Spec_Alubum < 0)
|
||||
{
|
||||
HashSet<int> levelIds = new HashSet<int>(special_level_list);
|
||||
List<SpecialImageLibrary> filtered = ConfigSystem.GetSpecialImageConfig().Where(x => !levelIds.Contains(x.id)).ToList();
|
||||
if (filtered.Count > 0)
|
||||
{
|
||||
Spec_Alubum = filtered[UnityEngine.Random.Range(0, filtered.Count)].id;
|
||||
}
|
||||
else
|
||||
{
|
||||
Spec_Alubum = ConfigSystem.GetSpecialImageConfig()[UnityEngine.Random.Range(0, ConfigSystem.GetSpecialImageConfig().Count)].id;
|
||||
}
|
||||
Debug.Log(JsonConvert.SerializeObject(filtered) + ",,,,,,,,,,,,,,,,,,,,");
|
||||
}
|
||||
|
||||
if (Vip_Alubum < 0)
|
||||
{
|
||||
HashSet<int> levelIds = new HashSet<int>(vip_level_list);
|
||||
List<VIPImageLibrary> filtered = ConfigSystem.GetVIPImageConfig().Where(x => !levelIds.Contains(x.id)).ToList();
|
||||
if (filtered.Count > 0)
|
||||
{
|
||||
Vip_Alubum = filtered[UnityEngine.Random.Range(0, filtered.Count)].id;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vip_Alubum = ConfigSystem.GetVIPImageConfig()[UnityEngine.Random.Range(0, ConfigSystem.GetVIPImageConfig().Count)].id;
|
||||
}
|
||||
Debug.Log(JsonConvert.SerializeObject(filtered) + ",,,,,,,,,,,,,,,,,,,,");
|
||||
}
|
||||
PlayerPrefs.SetInt("Free_Alubum_0", Free_Alubum_0);
|
||||
PlayerPrefs.SetInt("Free_Alubum_1", Free_Alubum_1);
|
||||
PlayerPrefs.SetInt("AD_Alubum", AD_Alubum);
|
||||
PlayerPrefs.SetInt("Spec_Alubum", Spec_Alubum);
|
||||
PlayerPrefs.SetInt("Vip_Alubum", Vip_Alubum);
|
||||
|
||||
var downloadNameList = new List<string>
|
||||
{
|
||||
FreeImageLibrary_[Free_Alubum_0].Name,
|
||||
FreeImageLibrary_[Free_Alubum_1].Name,
|
||||
ADImageLibrary_[AD_Alubum].Name,
|
||||
SpecialImageLibrary_[Spec_Alubum].Name,
|
||||
VIPImageLibrary_[Vip_Alubum].Name
|
||||
};
|
||||
|
||||
Debug.Log(
|
||||
$"[init down picture Album]---1---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
// 添加不在downloadNameList中的项,最多添加12个
|
||||
// var addedCount = 0;
|
||||
// for (var i = 0; i < liveConfigList.Count && addedCount < 6; i++)
|
||||
// if (!downloadNameList.Contains(liveConfigList[i].Name))
|
||||
// {
|
||||
// downloadNameList.Add(liveConfigList[i].Name);
|
||||
// addedCount++;
|
||||
// }
|
||||
|
||||
Debug.Log(
|
||||
$"[init down picture Album]---2---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
// int centerIndex = GameHelper.GetLevel();
|
||||
// int totalCount = downloadNameList.Count;
|
||||
|
||||
// // 计算起始索引和实际要取的数量
|
||||
// int rangeStart = Math.Max(0, centerIndex - 5);
|
||||
// int rangeEnd = Math.Min(totalCount, centerIndex + 5);
|
||||
// int rangeCount = rangeEnd - rangeStart;
|
||||
|
||||
// // 获取范围内元素并反转
|
||||
// var segment = downloadNameList.GetRange(rangeStart, rangeCount);
|
||||
// segment.Reverse();
|
||||
|
||||
// // 移除原始位置的元素
|
||||
// downloadNameList.RemoveRange(rangeStart, rangeCount);
|
||||
|
||||
// // 插入反转后的元素到最前面
|
||||
// downloadNameList.InsertRange(0, segment);
|
||||
|
||||
|
||||
Debug.Log(
|
||||
$"[init down picture Album]---3---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
foreach (var name in downloadNameList)
|
||||
{
|
||||
var localPath = Path.Combine(TextureHelper.getResPath(), FolderNames.AlbumName, name + ".jpg");
|
||||
Debug.Log($"[预下载 Albums 路径]-------localPath===={localPath}");
|
||||
if (!File.Exists(localPath))
|
||||
{
|
||||
Debug.Log($"[开始预下载 Albums ]--------------name-{name}");
|
||||
TextureHelper.SetImgLoader(null, name,
|
||||
s =>
|
||||
{
|
||||
Debug.Log($"[init down Album picture]----------------{name}");
|
||||
}, "LevelAlbums/", FolderNames.AlbumName, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void StartDownloadLivePicture()
|
||||
{
|
||||
var liveConfigList = ConfigSystem.GetLiveConfig();
|
||||
var liveList = DataMgr.SecretUnlockList.Value;
|
||||
|
||||
var downloadNameList = new List<string>();
|
||||
|
||||
// 先加入所有可用的图片
|
||||
for (var i = 0; i < liveConfigList.Count; i++)
|
||||
if (liveConfigList[i] != null && !downloadNameList.Contains(liveConfigList[i].Name))
|
||||
downloadNameList.Add(liveConfigList[i].Name);
|
||||
|
||||
Debug.Log(
|
||||
$"[init down picture LiveCover]---1---nameList----------{JsonConvert.SerializeObject(downloadNameList)}");
|
||||
|
||||
// 添加不在downloadNameList中的项,最多添加6个
|
||||
|
||||
foreach (var name in downloadNameList)
|
||||
{
|
||||
var localPath = Path.Combine(TextureHelper.getResPath(), FolderNames.VideoCoversName, name + "_cover" + ".jpg");
|
||||
Debug.Log($"[预下载 Secret 路径]-------localPath===={localPath}");
|
||||
if (!File.Exists(localPath))
|
||||
{
|
||||
Debug.Log("[开始预下载 Secret ]---------------");
|
||||
TextureHelper.SetImgLoader(null, name + "_cover",
|
||||
s =>
|
||||
{
|
||||
Debug.Log($"[init down VideoCovers picture]----------------{name}");
|
||||
}, "LiveAlbums/", FolderNames.VideoCoversName, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user