Skip to content
This repository has been archived by the owner on Jun 26, 2021. It is now read-only.

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
* Fixed warnings
* Begin adding off-road connections
  • Loading branch information
embeddedt authored and FritzsHero committed Jul 10, 2019
1 parent 1466145 commit 8a8bb72
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 54 deletions.
54 changes: 22 additions & 32 deletions Editor/GSDRoadEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public class GSDRoadEditor : Editor {

//Serialized properties:
SerializedProperty t_opt_GizmosEnabled;
SerializedProperty t_opt_roadType;
SerializedProperty t_opt_Lanes;
SerializedProperty t_opt_Lanes;
SerializedProperty t_opt_LaneWidth;
SerializedProperty t_opt_bShouldersEnabled;
SerializedProperty t_opt_ShoulderWidth;
Expand Down Expand Up @@ -92,10 +91,7 @@ public enum tempEnum{Two,Four,Six};
"Four",
"Six"
};
private enum RoadType { Local, Freeway };
private int roadtypeEnum;
private string[] roadtypeEnumdesc = new string[] { "Local Road", "Divided Freeway"};
GUIStyle WarningLabelStyle;
GUIStyle WarningLabelStyle;
Texture2D WarningLabelBG;
GUIStyle GSDImageButton = null;
GUIStyle GSDMaybeButton = null;
Expand All @@ -113,8 +109,7 @@ private enum RoadType { Local, Freeway };

