浏览代码

Added the ability to store Game Saves as PlayerPrefs strings

/main
Thomas ICHÉ 4 年前
当前提交
638d7c50
共有 2 个文件被更改,包括 33 次插入5 次删除
  1. 1
      CHANGELOG.md
  2. 37
      Runtime/Managers/Implementations/GameSaveManager.cs

1
CHANGELOG.md


- Added "Update SetStateAction" Button in State Machine components to populate the game object with Set State Actions
- Added **Check/Resolve** Window and API : The check window enables performing scriptable checks and resolution actions in your scene for maintenance purposes
- Added **ReachPositionRigSetTargetAction**
- Added the ability to store Game Saves as PlayerPrefs strings
#### Fixed

37
Runtime/Managers/Implementations/GameSaveManager.cs


[ManagerDefaultPrefab("GameSaveManager")]
public class GameSaveManager : Manager
{
[SerializeField, Tooltip("The path where system and user saves will be stored. Relative to the Application.persistantDataPath folder.")]
[InfoBox(@"Use PlayerPrefs will store save data in common target platform registry instead of individual files. For some platforms where writing on disk is forbidden, this is required.", InfoBoxType.Normal)]
public bool UsePlayerPrefs = false;
[DisableIf("UsePlayerPrefs"), SerializeField, Tooltip("The path where system and user saves will be stored. Relative to the Application.persistantDataPath folder.")]
private string savePath = "/";
[SerializeField, Tooltip("The file name of the System Save.")]
private string systemSaveName = "System.sav";

[ReorderableList]
public Callable[] OnSave;
const string kPreferencePrefix = "GameplayIngredients.GameSaveManager.";
void Awake()
{

Dictionary<string, object> LoadFile(string fileName)
{
if(!File.Exists(Application.persistentDataPath + savePath + fileName))
if (UsePlayerPrefs)
{
if(PlayerPrefs.GetString(kPreferencePrefix + fileName, string.Empty) == string.Empty)
SaveFile(fileName, new Dictionary<string, object>());
}
else
SaveFile(fileName, new Dictionary<string, object>());
if (!File.Exists(Application.persistentDataPath + savePath + fileName))
SaveFile(fileName, new Dictionary<string, object>());
string contents= File.ReadAllText(Application.persistentDataPath + savePath + fileName);
string contents = string.Empty;
if(UsePlayerPrefs)
{
contents = PlayerPrefs.GetString(kPreferencePrefix + fileName, string.Empty);
}
else
{
contents = File.ReadAllText(Application.persistentDataPath + savePath + fileName);
}
SerializableOutput data = JsonUtility.FromJson<SerializableOutput>(contents);

i++;
}
File.WriteAllText(Application.persistentDataPath + savePath + filename, JsonUtility.ToJson(data));
if (UsePlayerPrefs)
{
PlayerPrefs.SetString(kPreferencePrefix + filename, JsonUtility.ToJson(data));
}
else
{
File.WriteAllText(Application.persistentDataPath + savePath + filename, JsonUtility.ToJson(data));
}
}
[System.Serializable]

正在加载...
取消
保存