This commit is contained in:
JA
2026-06-20 19:34:23 +08:00
parent e5031c0068
commit d442805c3f
4136 changed files with 514641 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
using Manager;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MessageBox : UIWindow
{
public InputField playerName;
public Text infoText;
CharInfo info;
string path;
public void Init(string dataName,string datePath)
{
infoText.text = dataName + " 是一个空白存档,需要创建你的存档嘛?";
path = datePath;
}
public override void OnYesClick()
{
base.OnYesClick();
Debug.Log("创建存档");
//创建新存档
//初始化玩家数据
info = new CharInfo();
info.DatePath = path;
info.playerName = playerName.text; //名字
info.Level = 1;//等级
info.exp = 0;//经验值
info.attack = 50;//攻击力
info.maxHp = 400;//最大生命值
info.currentHp = info.maxHp;//本局血量
info.testAttack = info.attack;//本局攻击力
info.currentMap = 1;
//背包数据
info.BagKey = new List<int> { 0};//道具Id
info.BagValue = new List<int> { 6 };//道具数量
//升级数据
info.UpKey = new List<int> { 0, 1, 2, 3, 4, 5, 6,7,8 };//升级节点
info.UpValue = new List<bool> { false, false, false, false, false, false, false,false,false };//是否升级
SaveSystem.SaveDate(path, info);
//存档赋值
PlayerInfo.Instance.Init(info);
SenceManager.Instance.LoadScene(info.currentMap);
SoundManager.Instance.PlayMusic(SoundDefine.Map_1Music);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c73df666b571fe649b79bfb8ea5a15b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,71 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public static class SaveSystem
{
public static bool IsHaveFile(string FilePath)
{
if (File.Exists(FilePath))
return true;
else
return false;
}
public static void CreateFile(string FilePath, bool IfHaveFileIsCreate = false)
{
if (!File.Exists(FilePath))
{
File.CreateText(FilePath);
}
}
public static void SaveDate(string fileName, object date)
{
var json = JsonUtility.ToJson(date);
string path = Path.Combine(Application.persistentDataPath, fileName);
if (!IsHaveFile(path))
{
//Debug.Log("文件不存在");
CreateFile(path);
}
try
{
File.WriteAllText(path, json);
Debug.Log("存档成功");
}
catch (Exception)
{
Debug.Log("存档创建失败");
SaveDate(fileName,date);
}
}
public static T LoadDate<T>(string fileName)
{
var path = Path.Combine(Application.persistentDataPath, fileName);
if (IsHaveFile(path))
{
var json = File.ReadAllText(path);
T date = JsonUtility.FromJson<T>(json);
Debug.Log("读档成功}");
return date;
}
return default;
}
public static void DeleteDate(string fileName)
{
var path = Path.Combine(Application.persistentDataPath, fileName);
if (!IsHaveFile(path))
{
return;//不存在
}
File.Delete(path);
Debug.Log("删除成功");
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c2a8ed3c5fdface4383fffaf797a0b23
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: