This repository has been archived by the owner on Jun 26, 2021. It is now read-only.
forked from MicroGSD/RoadArchitect
-
Notifications
You must be signed in to change notification settings - Fork 2
/
GSDRoadConnector.cs
87 lines (73 loc) · 2.5 KB
/
GSDRoadConnector.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#region "Imports"
//using System.Collections; // Unused
//using System.Collections.Generic; // Unused
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
#endregion
[ExecuteInEditMode]
public class GSDRoadConnector : MonoBehaviour
{
public GSDSplineN connectedNode;
[HideInInspector]
public GSDOffRoadObject obj { get { return transform.parent.GetComponent<GSDOffRoadObject>(); } }
#if UNITY_EDITOR
#region "Gizmos"
private void OnDrawGizmos()
{
Gizmos.color = GSDOffRoadObject.Color_NodeOffRoadColor;
Gizmos.DrawCube(transform.position + new Vector3(0f, 6f, 0f), new Vector3(2f, 11f, 2f));
}
private void OnDrawGizmosSelected()
{
Gizmos.color = GSDOffRoadObject.Color_NodeOffRoadSelectedColor;
Gizmos.DrawCube(transform.position + new Vector3(0f, 6.25f, 0f), new Vector3(3.5f, 12.5f, 3.5f));
}
#endregion
public void ConnectToNode(GSDSplineN node)
{
Debug.Log("Would connect to " + node);
connectedNode = node;
connectedNode.transform.position = transform.position;
connectedNode.GSDSpline.tRoad.UpdateRoad();
}
// Update is called once per frame
private void Update()
{
if (connectedNode != null)
{
if (obj == null)
{
Debug.LogError("Parent should have GSDOffRoadObject component attached");
}
if (connectedNode.transform.position != transform.position)
{
connectedNode.transform.position = transform.position;
connectedNode.GSDSpline.tRoad.UpdateRoad();
}
}
}
#endif
}
#if UNITY_EDITOR
[CustomEditor(typeof(GSDRoadConnector))]
public class GSDRoadConnectorEditor : Editor
{
public GSDRoadConnector tConnector { get { return (GSDRoadConnector) target; } }
public override void OnInspectorGUI()
{
if (tConnector.connectedNode != null)
{
EditorGUILayout.BeginVertical();
EditorGUILayout.LabelField("Off-road connection:", EditorStyles.boldLabel);
EditorGUILayout.LabelField(tConnector.connectedNode.GSDSpline.tRoad.name + " to " + tConnector.obj.name);
if (GUILayout.Button("Break connection"))
{
tConnector.connectedNode = null;
}
EditorGUILayout.EndVertical();
}
}
}
#endif