2024-06-12 15:01:54 +08:00
|
|
|
using System;
|
|
|
|
using PhxhSDK;
|
|
|
|
using UnityEngine;
|
|
|
|
using Framework.BI;
|
|
|
|
using PhxhSDK.Phxh;
|
|
|
|
using Framework.Event;
|
|
|
|
using Framework.Manager;
|
|
|
|
using Framework.Constants;
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace Gameplay.Manager
|
|
|
|
{
|
|
|
|
public class LevelSelectManager : Singlenton<LevelSelectManager>, IInitable
|
|
|
|
{
|
|
|
|
private List<AllLevelData> _allLevels;
|
|
|
|
public GameObject CurBtnObj;
|
|
|
|
public GameObject GfxSelectLevel;
|
|
|
|
|
|
|
|
private string CurPassLevel
|
|
|
|
{
|
|
|
|
get { return AppInfoManager.Instance.AppUserInfo.PassLevel; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
AppInfoManager.Instance.AppUserInfo.PassLevel = value;
|
|
|
|
|
|
|
|
AppInfoManager.Instance.SetRemoteData(0, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<AllLevelData> CurAllLevelDatas => _allLevels;
|
|
|
|
public int CurPassLevelIndex;
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
{
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.RefreshGameData, UpdateLevelInfo);
|
|
|
|
_allLevels = new List<AllLevelData>() { new AllLevelData("level0") };
|
|
|
|
UpdateLevelInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async UniTask InitAsync()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2024-08-08 19:16:02 +08:00
|
|
|
var configFilePath = string.Format(PathConstants.LevelListPath);
|
2024-06-12 15:01:54 +08:00
|
|
|
_allLevels = await JsonHelper.LoadFromAddressable<List<AllLevelData>>(configFilePath);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2024-08-22 14:03:37 +08:00
|
|
|
DebugUtil.LogError("LevelSelectManager.InitAsync Error: {0}", e);
|
2024-06-12 15:01:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateLevelInfo()
|
|
|
|
{
|
|
|
|
CurPassLevelIndex = int.Parse(CurPassLevel.Substring("level".Length));
|
|
|
|
}
|
|
|
|
|
2024-08-20 16:49:01 +08:00
|
|
|
public void SaveNewPassLevel(string levelID, bool flyCoin = true)
|
2024-06-12 15:01:54 +08:00
|
|
|
{
|
2024-07-25 19:27:22 +08:00
|
|
|
if (GuideMananger.Instance.IsGuiding)
|
|
|
|
{
|
|
|
|
GuideMananger.Instance.PassLevelID = levelID;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-12 15:01:54 +08:00
|
|
|
var id = int.Parse(levelID.Substring("level".Length));
|
|
|
|
if (CurPassLevelIndex < id)
|
|
|
|
{
|
|
|
|
ShopManager.Instance.CurCoin += LevelConstants.RewardCoin;
|
|
|
|
CurPassLevelIndex = id;
|
|
|
|
CurPassLevel = levelID;
|
|
|
|
CurPassLevelIndex = int.Parse(CurPassLevel.Substring("level".Length));
|
|
|
|
StorageManager.Instance.SyncForce = true;
|
|
|
|
StorageManager.Instance.SyncRemoteForce = true;
|
|
|
|
BIManager.Instance.TrackEvent(cfg.BI.Event.main_unlock_level, (id + 1).ToString());
|
2024-08-20 16:49:01 +08:00
|
|
|
LevelManager.Instance.CanGfxCoin = flyCoin;
|
2024-06-12 15:01:54 +08:00
|
|
|
}
|
|
|
|
}
|
2024-07-25 19:27:22 +08:00
|
|
|
|
2024-06-12 15:01:54 +08:00
|
|
|
|
|
|
|
public void ClearFile()
|
|
|
|
{
|
|
|
|
PlayerPrefs.DeleteAll();
|
|
|
|
PlayerPrefs.Save();
|
|
|
|
UpdateLevelInfo();
|
|
|
|
}
|
|
|
|
|
2024-06-27 15:40:40 +08:00
|
|
|
public void PassAllLevel(int levelId = 0)
|
2024-06-12 15:01:54 +08:00
|
|
|
{
|
2024-06-27 15:40:40 +08:00
|
|
|
var id = levelId == 0 ? _allLevels.Count : levelId;
|
|
|
|
var level = $"level{id}";
|
2024-06-12 15:01:54 +08:00
|
|
|
SaveNewPassLevel(level);
|
|
|
|
UpdateLevelInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Release()
|
|
|
|
{
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.RefreshGameData, UpdateLevelInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Update(float deltaTime)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|