浏览代码

GameSaveManager continued + Actions

/main
Thomas ICHÉ 5 年前
当前提交
9280e6cb
共有 5 个文件被更改,包括 106 次插入17 次删除
  1. 34
      Runtime/Managers/Implementations/GameSaveManager.cs
  2. 37
      Runtime/Actions/GameSaveLoadSaveAction.cs
  3. 11
      Runtime/Actions/GameSaveLoadSaveAction.cs.meta
  4. 30
      Runtime/Actions/GameSaveSetValueAction.cs
  5. 11
      Runtime/Actions/GameSaveSetValueAction.cs.meta

34
Runtime/Managers/Implementations/GameSaveManager.cs


{
string val = data.values[i];
object value;
if (data.types[i] == SerializableOutput.ValueType.Bool)
if (data.types[i] == ValueType.Bool)
else if (data.types[i] == SerializableOutput.ValueType.Int)
else if (data.types[i] == ValueType.Int)
else if (data.types[i] == SerializableOutput.ValueType.Float)
else if (data.types[i] == ValueType.Float)
value = float.Parse(val);
else
value = val;

data.keys = new string[count];
data.values = new string[count];
data.types = new SerializableOutput.ValueType[count];
data.types = new ValueType[count];
int i = 0;
foreach (var kvp in entries)

if (value is bool)
data.types[i] = SerializableOutput.ValueType.Bool;
data.types[i] = ValueType.Bool;
data.types[i] = SerializableOutput.ValueType.Int;
data.types[i] = ValueType.Int;
data.types[i] = SerializableOutput.ValueType.Float;
data.types[i] = ValueType.Float;
data.types[i] = SerializableOutput.ValueType.String;
data.types[i] = ValueType.String;
data.values[i] = kvp.Value.ToString();
i++;

}
[System.Serializable]
public enum ValueType
{
Bool = 0,
Int = 1,
Float = 2,
String = 3
}
[System.Serializable]
[System.Serializable]
public enum ValueType
{
Bool = 0,
Int = 1,
Float = 2,
String = 3
}
}
#endregion

37
Runtime/Actions/GameSaveLoadSaveAction.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Actions
{
public class GameSaveLoadSaveAction : ActionBase
{
public enum Action
{
Load,
Save,
}
public GameSaveManager.Location saveLocation = GameSaveManager.Location.System;
public Action action = Action.Load;
public byte UserSaveIndex = 0;
public override void Execute()
{
if(action == Action.Load)
{
if (saveLocation == GameSaveManager.Location.System)
Manager.Get<GameSaveManager>().LoadSystemSave();
else
Manager.Get<GameSaveManager>().LoadUserSave(UserSaveIndex);
}
else
{
if (saveLocation == GameSaveManager.Location.System)
Manager.Get<GameSaveManager>().SaveSystemSave();
else
Manager.Get<GameSaveManager>().SaveUserSave(UserSaveIndex);
}
}
}
}

11
Runtime/Actions/GameSaveLoadSaveAction.cs.meta


fileFormatVersion: 2
guid: b961b0f0b44c73940bdbe58fb10266af
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

30
Runtime/Actions/GameSaveSetValueAction.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Actions
{
public class GameSaveSetValueAction : ActionBase
{
public string Key = "SomeKey";
public GameSaveManager.Location saveLocation = GameSaveManager.Location.System;
public GameSaveManager.ValueType valueType = GameSaveManager.ValueType.String;
public string StringValue;
public int IntValue;
public bool BoolValue;
public float FloatValue;
public override void Execute()
{
var gsm = Manager.Get<GameSaveManager>();
switch(valueType)
{
case GameSaveManager.ValueType.Bool: gsm.SetBool(Key, saveLocation, BoolValue); break;
case GameSaveManager.ValueType.Int: gsm.SetInt(Key, saveLocation, IntValue); break;
case GameSaveManager.ValueType.Float: gsm.SetFloat(Key, saveLocation, FloatValue); break;
case GameSaveManager.ValueType.String: gsm.SetString(Key, saveLocation, StringValue); break;
}
}
}
}

11
Runtime/Actions/GameSaveSetValueAction.cs.meta


fileFormatVersion: 2
guid: 418629731ee76d94981950d2da411d63
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存