WXGame/box1/Assets/Script/DataManager.cs
2024-11-26 15:44:50 +08:00

163 lines
3.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public static class DataManager
{
public static int Level
{
get
{
return GetInt("Level");
}
set
{
SetInt("Level",value);
}
}
public static int chapter
{
get
{
return GetInt("chapter");
}
set
{
SetInt("chapter",value);
}
}
public static bool chapterLock(int id)
{
return GetInt("chapterUnLock"+id)==1;
}
public static void chapterLock(int id, bool bo)
{
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 = 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;
SetInt("level"+id.ToString(),bo?1:0);
}
public static int HighestRecordPoints(int id)
{
return GetInt("HighestPoints"+id);
}
public static int LastTimePoints(int id)
{
return GetInt("LastPoints"+id);
}
public static void SetPointsData(int id, int num)
{
if (GetInt("HighestPoints"+id)<num)
{
SetInt("HighestPoints"+id,num);
}
SetInt("LastPoints" + id, num);
}
/// <summary>
/// 任务数据存储
/// </summary>
/// <param name="id"></param>
/// <param name="eventID"></param>
/// <param name="bo"></param>
public static void SetTask(int id,int eventID,bool bo)
{
SetInt(id + "_" + eventID, bo ? 1 : 0);
}
public static bool GetTask(int id,int eventID)
{
return GetInt(id + "_" + eventID) == 1;
}
public static void SaveAllStarNum()
{
int num = 0;
foreach (var bChapter in JsonTab.Instance.tables.Chapter.DataList)
{
foreach (var levelId in bChapter.Contain)
{
var lData = JsonTab.Instance.tables.Level.Get(levelId);
if (GetTask(lData.ID, lData.Maintasks))
{
num++;
}
foreach (var additionaltask in lData.Additionaltasks)
{
if (GetTask(lData.ID, additionaltask))
{
num++;
}
}
}
}
SetInt("star", num);
}
public static int GetStar()
{
return GetInt("star")-GetSpend();
}
public static int GetAllStar()
{
return GetInt("star");
}
public static void SetSpend(int num)
{
SetInt("Spend",num);
}
public static int GetSpend()
{
return GetInt("Spend");
}
public static void SetHomeFurnitureID(string key,int id)
{
SetInt("Furniture-" + key, id);
}
public static int GetHomeFurnitureID(string key)
{
return GetInt("Furniture-" + key);
}
public static void SetInt(string key, int num)
{
PlayerPrefs.SetInt(key, num);
}
public static int GetInt(string key)
{
return PlayerPrefs.GetInt(key);
}
}