-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: developing a generic Manager class and a DataManager that can s…
…ave/load individual managers
- Loading branch information
Showing
6 changed files
with
146 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using Urchin.Managers; | ||
|
||
public class DataManager : MonoBehaviour | ||
{ | ||
[SerializeField] PrimitiveMeshManager _primitiveMeshManager; | ||
|
||
[SerializeField] private string apiURL; | ||
|
||
private List<Manager> _managers; | ||
|
||
#region Unity | ||
private void Awake() | ||
{ | ||
_managers = new(); | ||
_managers.Add(_primitiveMeshManager); | ||
} | ||
#endregion | ||
|
||
public void Save(string sceneName) | ||
{ | ||
FlattenedData data = new(); | ||
data.Data = new ManagerData[_managers.Count]; | ||
|
||
for (int i = 0; i < _managers.Count; i++) | ||
{ | ||
data.Data[i].Type = _managers[i].Type; | ||
data.Data[i].Data = _managers[i].ToSerializedData(); | ||
} | ||
|
||
// Push data up to the REST API | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public void Load(string targetURL) | ||
{ | ||
throw new System.NotImplementedException(); | ||
|
||
// Get the manager data back from the API | ||
FlattenedData data = new(); | ||
|
||
foreach (ManagerData managerData in data.Data) | ||
{ | ||
switch (managerData.Type) | ||
{ | ||
case ManagerType.PrimitiveMeshManager: | ||
_primitiveMeshManager.FromSerializedData(managerData.Data); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private struct FlattenedData | ||
{ | ||
public ManagerData[] Data; | ||
} | ||
|
||
|
||
private struct ManagerData | ||
{ | ||
public ManagerType Type; | ||
public string Data; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
UnityClient/Packages/vbl.urchin/Scripts/DataManager.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
UnityClient/Packages/vbl.urchin/Scripts/Managers/Manager.cs
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,18 @@ | ||
using UnityEngine; | ||
|
||
namespace Urchin.Managers | ||
{ | ||
public abstract class Manager : MonoBehaviour | ||
{ | ||
public abstract ManagerType Type { get; } | ||
|
||
public abstract string ToSerializedData(); | ||
public abstract void FromSerializedData(string serializedData); | ||
} | ||
|
||
public enum ManagerType | ||
{ | ||
PrimitiveMeshManager = 0, | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
UnityClient/Packages/vbl.urchin/Scripts/Managers/Manager.cs.meta
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