浏览代码

Added TestScript for explanation of functionality

/main
Ujjwal Raut 4 年前
当前提交
bdf26d9d
共有 6 个文件被更改,包括 79 次插入1 次删除
  1. 9
      UOP1_Project/Assets/Scripts/SaveSystem/Save.cs
  2. 8
      UOP1_Project/Assets/Scripts/SaveSystem.meta
  3. 8
      UOP1_Project/Assets/Scripts/SaveSystem/TestScript.meta
  4. 44
      UOP1_Project/Assets/Scripts/SaveSystem/TestScript/TestScript.cs
  5. 11
      UOP1_Project/Assets/Scripts/SaveSystem/TestScript/TestScript.cs.meta

9
UOP1_Project/Assets/Scripts/SaveSystem/Save.cs


/// </summary>
[System.Serializable]
public class Save {
// This is test data, written accodring to TestScript.cs class
// This will change according to whatever data that needs to be stored
// The variables need to be public, else we would have to write trivial getter/setter functions.
public int _testInteger = default;
public float _testFloat = default;
public bool _testBool = default;
}

8
UOP1_Project/Assets/Scripts/SaveSystem.meta


fileFormatVersion: 2
guid: 2f2c4e28b0a202d40a01e4ac82d1aed8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/Scripts/SaveSystem/TestScript.meta


fileFormatVersion: 2
guid: 2e698415cd1e96f46876987ec02fa185
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

44
UOP1_Project/Assets/Scripts/SaveSystem/TestScript/TestScript.cs


using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// A test script showing usage of the save system.<br/>
/// This code corresponds to the code written in <see cref="Save"/> class.<br/>
/// Unfortunately, inspite of all my efforts, I wasn't able to remove all dependencies.
/// </summary>
public class TestScript : MonoBehaviour, ISaveable
{
int _testInteger = default;
float _testFloat = default;
bool _testBool = default;
private void OnEnable()
{
// This is necessary, otherwise the object won't get added to registry of objects which needs to be serialized
SaveSystem.AddToRegistry += AddToSaveRegistry;
}
private void OnDisable()
{
SaveSystem.AddToRegistry -= AddToSaveRegistry;
}
public void AddToSaveRegistry(HashSet<ISaveable> registry)
{
registry.Add(this);
}
public void Serialize(Save saveFile)
{
saveFile._testInteger = _testInteger;
saveFile._testFloat = _testFloat;
saveFile._testBool = _testBool;
}
public void Deserialize(Save saveFile)
{
_testInteger = saveFile._testInteger;
_testFloat = saveFile._testFloat;
_testBool = saveFile._testBool;
}
}

11
UOP1_Project/Assets/Scripts/SaveSystem/TestScript/TestScript.cs.meta


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