diff --git a/Assets/Scripts/Node.cs b/Assets/Scripts/Node.cs index 02f6a76..50f53fe 100644 --- a/Assets/Scripts/Node.cs +++ b/Assets/Scripts/Node.cs @@ -3,16 +3,18 @@ using UnityEngine; public class Node { - public FlatCircleRenderer circle = new FlatCircleRenderer(0.4f, 0.1f, 50); + public FlatCircleRenderer circle = new FlatCircleRenderer(0.2f, 0.05f, 32); public Vector3 position; public List roads = new List(); + public GameObject gameObject = new GameObject(); public Node(Vector3 position, Transform parent, Material material) { - GameObject child = new GameObject(); - child.transform.position = position; - child.AddComponent().material = material; - child.AddComponent().mesh = circle.mesh; - child.transform.parent = parent; + gameObject.transform.position = position; + gameObject.AddComponent().material = material; + gameObject.AddComponent().mesh = circle.mesh; + gameObject.AddComponent().radius = 0.25f; + gameObject.transform.parent = parent; + gameObject.layer = 7; this.position = position; } @@ -29,4 +31,12 @@ } return ((Node)other).position.Equals(position); } + + public void pull(Vector3 position) { + this.position = position; + gameObject.transform.position = position; + foreach (Road road in roads) { + road.update(); + } + } } diff --git a/Assets/Scripts/Node.cs b/Assets/Scripts/Node.cs index 02f6a76..50f53fe 100644 --- a/Assets/Scripts/Node.cs +++ b/Assets/Scripts/Node.cs @@ -3,16 +3,18 @@ using UnityEngine; public class Node { - public FlatCircleRenderer circle = new FlatCircleRenderer(0.4f, 0.1f, 50); + public FlatCircleRenderer circle = new FlatCircleRenderer(0.2f, 0.05f, 32); public Vector3 position; public List roads = new List(); + public GameObject gameObject = new GameObject(); public Node(Vector3 position, Transform parent, Material material) { - GameObject child = new GameObject(); - child.transform.position = position; - child.AddComponent().material = material; - child.AddComponent().mesh = circle.mesh; - child.transform.parent = parent; + gameObject.transform.position = position; + gameObject.AddComponent().material = material; + gameObject.AddComponent().mesh = circle.mesh; + gameObject.AddComponent().radius = 0.25f; + gameObject.transform.parent = parent; + gameObject.layer = 7; this.position = position; } @@ -29,4 +31,12 @@ } return ((Node)other).position.Equals(position); } + + public void pull(Vector3 position) { + this.position = position; + gameObject.transform.position = position; + foreach (Road road in roads) { + road.update(); + } + } } diff --git a/Assets/Scripts/Roads.cs b/Assets/Scripts/Roads.cs index 6480c47..4b54d35 100644 --- a/Assets/Scripts/Roads.cs +++ b/Assets/Scripts/Roads.cs @@ -7,7 +7,7 @@ public List roads = new List(); public FlatBezierRenderer roadRenderer; public Camera mainCamera; - private bool down = false; + private bool drawing = false; public Material material; void Start() { @@ -20,14 +20,14 @@ foreach (Node node in nodes) { if ((hit.point - node.position).magnitude < 1.0f) { startNode = node; - down = true; + drawing = true; return; } } Vector3 position = new Vector3(hit.point.x, 0.0f, hit.point.z); startNode = new Node(position, transform, material); nodes.Add(startNode); - down = true; + drawing = true; } private void endRoad() { @@ -44,7 +44,6 @@ endNode = new Node(position, transform, material); nodes.Add(endNode); } - Road road = new Road(startNode, endNode, material); if (!roads.Contains(road)) { road.initialize(transform); @@ -53,18 +52,31 @@ endNode.roads.Add(road); } startNode = null; - down = false; + drawing = false; } + Node pulling = null; + void Update() { if (Input.GetAxis("Fire1") != 0.0f) { - if (!down) { + if (!drawing) { startRoad(); } - } else { - if (down) { - endRoad(); + } else if (drawing) { + endRoad(); + } + Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); + if (Input.GetAxis("Fire2") != 0.0f) { + if (pulling == null && Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, 1 << 7)) { + pulling = nodes.Find(node => node.gameObject == hit.transform.gameObject); } + } else { + pulling = null; + } + if (pulling != null) { + Physics.Raycast(ray, out RaycastHit hit_, Mathf.Infinity, 1 << 6); + Vector3 position = new Vector3(hit_.point.x, 0.0f, hit_.point.z); + pulling.pull(position); } } }