private void OnEnable() {
t_opt_GizmosEnabled = serializedObject.FindProperty("opt_GizmosEnabled");
t_opt_roadType = serializedObject.FindProperty("opt_roadType");
t_opt_Lanes = serializedObject.FindProperty("opt_Lanes");
t_opt_Lanes = serializedObject.FindProperty("opt_Lanes");
t_opt_LaneWidth = serializedObject.FindProperty("opt_LaneWidth");
t_opt_bShouldersEnabled = serializedObject.FindProperty("opt_bShouldersEnabled");
t_opt_ShoulderWidth = serializedObject.FindProperty("opt_ShoulderWidth");
Expand Down Expand Up @@ -267,11 +262,9 @@ public override void OnInspectorGUI(){
Application.OpenURL("http://microgsd.com/Support/RoadArchitectManual.aspx");
}
EditorGUILayout.EndHorizontal();

t_opt_roadType.intValue = EditorGUILayout.Popup("Road Type: ", t_opt_roadType.intValue, roadtypeEnumdesc);

//Option: Lane count:
if (RS.opt_Lanes == 2){

//Option: Lane count:
if(RS.opt_Lanes == 2){
LanesEnum = tempEnum.Two;
}else if(RS.opt_Lanes == 4){
LanesEnum = tempEnum.Four;
Expand Down Expand Up @@ -918,7 +911,8 @@ public override void OnInspectorGUI(){
if(bApplyMatsCheck){
t_bApplyMatsCheck = true;
}
}
RS.UpdateRoad();
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.LabelField("Applying will overwrite any saved cuts' material(s).");

Expand Down Expand Up @@ -1108,41 +1102,37 @@ public void OnSceneGUI() {
Ray worldRay = HandleUtility.GUIPointToWorldRay (Event.current.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast (worldRay, out hitInfo)){
if(hitInfo.collider.transform.GetComponent<Terrain>() != null || hitInfo.collider.transform.name.ToLower().Contains("terrain")){
RS.Editor_MousePos = hitInfo.point;
RS.Editor_MouseTerrainHit = true;
if(RS.GSDSpline && RS.GSDSpline.PreviewSpline){
//Debug.Log("Drawing new node");
if(RS.GSDSpline.PreviewSpline.mNodes == null || RS.GSDSpline.PreviewSpline.mNodes.Count < 1){ RS.GSDSpline.Setup(); }
RS.GSDSpline.PreviewSpline.MousePos = hitInfo.point;
RS.GSDSpline.PreviewSpline.bGizmoDraw = true;
SceneView.RepaintAll();
}
}else{
RS.Editor_MouseTerrainHit = false;
/* There used to be a check for whether this was a terrain */
RS.Editor_MousePos = hitInfo.point;
RS.Editor_MouseTerrainHit = true;
if(RS.GSDSpline && RS.GSDSpline.PreviewSpline){
//Debug.Log("Drawing new node");
if(RS.GSDSpline.PreviewSpline.mNodes == null || RS.GSDSpline.PreviewSpline.mNodes.Count < 1){ RS.GSDSpline.Setup(); }
RS.GSDSpline.PreviewSpline.MousePos = hitInfo.point;
RS.GSDSpline.PreviewSpline.bGizmoDraw = true;
SceneView.RepaintAll();
}
}

GUI.changed = true;
}else if(current.shift){
Ray worldRay = HandleUtility.GUIPointToWorldRay (Event.current.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast (worldRay, out hitInfo)){
if(hitInfo.collider.transform.GetComponent<Terrain>() != null){
if (Physics.Raycast(worldRay, out hitInfo)) {
/* Used to check for terrain */
// if(hitInfo.collider.transform.name.ToLower().Contains("terrain")){
RS.Editor_MousePos = hitInfo.point;
RS.Editor_MouseTerrainHit = true;
if(RS.GSDSpline && RS.GSDSpline.PreviewSplineInsert){
//Debug.Log("Drawing insert node");
if(RS.GSDSpline.PreviewSplineInsert.mNodes == null || RS.GSDSpline.PreviewSplineInsert.mNodes.Count < 1){ RS.GSDSpline.PreviewSplineInsert.DetermineInsertNodes(); }
RS.GSDSpline.PreviewSplineInsert.MousePos = hitInfo.point;
RS.GSDSpline.PreviewSplineInsert.bGizmoDraw = true;
RS.GSDSpline.PreviewSplineInsert.UpdateActionNode();
SceneView.RepaintAll();
}
}else{
RS.Editor_MouseTerrainHit = false;
}
//}else{
// RS.Editor_MouseTerrainHit = false;
//}
}

GUI.changed = true;
Expand Down
37 changes: 16 additions & 21 deletions Editor/GSDSplineNEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,7 @@ public void OnSceneGUI() {
//Drag with left click release:
if(Event.current.type == EventType.MouseUp && Event.current.button == 0){
Object[] xNodeObjects = GameObject.FindObjectsOfType(typeof(GSDSplineN));
Object[] connectorObjects = GameObject.FindObjectsOfType(typeof(GSDRoadConnector));
foreach(GSDSplineN xNode in xNodeObjects){
if(Vector3.Distance(xNode.transform.position,tNode.transform.position) < 2f){
if(xNode == tNode){ continue; }
Expand Down Expand Up @@ -1749,16 +1750,20 @@ public void OnSceneGUI() {
continue;
}
}

if(!bMouseDragHasProcessed){
foreach (GSDRoadConnector connector in connectorObjects)
{
if (Vector3.Distance(connector.transform.position, tNode.transform.position) < 2f) {
if (connector.connectedNode != null) continue;
connector.ConnectToNode(tNode);
break;
}
}

if (!bMouseDragHasProcessed){
//Enforce maximum road grade:
Terrain terrain = GSD.Roads.GSDRoadUtil.GetTerrain(tNode.transform.position);
if (terrain != null)
if (tNode.IsLegitimate() && tNode.GSDSpline.tRoad.opt_bMaxGradeEnabled)
{
if (tNode.IsLegitimate() && tNode.GSDSpline.tRoad.opt_bMaxGradeEnabled)
{
tNode.EnsureGradeValidity();
}
tNode.EnsureGradeValidity();
}
TriggerRoadUpdate();
bUsed = true;
Expand All @@ -1773,20 +1778,10 @@ public void OnSceneGUI() {

Vector3 vChangeChecker = tNode.transform.position;
if(VectorDiff(vChangeChecker,tNode.pos)){
Terrain terrain = GSD.Roads.GSDRoadUtil.GetTerrain(tNode.transform.position);
if (true) /* WIP */
{
tNode.pos = vChangeChecker;
if (tNode.IsLegitimate() && tNode.GSDSpline.tRoad.opt_bMaxGradeEnabled)
{
tNode.EnsureGradeValidity();
}
} else
tNode.pos = vChangeChecker;
if (tNode.IsLegitimate() && tNode.GSDSpline.tRoad.opt_bMaxGradeEnabled)
{
Debug.Log("Terrain not found");
Vector3 pos = tNode.transform.position;
pos.y = 0.03f;
tNode.transform.position = pos;
tNode.EnsureGradeValidity();
}
TriggerRoadUpdate();
}
Expand Down
20 changes: 20 additions & 0 deletions GSDOffRoadObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GSDOffRoadObject : MonoBehaviour
{
public static readonly Color Color_NodeOffRoadColor = new Color(1f, 0f, 0.5f, 0.75f);
public static readonly Color Color_NodeOffRoadSelectedColor = new Color(1f, 0f, 0.8f, 1f);
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}
}
11 changes: 11 additions & 0 deletions GSDOffRoadObject.cs.meta

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

1 change: 1 addition & 0 deletions GSDRoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ public void EditorTerrainCalcs(ref List<GSDTerraforming.TempTerrainData> tList){
public readonly Color Color_NodeDefaultColor = new Color(0f,1f,1f,0.75f);
public readonly Color Color_NodeConnColor = new Color(0f,1f,0f,0.75f);
public readonly Color Color_NodeInter = new Color(0f,1f,0f,0.75f);

void OnDrawGizmosSelected(){
if(Editor_MouseTerrainHit){
Gizmos.color = Color.red;
Expand Down
72 changes: 72 additions & 0 deletions GSDRoadConnector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[ExecuteInEditMode]
public class GSDRoadConnector : MonoBehaviour
{
public GSDSplineN connectedNode;
[HideInInspector]
public GSDOffRoadObject obj { get { return transform.parent.GetComponent<GSDOffRoadObject>(); } }
// Start is called before the first frame update
void Start()
{
}
void OnDrawGizmos()
{
Gizmos.color = GSDOffRoadObject.Color_NodeOffRoadColor;
Gizmos.DrawCube(transform.position + new Vector3(0f, 6f, 0f), new Vector3(2f, 11f, 2f));
}
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));
}
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
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();
}
}
}
}

#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
11 changes: 11 additions & 0 deletions GSDRoadConnector.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 Spline/GSDSplineN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ public void BreakConnection(){
{
Object.DestroyImmediate(tNode2.transform.gameObject);
Object.DestroyImmediate(transform.gameObject);
} catch (MissingReferenceException e)
} catch (MissingReferenceException)
{

}
Expand Down

0 comments on commit 8a8bb72

Please sign in to comment.