Skip to content

Commit 6bf34fe

Browse files
committed
Minor Update
- тепер обов'язково імплементувати всі методи ISaveable - метод Read при незнаходженні ключа тепер не кидає помилку, перериваючи виконання коду, а друкує попередження в консоль - нове перевантаження метода Read з параметром 'T defaultValue' - перейменовано клас SaveSystemObjectEditor.cs
1 parent 72795ff commit 6bf34fe

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

Editor/SceneSaveEditor.cs renamed to Editor/SaveSystemObjectEditor.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public override void OnInspectorGUI()
6161
EditorGUILayout.EndHorizontal();
6262
EditorGUILayout.PropertyField(_fileName_string);
6363
EditorGUILayout.PropertyField(_path_enum);
64-
if(_path_enum.enumValueIndex == 2)
64+
if (_path_enum.enumValueIndex == 2)
6565
{
6666
EditorGUILayout.BeginHorizontal();
6767
EditorGUILayout.PropertyField(_customPath_string);
@@ -75,13 +75,13 @@ public override void OnInspectorGUI()
7575
EditorGUILayout.PropertyField(_collectSaveablesEverySave_bool);
7676
EditorGUILayout.BeginHorizontal();
7777
EditorGUILayout.PropertyField(_useEncryption_bool);
78-
if(_useEncryption_bool.boolValue)
78+
if (_useEncryption_bool.boolValue)
7979
EditorGUILayout.PropertyField(_encryptionPassword_string, new GUIContent(string.Empty));
8080
EditorGUILayout.EndHorizontal();
8181

8282
EditorGUILayout.BeginHorizontal();
8383
EditorGUILayout.PropertyField(_autoSaving_bool);
84-
if(_autoSaving_bool.boolValue)
84+
if (_autoSaving_bool.boolValue)
8585
EditorGUILayout.PropertyField(_savePerion_int, new GUIContent("Period (seconds)"));
8686
EditorGUILayout.EndHorizontal();
8787

@@ -94,11 +94,11 @@ public override void OnInspectorGUI()
9494
serializedObject.ApplyModifiedProperties();
9595

9696
// File preview
97-
97+
9898
EditorGUILayout.Space(10f);
9999
EditorGUILayout.BeginHorizontal();
100100
EditorGUILayout.LabelField("File Preview", EditorStyles.boldLabel);
101-
if(_file != null && GUILayout.Button("Save Changes"))
101+
if (_file != null && GUILayout.Button("Save Changes"))
102102
{
103103
_file.Save(_sceneSave.GetPath(), _sceneSave.GetPassword());
104104
}
@@ -109,7 +109,7 @@ public override void OnInspectorGUI()
109109
}
110110
EditorGUILayout.EndHorizontal();
111111

112-
if(_file != null)
112+
if (_file != null)
113113
{
114114
EditorGUILayout.Space(10f);
115115
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
@@ -123,7 +123,7 @@ public override void OnInspectorGUI()
123123

124124
EditorGUILayout.EndScrollView();
125125
}
126-
126+
127127
}
128128

129129
private void DrawFileValue(KeyValuePair<string, object> item)
@@ -181,4 +181,4 @@ public enum Type
181181
ObjectReference = 1,
182182
}
183183
}
184-
}
184+
}

Runtime/ISaveable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace TarasK8.SaveSystem
22
{
33
public interface ISaveable
44
{
5-
public void OnSave(SFile file) { }
6-
public void OnLoad(SFile file) { }
5+
public void OnSave(SFile file);
6+
public void OnLoad(SFile file);
77
}
88
}

Runtime/SFile.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,20 @@ public T Read<T>(string key)
3636
}
3737
else
3838
{
39-
throw new System.ArgumentOutOfRangeException(nameof(key));
39+
Debug.LogWarning(@$"No value found for '{key}'.");
40+
return default;
41+
}
42+
}
43+
44+
public T Read<T>(string key, T defaultValue)
45+
{
46+
if (_data.TryGetValue(key, out var data))
47+
{
48+
return ToObject<T>(data);
49+
}
50+
else
51+
{
52+
return defaultValue;
4053
}
4154
}
4255

0 commit comments

Comments
 (0)