浏览代码

Refactored the SerializedSO

/UI
Bronson Zgeb 3 年前
当前提交
4d990a64
共有 3 个文件被更改,包括 9 次插入9 次删除
  1. 4
      UOP1_Project/Assets/ScriptableObjects/SaveSystem/SaveSystem.asset
  2. 4
      UOP1_Project/Assets/Scripts/SaveSystem/SaveSystem.cs
  3. 10
      UOP1_Project/Assets/Scripts/SaveSystem/SerializableScriptableObject.cs

4
UOP1_Project/Assets/ScriptableObjects/SaveSystem/SaveSystem.asset


saveData:
_locationId: d102ba8fe3b291249aeb9de4b95c1904
_itemStacks:
- Guid: 0a7c779a15b2c4143ae2068725b8ece9
Amount: 1
- itemGuid: 0a7c779a15b2c4143ae2068725b8ece9
amount: 1

4
UOP1_Project/Assets/Scripts/SaveSystem/SaveSystem.cs


LocationSO locationSo = locationsToLoad[0] as LocationSO;
if (locationSo)
{
saveData._locationId = locationSo.SerializableGuid;
saveData._locationId = locationSo.Guid;
}
SaveGame();

saveData._itemStacks.Clear();
foreach (var itemStack in _playerInventory.Items)
{
saveData._itemStacks.Add(new SerializedItemStack(itemStack.Item.SerializableGuid, itemStack.Amount));
saveData._itemStacks.Add(new SerializedItemStack(itemStack.Item.Guid, itemStack.Amount));
}
if (FileManager.WriteToFile(saveFilename, saveData.ToJson()))

10
UOP1_Project/Assets/Scripts/SaveSystem/SerializableScriptableObject.cs


public class SerializableScriptableObject : ScriptableObject
{
private string _serializableGuid;
public string SerializableGuid => _serializableGuid;
[SerializeField, HideInInspector] private string _guid;
public string Guid => _guid;
#if UNITY_EDITOR
#if UNITY_EDITOR
_serializableGuid = AssetDatabase.AssetPathToGUID(path);
_guid = AssetDatabase.AssetPathToGUID(path);
}
}
}
正在加载...
取消
保存