Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add save system #30

Merged
merged 5 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Assets/Installer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public override void InstallBindings()
{
Container.Bind<Level>().FromComponentInHierarchy().AsSingle();
Container.Bind<Car>().FromComponentInHierarchy().AsSingle();
Container.Bind<SaveSystem>().FromComponentInHierarchy().AsSingle();
}
}
13 changes: 13 additions & 0 deletions Assets/Level/Prefabs/Level.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GameObject:
m_Component:
- component: {fileID: 3730233588541090756}
- component: {fileID: 7919559406662453164}
- component: {fileID: -6464488278121892307}
m_Layer: 0
m_Name: Level
m_TagString: Untagged
Expand Down Expand Up @@ -44,3 +45,15 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4cce93d9d25649b48869b0b87f2b7148, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &-6464488278121892307
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1072039847031320204}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d5544cf2801f2874bb8aa9df971e11e1, type: 3}
m_Name:
m_EditorClassIdentifier:
33 changes: 33 additions & 0 deletions Assets/Level/Scripts/SaveSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using UnityEngine;

public class SaveSystem : MonoBehaviour
{
private readonly string LEVEL_KEY = "LevelMaskChapter";

public bool GetLevelAccessState(int chapter, int level)
{
var mask = GetLevelChapterMask(chapter);
return mask[level-1] == '1';
}

public void SetLevelAccessState(int chapter, int level, bool state)
{
var mask = GetLevelChapterMask(chapter);

if (mask == string.Empty)
mask = "0000000000";

mask = mask.Insert(level-1, state ? "1" : "0");
mask = mask.Remove(level, 1);

PlayerPrefs.SetString($"{LEVEL_KEY}{chapter}", mask);
}

private string GetLevelChapterMask(int chapter)
=> PlayerPrefs.GetString($"{LEVEL_KEY}{chapter}", string.Empty);

private void Start()
{
SetLevelAccessState(1, 1, true);
}
}
11 changes: 11 additions & 0 deletions Assets/Level/Scripts/SaveSystem.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Loading Areas/Materials/Loading Area.mat
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Material:
- _QueueOffset: 0
- _ReceiveShadows: 1
- _SampleGI: 0
- _SizeMultiplier: 1
- _SizeMultiplier: 1.025
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
Expand Down
2 changes: 1 addition & 1 deletion Assets/Loading Areas/Materials/Radial Indicator.mat
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Material:
- _QueueOffset: 0
- _RadialFilling: 0.5
- _ReceiveShadows: 1
- _SizeMultiplier: 1
- _SizeMultiplier: 1.025
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
Expand Down
2 changes: 1 addition & 1 deletion Assets/Loading Areas/Materials/Unloading Area.mat
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Material:
- _QueueOffset: 0
- _ReceiveShadows: 1
- _SampleGI: 0
- _SizeMultiplier: 1
- _SizeMultiplier: 1.025
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
Expand Down
3 changes: 2 additions & 1 deletion Assets/Loading Areas/Prefabs/Unloading Zone.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6259880301c0fbe4f87458aafee026c3, type: 3}
m_Name:
m_EditorClassIdentifier:
levelName:
chapter: 0
level: 0
--- !u!114 &4523302815748661714
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
24 changes: 24 additions & 0 deletions Assets/Loading Areas/Scripts/ALoadScene.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using UnityEngine;
using Zenject;

public class ALoadScene : MonoBehaviour
{
private const float LOAD_LEVEL_DELAY = 1.5f;

protected string levelName;

private Level level;

public string LevelName => levelName;

public virtual void Load(bool isPermanent = false)
{
level.LoadLevel(levelName, isPermanent ? 0 : LOAD_LEVEL_DELAY);
}

[Inject]
private void Init(Level level)
{
this.level = level;
}
}
11 changes: 11 additions & 0 deletions Assets/Loading Areas/Scripts/ALoadScene.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 16 additions & 9 deletions Assets/Loading Areas/Scripts/LoadLevel.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
using UnityEngine;
using UnityEngine;
using Zenject;

