Fungus 本身是有自己的Save System 的,关于这个怎么用网上资料有很多
当然Fungus官方的documentation和视频讲得最清楚 不赘述 请看他们github和油管
虽然讲得很清楚 但是有一说一 很难用
所以我选择自己创造saveObject来处理
今后对话系统更复杂就转战Dialogue System
Anyway
尽管如此 Fungus自带的Save Variable Load Variable 看上去还是蛮好用的
比起
这一串看上去好用得多 至少不用自己明确表示其数据类型
但其实打开Save Variable Load Variable源码会发现
[Tooltip("Variable to read the value from. Only Boolean, Integer, Float and String are supported.")]
[VariableProperty(typeof(BooleanVariable),
typeof(IntegerVariable),
typeof(FloatVariable),
typeof(StringVariable))]
[SerializeField] protected Variable variable;
#region Public members
public override void OnEnter()
{
if (key == "" ||
variable == null)
{
Continue();
return;
}
var flowchart = GetFlowchart();
// Prepend the current save profile (if any)
string prefsKey = SetSaveProfile.SaveProfile + "_" + flowchart.SubstituteVariables(key);
System.Type variableType = variable.GetType();
if (variableType == typeof(BooleanVariable))
{
BooleanVariable booleanVariable = variable as BooleanVariable;
if (booleanVariable != null)
{
// PlayerPrefs does not have bool accessors, so just use int
PlayerPrefs.SetInt(prefsKey, booleanVariable.Value ? 1 : 0);
}
}
else if (variableType == typeof(IntegerVariable))
{
IntegerVariable integerVariable = variable as IntegerVariable;
if (integerVariable != null)
{
PlayerPrefs.SetInt(prefsKey, integerVariable.Value);
}
}
else if (variableType == typeof(FloatVariable))
{
FloatVariable floatVariable = variable as FloatVariable;
if (floatVariable != null)
{
PlayerPrefs.SetFloat(prefsKey, floatVariable.Value);
}
}
else if (variableType == typeof(StringVariable))
{
StringVariable stringVariable = variable as StringVariable;
if (stringVariable != null)
{
PlayerPrefs.SetString(prefsKey, stringVariable.Value);
}
}
Continue();
}
幻想破灭。
那么如果我们只想存储所有变量怎么做?
第一种方法在
这个方法的加持下,把所有变量转换为
variable name :variable toString
的格式存储,也就是类似Fungus用的方法
也是我所用的方法
每次存储/加载时execute一个特殊block
call这两个方法之一
public class myLoader : MonoBehaviour
{
public void saveName(string name){
var saveManager = FungusManager.Instance.SaveManager;
if (saveManager.SaveDataExists(name))
{
SaveManager.Delete(name);
}
saveManager.Save(name);
Debug.Log("save ok");
}
public void loadName(string name){
var saveManager = FungusManager.Instance.SaveManager;
if (saveManager.SaveDataExists(name))
{
saveManager.Load(name);
Debug.Log("laod ok");
}
}
}
这样我们虚拟了一个save point 不会显示一边说过的对话之类了
哦对了要先设定好saveData
其实savePoint 最大的问题在于不能每次Load都load到 想要的savePoint
因为Fungus会存出
这样一个格式(位置在Application.persistentDataPath)
要想每次存取都确定是某个 就得更改saveDataKey
不知道是怎么设计的 亦有可能是我理解有问题
总之我还是用自己改过的方式来用吧。



