diff --git a/.gitignore b/.gitignore index 5514081..1f2f5ec 100644 --- a/.gitignore +++ b/.gitignore @@ -85,3 +85,4 @@ Assets/Scripts/Primitives/Bezier.cs.meta Assets/Scripts/Car/Route.cs.meta Assets/Scripts/Buttons/SaveStructs.cs.meta +Assets/Scripts/Buttons/LoadButton.cs.meta diff --git a/.gitignore b/.gitignore index 5514081..1f2f5ec 100644 --- a/.gitignore +++ b/.gitignore @@ -85,3 +85,4 @@ Assets/Scripts/Primitives/Bezier.cs.meta Assets/Scripts/Car/Route.cs.meta Assets/Scripts/Buttons/SaveStructs.cs.meta +Assets/Scripts/Buttons/LoadButton.cs.meta diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 222795d..dfa40a3 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -1822,12 +1822,10 @@ m_GameObject: {fileID: 1812881467} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 93424ce963983d1449cd639ba857d364, type: 3} + m_Script: {fileID: 11500000, guid: cd94c0a758450494face61652a276f18, type: 3} m_Name: m_EditorClassIdentifier: config: {fileID: 128843415} - mode: 1 - index: 0 --- !u!114 &1812881470 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/.gitignore b/.gitignore index 5514081..1f2f5ec 100644 --- a/.gitignore +++ b/.gitignore @@ -85,3 +85,4 @@ Assets/Scripts/Primitives/Bezier.cs.meta Assets/Scripts/Car/Route.cs.meta Assets/Scripts/Buttons/SaveStructs.cs.meta +Assets/Scripts/Buttons/LoadButton.cs.meta diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 222795d..dfa40a3 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -1822,12 +1822,10 @@ m_GameObject: {fileID: 1812881467} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 93424ce963983d1449cd639ba857d364, type: 3} + m_Script: {fileID: 11500000, guid: cd94c0a758450494face61652a276f18, type: 3} m_Name: m_EditorClassIdentifier: config: {fileID: 128843415} - mode: 1 - index: 0 --- !u!114 &1812881470 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Buttons/LoadButton.cs b/Assets/Scripts/Buttons/LoadButton.cs new file mode 100644 index 0000000..2724452 --- /dev/null +++ b/Assets/Scripts/Buttons/LoadButton.cs @@ -0,0 +1,26 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.EventSystems; +using System; +using UnityEditor; +using System.IO; +using System.Text; + + +public class LoadButton : MonoBehaviour, IPointerDownHandler { + public Config config; + + public void OnPointerDown(PointerEventData eventData) { + config.onClick(); + string filePath = EditorUtility.OpenFilePanel("Open a road network", "", "json"); + if (filePath.Length == 0) { + return; + } + // todo: clear scene of all currently build nodes and roads and ensure Config.roadNetwork is empty + string fileContent = File.ReadAllText(filePath); + SaveStruct saveData = JsonUtility.FromJson(fileContent); + // todo: put the saved nodes and nodes into the world + print(saveData.nodes.Count); + } +}