diff --git a/Assets/Scripts/Buttons/SaveButton.cs b/Assets/Scripts/Buttons/SaveButton.cs index 063aed0..b6434f0 100644 --- a/Assets/Scripts/Buttons/SaveButton.cs +++ b/Assets/Scripts/Buttons/SaveButton.cs @@ -14,11 +14,18 @@ } [Serializable] + private struct SaveRoad { + public int start, end; + } + + [Serializable] private struct SaveStruct { public List nodes; + public List roads; } public void OnPointerDown(PointerEventData eventData) { + config.onClick(); List nodes = new List(); foreach (Node node in config.roadNetwork.nodes) { SaveNode saveNode = new SaveNode(); @@ -32,8 +39,16 @@ } nodes.Add(saveNode); } + List roads = new List(); + foreach (Road road in config.roadNetwork.roads) { + SaveRoad saveRoad = new SaveRoad(); + saveRoad.start = config.roadNetwork.nodes.IndexOf(road.nodes[0]); + saveRoad.end = config.roadNetwork.nodes.IndexOf(road.nodes[1]); + roads.Add(saveRoad); + } SaveStruct save = new SaveStruct(); save.nodes = nodes; + save.roads = roads; print(JsonUtility.ToJson(save)); } } diff --git a/Assets/Scripts/Buttons/SaveButton.cs b/Assets/Scripts/Buttons/SaveButton.cs index 063aed0..b6434f0 100644 --- a/Assets/Scripts/Buttons/SaveButton.cs +++ b/Assets/Scripts/Buttons/SaveButton.cs @@ -14,11 +14,18 @@ } [Serializable] + private struct SaveRoad { + public int start, end; + } + + [Serializable] private struct SaveStruct { public List nodes; + public List roads; } public void OnPointerDown(PointerEventData eventData) { + config.onClick(); List nodes = new List(); foreach (Node node in config.roadNetwork.nodes) { SaveNode saveNode = new SaveNode(); @@ -32,8 +39,16 @@ } nodes.Add(saveNode); } + List roads = new List(); + foreach (Road road in config.roadNetwork.roads) { + SaveRoad saveRoad = new SaveRoad(); + saveRoad.start = config.roadNetwork.nodes.IndexOf(road.nodes[0]); + saveRoad.end = config.roadNetwork.nodes.IndexOf(road.nodes[1]); + roads.Add(saveRoad); + } SaveStruct save = new SaveStruct(); save.nodes = nodes; + save.roads = roads; print(JsonUtility.ToJson(save)); } } diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index 27375c8..2867e64 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -17,11 +17,16 @@ public RoadNetwork roadNetwork = new RoadNetwork(); public void click(Mode mode, int index) { - this.mode = Mode.ClickButton; + onClick(); futureMode = mode; highlight.anchoredPosition = new Vector3(36f * (1.5f*index+1), 36f, 0f); } + public void onClick() { + futureMode = mode; + mode = Mode.ClickButton; + } + void Update() { if (Input.GetAxis("Fire1") == 0.0f && mode == Mode.ClickButton) { mode = futureMode; diff --git a/Assets/Scripts/Buttons/SaveButton.cs b/Assets/Scripts/Buttons/SaveButton.cs index 063aed0..b6434f0 100644 --- a/Assets/Scripts/Buttons/SaveButton.cs +++ b/Assets/Scripts/Buttons/SaveButton.cs @@ -14,11 +14,18 @@ } [Serializable] + private struct SaveRoad { + public int start, end; + } + + [Serializable] private struct SaveStruct { public List nodes; + public List roads; } public void OnPointerDown(PointerEventData eventData) { + config.onClick(); List nodes = new List(); foreach (Node node in config.roadNetwork.nodes) { SaveNode saveNode = new SaveNode(); @@ -32,8 +39,16 @@ } nodes.Add(saveNode); } + List roads = new List(); + foreach (Road road in config.roadNetwork.roads) { + SaveRoad saveRoad = new SaveRoad(); + saveRoad.start = config.roadNetwork.nodes.IndexOf(road.nodes[0]); + saveRoad.end = config.roadNetwork.nodes.IndexOf(road.nodes[1]); + roads.Add(saveRoad); + } SaveStruct save = new SaveStruct(); save.nodes = nodes; + save.roads = roads; print(JsonUtility.ToJson(save)); } } diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index 27375c8..2867e64 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -17,11 +17,16 @@ public RoadNetwork roadNetwork = new RoadNetwork(); public void click(Mode mode, int index) { - this.mode = Mode.ClickButton; + onClick(); futureMode = mode; highlight.anchoredPosition = new Vector3(36f * (1.5f*index+1), 36f, 0f); } + public void onClick() { + futureMode = mode; + mode = Mode.ClickButton; + } + void Update() { if (Input.GetAxis("Fire1") == 0.0f && mode == Mode.ClickButton) { mode = futureMode; diff --git a/Assets/Scripts/Roads/Road.cs b/Assets/Scripts/Roads/Road.cs index 0489387..5564a92 100644 --- a/Assets/Scripts/Roads/Road.cs +++ b/Assets/Scripts/Roads/Road.cs @@ -7,7 +7,7 @@ public Bezier path; private Bezier arrow1, arrow2; private FlatBezierRenderer pathLine, roadBody, arrow1Renderer, arrow2Renderer; - private Config config; + public Config config; private MeshCollider collider; public GameObject gameObject; public List carsOnRoute = new List(); diff --git a/Assets/Scripts/Buttons/SaveButton.cs b/Assets/Scripts/Buttons/SaveButton.cs index 063aed0..b6434f0 100644 --- a/Assets/Scripts/Buttons/SaveButton.cs +++ b/Assets/Scripts/Buttons/SaveButton.cs @@ -14,11 +14,18 @@ } [Serializable] + private struct SaveRoad { + public int start, end; + } + + [Serializable] private struct SaveStruct { public List nodes; + public List roads; } public void OnPointerDown(PointerEventData eventData) { + config.onClick(); List nodes = new List(); foreach (Node node in config.roadNetwork.nodes) { SaveNode saveNode = new SaveNode(); @@ -32,8 +39,16 @@ } nodes.Add(saveNode); } + List roads = new List(); + foreach (Road road in config.roadNetwork.roads) { + SaveRoad saveRoad = new SaveRoad(); + saveRoad.start = config.roadNetwork.nodes.IndexOf(road.nodes[0]); + saveRoad.end = config.roadNetwork.nodes.IndexOf(road.nodes[1]); + roads.Add(saveRoad); + } SaveStruct save = new SaveStruct(); save.nodes = nodes; + save.roads = roads; print(JsonUtility.ToJson(save)); } } diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index 27375c8..2867e64 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -17,11 +17,16 @@ public RoadNetwork roadNetwork = new RoadNetwork(); public void click(Mode mode, int index) { - this.mode = Mode.ClickButton; + onClick(); futureMode = mode; highlight.anchoredPosition = new Vector3(36f * (1.5f*index+1), 36f, 0f); } + public void onClick() { + futureMode = mode; + mode = Mode.ClickButton; + } + void Update() { if (Input.GetAxis("Fire1") == 0.0f && mode == Mode.ClickButton) { mode = futureMode; diff --git a/Assets/Scripts/Roads/Road.cs b/Assets/Scripts/Roads/Road.cs index 0489387..5564a92 100644 --- a/Assets/Scripts/Roads/Road.cs +++ b/Assets/Scripts/Roads/Road.cs @@ -7,7 +7,7 @@ public Bezier path; private Bezier arrow1, arrow2; private FlatBezierRenderer pathLine, roadBody, arrow1Renderer, arrow2Renderer; - private Config config; + public Config config; private MeshCollider collider; public GameObject gameObject; public List carsOnRoute = new List(); diff --git a/Assets/Scripts/Roads/RoadData.cs b/Assets/Scripts/Roads/RoadData.cs index eb620ba..6252bd0 100644 --- a/Assets/Scripts/Roads/RoadData.cs +++ b/Assets/Scripts/Roads/RoadData.cs @@ -4,4 +4,12 @@ public class RoadData : MonoBehaviour { public Road road; + + public void Start() { + road.config.roadNetwork.roads.Add(road); + } + + public void OnDestroy() { + road.config.roadNetwork.roads.Remove(road); + } }