Skip to content

Commit

Permalink
Rework Configuration to load Feature configuration from an attached S…
Browse files Browse the repository at this point in the history
…criptableObject

By moving the configuration for indicators to an indicator feature; we can keep config and feature closer together and serialize them from and to a JSON file.
  • Loading branch information
mvriel committed Aug 10, 2023
1 parent 7e8d797 commit 285ba08
Show file tree
Hide file tree
Showing 23 changed files with 139 additions and 38 deletions.
20 changes: 10 additions & 10 deletions Assets/Scenes/Main.unity

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

1 change: 1 addition & 0 deletions Assets/Scriptables/Configuration.asset

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

2 changes: 1 addition & 1 deletion Assets/Scriptables/Configurator.asset

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

3 changes: 2 additions & 1 deletion Assets/Scriptables/Features/Address Search.asset

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

3 changes: 2 additions & 1 deletion Assets/Scriptables/Features/Buildings.asset

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

8 changes: 8 additions & 0 deletions Assets/Scriptables/Features/Configuration.meta

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

15 changes: 15 additions & 0 deletions Assets/Scriptables/Features/Configuration/Indicators.asset

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

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

24 changes: 24 additions & 0 deletions Assets/Scriptables/Features/Indicators.asset

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

8 changes: 8 additions & 0 deletions Assets/Scriptables/Features/Indicators.asset.meta

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

3 changes: 2 additions & 1 deletion Assets/Scriptables/Features/Neighbourhoods.asset

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

3 changes: 2 additions & 1 deletion Assets/Scriptables/Features/Obj Importer.asset

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

3 changes: 2 additions & 1 deletion Assets/Scriptables/Features/Screenshots.asset

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

3 changes: 2 additions & 1 deletion Assets/Scriptables/Features/Streetnames.asset

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

3 changes: 2 additions & 1 deletion Assets/Scriptables/Features/Sun.asset

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

3 changes: 2 additions & 1 deletion Assets/Scriptables/Features/Terrain.asset

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

3 changes: 2 additions & 1 deletion Assets/Scriptables/Features/Traffic Simulation.asset

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

3 changes: 2 additions & 1 deletion Assets/Scriptables/Features/Trees.asset

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

39 changes: 24 additions & 15 deletions Assets/Scripts/Configuration/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,19 @@
using System.Linq;
using System.Text;
using Netherlands3D.Coordinates;
using Netherlands3D.Twin.Configuration.Indicators;
using Netherlands3D.Twin.Features;
using UnityEngine;
using UnityEngine.Events;

namespace Netherlands3D.Twin.Configuration
{
public struct IndicatorConfiguration
{
public string dossierId;
}

[CreateAssetMenu(menuName = "Netherlands3D/Twin/Configuration", fileName = "Configuration", order = 0)]
public class Configuration : ScriptableObject
{
[SerializeField]
public string title = "Amersfoort";
[SerializeField]
private Coordinate origin = new(CoordinateSystem.RD, 161088, 503050, 300);
[SerializeField] public string title = "Amersfoort";
[SerializeField] private Coordinate origin = new(CoordinateSystem.RD, 161088, 503050, 300);
public List<Feature> Features = new();
private IndicatorConfiguration indicatorConfiguration;

public string Title
{
Expand Down Expand Up @@ -62,15 +55,31 @@ public bool LoadFromUrl(string url)

LoadOriginFromString(queryParameters.Get("origin"));
LoadFeaturesFromString(queryParameters.Get("features"));
indicatorConfiguration.dossierId = queryParameters.Get("indicators.dossier");
if (indicatorConfiguration.dossierId != null)
{
OnDossierLoadingStart.Invoke(indicatorConfiguration.dossierId);
}
LoadIndicatorConfiguration(queryParameters);

return true;
}

private void LoadIndicatorConfiguration(NameValueCollection queryParameters)
{
var featureId = "indicators";
var indicatorFeature = GetFeatureById(featureId);
if (!indicatorFeature) return;

var indicatorConfiguration = indicatorFeature.configuration as Indicators.Configuration;
if (!indicatorConfiguration) return;

indicatorConfiguration.dossierId = queryParameters.Get("indicators.dossier");
if (indicatorConfiguration.dossierId == null) return;

OnDossierLoadingStart.Invoke(indicatorConfiguration.dossierId);
}

private Feature GetFeatureById(string featureId)
{
return Features.FirstOrDefault(feature => string.Equals(feature.Id, featureId));
}

private bool UrlContainsConfiguration(NameValueCollection queryParameters)
{
string origin = queryParameters.Get("origin");
Expand Down
10 changes: 10 additions & 0 deletions Assets/Scripts/Configuration/Indicators/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using UnityEngine;

namespace Netherlands3D.Twin.Configuration.Indicators
{
[CreateAssetMenu(menuName = "Netherlands3D/Twin/Configuration/Indicators", fileName = "IndicatorConfiguration", order = 0)]
public class Configuration : ScriptableObject
{
public string dossierId;
}
}
3 changes: 3 additions & 0 deletions Assets/Scripts/Configuration/Indicators/Configuration.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/Scripts/Configuration/Indicators/DossierLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Netherlands3D.Twin.Configuration.Indicators
{
public class DossierLoader : MonoBehaviour
{
[SerializeField] private Configuration configuration;
[SerializeField] private Twin.Configuration.Configuration configuration;
[SerializeField] private DossierSO dossier;

private void OnEnable()
Expand Down
7 changes: 6 additions & 1 deletion Packages/eu.netherlands3d.twin-features/Scripts/Feature.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using UnityEngine;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Serialization;

namespace Netherlands3D.Twin.Features
{
Expand All @@ -8,6 +10,9 @@ public class Feature : ScriptableObject
{
public string Id;
public string Caption;

[JsonProperty(TypeNameHandling = TypeNameHandling.Auto)]
public ScriptableObject configuration;

[SerializeField] private bool isEnabled;

Expand Down

0 comments on commit 285ba08

Please sign in to comment.