public class LoadLevel : MonoBehaviour
public class LoadLevel : ALoadScene
{
private const float LOAD_LEVEL_DELAY = 1.5f;
private readonly string LEVEL_KEY = "Level{0}_{1}";

[SerializeField]
private string levelName;
private int chapter;
[SerializeField]
private int level;

private SaveSystem saveSystem;

private Level level;
public int Chapter => chapter;
public int Level => level;

public void Load(bool isPermanent = false)
public override void Load(bool isPermanent = false)
{
level.LoadLevel(levelName, isPermanent ? 0 : LOAD_LEVEL_DELAY);
saveSystem.SetLevelAccessState(chapter, level, true);
levelName = string.Format(LEVEL_KEY, chapter, level);
base.Load(isPermanent);
}

[Inject]
private void Init(Level level)
private void Init(SaveSystem saveSystem)
{
this.level = level;
this.saveSystem = saveSystem;
}
}
12 changes: 12 additions & 0 deletions Assets/Loading Areas/Scripts/LoadScene.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using UnityEngine;

public class LoadScene : ALoadScene
{
[SerializeField]
protected new string levelName;

private void Start()
{
base.levelName = levelName;
}
}
11 changes: 11 additions & 0 deletions Assets/Loading Areas/Scripts/LoadScene.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Assets/Loading Areas/Scripts/UnloadingArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
using UnityEngine;
using Zenject;

[RequireComponent(typeof(LoadLevel))]
[RequireComponent(typeof(ALoadScene))]
public class UnloadingArea : Area
{
private LoadLevel loadLevel;
private ALoadScene loadLevel;
private Car car;

protected override IEnumerator CargoOperation(Inventory carInventory)
=> ShiftCargo(carInventory, inventory);

protected override void OnStart()
{
loadLevel = GetComponent<LoadLevel>();
loadLevel = GetComponent<ALoadScene>();
inventory.CurentCountChanged += OnInventoryCurentCountChanged;
}

Expand Down
8 changes: 8 additions & 0 deletions Assets/Scenes/1/Level1_1.unity
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,14 @@ PrefabInstance:
propertyPath: radius
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: level
value: 2
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: chapter
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: levelName
value: Level1_2
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scenes/1/Level1_10.unity
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,14 @@ PrefabInstance:
propertyPath: radius
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: level
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: chapter
value: 2
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: levelName
value: Level2_1
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scenes/1/Level1_2.unity
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,14 @@ PrefabInstance:
propertyPath: radius
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: level
value: 3
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: chapter
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: levelName
value: Level1_3
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scenes/1/Level1_3.unity
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,14 @@ PrefabInstance:
propertyPath: radius
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: level
value: 4
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: chapter
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: levelName
value: Level1_4
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scenes/1/Level1_4.unity
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@ PrefabInstance:
propertyPath: radius
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: level
value: 5
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: chapter
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: levelName
value: Level1_5
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scenes/1/Level1_5.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,14 @@ PrefabInstance:
propertyPath: radius
value: 30
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: level
value: 6
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: chapter
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: levelName
value: Level1_6
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scenes/1/Level1_6.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,14 @@ PrefabInstance:
propertyPath: radius
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: level
value: 7
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: chapter
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: levelName
value: Level1_7
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scenes/1/Level1_7.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,14 @@ PrefabInstance:
propertyPath: radius
value: 20
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: level
value: 8
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: chapter
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: levelName
value: Level1_8
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scenes/1/Level1_8.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2727,6 +2727,14 @@ PrefabInstance:
propertyPath: radius
value: 20
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: level
value: 9
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: chapter
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: levelName
value: Level1_9
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scenes/1/Level1_9.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2873,6 +2873,14 @@ PrefabInstance:
propertyPath: radius
value: 20
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: level
value: 10
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: chapter
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5100768909755800963, guid: 28e81ccbfb764de4e84c79524a229193, type: 3}
propertyPath: levelName
value: Level1_10
Expand Down
Loading