-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from GinoxXP/feature/save-system
Add save system
- Loading branch information
Showing
64 changed files
with
1,895 additions
and
1,341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.