WXGame/box1/Assets/Script/DataManager.cs
2024-11-21 10:26:47 +08:00

63 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public static class DataManager
{
public static int Level
{
get
{
return PlayerPrefs.GetInt("Level");
}
set
{
PlayerPrefs.SetInt("Level",value);
}
}
public static int chapter
{
get
{
return PlayerPrefs.GetInt("chapter");
}
set
{
PlayerPrefs.SetInt("chapter",value);
}
}
public static bool chapterLock(int id)
{
return PlayerPrefs.GetInt("chapterUnLock"+id)==1;
}
public static void chapterLock(int id, bool bo)
{
PlayerPrefs.SetInt("chapterUnLock"+id,bo?1:0);
}
private static Dictionary<int, bool> _directory=new Dictionary<int, bool>();
public static bool LevelOpen(int id)
{
if (_directory.TryGetValue(id, out var open)) return open;
var bo = PlayerPrefs.GetInt("level"+id.ToString())==1;
if (id==0)
{
bo = true;
}
_directory.Add(id,bo);
return _directory[id];
}
public static void SetLevelOpen(int id,bool bo)
{
_directory[id] = bo;
PlayerPrefs.SetInt("level"+id.ToString(),bo?1:0);
}
}