106 lines
3.2 KiB
C#
106 lines
3.2 KiB
C#
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
|
|
{
|
|
var configFilePath = string.Format(PathConstants.LevelListPath);
|
|
_allLevels = await JsonHelper.LoadFromAddressable<List<AllLevelData>>(configFilePath);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
DebugUtil.LogError("LevelSelectMgr.Init Error: {0}", e);
|
|
}
|
|
}
|
|
|
|
public void UpdateLevelInfo()
|
|
{
|
|
CurPassLevelIndex = int.Parse(CurPassLevel.Substring("level".Length));
|
|
}
|
|
|
|
public void SaveNewPassLevel(string levelID, bool flyCoin = true)
|
|
{
|
|
if (GuideMananger.Instance.IsGuiding)
|
|
{
|
|
GuideMananger.Instance.PassLevelID = levelID;
|
|
return;
|
|
}
|
|
|
|
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());
|
|
LevelManager.Instance.CanGfxCoin = flyCoin;
|
|
}
|
|
}
|
|
|
|
|
|
public void ClearFile()
|
|
{
|
|
PlayerPrefs.DeleteAll();
|
|
PlayerPrefs.Save();
|
|
UpdateLevelInfo();
|
|
}
|
|
|
|
public void PassAllLevel(int levelId = 0)
|
|
{
|
|
var id = levelId == 0 ? _allLevels.Count : levelId;
|
|
var level = $"level{id}";
|
|
SaveNewPassLevel(level);
|
|
UpdateLevelInfo();
|
|
}
|
|
|
|
public void Release()
|
|
{
|
|
EventManager.Instance.Unregister(EventManager.EventName.RefreshGameData, UpdateLevelInfo);
|
|
}
|
|
|
|
public void Update(float deltaTime)
|
|
{
|
|
}
|
|
}
|
|
} |