773 lines
23 KiB
C#
773 lines
23 KiB
C#
using cfg.AudioCfg;
|
||
using Cysharp.Threading.Tasks;
|
||
using Framework;
|
||
using Gameplay;
|
||
using Gameplay.Common;
|
||
using Gameplay.Net;
|
||
using PhxhSDK;
|
||
using System.Threading;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UIElements;
|
||
using Button = UnityEngine.UI.Button;
|
||
using Image = UnityEngine.UI.Image;
|
||
|
||
public class UI_MusicPannelController : UIWindow
|
||
{
|
||
#region UI_Obj
|
||
//UI GameObj
|
||
///Auto Gen Start///
|
||
public Image Image_CurrentAlbum;
|
||
public Image Image_Dd;
|
||
public Image Image_Rd;
|
||
public Image Image_Top;
|
||
public Image Image_Ld;
|
||
public Image Image_LD;
|
||
public Image Image_CDbox;
|
||
public Image Image_CDB;
|
||
public Image Image_CD;
|
||
//public Button Button_Back;
|
||
public Button Button_back;
|
||
public TMP_Text Text_Back;
|
||
public Button Button_Home;
|
||
public Button Button_Left;
|
||
public Button Button_Right;
|
||
public Image Image_DBG;
|
||
public Image Image_RightBg;
|
||
public Image Image_ChooseBar;
|
||
public TMP_Text Text_Num_Choose;
|
||
public TMP_Text Text_MusicName_Choose;
|
||
public Image Image_Play;
|
||
public Image Image_Pause;
|
||
public TMP_Text Text_Author_Choose;
|
||
public Image Image_NotChoose;
|
||
public TMP_Text Text_Num_NotChoose;
|
||
public TMP_Text Text_MusicName_NotChoose;
|
||
public TMP_Text Text_Author_NotChoose;
|
||
public Image Image_EmptyH;
|
||
public Image Image_Heart;
|
||
public Image Image_PlayBg;
|
||
public Image Image_DownPoint;
|
||
public Image Image_Analysis1;
|
||
public Image Image_Analysis2;
|
||
public Image Image_Analysis3;
|
||
public Image Image_Analysis4;
|
||
public Image Image_Analysis5;
|
||
public Image Image_Analysis6;
|
||
public Image Image_Analysis7;
|
||
public Image Image_Analysis8;
|
||
public Image Image_Analysis9;
|
||
public Image Image_Analysis10;
|
||
public Image Image_Analysis11;
|
||
public Image Image_Analysis12;
|
||
public Image Image_Analysis13;
|
||
public Image Image_Analysis14;
|
||
public Image Image_Analysis15;
|
||
public Image Image_Analysis16;
|
||
public Image Image_MusicRect;
|
||
public Image Image_Logo;
|
||
public Image Image_ProcessBg;
|
||
public Image Image_ProcessNow;
|
||
public TMP_Text Text_TimeNow;
|
||
public TMP_Text Text_AllTime;
|
||
public Image Image_PL;
|
||
public TMP_Text Text_Play;
|
||
public Image Image_PA;
|
||
public TMP_Text Text_Pause;
|
||
public Image Image_Lbg;
|
||
public Button Button_Previous;
|
||
public TMP_Text Text_Previous;
|
||
public Button Button_PlayAndPause;
|
||
public TMP_Text Text_PP;
|
||
public Image Image_circle;
|
||
public Button Button_Next;
|
||
public TMP_Text Text_Next;
|
||
public Image Image_Seperate;
|
||
public Image Image_Rbg;
|
||
public Button Button_Seq;
|
||
public Image Image_CSeq;
|
||
public TMP_Text Text_Sequence;
|
||
public Button Button_Shu;
|
||
public Image Image_CShu;
|
||
public TMP_Text Text_Shuffle;
|
||
public Button Button_Rep;
|
||
public Image Image_CRep;
|
||
public TMP_Text Text_Repeat;
|
||
public Button Button_Set;
|
||
public TMP_Text Text_Set;
|
||
public Button Button_Lock;
|
||
public TMP_Text Text_LockButton;
|
||
public Button Button_Seted;
|
||
public TMP_Text Text_Seted;
|
||
public Button Button_UnLock;
|
||
public TMP_Text Text_Unlock;
|
||
public TMP_Text Text_SpendLocalText;
|
||
public TMP_Text Text_Spend;
|
||
public TMP_Text Text_SpecialLock;
|
||
public Image Image_CoinLogo;
|
||
public Image Image_DiamondLogo;
|
||
public Image Image_MusicNameBG;
|
||
public TMP_Text Text_Name;
|
||
public TMP_Text Text_Name2;
|
||
public TMP_Text Text_Lock;
|
||
|
||
///Auto Gen End///
|
||
#endregion
|
||
PhxhScrollView AlbumPageScrollView;
|
||
PhxhScrollView AudioListScrollView;
|
||
|
||
/// <summary>
|
||
/// 频谱分析数组
|
||
/// </summary>
|
||
private float[] spectrums;
|
||
MusicDance musicDance;
|
||
|
||
AlbumCoverFader coverFader;
|
||
|
||
float curAudioLength = 0f;
|
||
int curAlbumIndex = 0;
|
||
|
||
public static async UniTask<UIWindow> Open()
|
||
{
|
||
await CommonUtils.CaptureScreenshot();
|
||
|
||
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_MusicPanel);
|
||
}
|
||
private void _OnClickClose()
|
||
{
|
||
CloseWindow();
|
||
}
|
||
|
||
// deal with input data
|
||
public override void PreLoad(object data = null)
|
||
{
|
||
|
||
}
|
||
|
||
// Use this for initialization
|
||
public override void OnInit()
|
||
{
|
||
//bind UI GameObj
|
||
UI_MusicPannelBinder.GetComponents(this);
|
||
|
||
AlbumPageScrollView = GetComponent<PhxhScrollView>("PhxhScrollView");
|
||
AudioListScrollView = GetComponent<PhxhScrollView>("Image_RightBg/PhxhScrollView");
|
||
musicDance = new(FindObj("Image_RightBg/Image_PlayBg/Music/MusicAnalyzers"));
|
||
|
||
BindButton(Button_back, _OnClickClose);
|
||
|
||
if (AlbumManager.Instance.GetCurThemeAlbum() == 0)//未设置主题专辑在播放默认bgm
|
||
{
|
||
DebugUtil.Log("pause music");
|
||
AudioManager.Instance.PauseBackgroundMusic();
|
||
}
|
||
|
||
BindButton(Button_PlayAndPause, PauseAndResume);
|
||
BindButton(Button_Left, preAlbum);
|
||
BindButton(Button_Right, nextAlbum);
|
||
BindButton(Button_Previous, preMusic);
|
||
BindButton(Button_Next, nextMusic);
|
||
BindButton(Button_Seq, () => { SwitchPlayMode(AlbumManager.PlayMode.Order); });
|
||
BindButton(Button_Shu, () => { SwitchPlayMode(AlbumManager.PlayMode.Random); });
|
||
BindButton(Button_Rep, () => { SwitchPlayMode(AlbumManager.PlayMode.Single); });
|
||
BindButton(Button_UnLock, OnUnlockAlbumClick);
|
||
BindButton(Button_Set, OnSetThemeAlbumClick);
|
||
BindButton(Button_Seted, ClearThemeAlbum);
|
||
|
||
coverFader = new(Image_CDB, Image_CD);
|
||
|
||
curAlbumIndex = AlbumManager.Instance.GetCurAlbum().Id;
|
||
|
||
AlbumPageScrollView.SetItemCountFunc(() => AlbumManager.Instance.AlbumsLst.Count);
|
||
AlbumPageScrollView.SetUpdateFunc(AlbumPageRefreshFunc);
|
||
AlbumPageScrollView.itemTemplate.gameObject.SetActive(false);
|
||
AlbumPageScrollView.UpdateData();
|
||
|
||
AudioListScrollView.SetItemCountFunc(() => AlbumManager.Instance.AlbumsDic[curAlbumIndex].PlayList.Length);
|
||
AudioListScrollView.SetUpdateFunc(AlbumListRefreshFunc);
|
||
AudioListScrollView.itemTemplate.gameObject.SetActive(false);
|
||
AudioListScrollView.UpdateData();
|
||
|
||
CDPagesImage(curAlbumIndex, true);
|
||
CheckLock();
|
||
RefreshPlayOrder();
|
||
|
||
AlbumManager.Instance.playTimer.onSecondChange += TimerRefresh;
|
||
AlbumManager.Instance.playTimer.onPlayEnd += PlayEndRefresh;
|
||
EventManager.Instance.Register<uint>(EventManager.EventName.ItemChange, OnItemChange);
|
||
}
|
||
|
||
//invoke when open window
|
||
protected override void OnShowWindow(object data = null)
|
||
{
|
||
//bool isPlaying = AudioManager.Instance.IsPlayingAlbum;
|
||
PauseAndResume();
|
||
//if (!isPlaying)
|
||
//{
|
||
PauseAndResume();//用于加载音频
|
||
//}
|
||
curAudioLength = AlbumManager.Instance.GetAlbumLength(AlbumManager.Instance.curMusicKey);
|
||
|
||
float totalSeconds = AlbumManager.Instance.GetAlbumProgress();
|
||
DebugUtil.Log(AlbumManager.Instance.curMusicKey + "当前已播放时长:" + totalSeconds);
|
||
int minutes = Mathf.FloorToInt(totalSeconds / 60F);
|
||
int seconds = Mathf.FloorToInt(totalSeconds - minutes * 60);
|
||
Text_TimeNow.text = $"{minutes:00}:{seconds:00}";
|
||
if (curAudioLength > 0)
|
||
{
|
||
minutes = Mathf.FloorToInt(curAudioLength / 60F);
|
||
seconds = Mathf.FloorToInt(curAudioLength - minutes * 60);
|
||
Text_AllTime.text = $"{minutes:00}:{seconds:00}";
|
||
|
||
|
||
Image_ProcessNow.fillAmount = totalSeconds / curAudioLength;
|
||
}
|
||
}
|
||
|
||
//invoke when reload window
|
||
protected override void OnReloadWindow(object data = null)
|
||
{
|
||
|
||
}
|
||
|
||
//invoke when close window
|
||
protected override void OnHideWindow()
|
||
{
|
||
|
||
}
|
||
|
||
//invoke when destroy
|
||
public override void OnRelease()
|
||
{
|
||
base.OnRelease();
|
||
if (AlbumManager.Instance.GetCurThemeAlbum() == 0)//未设置主题专辑
|
||
{
|
||
DebugUtil.Log("resume music");
|
||
if (AudioManager.Instance.IsPlayingAlbum)
|
||
PauseAndResume();
|
||
AudioManager.Instance.ResumeBackgroundMusic();
|
||
//AudioManager.Instance.PlayAudio("NLD_BGM_02").Forget();
|
||
AudioManager.Instance.PlayAudio("bgm_2", AudioCriManager.EPlayType.Music);
|
||
}
|
||
else if (AlbumManager.Instance.GetCurThemeAlbum() != AlbumManager.Instance.GetCurAlbum().Id)//设置主题专辑但与当前播放不一致
|
||
{
|
||
AlbumManager.Instance.SetCurAlbum(AlbumManager.Instance.GetCurThemeAlbum(), AlbumManager.Instance.GetCurThemeAudioIndex());
|
||
int curAlbumIndex = AlbumManager.Instance.GetCurThemeAlbum();
|
||
int curAudioIndex = AlbumManager.Instance.CurPlayAudioIndex();
|
||
|
||
if (!AudioManager.Instance.IsPlayingAlbum)
|
||
PauseAndResume();
|
||
|
||
AlbumManager.Instance.PlayAlbumAudio(curAlbumIndex, curAudioIndex);
|
||
AlbumManager.Instance.SetPlayList();
|
||
}
|
||
AlbumManager.Instance.playTimer.onSecondChange -= TimerRefresh;
|
||
AlbumManager.Instance.playTimer.onPlayEnd -= PlayEndRefresh;
|
||
EventManager.Instance.Unregister<uint>(EventManager.EventName.ItemChange, OnItemChange);
|
||
}
|
||
|
||
#region button_click
|
||
|
||
void preAlbum()
|
||
{
|
||
//AlbumManager.Instance.PreAlbum();
|
||
//CDPagesImage(AlbumManager.Instance.GetCurAlbum().Id);
|
||
curAlbumIndex--;
|
||
if (curAlbumIndex <= 0)
|
||
{
|
||
curAlbumIndex = AlbumManager.Instance.AlbumsLst.Count;
|
||
}
|
||
CDPagesImage(curAlbumIndex);
|
||
CheckLock();
|
||
AudioListScrollView.UpdateData();
|
||
}
|
||
void nextAlbum()
|
||
{
|
||
curAlbumIndex++;
|
||
if (curAlbumIndex > AlbumManager.Instance.AlbumsLst.Count)
|
||
{
|
||
curAlbumIndex = 1;
|
||
}
|
||
CDPagesImage(curAlbumIndex);
|
||
CheckLock();
|
||
AudioListScrollView.UpdateData();
|
||
}
|
||
void preMusic()
|
||
{
|
||
AlbumManager.Instance.PlayPreAudio();
|
||
PlayEndRefresh();
|
||
}
|
||
void nextMusic()
|
||
{
|
||
AlbumManager.Instance.PlayNextAudio();
|
||
PlayEndRefresh();
|
||
}
|
||
|
||
void SwitchPlayMode(AlbumManager.PlayMode playMode)
|
||
{
|
||
if (playMode != AlbumManager.Instance.CurPlayMode)
|
||
AlbumManager.Instance.SetPlayMode(playMode);
|
||
RefreshPlayOrder();
|
||
}
|
||
void PauseAndResume()
|
||
{
|
||
AudioManager.Instance.IsPlayingAlbum = !AudioManager.Instance.IsPlayingAlbum;
|
||
if (AudioManager.Instance.IsPlayingAlbum)
|
||
{
|
||
if (!AlbumManager.Instance.PauseAndResumeAlbum(false))//未播放
|
||
{
|
||
//await AudioManager.Instance.PlayAlbum(dataAudio.ID);
|
||
//AlbumManager.Instance.curMusicKey = dataAudio.Key;
|
||
//albumTimer.Start(Text_TimeNow, Image_ProcessNow, totalSeconds);
|
||
int curAudioIndex = AlbumManager.Instance.CurPlayAudioIndex();
|
||
AlbumManager.Instance.PlayAlbumAudio(curAlbumIndex, curAudioIndex);
|
||
AlbumManager.Instance.SetPlayList();//SetPlayMode(AlbumManager.Instance.CurPlayMode);
|
||
curAudioLength = -1;//AlbumManager.Instance.GetAlbumLength(AlbumManager.Instance.CurPlayAudio().Key);
|
||
int minutes = Mathf.FloorToInt(curAudioLength / 60F);
|
||
int seconds = Mathf.FloorToInt(curAudioLength - minutes * 60);
|
||
Text_AllTime.text = $"{minutes:00}:{seconds:00}";
|
||
}
|
||
//else//从暂停中恢复
|
||
//{
|
||
// albumTimer.Start(Text_TimeNow);
|
||
//}
|
||
Image_PL.gameObject.SetActive(true);
|
||
Image_PA.gameObject.SetActive(false);
|
||
}
|
||
else
|
||
{
|
||
//albumTimer.Stop();
|
||
AlbumManager.Instance.PauseAndResumeAlbum(true);
|
||
Image_PL.gameObject.SetActive(false);
|
||
Image_PA.gameObject.SetActive(true);
|
||
}
|
||
}
|
||
|
||
void OnPlayListClick(int index)
|
||
{
|
||
AudioManager.Instance.IsPlayingAlbum = true;
|
||
|
||
//AlbumManager.Instance.SetCurAlbum(curAlbumIndex, index);
|
||
AlbumManager.Instance.PauseAndResumeAlbum(false);
|
||
|
||
AlbumManager.Instance.PlayAlbumAudio(curAlbumIndex, index);
|
||
AlbumManager.Instance.SetPlayList();//SetPlayMode(AlbumManager.Instance.CurPlayMode);//TODO 播放模式
|
||
|
||
if (AlbumManager.Instance.GetPlayListContentType(curAlbumIndex) == typeof(int[]))//过时方法
|
||
{
|
||
DataAudio dataAudio = TableManager.Instance.Tables.Audios.GetByID(AlbumManager.Instance.AlbumPlayListOld(curAlbumIndex)[index]);
|
||
|
||
AlbumManager.Instance.curMusicKey = dataAudio.Key;
|
||
DebugUtil.Log("cur music key: " + dataAudio.Key);
|
||
curAudioLength = AlbumManager.Instance.GetAlbumLength(dataAudio.Key);
|
||
}
|
||
else
|
||
{
|
||
var playName = AlbumManager.Instance.AlbumPlayList(curAlbumIndex)[index];
|
||
AlbumManager.Instance.curMusicKey = playName;
|
||
curAudioLength = AlbumManager.Instance.GetAlbumLength(playName);
|
||
}
|
||
|
||
int minutes = Mathf.FloorToInt(curAudioLength / 60F);
|
||
int seconds = Mathf.FloorToInt(curAudioLength - minutes * 60);
|
||
Text_AllTime.text = $"{minutes:00}:{seconds:00}";
|
||
|
||
Image_PL.gameObject.SetActive(true);
|
||
Image_PA.gameObject.SetActive(false);
|
||
PlayEndRefresh();
|
||
}
|
||
|
||
void OnUnlockAlbumClick()
|
||
{
|
||
var cost = AlbumManager.Instance.AlbumUnlockCost(curAlbumIndex);
|
||
if (cost.Count > 0)
|
||
{
|
||
if (CategoryManager.Instance.GetItemCount(cost[0].Id) < cost[0].Count)
|
||
{
|
||
DebugUtil.LogError("货币不足!");
|
||
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("shop_noMoney"));
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
NetHelper.BuyAlbum((uint)curAlbumIndex);//(uint)AlbumManager.Instance.AlbumsDic[].ItemID
|
||
}
|
||
}
|
||
else
|
||
{
|
||
DebugUtil.LogError("未配置解锁消耗道具!");
|
||
return;
|
||
}
|
||
}
|
||
void OnSetThemeAlbumClick()
|
||
{
|
||
DebugUtil.Log("当前专辑ID:" + curAlbumIndex);
|
||
if (curAlbumIndex != AlbumManager.Instance.GetCurThemeAlbum())
|
||
{
|
||
AlbumManager.Instance.SetCurThemeAlbum(curAlbumIndex);
|
||
Button_Seted.gameObject.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
AlbumManager.Instance.SetCurThemeAlbum(0);
|
||
Button_Seted.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
void ClearThemeAlbum()
|
||
{
|
||
AlbumManager.Instance.SetCurThemeAlbum(0);
|
||
Button_Seted.gameObject.SetActive(false);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region album_page_SV
|
||
void AlbumPageRefreshFunc(int index,RectTransform rt)
|
||
{
|
||
rt.gameObject.SetActive(true);
|
||
int ID = index + 1;
|
||
SetPageImage(rt.GetComponent<Image>(), ID);
|
||
}
|
||
async void SetPageImage(Image img, int index)
|
||
{
|
||
var path = "Assets/Art/UI/Texture/Icon/MusicBox/" + AlbumManager.Instance.AlbumsDic[index].CoverPath + ".png";
|
||
var sprite = await LoadAssetAsync<Sprite>(path);
|
||
img.sprite = sprite;
|
||
}
|
||
#endregion
|
||
|
||
#region album_list_SV
|
||
void AlbumListRefreshFunc(int index, RectTransform rt)
|
||
{
|
||
rt.gameObject.SetActive(true);
|
||
string audioName;
|
||
if (AlbumManager.Instance.GetPlayListContentType(curAlbumIndex) == typeof(string[]))
|
||
{
|
||
audioName = AlbumManager.Instance.AlbumPlayList(curAlbumIndex)[index];
|
||
}
|
||
else//过时方法
|
||
{
|
||
var audioLst = AlbumManager.Instance.AlbumPlayListOld(curAlbumIndex);
|
||
if (audioLst == null)
|
||
{
|
||
DebugUtil.LogError("album list is null");
|
||
return;
|
||
}
|
||
var audioID = audioLst[index];
|
||
DataAudio audioCfg = TableManager.Instance.Tables.Audios.GetByID(audioID);//.GetConfigData(audioID);
|
||
audioName = audioCfg.CueName;
|
||
}
|
||
|
||
int id = index + 1;
|
||
rt.Find("Image_ChooseBar/Text_Num_Choose").GetComponent<TMP_Text>().text = $"{id:00}";
|
||
rt.Find("Image_NotChoose/Text_Num_NotChoose").GetComponent<TMP_Text>().text = $"{id:00}";
|
||
|
||
if (curAlbumIndex == AlbumManager.Instance.GetCurAlbum().Id && index == AlbumManager.Instance.GetCurAudioIndex())//当前播放
|
||
{
|
||
rt.Find("Image_NotChoose").gameObject.SetActive(false);
|
||
rt.Find("Image_ChooseBar").gameObject.SetActive(true);
|
||
|
||
var musicName = rt.Find("Image_ChooseBar/Text_MusicName_Choose").gameObject;
|
||
var authorName = rt.Find("Image_ChooseBar/Text_Author_Choose").gameObject;
|
||
if (musicName != null)
|
||
{
|
||
musicName.GetComponent<TMP_Text>().text = audioName;
|
||
}
|
||
//if (authorName != null)
|
||
//{
|
||
// authorName.GetComponent<TMP_Text>().text = audioCfg.Artist;
|
||
//}
|
||
rt.Find("Image_ChooseBar/Text_MusicName_Choose/Image_Pause").gameObject.SetActive(!AudioManager.Instance.IsPlayingAlbum);
|
||
rt.Find("Image_ChooseBar/Text_MusicName_Choose/Image_Play").gameObject.SetActive(AudioManager.Instance.IsPlayingAlbum);
|
||
|
||
ClearBind(rt.Find("Image_ChooseBar").GetComponent<Button>());
|
||
BindButton(rt.Find("Image_ChooseBar").GetComponent<Button>(), PauseAndResume);
|
||
}
|
||
else//未播放
|
||
{
|
||
rt.Find("Image_NotChoose").gameObject.SetActive(true);
|
||
rt.Find("Image_ChooseBar").gameObject.SetActive(false);
|
||
|
||
var musicName = rt.Find("Image_NotChoose/Text_MusicName_NotChoose").gameObject;
|
||
var authorName = rt.Find("Image_NotChoose/Text_Author_NotChoose").gameObject;
|
||
if (musicName != null)
|
||
{
|
||
musicName.GetComponent<TMP_Text>().text = audioName;
|
||
}
|
||
//if (authorName != null)
|
||
//{
|
||
// authorName.GetComponent<TMP_Text>().text = audioCfg.Artist;
|
||
//}
|
||
ClearBind(rt.Find("Image_NotChoose").GetComponent<Button>());
|
||
BindButton(rt.Find("Image_NotChoose").GetComponent<Button>(), () => OnPlayListClick(index));
|
||
}
|
||
|
||
var rtHeart = rt.Find("Like/Image_Heart").gameObject;
|
||
|
||
rtHeart.SetActive(AlbumManager.Instance.CheckIsFavor(audioName));
|
||
ClearBind(rt.Find("Like/Image_Heart").GetComponent<Button>());
|
||
ClearBind(rt.Find("Like/Image_EmptyH").GetComponent<Button>());
|
||
BindButton(rt.Find("Like/Image_Heart").GetComponent<Button>(), () =>
|
||
{
|
||
rtHeart.SetActive(false);
|
||
AlbumManager.Instance.RemoveFavorAudio(audioName);
|
||
});
|
||
BindButton(rt.Find("Like/Image_EmptyH").GetComponent<Button>(), () =>
|
||
{
|
||
rtHeart.SetActive(true);
|
||
AlbumManager.Instance.AddFavorAudio(audioName);
|
||
});
|
||
}
|
||
#endregion
|
||
|
||
void CDPagesImage(int index, bool init = false)
|
||
{
|
||
Text_Name.text = AlbumManager.Instance.AlbumsDic[index].Name;
|
||
|
||
var CDBpath = "Assets/Art/UI/Texture/Icon/MusicBox/" + AlbumManager.Instance.AlbumsDic[index].TapesPath + ".png";
|
||
var CDBimg = LoadAsset<Sprite>(CDBpath);
|
||
var CDpath = "Assets/Art/UI/Texture/Icon/MusicBox/Tapes/" + AlbumManager.Instance.AlbumsDic[index].CoverPath + ".png";
|
||
var CDimg = LoadAsset<Sprite>(CDpath);
|
||
|
||
if (init)
|
||
{
|
||
Image_CDB.sprite = CDBimg;
|
||
Image_CD.sprite = CDimg;
|
||
}
|
||
else
|
||
{
|
||
coverFader.FadeChangeCover(CDBimg, CDimg);
|
||
}
|
||
|
||
|
||
|
||
if (index == AlbumManager.Instance.GetCurThemeAlbum())
|
||
{
|
||
Button_Seted.gameObject.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
Button_Seted.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
void CheckLock()
|
||
{
|
||
bool isUnLocked = AlbumManager.Instance.AlbumUnlocked(curAlbumIndex);
|
||
FindObj("Image_RightBg/Locked").SetActive(!isUnLocked);
|
||
Button_Lock.gameObject.SetActive(!isUnLocked);
|
||
if (!isUnLocked)
|
||
{
|
||
var cost = AlbumManager.Instance.AlbumUnlockCost(curAlbumIndex);
|
||
if (cost.Count > 0)
|
||
{
|
||
Text_SpendLocalText.gameObject.SetActive(true);
|
||
Button_UnLock.gameObject.SetActive(true);
|
||
Text_SpecialLock.gameObject.SetActive(false);
|
||
|
||
if (cost[0].Id == GLConfig.Inst.data.GoldItemId)
|
||
{
|
||
Text_Spend.text = cost[0].Count.ToString();
|
||
Image_CoinLogo.gameObject.SetActive(true);
|
||
Image_DiamondLogo.gameObject.SetActive(false);
|
||
}
|
||
else if (cost[0].Id == GLConfig.Inst.data.DiamondItemId)
|
||
{
|
||
Text_Spend.text = cost[0].Count.ToString();
|
||
Image_CoinLogo.gameObject.SetActive(false);
|
||
Image_DiamondLogo.gameObject.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
DebugUtil.LogError("错误的解锁消耗类型!");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
DebugUtil.LogError("未配置解锁消耗道具!");
|
||
|
||
Text_SpendLocalText.gameObject.SetActive(false);
|
||
Button_UnLock.gameObject.SetActive(false);
|
||
Text_SpecialLock.gameObject.SetActive(true);
|
||
Text_Spend.text = "";
|
||
Image_CoinLogo.gameObject.SetActive(false);
|
||
Image_DiamondLogo.gameObject.SetActive(false);
|
||
|
||
}
|
||
Text_Lock.gameObject.SetActive(false);
|
||
}
|
||
else
|
||
{
|
||
Text_Lock.gameObject.SetActive(true);
|
||
}
|
||
}
|
||
void RefreshPlayOrder()
|
||
{
|
||
var order = AlbumManager.Instance.CurPlayMode;
|
||
|
||
Image_CSeq.gameObject.SetActive(order == AlbumManager.PlayMode.Order);
|
||
Image_CShu.gameObject.SetActive(order == AlbumManager.PlayMode.Random);
|
||
Image_CRep.gameObject.SetActive(order == AlbumManager.PlayMode.Single);
|
||
|
||
}
|
||
/// <summary>
|
||
/// 计时器更新回调
|
||
/// </summary>
|
||
void TimerRefresh()
|
||
{
|
||
float totalSeconds = AlbumManager.Instance.GetAlbumProgress();
|
||
|
||
int minutes = Mathf.FloorToInt(totalSeconds / 60F);
|
||
int seconds = Mathf.FloorToInt(totalSeconds - minutes * 60);
|
||
Text_TimeNow.text = $"{minutes:00}:{seconds:00}";
|
||
|
||
Image_ProcessNow.fillAmount = totalSeconds / curAudioLength;
|
||
|
||
AudioManager.Instance.GetAnalyzer().GetSpectrumLevels(ref spectrums);
|
||
musicDance.SetInfo(spectrums);
|
||
}
|
||
/// <summary>
|
||
/// 当音乐播放结束或切歌时刷新显示当前播放歌曲
|
||
/// </summary>
|
||
void PlayEndRefresh()
|
||
{
|
||
AudioListScrollView.UpdateData();
|
||
curAudioLength = AlbumManager.Instance.GetAlbumLength(AlbumManager.Instance.curMusicKey);
|
||
int minutes = Mathf.FloorToInt(curAudioLength / 60F);
|
||
int seconds = Mathf.FloorToInt(curAudioLength - minutes * 60);
|
||
Text_AllTime.text = $"{minutes:00}:{seconds:00}";
|
||
}
|
||
void OnItemChange(uint id)
|
||
{
|
||
if (id == (uint)AlbumManager.Instance.AlbumsDic[curAlbumIndex].ItemID)
|
||
{
|
||
CheckLock();
|
||
}
|
||
}
|
||
|
||
///// <summary>
|
||
///// 播放进度计时器
|
||
///// </summary>
|
||
//class Timer
|
||
//{
|
||
// TMP_Text timeTxt;
|
||
// bool isPlaying;
|
||
// float audioLength = -1;
|
||
// Image progressBar;
|
||
//
|
||
// async UniTask AudioTimer()
|
||
// {
|
||
// while(isPlaying)
|
||
// {
|
||
// float totalSeconds = AudioManager.Instance.GetAlbumProgress();
|
||
// if (totalSeconds < 0)
|
||
// {
|
||
// isPlaying = false;
|
||
// break;
|
||
// }
|
||
// int minutes = Mathf.FloorToInt(totalSeconds / 60F);
|
||
// int seconds = Mathf.FloorToInt(totalSeconds - minutes * 60);
|
||
// timeTxt.text = $"{minutes:00}:{seconds:00}";
|
||
//
|
||
// if (progressBar != null && audioLength > 0)
|
||
// {
|
||
// progressBar.fillAmount = totalSeconds / audioLength;
|
||
// }
|
||
// await UniTask.Delay(1000);
|
||
// }
|
||
// }
|
||
//
|
||
// public void Start(TMP_Text text, Image progressBar, float audiolen)
|
||
// {
|
||
// audioLength = audiolen;
|
||
// if (isPlaying)
|
||
// {
|
||
// return;
|
||
// }
|
||
// isPlaying = true;
|
||
// timeTxt = text;
|
||
// this.progressBar = progressBar;
|
||
// AudioTimer().Forget();
|
||
// }
|
||
// public void Start(TMP_Text text)
|
||
// {
|
||
// if (isPlaying)
|
||
// {
|
||
// return;
|
||
// }
|
||
// isPlaying = true;
|
||
// timeTxt = text;
|
||
// AudioTimer().Forget();
|
||
// }
|
||
//
|
||
// public void Stop()
|
||
// {
|
||
// isPlaying = false;
|
||
// }
|
||
//}
|
||
|
||
class AlbumCoverFader
|
||
{
|
||
CancellationTokenSource cts;
|
||
Image Image_CDB;
|
||
Image Image_CD;
|
||
|
||
float duration = 0.2f;
|
||
|
||
public AlbumCoverFader(Image CDB, Image CD)
|
||
{
|
||
Image_CDB = CDB;
|
||
Image_CD = CD;
|
||
}
|
||
|
||
public void FadeChangeCover(Sprite CDB, Sprite CD)
|
||
{
|
||
if(cts != null)
|
||
{
|
||
cts.Cancel();
|
||
}
|
||
cts = new CancellationTokenSource();
|
||
Fader(CDB, CD, cts.Token);
|
||
}
|
||
|
||
async void Fader(Sprite CDB, Sprite CD, CancellationToken token)
|
||
{
|
||
float time = 0;
|
||
while (time < duration / 2)
|
||
{
|
||
time += Time.deltaTime;
|
||
if (token.IsCancellationRequested)
|
||
{
|
||
Image_CDB.sprite = CDB;
|
||
Image_CD.sprite = CD;
|
||
Image_CDB.color = new Color(1, 1, 1, 1);
|
||
Image_CD.color = new Color(1, 1, 1, 1);
|
||
return;
|
||
}
|
||
|
||
Image_CDB.color = new Color(1, 1, 1, 1 - time / duration);
|
||
Image_CD.color = new Color(1, 1, 1, 1 - time / duration);
|
||
await UniTask.Yield();
|
||
}
|
||
|
||
Image_CDB.sprite = CDB;
|
||
Image_CD.sprite = CD;
|
||
|
||
while (time < duration)
|
||
{
|
||
time += Time.deltaTime;
|
||
if (token.IsCancellationRequested)
|
||
{
|
||
Image_CDB.sprite = CDB;
|
||
Image_CD.sprite = CD;
|
||
Image_CDB.color = new Color(1, 1, 1, 1);
|
||
Image_CD.color = new Color(1, 1, 1, 1);
|
||
return;
|
||
}
|
||
|
||
Image_CDB.color = new Color(1, 1, 1, time / duration);
|
||
Image_CD.color = new Color(1, 1, 1, time / duration);
|
||
await UniTask.Yield();
|
||
}
|
||
}
|
||
}
|
||
} |