diff --git a/CHANGELOG.md b/CHANGELOG.md index db3e915e..213b46df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,26 @@ All notable changes to this RoadArchitect project will be documented in this fil The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Version: 1.8_FH] - 2019.02.10 +### Improvements +- Added some FH_Tag Optimizable as comments, since there is a way to further optimize the Code tagged by this +- Added a few Lines of comments to the code, to get a better idea of what the code does + +### Changed +- Changed some Layouts of the Scripts +- Changed some Vars in Scripts to better reflect their purpose + +### Added +- Added a few Regions to some Scripts + +###Fixed +- Fixed embeddedt/RoadArchitect/issues/4 + ## [Version: 1.7.5a_FH] - 2019.01.31 ### Changed -- Changed most Layouts of the Scripts. -- Changed some Vars in Scripts to better reflect their purpose. +- Changed most Layouts of the Scripts +- Changed some Vars in Scripts to better reflect their purpose ## [Version 1.7] - 2018.07.16 ### Changed diff --git a/CHANGELOG.md.meta b/CHANGELOG.md.meta new file mode 100644 index 00000000..0c0897b8 --- /dev/null +++ b/CHANGELOG.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 82263ce59907a4c45acd2234af48e7e9 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/GSDEditorProgressWindow.cs b/Editor/GSDEditorProgressWindow.cs index 2cf36672..431b5507 100644 --- a/Editor/GSDEditorProgressWindow.cs +++ b/Editor/GSDEditorProgressWindow.cs @@ -1,7 +1,9 @@ +#region "Imports" #if UNITY_EDITOR using UnityEditor; #endif using UnityEngine; +#endregion /// diff --git a/Editor/GSDObjExporter.cs b/Editor/GSDObjExporter.cs index 679e0a8e..2bef8ad1 100644 --- a/Editor/GSDObjExporter.cs +++ b/Editor/GSDObjExporter.cs @@ -12,7 +12,7 @@ same folder. */ -#region Imports +#region "Imports" using UnityEngine; using UnityEditor; using System.Collections; @@ -102,11 +102,11 @@ private static string MeshToString(MeshFilter mf, Dictionary materialList int stripIndex = destinationFile.LastIndexOf('/');//FIXME: Should be Path.PathSeparator; if (stripIndex >= 0) + { destinationFile = destinationFile.Substring(stripIndex + 1).Trim(); + } string relativeFile = destinationFile; @@ -209,9 +211,9 @@ private static void MeshesToFile(MeshFilter[] mf, string folder, string filename { sw.Write("mtllib ./" + filename + ".mtl\n"); - for (int i = 0; i < mf.Length; i++) + for (int index = 0; index < mf.Length; index++) { - sw.Write(MeshToString(mf[i], materialList)); + sw.Write(MeshToString(mf[index], materialList)); } } @@ -239,7 +241,9 @@ private static bool CreateTargetFolder() static void ExportSelectionToSeparate() { if (!CreateTargetFolder()) + { return; + } Transform[] selection = Selection.GetTransforms(SelectionMode.Editable | SelectionMode.ExcludePrefab); @@ -251,21 +255,25 @@ static void ExportSelectionToSeparate() int exportedObjects = 0; - for (int i = 0; i < selection.Length; i++) + for (int index = 0; index < selection.Length; index++) { - Component[] meshfilter = selection[i].GetComponentsInChildren(typeof(MeshFilter)); + Component[] meshfilter = selection[index].GetComponentsInChildren(typeof(MeshFilter)); for (int m = 0; m < meshfilter.Length; m++) { exportedObjects++; - MeshToFile((MeshFilter) meshfilter[m], targetFolder, selection[i].name + "_" + i + "_" + m); + MeshToFile((MeshFilter) meshfilter[m], targetFolder, selection[index].name + "_" + index + "_" + m); } } if (exportedObjects > 0) + { EditorUtility.DisplayDialog("Objects exported", "Exported " + exportedObjects + " objects", ""); + } else + { EditorUtility.DisplayDialog("Objects not exported", "Make sure at least some of your selected objects have mesh filters!", ""); + } } @@ -290,9 +298,9 @@ static void ExportWholeSelectionToSingle() ArrayList mfList = new ArrayList(); - for (int i = 0; i < selection.Length; i++) + for (int index = 0; index < selection.Length; index++) { - Component[] meshfilter = selection[i].GetComponentsInChildren(typeof(MeshFilter)); + Component[] meshfilter = selection[index].GetComponentsInChildren(typeof(MeshFilter)); for (int m = 0; m < meshfilter.Length; m++) { @@ -305,9 +313,9 @@ static void ExportWholeSelectionToSingle() { MeshFilter[] mf = new MeshFilter[mfList.Count]; - for (int i = 0; i < mfList.Count; i++) + for (int index = 0; index < mfList.Count; index++) { - mf[i] = (MeshFilter) mfList[i]; + mf[index] = (MeshFilter) mfList[index]; } @@ -352,9 +360,9 @@ static void ExportEachSelectionToSingle() int exportedObjects = 0; - for (int i = 0; i < selection.Length; i++) + for (int index = 0; index < selection.Length; index++) { - Component[] meshfilter = selection[i].GetComponentsInChildren(typeof(MeshFilter)); + Component[] meshfilter = selection[index].GetComponentsInChildren(typeof(MeshFilter)); MeshFilter[] mf = new MeshFilter[meshfilter.Length]; @@ -364,7 +372,7 @@ static void ExportEachSelectionToSingle() mf[m] = (MeshFilter) meshfilter[m]; } - MeshesToFile(mf, targetFolder, selection[i].name + "_" + i); + MeshesToFile(mf, targetFolder, selection[index].name + "_" + index); } if (exportedObjects > 0) diff --git a/Editor/GSDRoadEditor.cs b/Editor/GSDRoadEditor.cs index b40a319e..4f85d8f8 100644 --- a/Editor/GSDRoadEditor.cs +++ b/Editor/GSDRoadEditor.cs @@ -259,7 +259,9 @@ public override void OnInspectorGUI() bSetDefaultMats = false; //Graphic null checks: if (!bHasInit) - { Init(); } + { + Init(); + } @@ -883,7 +885,8 @@ public override void OnInspectorGUI() EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(t_RoadMaterial1, new GUIContent(" Mat #1: ")); if (RS.RoadMaterial1 != null && GUILayout.Button(btnDeleteText, GSDImageButton, GUILayout.Width(16f))) - { RS.RoadMaterial1 = null; } + { + RS.RoadMaterial1 = null; } EditorGUILayout.EndHorizontal(); if (RS.RoadMaterial1 != null) { @@ -913,8 +916,6 @@ public override void OnInspectorGUI() - - // //Road marker material defaults: GUILayout.Label("Road marker material(s) defaults:"); // EditorGUILayout.PropertyField (t_RoadMaterialMarker1, new GUIContent (" Mat #1: ")); @@ -925,14 +926,16 @@ public override void OnInspectorGUI() EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(t_RoadMaterialMarker1, new GUIContent(" Mat #1: ")); if (RS.RoadMaterialMarker1 != null && GUILayout.Button(btnDeleteText, GSDImageButton, GUILayout.Width(16f))) - { RS.RoadMaterialMarker1 = null; } + { + RS.RoadMaterialMarker1 = null; } EditorGUILayout.EndHorizontal(); if (RS.RoadMaterialMarker1 != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(t_RoadMaterialMarker2, new GUIContent(" Mat #2: ")); if (RS.RoadMaterialMarker2 != null && GUILayout.Button(btnDeleteText, GSDImageButton, GUILayout.Width(16f))) - { RS.RoadMaterialMarker2 = null; } + { + RS.RoadMaterialMarker2 = null; } EditorGUILayout.EndHorizontal(); } if (RS.RoadMaterialMarker1 != null && RS.RoadMaterialMarker2 != null) @@ -940,7 +943,8 @@ public override void OnInspectorGUI() EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(t_RoadMaterialMarker3, new GUIContent(" Mat #3: ")); if (RS.RoadMaterialMarker3 != null && GUILayout.Button(btnDeleteText, GSDImageButton, GUILayout.Width(16f))) - { RS.RoadMaterialMarker3 = null; } + { + RS.RoadMaterialMarker3 = null; } EditorGUILayout.EndHorizontal(); } if (RS.RoadMaterialMarker1 != null && RS.RoadMaterialMarker2 != null && RS.RoadMaterialMarker3 != null) @@ -948,7 +952,8 @@ public override void OnInspectorGUI() EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(t_RoadMaterialMarker4, new GUIContent(" Mat #4: ")); if (RS.RoadMaterialMarker4 != null && GUILayout.Button(btnDeleteText, GSDImageButton, GUILayout.Width(16f))) - { RS.RoadMaterialMarker4 = null; } + { + RS.RoadMaterialMarker4 = null; } EditorGUILayout.EndHorizontal(); } @@ -967,7 +972,8 @@ public override void OnInspectorGUI() EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(t_ShoulderMaterial1, new GUIContent(" Mat #1: ")); if (RS.ShoulderMaterial1 != null && GUILayout.Button(btnDeleteText, GSDImageButton, GUILayout.Width(16f))) - { RS.ShoulderMaterial1 = null; } + { + RS.ShoulderMaterial1 = null; } EditorGUILayout.EndHorizontal(); if (RS.ShoulderMaterial1 != null) { @@ -982,7 +988,8 @@ public override void OnInspectorGUI() EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(t_ShoulderMaterial3, new GUIContent(" Mat #3: ")); if (RS.ShoulderMaterial3 != null && GUILayout.Button(btnDeleteText, GSDImageButton, GUILayout.Width(16f))) - { RS.ShoulderMaterial3 = null; } + { + RS.ShoulderMaterial3 = null; } EditorGUILayout.EndHorizontal(); } if (RS.ShoulderMaterial1 != null && RS.ShoulderMaterial2 != null && RS.ShoulderMaterial3 != null) @@ -990,7 +997,8 @@ public override void OnInspectorGUI() EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(t_ShoulderMaterial4, new GUIContent(" Mat #4: ")); if (RS.ShoulderMaterial4 != null && GUILayout.Button(btnDeleteText, GSDImageButton, GUILayout.Width(16f))) - { RS.ShoulderMaterial4 = null; } + { + RS.ShoulderMaterial4 = null; } EditorGUILayout.EndHorizontal(); } } @@ -1010,7 +1018,8 @@ public override void OnInspectorGUI() EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(t_ShoulderMaterialMarker1, new GUIContent(" Mat #1: ")); if (RS.ShoulderMaterialMarker1 != null && GUILayout.Button(btnDeleteText, GSDImageButton, GUILayout.Width(16f))) - { RS.ShoulderMaterialMarker1 = null; } + { + RS.ShoulderMaterialMarker1 = null; } EditorGUILayout.EndHorizontal(); if (RS.ShoulderMaterialMarker1 != null) { @@ -1025,7 +1034,8 @@ public override void OnInspectorGUI() EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(t_ShoulderMaterialMarker3, new GUIContent(" Mat #3: ")); if (RS.ShoulderMaterialMarker3 != null && GUILayout.Button(btnDeleteText, GSDImageButton, GUILayout.Width(16f))) - { RS.ShoulderMaterialMarker3 = null; } + { + RS.ShoulderMaterialMarker3 = null; } EditorGUILayout.EndHorizontal(); } if (RS.ShoulderMaterialMarker1 != null && RS.ShoulderMaterialMarker2 != null && RS.ShoulderMaterialMarker3 != null) @@ -1033,7 +1043,8 @@ public override void OnInspectorGUI() EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(t_ShoulderMaterialMarker4, new GUIContent(" Mat #4: ")); if (RS.ShoulderMaterialMarker4 != null && GUILayout.Button(btnDeleteText, GSDImageButton, GUILayout.Width(16f))) - { RS.ShoulderMaterialMarker4 = null; } + { + RS.ShoulderMaterialMarker4 = null; } EditorGUILayout.EndHorizontal(); } } @@ -1299,7 +1310,8 @@ public void OnSceneGUI() { //Debug.Log("Drawing new node"); if (RS.GSDSpline.PreviewSpline.mNodes == null || RS.GSDSpline.PreviewSpline.mNodes.Count < 1) - { RS.GSDSpline.Setup(); } + { + RS.GSDSpline.Setup(); } RS.GSDSpline.PreviewSpline.MousePos = hitInfo.point; RS.GSDSpline.PreviewSpline.bGizmoDraw = true; SceneView.RepaintAll(); @@ -1321,7 +1333,8 @@ public void OnSceneGUI() if (RS.GSDSpline && RS.GSDSpline.PreviewSplineInsert) { if (RS.GSDSpline.PreviewSplineInsert.mNodes == null || RS.GSDSpline.PreviewSplineInsert.mNodes.Count < 1) - { RS.GSDSpline.PreviewSplineInsert.DetermineInsertNodes(); } + { + RS.GSDSpline.PreviewSplineInsert.DetermineInsertNodes(); } RS.GSDSpline.PreviewSplineInsert.MousePos = hitInfo.point; RS.GSDSpline.PreviewSplineInsert.bGizmoDraw = true; RS.GSDSpline.PreviewSplineInsert.UpdateActionNode(); @@ -1490,6 +1503,7 @@ void GSDProgressBar(float tV, string tL) #endregion + // FH_Tag Optimizable void Line() { GUILayout.Space(4f); @@ -1504,5 +1518,5 @@ void LineSmall() GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1f)); //Horizontal bar GUILayout.Space(1f); } - + // FH_Tag Optimizable } \ No newline at end of file diff --git a/Editor/GSDRoadIntersectionEditor.cs b/Editor/GSDRoadIntersectionEditor.cs index 7862fcf4..ff15efe1 100644 --- a/Editor/GSDRoadIntersectionEditor.cs +++ b/Editor/GSDRoadIntersectionEditor.cs @@ -1,7 +1,9 @@ +#region "Imports" using UnityEngine; using UnityEditor; using System.Collections.Generic; using GSD; +#endregion [CustomEditor(typeof(GSDRoadIntersection))] @@ -262,7 +264,9 @@ public override void OnInspectorGUI() EditorGUILayout.BeginHorizontal(); t_opt_FixedTime_RegularLightLength.floatValue = EditorGUILayout.Slider("Green length: ", tInter.opt_FixedTime_RegularLightLength, 0.1f, 180f); if (GUILayout.Button(btnRefreshText, GSDImageButton, GUILayout.Width(16f))) - { t_opt_FixedTime_RegularLightLength.floatValue = 30f; } + { + t_opt_FixedTime_RegularLightLength.floatValue = 30f; + } EditorGUILayout.EndHorizontal(); if (tInter.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane) @@ -270,20 +274,26 @@ public override void OnInspectorGUI() EditorGUILayout.BeginHorizontal(); t_opt_FixedTime_LeftTurnLightLength.floatValue = EditorGUILayout.Slider("Left turn only length: ", tInter.opt_FixedTime_LeftTurnLightLength, 0.1f, 180f); if (GUILayout.Button(btnRefreshText, GSDImageButton, GUILayout.Width(16f))) - { t_opt_FixedTime_LeftTurnLightLength.floatValue = 10f; } + { + t_opt_FixedTime_LeftTurnLightLength.floatValue = 10f; + } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); t_opt_FixedTime_AllRedLightLength.floatValue = EditorGUILayout.Slider("All red length: ", tInter.opt_FixedTime_AllRedLightLength, 0.1f, 180f); if (GUILayout.Button(btnRefreshText, GSDImageButton, GUILayout.Width(16f))) - { t_opt_FixedTime_AllRedLightLength.floatValue = 1f; } + { + t_opt_FixedTime_AllRedLightLength.floatValue = 1f; + } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); t_opt_FixedTime_YellowLightLength.floatValue = EditorGUILayout.Slider("Yellow light length: ", tInter.opt_FixedTime_YellowLightLength, 0.1f, 180f); if (GUILayout.Button(btnRefreshText, GSDImageButton, GUILayout.Width(16f))) - { t_opt_FixedTime_YellowLightLength.floatValue = 3f; } + { + t_opt_FixedTime_YellowLightLength.floatValue = 3f; + } EditorGUILayout.EndHorizontal(); } } @@ -1103,7 +1113,9 @@ public void OnSceneGUI() //Do nothing } if (GUI.changed) - { EditorUtility.SetDirty(tInter); } + { + EditorUtility.SetDirty(tInter); + } } diff --git a/Editor/GSDRoadSystemEditor.cs b/Editor/GSDRoadSystemEditor.cs index 228526f9..483b0473 100644 --- a/Editor/GSDRoadSystemEditor.cs +++ b/Editor/GSDRoadSystemEditor.cs @@ -137,6 +137,7 @@ public override void OnInspectorGUI() } } + void InitChecks() { if (WarningLabelBG == null) @@ -179,6 +180,7 @@ void InitChecks() } } + // void DoInter(){ // //View intersection // if(!bHasInterInit){ @@ -200,6 +202,7 @@ void InitChecks() // } // } // + // // void IncrementIntersection(){ // if(tInters != null && tInters.Length > 0){ // tInterIndex+=1; @@ -208,6 +211,7 @@ void InitChecks() // } // } // + // // void DoBridges(){ // //View bridges // if(!bHasBridgeInit){ @@ -275,6 +279,7 @@ void InitChecks() // } // } // + // // void IncrementBridge(){ // if(tBridges != null && tBridges.Length > 0){ // tBridgesIndex+=1; @@ -283,6 +288,7 @@ void InitChecks() // } // } // + // // void ShowIntersection(int i){ // if(EditorApplication.isPlaying && GSDRS.EditorPlayCamera != null){ // GSDRS.EditorPlayCamera.transform.position = tInters[i].transform.position + new Vector3(-40f,20f,-40f); @@ -293,6 +299,7 @@ void InitChecks() // } // } // + // // void ShowBridge(int i){ // if(EditorApplication.isPlaying && GSDRS.EditorPlayCamera != null){ // Vector3 tBridgePos = ((tBridges[i].pos - tBridges[i].BridgeCounterpartNode.pos)*0.5f)+tBridges[i].BridgeCounterpartNode.pos; diff --git a/Editor/GSDRoadSystemEditorMenu.cs b/Editor/GSDRoadSystemEditorMenu.cs index 49793f26..87f02c66 100644 --- a/Editor/GSDRoadSystemEditorMenu.cs +++ b/Editor/GSDRoadSystemEditorMenu.cs @@ -1,5 +1,7 @@ +#region "Imports" using UnityEngine; using UnityEditor; +#endregion public class GSDRoadSystemEditorMenu : ScriptableObject diff --git a/Editor/GSDSplineNEditor.cs b/Editor/GSDSplineNEditor.cs index de3e4a86..67513624 100644 --- a/Editor/GSDSplineNEditor.cs +++ b/Editor/GSDSplineNEditor.cs @@ -26,7 +26,8 @@ public class GSDSplineNEditor : Editor bool bRemoveAll = false; float HorizRoadMax = 0; - //Button icons: + + #region Button icons: Texture btnDeleteText = null; Texture btnCopyText = null; Texture btnSaveText = null; @@ -40,6 +41,8 @@ public class GSDSplineNEditor : Editor Texture2D GSDTextAreaBG = null; Texture2D LoadBtnBGGlow = null; Texture2D ManualBG = null; + #endregion + public bool bLoadingEOS = false; public int LoadingEOSIndex = 0; @@ -60,6 +63,7 @@ public class GSDSplineNEditor : Editor GSD.Roads.Splination.SplinatedMeshMaker SMM = null; + #region "Enums" public enum EndObjectsDefaultsEnum { None, @@ -177,6 +181,7 @@ public enum HorizMatchingDefaultsEnum public enum EOMDefaultsEnum { None, Custom, StreetLightSingle, StreetLightDouble }; + #endregion //GSD.Roads.Splination.CollisionTypeEnum tCollisionTypeSpline = GSD.Roads.Splination.CollisionTypeEnum.SimpleMeshTriangle; @@ -610,9 +615,13 @@ void DoExtAndEdgeOverview() {// || GUILayout.Button(btnLoadText,GSDImageButton,GUILayout.Width(16f))){ GSDWizard tWiz = EditorWindow.GetWindow(); if (tSceneRect.x < 0) - { tSceneRect.x = 0f; } + { + tSceneRect.x = 0f; + } if (tSceneRect.y < 0) - { tSceneRect.y = 0f; } + { + tSceneRect.y = 0f; + } tWiz.xRect = tSceneRect; if (tNode.bIsBridgeStart) { @@ -780,10 +789,10 @@ public void DoSplineObjects() } - for (int i = 0; i < tNode.SplinatedObjects.Count; i++) + for (int index = 0; index < tNode.SplinatedObjects.Count; index++) { currentCount += 1; - SMM = tNode.SplinatedObjects[i]; + SMM = tNode.SplinatedObjects[index]; if (SMM.EM == null) { SMM.EM = new GSD.Roads.Splination.SplinatedMeshMaker.SplinatedMeshEditorMaker(); @@ -795,7 +804,9 @@ public void DoSplineObjects() EditorGUILayout.BeginVertical("TextArea"); if (SMM.bNeedsUpdate) - { SMM.Setup(true); } + { + SMM.Setup(true); + } EditorGUILayout.BeginHorizontal(); @@ -825,12 +836,15 @@ public void DoSplineObjects() if (GUILayout.Button(btnDeleteText, GSDImageButton, GUILayout.Width(16f))) { Undo.RecordObject(tNode, "Delete"); - tNode.RemoveSplinatedObject(i); + tNode.RemoveSplinatedObject(index); EditorUtility.SetDirty(tNode); } EditorGUILayout.EndHorizontal(); if (!SMM.bToggle) - { EditorGUILayout.EndVertical(); continue; } + { + EditorGUILayout.EndVertical(); + continue; + } GUILayout.Space(8f); EditorGUILayout.BeginHorizontal(); @@ -1079,7 +1093,9 @@ public void DoSplineObjects() //Horizontal curve: if (SMM.HorizontalCurve == null || SMM.HorizontalCurve.keys.Length < 2) - { EnforceCurve(ref SMM.HorizontalCurve); } + { + EnforceCurve(ref SMM.HorizontalCurve); + } EditorGUILayout.BeginHorizontal(); SMM.EM.HorizontalCurve = EditorGUILayout.CurveField("Curve: ", SMM.HorizontalCurve); @@ -1306,9 +1322,9 @@ public void UpdateSplineObjects() tNode.SplinatedObjects = new List(); } eCount = tNode.SplinatedObjects.Count; - for (int i = 0; i < eCount; i++) + for (int index = 0; index < eCount; index++) { - SMM = tNode.SplinatedObjects[i]; + SMM = tNode.SplinatedObjects[index]; if (SMM.EM != null) { if (!SMM.EM.IsEqualToSMM(SMM)) @@ -1352,16 +1368,16 @@ public void UpdateSplineObjects_OnUndo() } //Destroy all children: - for (int i = tNode.transform.childCount - 1; i >= 0; i--) + for (int index = tNode.transform.childCount - 1; index >= 0; index--) { - Object.DestroyImmediate(tNode.transform.GetChild(i).gameObject); + Object.DestroyImmediate(tNode.transform.GetChild(index).gameObject); } //Re-setup the SMM: eCount = tNode.SplinatedObjects.Count; - for (int i = 0; i < eCount; i++) + for (int index = 0; index < eCount; index++) { - SMM = tNode.SplinatedObjects[i]; + SMM = tNode.SplinatedObjects[index]; SMM.UpdatePositions(); //if(SMM.bIsStretch != SMM.bIsStretch){ if (SMM.bIsStretch) @@ -1399,9 +1415,9 @@ public void DoEdgeObjects() EOM = null; - for (int i = 0; i < tNode.EdgeObjects.Count; i++) + for (int index = 0; index < tNode.EdgeObjects.Count; index++) { - EOM = tNode.EdgeObjects[i]; + EOM = tNode.EdgeObjects[index]; if (EOM.EM == null) { EOM.EM = new GSD.Roads.EdgeObjects.EdgeObjectMaker.EdgeObjectEditorMaker(); @@ -1439,13 +1455,13 @@ public void DoEdgeObjects() if (GUILayout.Button(btnCopyText, GSDImageButton, GUILayout.Width(16f))) { Undo.RecordObject(tNode, "Copy"); - tNode.CopyEdgeObject(i); + tNode.CopyEdgeObject(index); EditorUtility.SetDirty(tNode); } if (GUILayout.Button(btnDeleteText, GSDImageButton, GUILayout.Width(16f))) { Undo.RecordObject(tNode, "Delete"); - tNode.RemoveEdgeObject(i); + tNode.RemoveEdgeObject(index); EditorUtility.SetDirty(tNode); } EditorGUILayout.EndHorizontal(); @@ -1640,9 +1656,13 @@ public void DoEdgeObjects() if (!EOM.bSingle) { if (EOM.EM.StartTime < tNode.MinSplination) - { EOM.EM.StartTime = tNode.MinSplination; } + { + EOM.EM.StartTime = tNode.MinSplination; + } if (EOM.EM.EndTime > tNode.MaxSplination) - { EOM.EM.EndTime = tNode.MaxSplination; } + { + EOM.EM.EndTime = tNode.MaxSplination; + } #region Start param @@ -1709,7 +1729,9 @@ public void DoEdgeObjects() EditorGUILayout.EndHorizontal(); if (EOM.VerticalCurve == null || EOM.VerticalCurve.keys.Length < 2) - { EnforceCurve(ref EOM.VerticalCurve); } + { + EnforceCurve(ref EOM.VerticalCurve); + } EditorGUILayout.BeginHorizontal(); EOM.EM.VerticalCurve = EditorGUILayout.CurveField("Curve: ", EOM.VerticalCurve); if (GUILayout.Button(btnDefaultText, GSDImageButton, GUILayout.Width(16f))) @@ -1837,9 +1859,9 @@ public void UpdateEdgeObjects() return; } eCount = tNode.EdgeObjects.Count; - for (int i = 0; i < tNode.EdgeObjects.Count; i++) + for (int index = 0; index < tNode.EdgeObjects.Count; index++) { - EOM = tNode.EdgeObjects[i]; + EOM = tNode.EdgeObjects[index]; if (EOM.EM != null) { if (!EOM.EM.IsEqual(EOM)) @@ -1861,9 +1883,9 @@ public void UpdateEdgeObjects_OnUndo() return; } eCount = tNode.EdgeObjects.Count; - for (int i = 0; i < tNode.EdgeObjects.Count; i++) + for (int index = 0; index < tNode.EdgeObjects.Count; index++) { - EOM = tNode.EdgeObjects[i]; + EOM = tNode.EdgeObjects[index]; EOM.Setup(); } } @@ -2196,10 +2218,10 @@ private void ExtrusionQuickAdd(bool bHorizOverride = false, float tHorizSep = 0f { ExtrusionQuickAdd_Do(); } - catch (System.Exception e) + catch (System.Exception exception) { tSMMQuickAdd = SMMDefaultsEnum.None; - throw e; + throw exception; } } @@ -2234,15 +2256,21 @@ private void ExtrudeHelper(string tPath, string tName, float DefaultHoriz, GSD.R else { if (tNode.bIsBridgeStart) - { SMM.VerticalRaise = -0.01f; } + { + SMM.VerticalRaise = -0.01f; + } } SMM.bFlipRotation = bFlipRot; SMM.Axis = tAxis; if (SMM.StartTime < tNode.MinSplination) - { SMM.StartTime = tNode.MinSplination; } + { + SMM.StartTime = tNode.MinSplination; + } if (SMM.EndTime > tNode.MaxSplination) - { SMM.EndTime = tNode.MaxSplination; } + { + SMM.EndTime = tNode.MaxSplination; + } SMM.tName = tName; } #endregion @@ -2283,7 +2311,9 @@ public void OnSceneGUI() } if (controlID != tNode.GetHashCode()) - { tNode.bEditorSelected = false; } + { + tNode.bEditorSelected = false; + } //Drag with left click: if (Event.current.type == EventType.MouseDrag && Event.current.button == 0) @@ -2301,9 +2331,13 @@ public void OnSceneGUI() if (Vector3.Distance(xNode.transform.position, tNode.transform.position) < 2f) { if (xNode == tNode) - { continue; } + { + continue; + } if (tNode.bSpecialEndNode || xNode.bSpecialEndNode) - { continue; } + { + continue; + } if (xNode.bIsEndPoint && tNode.bIsEndPoint) { //End point connection. @@ -2314,11 +2348,17 @@ public void OnSceneGUI() break; } if (xNode.bIsIntersection) - { continue; } + { + continue; + } if (xNode.bNeverIntersect) - { continue; } + { + continue; + } if (tNode.bIsEndPoint && xNode.bIsEndPoint) - { continue; } + { + continue; + } if (xNode.GSDSpline == tNode.GSDSpline) { //Don't let intersection be created on consecutive nodes: if ((tNode.idOnSpline + 1) == xNode.idOnSpline || (tNode.idOnSpline - 1) == xNode.idOnSpline) @@ -2341,7 +2381,9 @@ public void OnSceneGUI() if (Vector3.Distance(connector.transform.position, tNode.transform.position) < 2f) { if (connector.connectedNode != null) + { continue; + } connector.ConnectToNode(tNode); break; } diff --git a/Editor/GSDWizard.cs b/Editor/GSDWizard.cs index efbd5a8a..b2699e86 100644 --- a/Editor/GSDWizard.cs +++ b/Editor/GSDWizard.cs @@ -357,9 +357,9 @@ private void LoadGroupObjs(ref string[] tNames, ref string[] tPaths, bool bIsBri // string tDesc = ""; // string tDisplayName = ""; // string ThumbString = ""; - for (int i = 0; i < tCount; i++) + for (int index = 0; index < tCount; index++) { - GSDRoadUtil.WizardObject tO = GSDRoadUtil.WizardObject.LoadFromLibrary(tPaths[i]); + GSDRoadUtil.WizardObject tO = GSDRoadUtil.WizardObject.LoadFromLibrary(tPaths[index]); if (tO == null) { continue; @@ -376,7 +376,7 @@ private void LoadGroupObjs(ref string[] tNames, ref string[] tPaths, bool bIsBri { tO.Thumb = null; } - tO.FileName = tNames[i]; + tO.FileName = tNames[index]; tO.FullPath = tPath; if (tO.bIsDefault && bIsBridge) @@ -624,7 +624,9 @@ private void LoadObjs(ref string[] tNames, ref string[] tPaths, bool bIsDefault { SplinatedMeshMaker.SplinatedMeshLibraryMaker SLM = (SplinatedMeshMaker.SplinatedMeshLibraryMaker) GSDRootUtil.LoadXML(ref tPath); if (SLM == null) - { continue; } + { + continue; + } tStringPath = SLM.CurrentSplinationString; tDesc = SLM.Desc; tDisplayName = SLM.DisplayName; @@ -635,7 +637,9 @@ private void LoadObjs(ref string[] tNames, ref string[] tPaths, bool bIsDefault { EdgeObjectMaker.EdgeObjectLibraryMaker ELM = (EdgeObjectMaker.EdgeObjectLibraryMaker) GSDRootUtil.LoadXML(ref tPath); if (ELM == null) - { continue; } + { + continue; + } tStringPath = ELM.EdgeObjectString; tDesc = ELM.Desc; tDisplayName = ELM.DisplayName; diff --git a/GSDRigidBody.cs b/GSDRigidBody.cs index 6dcc3290..da54bbbd 100644 --- a/GSDRigidBody.cs +++ b/GSDRigidBody.cs @@ -5,15 +5,16 @@ public class GSDRigidBody : MonoBehaviour { public float MinCollVelocity = 2f; // bool bIsForcedSleeping = false; - Rigidbody rigidbody; // Formerly RB // FH 29.01.19 + Rigidbody rigidBody; // Formerly RB // FH 29.01.19 // bool bIgnoreRB = false; + void Awake() { - rigidbody = transform.GetComponent(); - if (rigidbody != null) + rigidBody = transform.GetComponent(); + if (rigidBody != null) { - DestroyImmediate(rigidbody); + DestroyImmediate(rigidBody); } } diff --git a/GSDRoadAutomation.cs b/GSDRoadAutomation.cs index 07a88709..d474dccd 100644 --- a/GSDRoadAutomation.cs +++ b/GSDRoadAutomation.cs @@ -41,9 +41,9 @@ public static GSDRoad CreateRoad_Programmatically(GSDRoadSystem GSDRS, ref List< GSDRoad tRoad = tRoadObj.GetComponent(); int hCount = tLocs.Count; - for (int i = 0; i < hCount; i++) + for (int index = 0; index < hCount; index++) { - CreateNode_Programmatically(tRoad, tLocs[i]); + CreateNode_Programmatically(tRoad, tLocs[index]); } return tRoad; @@ -97,7 +97,9 @@ public static GSDSplineN InsertNode_Programmatically(GSDRoad RS, Vector3 NodeLoc //Set node location: if (NodeLocation.y < 0.03f) - { NodeLocation.y = 0.03f; } //Make sure it doesn't try to create a node below 0 height. + { + NodeLocation.y = 0.03f; //Make sure it doesn't try to create a node below 0 height. + } tNodeObj.transform.position = NodeLocation; //Set the node's parent: @@ -124,9 +126,9 @@ public static GSDSplineN InsertNode_Programmatically(GSDRoad RS, Vector3 NodeLoc } //Figure out where to insert the node: - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - GSDSplineN xNode = RS.GSDSpline.mNodes[i]; + GSDSplineN xNode = RS.GSDSpline.mNodes[index]; if (!bZeroInsert && !bEndInsert) { if (tParam > xNode.tTime) @@ -135,9 +137,9 @@ public static GSDSplineN InsertNode_Programmatically(GSDRoad RS, Vector3 NodeLoc } } } - for (int i = iStart; i < cCount; i++) + for (int index = iStart; index < cCount; index++) { - RS.GSDSpline.mNodes[i].idOnSpline += 1; + RS.GSDSpline.mNodes[index].idOnSpline += 1; } GSDSplineN tNode = tNodeObj.AddComponent(); @@ -188,9 +190,9 @@ create intersection with above two nodes float xRoadMod = EarlyDistanceCheckMeters / xRoad.GSDSpline.distance; Vector3 tVect1 = default(Vector3); Vector3 tVect2 = default(Vector3); - for (float i = 0f; i < 1.0000001f; i += tRoadMod) + for (float index = 0f; index < 1.0000001f; index += tRoadMod) { - tVect1 = tRoad.GSDSpline.GetSplineValue(i); + tVect1 = tRoad.GSDSpline.GetSplineValue(index); for (float x = 0f; x < 1.000001f; x += xRoadMod) { tVect2 = xRoad.GSDSpline.GetSplineValue(x); @@ -219,11 +221,15 @@ create intersection with above two nodes foreach (GSDSplineN IntersectionNode1 in tRoad.GSDSpline.mNodes) { if (IntersectionNode1.bIsIntersection || !IntersectionNode1.IsLegitimate()) - { continue; } + { + continue; + } foreach (GSDSplineN IntersectionNode2 in xRoad.GSDSpline.mNodes) { if (IntersectionNode2.bIsIntersection || !IntersectionNode2.IsLegitimate()) - { continue; } + { + continue; + } if (IntersectionNode1.transform.position == IntersectionNode2.transform.position) { //Only do T intersections and let the next algorithm handle the +, since T might not intersect all the time. @@ -261,12 +267,14 @@ create intersection with above two nodes Vector2 xVect2 = default(Vector2); Vector2 IntersectPoint2D = default(Vector2); float i2 = 0f; - for (float i = 0f; i < 1.0000001f; i += tRoadMod) + for (float index = 0f; index < 1.0000001f; index += tRoadMod) { - i2 = (i + tRoadMod); + i2 = (index + tRoadMod); if (i2 > 1f) - { i2 = 1f; } - tVect = tRoad.GSDSpline.GetSplineValue(i); + { + i2 = 1f; + } + tVect = tRoad.GSDSpline.GetSplineValue(index); iVect1 = new Vector2(tVect.x, tVect.z); tVect = tRoad.GSDSpline.GetSplineValue(i2); iVect2 = new Vector2(tVect.x, tVect.z); @@ -276,7 +284,9 @@ create intersection with above two nodes { x2 = (x + xRoadMod); if (x2 > 1f) - { x2 = 1f; } + { + x2 = 1f; + } tVect = xRoad.GSDSpline.GetSplineValue(x); xVect1 = new Vector2(tVect.x, tVect.z); tVect = xRoad.GSDSpline.GetSplineValue(x2); diff --git a/GSDRoadEdgeObjects.cs b/GSDRoadEdgeObjects.cs index c4f21792..f5297890 100644 --- a/GSDRoadEdgeObjects.cs +++ b/GSDRoadEdgeObjects.cs @@ -160,9 +160,9 @@ public EdgeObjectMaker Copy() EOM.VerticalCurve = new AnimationCurve(); if (VerticalCurve != null && VerticalCurve.keys.Length > 0) { - for (int i = 0; i < VerticalCurve.keys.Length; i++) + for (int index = 0; index < VerticalCurve.keys.Length; index++) { - EOM.VerticalCurve.AddKey(VerticalCurve.keys[i]); + EOM.VerticalCurve.AddKey(VerticalCurve.keys[index]); } } @@ -333,7 +333,9 @@ private void SaveMesh(Mesh tMesh, bool bIsCollider) { #if UNITY_EDITOR if (!tNode.GSDSpline.tRoad.GSDRS.opt_bSaveMeshes) - { return; } + { + return; + } //string tSceneName = System.IO.Path.GetFileName(UnityEditor.EditorApplication.currentScene).ToLower().Replace(".unity",""); string tSceneName = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name; @@ -643,61 +645,111 @@ public void LoadTo(EdgeObjectMaker EOM) public bool IsEqual(EdgeObjectMaker EOM) { if (EOM.EdgeObject != EdgeObject) - { return false; } + { + return false; + } if (EOM.bMaterialOverride != bMaterialOverride) - { return false; } + { + return false; + } if (EOM.EdgeMaterial1 != EdgeMaterial1) - { return false; } + { + return false; + } if (EOM.EdgeMaterial2 != EdgeMaterial2) - { return false; } + { + return false; + } if (EOM.bCombineMesh != bCombineMesh) - { return false; } + { + return false; + } if (EOM.bCombineMeshCollider != bCombineMeshCollider) - { return false; } + { + return false; + } if (EOM.SubType != SubType) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(EOM.MeterSep, MeterSep, 0.001f)) - { return false; } + { + return false; + } // if(EOM.bToggle != bToggle) // { return false; } if (!GSDRootUtil.IsApproximately(EOM.HorizontalSep, HorizontalSep, 0.001f)) - { return false; } + { + return false; + } if (EOM.HorizontalCurve != HorizontalCurve) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(EOM.VerticalRaise, VerticalRaise, 0.001f)) - { return false; } + { + return false; + } if (EOM.VerticalCurve != VerticalCurve) - { return false; } + { + return false; + } if (EOM.bMatchTerrain != bMatchTerrain) - { return false; } + { + return false; + } if (EOM.CustomRotation != CustomRotation) - { return false; } + { + return false; + } if (EOM.CustomScale != CustomScale) - { return false; } + { + return false; + } if (EOM.bOncomingRotation != bOncomingRotation) - { return false; } + { + return false; + } if (EOM.bStatic != bStatic) - { return false; } + { + return false; + } if (EOM.bSingle != bSingle) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(EOM.SinglePosition, SinglePosition, 0.001f)) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(EOM.StartTime, StartTime, 0.001f)) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(EOM.EndTime, EndTime, 0.001f)) - { return false; } + { + return false; + } if (EOM.tName != tName) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(EOM.SingleOnlyBridgePercent, SingleOnlyBridgePercent, 0.001f)) - { return false; } + { + return false; + } if (EOM.bStartMatchRoadDefinition != bStartMatchRoadDefinition) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(EOM.StartMatchRoadDef, StartMatchRoadDef, 0.001f)) - { return false; } + { + return false; + } return true; } @@ -713,19 +765,19 @@ public void Setup(bool bCollect = true) { Setup_Do(bCollect, ref tErrorObjs); } - catch (System.Exception e) + catch (System.Exception exception) { if (tErrorObjs != null && tErrorObjs.Count > 0) { int tCount = tErrorObjs.Count; - for (int i = 0; i < tCount; i++) + for (int index = 0; index < tCount; index++) { - if (tErrorObjs[i] != null) + if (tErrorObjs[index] != null) { - Object.DestroyImmediate(tErrorObjs[i]); + Object.DestroyImmediate(tErrorObjs[index]); } } - throw e; + throw exception; } } #endif @@ -796,7 +848,7 @@ private void Setup_Do(bool bCollect, ref List tErrorObjs) else { tObj = GameObject.Instantiate(EdgeObject, EdgeObjectLocations[j], Quaternion.LookRotation(EdgeObjectRotations[j])); - // (GameObject) removed; FH Experimental 25.01.19 + // (GameObject) removed, since Instantiate returns a GameObject anyway; FH Experimental 25.01.19 tErrorObjs.Add(tObj); } // OrigRot = tObj.transform.rotation; @@ -899,18 +951,20 @@ private void Setup_Do(bool bCollect, ref List tErrorObjs) System.Array.Copy(kUV, hUV[j], OrigMVL); Vector3 tVect = default(Vector3); - for (int i = 0; i < OrigMVL; i++) + for (int index = 0; index < OrigMVL; index++) { - tVect = hVerts[j][i]; - hVerts[j][i] = tTrans.rotation * tVect; - hVerts[j][i] += tTrans.localPosition; + tVect = hVerts[j][index]; + hVerts[j][index] = tTrans.rotation * tVect; + hVerts[j][index] += tTrans.localPosition; } } GameObject xObj = new GameObject(tName); MeshRenderer MR = xObj.GetComponent(); if (MR == null) - { MR = xObj.AddComponent(); } + { + MR = xObj.AddComponent(); + } xObj.isStatic = bStatic; xObj.transform.parent = MasterObj.transform; tErrorObjs.Add(xObj); @@ -1012,6 +1066,7 @@ private void Setup_Do(bool bCollect, ref List tErrorObjs) } + // FH_Tag Optimizable private void SetupLocations() { float OrigHeight = 0f; @@ -1071,8 +1126,11 @@ private void SetupLocations() Ray tRay = default(Ray); RaycastHit[] tRayHit = null; float[] tRayYs = null; - if (bSingle) + if (bSingle) { + // If the Object is a SingleObject // FH 03.02.19 + + tNode.GSDSpline.GetSplineValue_Both(SinglePosition, out tVect, out POS); OrigHeight = tVect.y; @@ -1118,6 +1176,7 @@ private void SetupLocations() } else { + // If this Object is not marked as a single Object // FH 03.02.19 //Get the vector series that this mesh is interpolated on: List tTimes = new List(); @@ -1136,15 +1195,22 @@ private void SetupLocations() fHeight = HorizontalCurve.Evaluate((cTime - FakeStartTime) / pDiffTime); CurrentH = fHeight * HorizontalSep; + // FH 06.02.19 + // Hoirzontal1: if (CurrentH < 0f) { - CurrentH *= -1f; - tVect = (tVect + new Vector3(CurrentH * -POS.normalized.z, 0, CurrentH * POS.normalized.x)); + CurrentH *= -1f; // So we get a positiv Number again + tVect = (tVect + new Vector3(CurrentH * (-POS.normalized.x + (POS.normalized.y / 2)), 0, CurrentH * (POS.normalized.z + +(POS.normalized.y / 2)))); + // I implemented the POS.normalized.y value to make sure we get to a value of 1 overall to ensure 50m distance, is this mathematicly correct?? FH 10.02.19 + // Original: tVect = (tVect + new Vector3(CurrentH * -POS.normalized.z, 0, CurrentH * POS.normalized.x)); } else if (CurrentH > 0f) { - tVect = (tVect + new Vector3(CurrentH * POS.normalized.z, 0, CurrentH * -POS.normalized.x)); + tVect = (tVect + new Vector3(CurrentH * (-POS.normalized.x + (POS.normalized.y / 2)), 0, CurrentH * (POS.normalized.z + (POS.normalized.y / 2)))); + // I implemented the POS.normalized.y value to make sure we get to a value of 1 overall to ensure 50m distance, is this mathematicly correct?? FH 10.02.19 + //Original: tVect = (tVect + new Vector3(CurrentH * POS.normalized.z, 0, CurrentH * -POS.normalized.x)); } + // FH 06.02.19 xVect = (POS.normalized * MeterSep) + tVect; @@ -1162,22 +1228,27 @@ private void SetupLocations() float mMin = FakeStartTime; float mMax = EndTime; float tPercent = 0; - for (int i = 0; i < vSeriesCount; i++) + for (int index = 0; index < vSeriesCount; index++) { - tNode.GSDSpline.GetSplineValue_Both(tTimes[i], out tVect, out POS); + tNode.GSDSpline.GetSplineValue_Both(tTimes[index], out tVect, out POS); - tPercent = ((tTimes[i] - mMin) / (mMax - mMin)); + tPercent = ((tTimes[index] - mMin) / (mMax - mMin)); //Horiz: CurrentH = (HorizontalCurve.Evaluate(tPercent) * HorizontalSep); if (CurrentH < 0f) { CurrentH *= -1f; - tVect = (tVect + new Vector3(CurrentH * -POS.normalized.z, 0, CurrentH * POS.normalized.x)); + // FH 03.02.19 // Why has this Code a "wrong" logic, it multiplies z to x and x to z. + // Original Code: tVect = (tVect + new Vector3(CurrentH * -POS.normalized.z, 0, CurrentH * POS.normalized.x)); + tVect = (tVect + new Vector3(CurrentH * (-POS.normalized.z + (POS.normalized.y / 2)), 0, CurrentH * (POS.normalized.x + (POS.normalized.y / 2)))); } else if (CurrentH > 0f) { - tVect = (tVect + new Vector3(CurrentH * POS.normalized.z, 0, CurrentH * -POS.normalized.x)); + // FH 03.02.19 + // Original Code: tVect = (tVect + new Vector3(CurrentH * POS.normalized.z, 0, CurrentH * -POS.normalized.x)); + // Look at the Bug embeddedt/RoadArchitect/issues/4 + tVect = (tVect + new Vector3(CurrentH * (POS.normalized.z + (POS.normalized.y / 2)), 0, CurrentH * (-POS.normalized.x + (POS.normalized.y / 2)))); } //Vertical: @@ -1196,14 +1267,16 @@ private void SetupLocations() } } - tVect.y += (VerticalCurve.Evaluate(tPercent) * VerticalRaise); + tVect.y += (VerticalCurve.Evaluate(tPercent) * VerticalRaise); // Adds the Height to the Node including the VerticalRaise + // Adds the Vector and the POS to the List of the EdgeObjects, so they can be created EdgeObjectLocations.Add(tVect); EdgeObjectRotations.Add(POS); } StartPos = tNode.GSDSpline.GetSplineValue(StartTime); EndPos = tNode.GSDSpline.GetSplineValue(EndTime); } + // FH_Tag Optimizable } @@ -1226,9 +1299,9 @@ private Mesh GSDCombineMeshes(ref List hVerts, ref List hTris, if (j > 0) { - for (int i = 0; i < OrigTriCount; i++) + for (int index = 0; index < OrigTriCount; index++) { - hTris[j][i] += CurrentMVLIndex; + hTris[j][index] += CurrentMVLIndex; } } diff --git a/GSDRoadIntersection.cs b/GSDRoadIntersection.cs index f2d42421..9272b38c 100644 --- a/GSDRoadIntersection.cs +++ b/GSDRoadIntersection.cs @@ -205,17 +205,17 @@ public void Setup(GSDSplineN tNode, GSDSplineN xNode) public void DeleteRelevantChildren(GSDSplineN tNode, string tString) { int cCount = transform.childCount; - for (int i = cCount - 1; i >= 0; i--) + for (int index = cCount - 1; index >= 0; index--) { - if (transform.GetChild(i).name.ToLower().Contains(tString.ToLower())) + if (transform.GetChild(index).name.ToLower().Contains(tString.ToLower())) { - Object.DestroyImmediate(transform.GetChild(i).gameObject); + Object.DestroyImmediate(transform.GetChild(index).gameObject); } else if (tNode == Node1) { - if (transform.GetChild(i).name.ToLower().Contains("centermarkers")) + if (transform.GetChild(index).name.ToLower().Contains("centermarkers")) { - Object.DestroyImmediate(transform.GetChild(i).gameObject); + Object.DestroyImmediate(transform.GetChild(index).gameObject); } } } @@ -256,7 +256,9 @@ public bool Contains(ref Vector3 tVect) { Vector2 vVect = new Vector2(tVect.x, tVect.z); if (BoundsRect == null) - { ConstructBoundsRect(); } + { + ConstructBoundsRect(); + } return BoundsRect.Contains(ref vVect); } @@ -271,18 +273,18 @@ private bool ContainsLineOld(Vector3 tVect1, Vector3 tVect2, int LineDef = 30) tVects[0] = tVect1; float mMod = 0f; float fcounter = 1f; - for (int i = 1; i < (MaxDef - 1); i++) + for (int index = 1; index < (MaxDef - 1); index++) { mMod = fcounter / MaxDefF; - tVects[i] = ((tVect2 - tVect1) * mMod) + tVect1; + tVects[index] = ((tVect2 - tVect1) * mMod) + tVect1; fcounter += 1f; } tVects[MaxDef - 1] = tVect2; Vector2 xVect = default(Vector2); - for (int i = 0; i < MaxDef; i++) + for (int index = 0; index < MaxDef; index++) { - xVect = new Vector2(tVects[i].x, tVects[i].z); + xVect = new Vector2(tVects[index].x, tVects[index].z); if (BoundsRect.Contains(ref xVect)) { return true; @@ -298,13 +300,19 @@ public bool ContainsLine(Vector3 tVect1, Vector3 tVect2) Vector2 tVectEnd = new Vector2(tVect2.x, tVect2.z); bool bIntersects = Intersects2D(ref tVectStart, ref tVectEnd, ref CornerRR_2D, ref CornerRL_2D); if (bIntersects) - { return true; } + { + return true; + } bIntersects = Intersects2D(ref tVectStart, ref tVectEnd, ref CornerRL_2D, ref CornerLL_2D); if (bIntersects) - { return true; } + { + return true; + } bIntersects = Intersects2D(ref tVectStart, ref tVectEnd, ref CornerLL_2D, ref CornerLR_2D); if (bIntersects) - { return true; } + { + return true; + } bIntersects = Intersects2D(ref tVectStart, ref tVectEnd, ref CornerLR_2D, ref CornerRR_2D); return bIntersects; } @@ -339,7 +347,9 @@ private static bool Intersects2D(ref Vector2 Line1S, ref Vector2 Line1E, ref Vec void OnDrawGizmos() { if (!bDrawGizmo) - { return; } + { + return; + } Gizmos.color = Color.blue; Gizmos.DrawCube(transform.position + new Vector3(0f, 5f, 0f), new Vector3(2f, 11f, 2f)); } @@ -372,9 +382,15 @@ private void CreateFixedSequence() GSDTrafficLightSequence SMaker = null; FixedTimeSequenceList = new List(); if (rType != RoadTypeEnum.NoTurnLane) - { SMaker = new GSDTrafficLightSequence(true, GSDTrafficLightController.iLightControllerEnum.LeftTurn, GSDTrafficLightController.iLightSubStatusEnum.Green, opt_FixedTime_LeftTurnLightLength); FixedTimeSequenceList.Add(SMaker); } + { + SMaker = new GSDTrafficLightSequence(true, GSDTrafficLightController.iLightControllerEnum.LeftTurn, GSDTrafficLightController.iLightSubStatusEnum.Green, opt_FixedTime_LeftTurnLightLength); + FixedTimeSequenceList.Add(SMaker); + } if (rType != RoadTypeEnum.NoTurnLane) - { SMaker = new GSDTrafficLightSequence(true, GSDTrafficLightController.iLightControllerEnum.LeftTurn, GSDTrafficLightController.iLightSubStatusEnum.Yellow, opt_FixedTime_YellowLightLength); FixedTimeSequenceList.Add(SMaker); } + { + SMaker = new GSDTrafficLightSequence(true, GSDTrafficLightController.iLightControllerEnum.LeftTurn, GSDTrafficLightController.iLightSubStatusEnum.Yellow, opt_FixedTime_YellowLightLength); + FixedTimeSequenceList.Add(SMaker); + } SMaker = new GSDTrafficLightSequence(true, GSDTrafficLightController.iLightControllerEnum.Red, GSDTrafficLightController.iLightSubStatusEnum.Green, opt_FixedTime_AllRedLightLength); FixedTimeSequenceList.Add(SMaker); SMaker = new GSDTrafficLightSequence(true, GSDTrafficLightController.iLightControllerEnum.Regular, GSDTrafficLightController.iLightSubStatusEnum.Green, opt_FixedTime_RegularLightLength); @@ -385,9 +401,15 @@ private void CreateFixedSequence() FixedTimeSequenceList.Add(SMaker); if (rType != RoadTypeEnum.NoTurnLane) - { SMaker = new GSDTrafficLightSequence(false, GSDTrafficLightController.iLightControllerEnum.LeftTurn, GSDTrafficLightController.iLightSubStatusEnum.Green, opt_FixedTime_LeftTurnLightLength); FixedTimeSequenceList.Add(SMaker); } + { + SMaker = new GSDTrafficLightSequence(false, GSDTrafficLightController.iLightControllerEnum.LeftTurn, GSDTrafficLightController.iLightSubStatusEnum.Green, opt_FixedTime_LeftTurnLightLength); + FixedTimeSequenceList.Add(SMaker); + } if (rType != RoadTypeEnum.NoTurnLane) - { SMaker = new GSDTrafficLightSequence(false, GSDTrafficLightController.iLightControllerEnum.LeftTurn, GSDTrafficLightController.iLightSubStatusEnum.Yellow, opt_FixedTime_YellowLightLength); FixedTimeSequenceList.Add(SMaker); } + { + SMaker = new GSDTrafficLightSequence(false, GSDTrafficLightController.iLightControllerEnum.LeftTurn, GSDTrafficLightController.iLightSubStatusEnum.Yellow, opt_FixedTime_YellowLightLength); + FixedTimeSequenceList.Add(SMaker); + } SMaker = new GSDTrafficLightSequence(true, GSDTrafficLightController.iLightControllerEnum.Red, GSDTrafficLightController.iLightSubStatusEnum.Green, opt_FixedTime_AllRedLightLength); FixedTimeSequenceList.Add(SMaker); SMaker = new GSDTrafficLightSequence(false, GSDTrafficLightController.iLightControllerEnum.Regular, GSDTrafficLightController.iLightSubStatusEnum.Green, opt_FixedTime_RegularLightLength); @@ -414,7 +436,9 @@ private void FixedTime_Increment() GSDTrafficLightSequence SMaker = FixedTimeSequenceList[FixedTimeIndex]; FixedTimeIndex += 1; if (FixedTimeIndex > (FixedTimeSequenceList.Count - 1)) - { FixedTimeIndex = 0; } + { + FixedTimeIndex = 0; + } GSDTrafficLightController Lights1 = null; GSDTrafficLightController Lights2 = null; @@ -1221,12 +1245,12 @@ public void ToggleTrafficLightPoleColor() MeshRenderer MR = null; Material[] tMats = new Material[1]; tMats[0] = TrafficLightMaterial; - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - tName = transform.GetChild(i).name.ToLower(); + tName = transform.GetChild(index).name.ToLower(); if (tName.Contains("trafficlight")) { - MR = transform.GetChild(i).GetComponent(); + MR = transform.GetChild(index).GetComponent(); MR.materials = tMats; } } @@ -1239,11 +1263,11 @@ public void TogglePointLights(bool _bLightsEnabled) int cCount = transform.childCount; Light[] fLights = null; Transform tTrans = null; - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - if (transform.GetChild(i).name.ToLower().Contains("trafficlight")) + if (transform.GetChild(index).name.ToLower().Contains("trafficlight")) { - tTrans = transform.GetChild(i); + tTrans = transform.GetChild(index); int kCount = tTrans.childCount; for (int k = 0; k < kCount; k++) { diff --git a/GSDRoadMeshSplinate.cs b/GSDRoadMeshSplinate.cs index 68b5920e..41ecc738 100644 --- a/GSDRoadMeshSplinate.cs +++ b/GSDRoadMeshSplinate.cs @@ -64,6 +64,7 @@ public class SplinatedMeshMaker public bool bBCFlipX = false; public bool bBCFlipZ = false; + #region Horizontal offsets: public float HorizontalSep = 0f; public AnimationCurve HorizontalCurve; @@ -1149,166 +1150,306 @@ public void LoadToSMM(SplinatedMeshMaker SMM) public bool IsEqualToSMM(SplinatedMeshMaker SMM) { if (SMM.CurrentSplination != CurrentSplination) - { return false; } + { + return false; + } if (SMM.CurrentSplinationCap1 != CurrentSplinationCap1) - { return false; } + { + return false; + } if (SMM.CurrentSplinationCap2 != CurrentSplinationCap2) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(SMM.CapHeightOffset1, CapHeightOffset1, 0.0001f)) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(SMM.CapHeightOffset2, CapHeightOffset2, 0.0001f)) - { return false; } + { + return false; + } if (SMM.bMaterialOverride != bMaterialOverride) - { return false; } + { + return false; + } if (SMM.SplinatedMaterial1 != SplinatedMaterial1) - { return false; } + { + return false; + } if (SMM.SplinatedMaterial2 != SplinatedMaterial2) - { return false; } + { + return false; + } if (SMM.bExactSplination != bExactSplination) - { return false; } + { + return false; + } if (SMM.bMatchRoadDefinition != bMatchRoadDefinition) - { return false; } + { + return false; + } if (SMM.bMatchRoadIncrements != bMatchRoadIncrements) - { return false; } + { + return false; + } if (SMM.bTrimStart != bTrimStart) - { return false; } + { + return false; + } if (SMM.bTrimEnd != bTrimEnd) - { return false; } + { + return false; + } if (SMM.bMatchTerrain != bMatchTerrain) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(SMM.MinMaxMod, MinMaxMod, 0.0001f)) - { return false; } + { + return false; + } if (SMM.bIsBridge != bIsBridge) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(SMM.VertexMatchingPrecision, VertexMatchingPrecision, 0.0001f)) - { return false; } + { + return false; + } if (SMM.bIsStretch != bIsStretch) - { return false; } + { + return false; + } if (SMM.bStretchLocOffset != bStretchLocOffset) - { return false; } + { + return false; + } if (SMM.bStretchSize != bStretchSize) - { return false; } + { + return false; + } if (SMM.StretchBC_LocOffset != StretchBC_LocOffset) - { return false; } + { + return false; + } if (SMM.StretchBC_Size != StretchBC_Size) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(SMM.Stretch_UVThreshold, Stretch_UVThreshold, 0.0001f)) - { return false; } + { + return false; + } if (SMM.bStraightLineMatchStartEnd != bStraightLineMatchStartEnd) - { return false; } + { + return false; + } if (SMM.bBCFlipX != bBCFlipX) - { return false; } + { + return false; + } if (SMM.bBCFlipZ != bBCFlipZ) - { return false; } + { + return false; + } //Horizontal offsets: if (!GSDRootUtil.IsApproximately(SMM.HorizontalSep, HorizontalSep, 0.0001f)) - { return false; } + { + return false; + } if (SMM.HorizontalCurve != HorizontalCurve) - { return false; } + { + return false; + } //Vertical offset: if (!GSDRootUtil.IsApproximately(SMM.VerticalRaise, VerticalRaise, 0.0001f)) - { return false; } + { + return false; + } if (SMM.VerticalCurve != VerticalCurve) - { return false; } + { + return false; + } //Vertical cutoff: if (!GSDRootUtil.IsApproximately(SMM.VerticalCutoff, VerticalCutoff, 0.0001f)) - { return false; } + { + return false; + } if (SMM.bVerticalCutoff != bVerticalCutoff) - { return false; } + { + return false; + } if (SMM.bVerticalCutoffDownwards != bVerticalCutoffDownwards) - { return false; } + { + return false; + } if (SMM.bVerticalMeshCutoff_OppositeDir != bVerticalMeshCutoff_OppositeDir) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(SMM.VerticalMeshCutoffOffset, VerticalMeshCutoffOffset, 0.0001f)) - { return false; } + { + return false; + } if (SMM.bVerticalCutoff_MatchZero != bVerticalCutoff_MatchZero) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(SMM.RoadRaise, RoadRaise, 0.0001f)) - { return false; } + { + return false; + } if (SMM.CustomRotation != CustomRotation) - { return false; } + { + return false; + } if (SMM.bFlipRotation != bFlipRotation) - { return false; } + { + return false; + } if (SMM.bStatic != bStatic) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(SMM.StartTime, StartTime, 0.0001f)) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(SMM.EndTime, EndTime, 0.0001f)) - { return false; } + { + return false; + } if (SMM.Axis != Axis) - { return false; } + { + return false; + } if (SMM.RepeatUVType != RepeatUVType) - { return false; } + { + return false; + } //Ending objects: if (SMM.EndCapStart != EndCapStart) - { return false; } + { + return false; + } if (SMM.EndCapEnd != EndCapEnd) - { return false; } + { + return false; + } if (SMM.bEndCapCustomMatchStart != bEndCapCustomMatchStart) - { return false; } + { + return false; + } if (SMM.EndCapCustomOffsetStart != EndCapCustomOffsetStart) - { return false; } + { + return false; + } if (SMM.EndCapCustomOffsetEnd != EndCapCustomOffsetEnd) - { return false; } + { + return false; + } if (SMM.EndCapCustomRotOffsetStart != EndCapCustomRotOffsetStart) - { return false; } + { + return false; + } if (SMM.EndCapCustomRotOffsetEnd != EndCapCustomRotOffsetEnd) - { return false; } + { + return false; + } if (SMM.bEndObjectsMatchGround != bEndObjectsMatchGround) - { return false; } + { + return false; + } //Endings down: if (SMM.bStartDown != bStartDown) - { return false; } + { + return false; + } if (SMM.bStartTypeDownOverride != bStartTypeDownOverride) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(SMM.StartTypeDownOverride, StartTypeDownOverride, 0.0001f)) - { return false; } + { + return false; + } if (SMM.bEndDown != bEndDown) - { return false; } + { + return false; + } if (SMM.bEndTypeDownOverride != bEndTypeDownOverride) - { return false; } + { + return false; + } if (!GSDRootUtil.IsApproximately(SMM.EndTypeDownOverride, EndTypeDownOverride, 0.0001f)) - { return false; } + { + return false; + } //Collision: if (SMM.CollisionType != CollisionType) - { return false; } + { + return false; + } if (SMM.bCollisionConvex != bCollisionConvex) - { return false; } + { + return false; + } if (SMM.bSimpleCollisionAutomatic != bSimpleCollisionAutomatic) - { return false; } + { + return false; + } if (SMM.bCollisionTrigger != bCollisionTrigger) - { return false; } + { + return false; + } if (SMM.CollisionBoxBL != CollisionBoxBL) - { return false; } + { + return false; + } if (SMM.CollisionBoxBR != CollisionBoxBR) - { return false; } + { + return false; + } if (SMM.CollisionBoxTL != CollisionBoxTL) - { return false; } + { + return false; + } if (SMM.CollisionBoxTR != CollisionBoxTR) - { return false; } + { + return false; + } if (SMM.CollisionTriBL != CollisionTriBL) - { return false; } + { + return false; + } if (SMM.CollisionTriBR != CollisionTriBR) - { return false; } + { + return false; + } if (SMM.CollisionTriT != CollisionTriT) - { return false; } + { + return false; + } if (string.CompareOrdinal(SMM.tName, tName) != 0) - { return false; } + { + return false; + } return true; } @@ -1329,9 +1470,9 @@ public static Vector3 GetVector3Average(Vector3[] tVects) { int tCount = tVects.Length; Vector3 mVect = default(Vector3); - for (int i = 0; i < tCount; i++) + for (int index = 0; index < tCount; index++) { - mVect += tVects[i]; + mVect += tVects[index]; } mVect /= tCount; return mVect; @@ -1341,7 +1482,9 @@ public static Vector3 GetVector3Average(Vector3[] tVects) private static bool FloatsNear(float tNear, float tVal1, float tVal2) { if (GSDRootUtil.IsApproximately(tVal1, tVal2, tNear)) - { return true; } + { + return true; + } if (tVal1 < (tVal2 + tNear) && tVal1 > (tVal2 - tNear)) { @@ -1368,9 +1511,9 @@ private static int[] GetCollisionTris_Tri(int MeshCount, int cTriCount, int cCou tTris[tCounter] = 1; tCounter += 1; int tMod = -1; - for (int i = 0; i < (MeshCount); i++) + for (int index = 0; index < (MeshCount); index++) { - tMod = (i * 3); + tMod = (index * 3); //Bottom side: *** tTris[tCounter] = 1 + tMod; tCounter += 1; @@ -1443,9 +1586,9 @@ private static int[] GetCollisionTris_Box(int MeshCount, int cTriCount, int cCou tCounter += 1; int tMod = -1; - for (int i = 0; i < (MeshCount); i++) + for (int index = 0; index < (MeshCount); index++) { - tMod = (i * 4); + tMod = (index * 4); //Bottom side: *** tTris[tCounter] = tMod + 1; tCounter += 1; @@ -1683,19 +1826,19 @@ public void Setup(bool bGetStrings = false, bool bCollect = true) { SplinateMesh_Do(bGetStrings, ref tObj, bCollect); } - catch (System.Exception e) + catch (System.Exception exception) { if (tObj != null) { - for (int i = 0; i < 5; i++) + for (int index = 0; index < 5; index++) { - if (tObj[i] != null) + if (tObj[index] != null) { - Object.DestroyImmediate(tObj[i]); + Object.DestroyImmediate(tObj[index]); } } } - throw e; + throw exception; } #endif } @@ -1757,21 +1900,35 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool { CurrentSplinationString = GSDRootUtil.GetPrefabString(CurrentSplination); if (CurrentSplinationCap1 != null) - { CurrentSplinationCap1String = GSDRootUtil.GetPrefabString(CurrentSplinationCap1); } + { + CurrentSplinationCap1String = GSDRootUtil.GetPrefabString(CurrentSplinationCap1); + } if (CurrentSplinationCap2 != null) - { CurrentSplinationCap2String = GSDRootUtil.GetPrefabString(CurrentSplinationCap2); } + { + CurrentSplinationCap2String = GSDRootUtil.GetPrefabString(CurrentSplinationCap2); + } if (EndCapStart != null) - { EndCapStartString = GSDRootUtil.GetPrefabString(EndCapStart); } + { + EndCapStartString = GSDRootUtil.GetPrefabString(EndCapStart); + } if (EndCapEnd != null) - { EndCapEndString = GSDRootUtil.GetPrefabString(EndCapEnd); } + { + EndCapEndString = GSDRootUtil.GetPrefabString(EndCapEnd); + } if (SplinatedMaterial1 != null) - { SplinatedMaterial1String = UnityEditor.AssetDatabase.GetAssetPath(SplinatedMaterial1); } + { + SplinatedMaterial1String = UnityEditor.AssetDatabase.GetAssetPath(SplinatedMaterial1); + } if (SplinatedMaterial2 != null) - { SplinatedMaterial2String = UnityEditor.AssetDatabase.GetAssetPath(SplinatedMaterial2); } + { + SplinatedMaterial2String = UnityEditor.AssetDatabase.GetAssetPath(SplinatedMaterial2); + } } if (CurrentSplination == null) - { return; } + { + return; + } GameObject tObj = (GameObject) GameObject.Instantiate(CurrentSplination); ErrortObj[0] = tObj; @@ -1842,15 +1999,23 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool tVect1 = new Vector3(0f, 180f, 0f); tObj.transform.Rotate(tVect1, Space.World); if (Cap1 != null) - { Cap1.transform.Rotate(tVect1, Space.World); } + { + Cap1.transform.Rotate(tVect1, Space.World); + } if (Cap2 != null) - { Cap2.transform.Rotate(tVect1, Space.World); } + { + Cap2.transform.Rotate(tVect1, Space.World); + } } tObj.transform.Rotate(CustomRotation, Space.World); if (Cap1 != null) - { Cap1.transform.Rotate(CustomRotation, Space.World); } + { + Cap1.transform.Rotate(CustomRotation, Space.World); + } if (Cap2 != null) - { Cap2.transform.Rotate(CustomRotation, Space.World); } + { + Cap2.transform.Rotate(CustomRotation, Space.World); + } if (tMesh == null) { @@ -1880,12 +2045,12 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool //Transform vertices: Vector3[] OrigNormals = tMesh.normals; bool bCheckingNormal = true; - for (int i = 0; i < OrigMVL; i++) + for (int index = 0; index < OrigMVL; index++) { - OrigVerts[i] = tObj.transform.TransformPoint(OrigVerts[i]); + OrigVerts[index] = tObj.transform.TransformPoint(OrigVerts[index]); if (bCheckingNormal) { - if (!V3EqualToNone(OrigNormals[i])) + if (!V3EqualToNone(OrigNormals[index])) { bCheckingNormal = false; } @@ -1908,9 +2073,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool int CapTriCount2 = 0; if (CapMesh1 != null) { - for (int i = 0; i < CapOrigMVL1; i++) + for (int index = 0; index < CapOrigMVL1; index++) { - CapOrigVerts1[i] = Cap1.transform.TransformPoint(CapOrigVerts1[i]); + CapOrigVerts1[index] = Cap1.transform.TransformPoint(CapOrigVerts1[index]); } float[] oMinMaxX = new float[CapOrigMVL1]; @@ -1929,20 +2094,20 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool // float oMinZ = Mathf.Min(oMinMaxZ); float oMaxZ = Mathf.Max(oMinMaxZ); - for (int i = 0; i < CapOrigMVL1; i++) + for (int index = 0; index < CapOrigMVL1; index++) { if (Axis == AxisTypeEnum.Z) { - if (GSDRootUtil.IsApproximately(CapOrigVerts1[i].z, oMaxZ, MinMaxMod)) + if (GSDRootUtil.IsApproximately(CapOrigVerts1[index].z, oMaxZ, MinMaxMod)) { - tCapMatchIndices1.Add(i); + tCapMatchIndices1.Add(index); } } else { - if (GSDRootUtil.IsApproximately(CapOrigVerts1[i].x, oMaxX, MinMaxMod)) + if (GSDRootUtil.IsApproximately(CapOrigVerts1[index].x, oMaxX, MinMaxMod)) { - tCapMatchIndices1.Add(i); + tCapMatchIndices1.Add(index); } } } @@ -1955,19 +2120,19 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool } if (CapMesh2 != null) { - for (int i = 0; i < CapOrigMVL2; i++) + for (int index = 0; index < CapOrigMVL2; index++) { - CapOrigVerts2[i] = Cap2.transform.TransformPoint(CapOrigVerts2[i]); + CapOrigVerts2[index] = Cap2.transform.TransformPoint(CapOrigVerts2[index]); } float[] oMinMaxX = new float[CapOrigMVL2]; float[] oMinMaxY = new float[CapOrigMVL2]; float[] oMinMaxZ = new float[CapOrigMVL2]; - for (int i = 0; i < CapOrigMVL2; i++) + for (int index = 0; index < CapOrigMVL2; index++) { - oMinMaxX[i] = CapOrigVerts2[i].x; - oMinMaxY[i] = CapOrigVerts2[i].y; - oMinMaxZ[i] = CapOrigVerts2[i].z; + oMinMaxX[index] = CapOrigVerts2[index].x; + oMinMaxY[index] = CapOrigVerts2[index].y; + oMinMaxZ[index] = CapOrigVerts2[index].z; } float oMinX = Mathf.Min(oMinMaxX); // float oMaxX = Mathf.Max(oMinMaxX); @@ -1976,20 +2141,20 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool float oMinZ = Mathf.Min(oMinMaxZ); // float oMaxZ = Mathf.Max(oMinMaxZ); - for (int i = 0; i < CapOrigMVL2; i++) + for (int index = 0; index < CapOrigMVL2; index++) { if (Axis == AxisTypeEnum.Z) { - if (GSDRootUtil.IsApproximately(CapOrigVerts2[i].z, oMinZ, MinMaxMod)) + if (GSDRootUtil.IsApproximately(CapOrigVerts2[index].z, oMinZ, MinMaxMod)) { - tCapMatchIndices2.Add(i); + tCapMatchIndices2.Add(index); } } else { - if (GSDRootUtil.IsApproximately(CapOrigVerts2[i].x, oMinX, MinMaxMod)) + if (GSDRootUtil.IsApproximately(CapOrigVerts2[index].x, oMinX, MinMaxMod)) { - tCapMatchIndices2.Add(i); + tCapMatchIndices2.Add(index); } } } @@ -2061,28 +2226,28 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool List MaxVectorIndices = new List(); List MiddleVectorIndicies = new List(); float tBuffer = 0f; - for (int i = 0; i < OrigMVL; i++) + for (int index = 0; index < OrigMVL; index++) { if (Axis == AxisTypeEnum.X) { - tBuffer = OrigVerts[i].x; + tBuffer = OrigVerts[index].x; } else { - tBuffer = OrigVerts[i].z; + tBuffer = OrigVerts[index].z; } if (tBuffer > mMaxThreshold) { - MaxVectorIndices.Add(i); + MaxVectorIndices.Add(index); } else if (tBuffer < mMinThreshold) { - MinVectorIndices.Add(i); + MinVectorIndices.Add(index); } else { - MiddleVectorIndicies.Add(i); + MiddleVectorIndicies.Add(index); } } int MiddleCount = MiddleVectorIndicies.Count; @@ -2103,9 +2268,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool // UVStep = new Dictionary(); // } List AlreadyAddedList = new List(); - for (int i = 0; i < tCount1; i++) + for (int index = 0; index < tCount1; index++) { - tIntBuffer1 = MaxVectorIndices[i]; + tIntBuffer1 = MaxVectorIndices[index]; tVect1 = OrigVerts[tIntBuffer1]; bool bAdded = false; @@ -2138,7 +2303,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool if (tIntBuffer2 == tIntBuffer3) { if (AlreadyAddedList.Contains(tIntBuffer2)) - { break; } + { + break; + } if (IsApproxTwoThirds(ref tVect1, OrigVerts[tIntBuffer2], VertexMatchingPrecision)) { MatchingIndices.Add(tIntBuffer1, tIntBuffer2); @@ -2158,7 +2325,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool if (tIntBuffer2 == tIntBuffer4) { if (AlreadyAddedList.Contains(tIntBuffer2)) - { break; } + { + break; + } if (IsApproxTwoThirds(ref tVect1, OrigVerts[tIntBuffer2], VertexMatchingPrecision)) { MatchingIndices.Add(tIntBuffer1, tIntBuffer2); @@ -2171,7 +2340,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool } } if (bAdded) - { break; } + { + break; + } } } @@ -2179,11 +2350,13 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool if (MatchingIndices.Count < MaxVectorIndices.Count) { bool bIsZAxis = (Axis == AxisTypeEnum.Z); - for (int i = 0; i < tCount1; i++) + for (int index = 0; index < tCount1; index++) { - tIntBuffer1 = MaxVectorIndices[i]; + tIntBuffer1 = MaxVectorIndices[index]; if (MatchingIndices.ContainsKey(tIntBuffer1)) - { continue; } + { + continue; + } tVect1 = OrigVerts[tIntBuffer1]; if (Axis == AxisTypeEnum.Z) { @@ -2214,11 +2387,11 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool { List tList = new List(); tVect1 = OrigVerts[KVP.Key]; - for (int i = 0; i < CapOrigMVL1; i++) + for (int index = 0; index < CapOrigMVL1; index++) { - if (tCapMatchIndices1.Contains(i) && IsApproxTwoThirds(ref tVect1, CapOrigVerts1[i], VertexMatchingPrecision)) + if (tCapMatchIndices1.Contains(index) && IsApproxTwoThirds(ref tVect1, CapOrigVerts1[index], VertexMatchingPrecision)) { - tList.Add(i); + tList.Add(index); bDidAdd = true; } } @@ -2250,11 +2423,11 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool { List tList = new List(); tVect1 = OrigVerts[KVP.Key]; - for (int i = 0; i < CapOrigMVL2; i++) + for (int index = 0; index < CapOrigMVL2; index++) { - if (tCapMatchIndices2.Contains(i) && IsApproxTwoThirds(ref tVect1, CapOrigVerts2[i], VertexMatchingPrecision)) + if (tCapMatchIndices2.Contains(index) && IsApproxTwoThirds(ref tVect1, CapOrigVerts2[index], VertexMatchingPrecision)) { - tList.Add(i); + tList.Add(index); bDidAdd = true; } } @@ -2271,7 +2444,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool } if (Cap2 != null) - { Object.DestroyImmediate(Cap2); } + { + Object.DestroyImmediate(Cap2); + } CapMesh2 = null; CapOrigMVL2 = 0; CapTriCount2 = 0; @@ -2313,26 +2488,26 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool tMinMaxX = new float[OrigMVL]; tMinMaxY = new float[OrigMVL]; tMinMaxZ = new float[OrigMVL]; - for (int i = 0; i < OrigMVL; i++) + for (int index = 0; index < OrigMVL; index++) { if (Axis == AxisTypeEnum.X) { - tMinMax[i] = OrigVerts[i].x; + tMinMax[index] = OrigVerts[index].x; } else { - tMinMax[i] = OrigVerts[i].z; + tMinMax[index] = OrigVerts[index].z; } - tMinMaxX[i] = OrigVerts[i].x; - tMinMaxY[i] = OrigVerts[i].y; - tMinMaxZ[i] = OrigVerts[i].z; + tMinMaxX[index] = OrigVerts[index].x; + tMinMaxY[index] = OrigVerts[index].y; + tMinMaxZ[index] = OrigVerts[index].z; if (RepeatUVType == RepeatUVTypeEnum.X) { - tMinMaxUV[i] = OrigUV[i].x; + tMinMaxUV[index] = OrigUV[index].x; } else if (RepeatUVType == RepeatUVTypeEnum.Y) { - tMinMaxUV[i] = OrigUV[i].y; + tMinMaxUV[index] = OrigUV[index].y; } } //UV Changes: @@ -2718,40 +2893,40 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool tMatrix.SetTRS(tVect1, Quaternion.LookRotation(tDir), new Vector3(1f, 1f, 1f)); //Rotate and set vertex positions: - for (int i = 0; i < OrigMVL; i++) + for (int index = 0; index < OrigMVL; index++) { - xVect = OrigVerts[i]; - tVerts[vManuver + i] = tMatrix.MultiplyPoint3x4(xVect); + xVect = OrigVerts[index]; + tVerts[vManuver + index] = tMatrix.MultiplyPoint3x4(xVect); // tVerts[vManuver+i] = (Quaternion.LookRotation(tDir)*xVect) + tVect1; //UV: - tUV[vManuver + i] = OrigUV[i]; + tUV[vManuver + index] = OrigUV[index]; //Vertical cutoff: if (bVerticalCutoff) { - if (MiddleVectorIndicies.Contains(i)) + if (MiddleVectorIndicies.Contains(index)) { - tFloat5 = tVerts[vManuver + i].y; + tFloat5 = tVerts[vManuver + index].y; if (bVerticalCutoffDownwards) { if (bVerticalCutoff_MatchZero) { if (tFloat5 < tOrigHeightBuffer_Orig) { - tVerts[vManuver + i].y = tOrigHeightBuffer_Orig; + tVerts[vManuver + index].y = tOrigHeightBuffer_Orig; } } else { if (tFloat5 < tOrigHeightBuffer) { - tVerts[vManuver + i].y = tOrigHeightBuffer; + tVerts[vManuver + index].y = tOrigHeightBuffer; } } tFloat1 = (tOrigHeightBuffer_Orig - tOrigHeightBuffer) / mMaxHeight; - tUV[vManuver + i].x *= tFloat1; + tUV[vManuver + index].x *= tFloat1; } else @@ -2760,19 +2935,19 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool { if (tFloat5 > tOrigHeightBuffer_Orig) { - tVerts[vManuver + i].y = tOrigHeightBuffer_Orig; + tVerts[vManuver + index].y = tOrigHeightBuffer_Orig; } } else { if (tFloat5 > tOrigHeightBuffer) { - tVerts[vManuver + i].y = tOrigHeightBuffer; + tVerts[vManuver + index].y = tOrigHeightBuffer; } } tFloat1 = (tOrigHeightBuffer - tOrigHeightBuffer_Orig) / mMaxHeight; - tUV[vManuver + i].x *= tFloat1; + tUV[vManuver + index].x *= tFloat1; } } } @@ -2780,9 +2955,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool if (RepeatUVType != RepeatUVTypeEnum.None) { - for (int i = 0; i < MaxCount; i++) + for (int index = 0; index < MaxCount; index++) { - tIntBuffer1 = MaxVectorIndices[i]; + tIntBuffer1 = MaxVectorIndices[index]; if (RepeatUVType == RepeatUVTypeEnum.X) { tUV[vManuver + tIntBuffer1].x = mUVDiff * (j + 1); @@ -2792,9 +2967,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool tUV[vManuver + tIntBuffer1].y = mUVDiff * (j + 1); } } - for (int i = 0; i < MinCount; i++) + for (int index = 0; index < MinCount; index++) { - tIntBuffer1 = MinVectorIndices[i]; + tIntBuffer1 = MinVectorIndices[index]; if (RepeatUVType == RepeatUVTypeEnum.X) { tUV[vManuver + tIntBuffer1].x = mUVDiff * j; @@ -2911,9 +3086,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool } //Triangles: - for (int i = 0; i < OrigTriCount; i++) + for (int index = 0; index < OrigTriCount; index++) { - tTris[i + TriManuver] = OrigTris[i] + vManuver; + tTris[index + TriManuver] = OrigTris[index] + vManuver; } //Vert cut reverse: @@ -2924,16 +3099,16 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool VertCutBuffer1 = tVerts[vManuver + VertCutTriIndex1]; VertCutBuffer2 = tVerts[vManuver + VertCutTriIndex2]; - for (int i = 0; i < MiddleCount; i++) + for (int index = 0; index < MiddleCount; index++) { - VertCutBuffer3 = tVerts[vManuver + MiddleVectorIndicies[i]]; + VertCutBuffer3 = tVerts[vManuver + MiddleVectorIndicies[index]]; if (!bVerticalCutoffDownwards) { tBuffer = GetVHeightAtXY(ref VertCutBuffer1, ref VertCutBuffer2, ref VertCutBuffer3) + VerticalMeshCutoffOffset; if (VertCutBuffer3.y < tBuffer) { - tVerts[vManuver + MiddleVectorIndicies[i]].y = tBuffer; + tVerts[vManuver + MiddleVectorIndicies[index]].y = tBuffer; } } else @@ -2941,7 +3116,7 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool tBuffer = GetVHeightAtXY(ref VertCutBuffer1, ref VertCutBuffer2, ref VertCutBuffer3) - VerticalMeshCutoffOffset; if (VertCutBuffer3.y > tBuffer) { - tVerts[vManuver + MiddleVectorIndicies[i]].y = tBuffer; + tVerts[vManuver + MiddleVectorIndicies[index]].y = tBuffer; } } } @@ -2959,9 +3134,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool } if (j == 0) { - for (int i = 0; i < MinCount; i++) + for (int index = 0; index < MinCount; index++) { - tIntBuffer1 = MinVectorIndices[i]; + tIntBuffer1 = MinVectorIndices[index]; tVerts[vManuver + tIntBuffer1].y -= tFloat1; } @@ -2976,9 +3151,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool break; } - for (int i = 0; i < MiddleCount; i++) + for (int index = 0; index < MiddleCount; index++) { - tIntBuffer1 = MiddleVectorIndicies[i]; + tIntBuffer1 = MiddleVectorIndicies[index]; float tDistTo1 = Vector3.Distance(tVerts[vManuver + tIntBuffer1], pVect1); tVerts[vManuver + tIntBuffer1].y -= (tFloat1 * (tDistTo1 / tTotalDistDown)); } @@ -3008,9 +3183,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool } if (j == (MeshCount - 1)) { - for (int i = 0; i < MaxCount; i++) + for (int index = 0; index < MaxCount; index++) { - tIntBuffer1 = MaxVectorIndices[i]; + tIntBuffer1 = MaxVectorIndices[index]; tVerts[vManuver + tIntBuffer1].y -= tFloat1; } @@ -3168,7 +3343,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool StretchSkip: if (bIsStretch) - { vManuver = 0; } + { + vManuver = 0; + } //End/Start for stretch: if (bIsStretch) @@ -3229,32 +3406,32 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool foreach (KeyValuePair> KVP in MatchingIndices_Min_Cap) { int wCount = KVP.Value.Count; - for (int i = 0; i < wCount; i++) + for (int index = 0; index < wCount; index++) { if (bcapstart) { - tVect1 = cap1_verts[KVP.Value[i]] - tVerts[KVP.Key]; + tVect1 = cap1_verts[KVP.Value[index]] - tVerts[KVP.Key]; } - cap1_verts[KVP.Value[i]] = tVerts[KVP.Key]; - cap1_hit[KVP.Value[i]] = true; + cap1_verts[KVP.Value[index]] = tVerts[KVP.Key]; + cap1_hit[KVP.Value[index]] = true; if (bcapstart) { - tHeight = tSpline.GetSplineValue(tSpline.GetClosestParam(cap1_verts[KVP.Value[i]]), false).y; + tHeight = tSpline.GetSplineValue(tSpline.GetClosestParam(cap1_verts[KVP.Value[index]]), false).y; bcapstart = false; } } } float tParam = 0f; - for (int i = 0; i < CapOrigMVL1; i++) + for (int index = 0; index < CapOrigMVL1; index++) { - if (!cap1_hit[i]) + if (!cap1_hit[index]) { - cap1_verts[i] -= tVect1; - tParam = tSpline.GetClosestParam(cap1_verts[i]); + cap1_verts[index] -= tVect1; + tParam = tSpline.GetClosestParam(cap1_verts[index]); tVect2 = tSpline.GetSplineValue(tParam, false); - cap1_verts[i].y -= (tHeight - tVect2.y); - cap1_verts[i].y += CapHeightOffset1; + cap1_verts[index].y -= (tHeight - tVect2.y); + cap1_verts[index].y += CapHeightOffset1; } } @@ -3275,9 +3452,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool System.Array.Copy(tTris, 0, nTris, CapTriCount1, OldTriCount); System.Array.Copy(tUV, 0, nUV, CapOrigMVL1, OldMVL); - for (int i = CapTriCount1; i < (CapTriCount1 + OldTriCount); i++) + for (int index = CapTriCount1; index < (CapTriCount1 + OldTriCount); index++) { - nTris[i] += CapOrigMVL1; + nTris[index] += CapOrigMVL1; } tVerts = nVerts; @@ -3303,34 +3480,34 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool foreach (KeyValuePair> KVP in MatchingIndices_Max_Cap) { int wCount = KVP.Value.Count; - for (int i = 0; i < wCount; i++) + for (int index = 0; index < wCount; index++) { if (bcapstart) { - tVect1 = cap2_verts[KVP.Value[i]] - tVerts[vManuver + KVP.Key + CapOrigMVL1]; + tVect1 = cap2_verts[KVP.Value[index]] - tVerts[vManuver + KVP.Key + CapOrigMVL1]; } - cap2_verts[KVP.Value[i]] = tVerts[vManuver + KVP.Key + CapOrigMVL1]; - cap2_hit[KVP.Value[i]] = true; + cap2_verts[KVP.Value[index]] = tVerts[vManuver + KVP.Key + CapOrigMVL1]; + cap2_hit[KVP.Value[index]] = true; if (bcapstart) { - tHeight = tSpline.GetSplineValue(tSpline.GetClosestParam(cap2_verts[KVP.Value[i]]), false).y; + tHeight = tSpline.GetSplineValue(tSpline.GetClosestParam(cap2_verts[KVP.Value[index]]), false).y; bcapstart = false; } } } float tParam = 0f; - for (int i = 0; i < CapOrigMVL2; i++) + for (int index = 0; index < CapOrigMVL2; index++) { - if (!cap2_hit[i]) + if (!cap2_hit[index]) { - cap2_verts[i] -= tVect1; - tParam = tSpline.GetClosestParam(cap2_verts[i]); + cap2_verts[index] -= tVect1; + tParam = tSpline.GetClosestParam(cap2_verts[index]); tVect2 = tSpline.GetSplineValue(tParam, false); - cap2_verts[i].y -= (tHeight - tVect2.y); - cap2_verts[i].y += CapHeightOffset2; + cap2_verts[index].y -= (tHeight - tVect2.y); + cap2_verts[index].y += CapHeightOffset2; } } @@ -3351,9 +3528,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool System.Array.Copy(cap2_tris, 0, nTris, OldTriCount, CapTriCount2); System.Array.Copy(cap2_uv, 0, nUV, OldMVL, CapOrigMVL2); - for (int i = OldTriCount; i < nTris.Length; i++) + for (int index = OldTriCount; index < nTris.Length; index++) { - nTris[i] += OldMVL; + nTris[index] += OldMVL; } tVerts = nVerts; @@ -3363,16 +3540,16 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool } int tVertCount = tVerts.Length; - for (int i = 0; i < tVertCount; i++) + for (int index = 0; index < tVertCount; index++) { - tVerts[i] -= tNode.pos; + tVerts[index] -= tNode.pos; } if (cVerts != null) { int cVertCount = cVerts.Length; - for (int i = 0; i < cVertCount; i++) + for (int index = 0; index < cVertCount; index++) { - cVerts[i] -= tNode.pos; + cVerts[index] -= tNode.pos; } } @@ -3393,7 +3570,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool vManuver = j * OrigMVL; vManuver_Prev = (j - 1) * OrigMVL; if (CapMesh1 != null) - { tIntBuffer1 = CapOrigMVL1; } + { + tIntBuffer1 = CapOrigMVL1; + } foreach (KeyValuePair KVP in MatchingIndices_Min) { tAvgNormal = (tNormals[tIntBuffer1 + vManuver + KVP.Key] + tNormals[tIntBuffer1 + vManuver_Prev + KVP.Value]) * 0.5f; @@ -3431,7 +3610,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool cMesh.triangles = cTris; cMesh.normals = new Vector3[cVerts.Length]; if (MC != null) - { MC.sharedMesh = cMesh; } + { + MC.sharedMesh = cMesh; + } if (MC != null) { MC.convex = bCollisionConvex; @@ -3452,7 +3633,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool cMesh.triangles = cTris; cMesh.normals = new Vector3[cVerts.Length]; if (MC != null) - { MC.sharedMesh = cMesh; } + { + MC.sharedMesh = cMesh; + } if (MC != null) { MC.convex = bCollisionConvex; @@ -3469,7 +3652,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool { MC = Output.AddComponent(); if (MC != null) - { MC.sharedMesh = xMesh; } + { + MC.sharedMesh = xMesh; + } if (MC != null) { MC.convex = bCollisionConvex; @@ -3601,11 +3786,17 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool //Destroy the instantiated prefab: if (tObj != null) - { Object.DestroyImmediate(tObj); } + { + Object.DestroyImmediate(tObj); + } if (Cap1 != null) - { Object.DestroyImmediate(Cap1); } + { + Object.DestroyImmediate(Cap1); + } if (Cap2 != null) - { Object.DestroyImmediate(Cap2); } + { + Object.DestroyImmediate(Cap2); + } Material[] fMats = MR.sharedMaterials; @@ -3619,7 +3810,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool MeshRenderer eMR = EndCapStartObj.GetComponent(); if (eMR == null) - { eMR = EndCapStartObj.AddComponent(); } + { + eMR = EndCapStartObj.AddComponent(); + } if (eMR.sharedMaterials == null || (eMR.sharedMaterial != null && eMR.sharedMaterial.name.ToLower().Contains("default-diffuse"))) { eMR.sharedMaterials = fMats; @@ -3631,7 +3824,9 @@ private void SplinateMesh_Do(bool bGetStrings, ref GameObject[] ErrortObj, bool EndCapEndOutput = EndCapEndObj; MeshRenderer eMR = EndCapEndObj.GetComponent(); if (eMR == null) - { eMR = EndCapEndObj.AddComponent(); } + { + eMR = EndCapEndObj.AddComponent(); + } if (eMR.sharedMaterials == null || (eMR.sharedMaterial != null && eMR.sharedMaterial.name.ToLower().Contains("default-diffuse"))) { eMR.sharedMaterials = fMats; @@ -3650,7 +3845,9 @@ private void SaveMesh(ref Mesh tMesh, bool bIsCollider) { #if UNITY_EDITOR if (!tNode.GSDSpline.tRoad.GSDRS.opt_bSaveMeshes) - { return; } + { + return; + } //string tSceneName = System.IO.Path.GetFileName(UnityEditor.EditorApplication.currentScene).ToLower().Replace(".unity",""); string tSceneName = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name; tSceneName = tSceneName.Replace("/", ""); @@ -3725,30 +3922,30 @@ void DoStretch(ref Vector3[] OrigVerts, ref Vector2[] OrigUV, ref int[] OrigTris float NewDiff = Vector3.Distance(tVect1, tVect2); float UVMod = NewDiff / mMaxDiff; Vector3 xVect = default(Vector3); - for (int i = 0; i < OrigMVL; i++) + for (int index = 0; index < OrigMVL; index++) { - xVect = OrigVerts[i]; - if (MaxVectorIndices.Contains(i)) + xVect = OrigVerts[index]; + if (MaxVectorIndices.Contains(index)) { - tVerts[i] = tMatrixEnd.MultiplyPoint3x4(xVect); + tVerts[index] = tMatrixEnd.MultiplyPoint3x4(xVect); } else { - tVerts[i] = tMatrixStart.MultiplyPoint3x4(xVect); + tVerts[index] = tMatrixStart.MultiplyPoint3x4(xVect); } if (RepeatUVType == RepeatUVTypeEnum.X) { - if (OrigUV[i].x > Stretch_UVThreshold) + if (OrigUV[index].x > Stretch_UVThreshold) { - tUV[i].x = OrigUV[i].x * UVMod; + tUV[index].x = OrigUV[index].x * UVMod; } } else { - if (OrigUV[i].y > Stretch_UVThreshold) + if (OrigUV[index].y > Stretch_UVThreshold) { - tUV[i].y = OrigUV[i].y * UVMod; + tUV[index].y = OrigUV[index].y * UVMod; } } } @@ -3777,9 +3974,9 @@ Vector3 GetAverageNormalToGround(GameObject tObj) List xVects = new List(); - for (int i = 0; i < 8; i++) + for (int index = 0; index < 8; index++) { - tRay = new Ray(tVects[i] + new Vector3(0f, 1f, 0f), Vector3.down); + tRay = new Ray(tVects[index] + new Vector3(0f, 1f, 0f), Vector3.down); tRayHit = Physics.RaycastAll(tRay); tHitIndex = -1; tHitY = -1f; @@ -3806,9 +4003,9 @@ Vector3 GetAverageNormalToGround(GameObject tObj) } - for (int i = 0; i < xVects.Count; i++) + for (int index = 0; index < xVects.Count; index++) { - tHitNormal += xVects[i]; + tHitNormal += xVects[index]; } tHitNormal /= xVects.Count; diff --git a/GSDRoadSystem.cs b/GSDRoadSystem.cs index 791a6de2..e34cdd6c 100644 --- a/GSDRoadSystem.cs +++ b/GSDRoadSystem.cs @@ -1,7 +1,9 @@ +#region "Imports" using UnityEngine; #if UNITY_EDITOR using System.Collections; #endif +#endregion diff --git a/GSDRoadUtility.cs b/GSDRoadUtility.cs index 7ecdc422..2296f90d 100644 --- a/GSDRoadUtility.cs +++ b/GSDRoadUtility.cs @@ -56,9 +56,9 @@ private static bool IsApproximately(float a, float b, float tolerance) tNodeObj.transform.position = RS.Editor_MousePos; //This helps prevent double clicks: int mCount = RS.GSDSpline.GetNodeCount(); - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - if (Vector3.Distance(RS.Editor_MousePos, RS.GSDSpline.mNodes[i].pos) < 5f) + if (Vector3.Distance(RS.Editor_MousePos, RS.GSDSpline.mNodes[index].pos) < 5f) { Object.DestroyImmediate(tNodeObj); return null; @@ -68,7 +68,8 @@ private static bool IsApproximately(float a, float b, float tolerance) } Vector3 xVect = tNodeObj.transform.position; if (xVect.y < 0.03f) - { xVect.y = 0.03f; } + { + xVect.y = 0.03f; } tNodeObj.transform.position = xVect; tNodeObj.transform.parent = RS.GSDSplineObj.transform; @@ -119,9 +120,9 @@ private static bool IsApproximately(float a, float b, float tolerance) //This helps prevent double clicks: int mCount = RS.GSDSpline.GetNodeCount(); - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - if (Vector3.Distance(RS.Editor_MousePos, RS.GSDSpline.mNodes[i].pos) < 15f) + if (Vector3.Distance(RS.Editor_MousePos, RS.GSDSpline.mNodes[index].pos) < 15f) { Object.DestroyImmediate(tNodeObj); return null; @@ -135,7 +136,9 @@ private static bool IsApproximately(float a, float b, float tolerance) } Vector3 xVect = tNodeObj.transform.position; if (xVect.y < 0.03f) - { xVect.y = 0.03f; } + { + xVect.y = 0.03f; + } tNodeObj.transform.position = xVect; tNodeObj.transform.parent = RS.GSDSplineObj.transform; @@ -171,9 +174,9 @@ private static bool IsApproximately(float a, float b, float tolerance) } else { - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - GSDSplineN xNode = RS.GSDSpline.mNodes[i]; + GSDSplineN xNode = RS.GSDSpline.mNodes[index]; if (!bZeroInsert && !bEndInsert) { if (tParam > xNode.tTime) @@ -271,9 +274,6 @@ public class TempTerrainData public float DetailToHeightRatio; - - - // public Dictionary DetailHasProcessed; public HashSet DetailHasProcessed; @@ -295,6 +295,7 @@ public class TempTerrainData public Vector3 TerrainPos; public int GSDID; + public void Nullify() { heights = null; @@ -357,16 +358,22 @@ public static void ProcessRoad_Terrain_Hook1(GSDSplineC tSpline, GSDRoad tRoad, private static void ProcessRoad_Terrain_Hook1_Do(ref GSDSplineC tSpline, ref GSDRoad tRoad, bool bMultithreaded) { if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.BeginSample("ProcessRoad_Terrain_Hook1_Do"); } + { + UnityEngine.Profiling.Profiler.BeginSample("ProcessRoad_Terrain_Hook1_Do"); + } //First lets make sure all terrains have GSD shit on them: CheckAllTerrains(); //Reset the terrain: if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.BeginSample("TerrainsReset"); } + { + UnityEngine.Profiling.Profiler.BeginSample("TerrainsReset"); + } GSDTerraforming.TerrainsReset(tRoad); if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.EndSample(); } + { + UnityEngine.Profiling.Profiler.EndSample(); + } float heightDistance = tRoad.opt_MatchHeightsDistance; // float treeDistance = tRoad.opt_ClearTreesDistance; @@ -411,9 +418,9 @@ private static void ProcessRoad_Terrain_Hook1_Do(ref GSDSplineC tSpline, ref GSD { int mCount3 = tRoad.GSDSpline.GetNodeCount(); Vector2 tVect2D_321 = default(Vector2); - for (int i = 0; i < mCount3; i++) + for (int index = 0; index < mCount3; index++) { - tVect2D_321 = new Vector2(tRoad.GSDSpline.mNodes[i].pos.x, tRoad.GSDSpline.mNodes[i].pos.z); + tVect2D_321 = new Vector2(tRoad.GSDSpline.mNodes[index].pos.x, tRoad.GSDSpline.mNodes[index].pos.z); if (tRect.Contains(ref tVect2D_321)) { bContains = true; @@ -426,9 +433,9 @@ private static void ProcessRoad_Terrain_Hook1_Do(ref GSDSplineC tSpline, ref GSD float tDef = 5f / tSpline.distance; Vector2 x2D = default(Vector2); Vector3 x3D = default(Vector3); - for (float i = 0f; i <= 1f; i += tDef) + for (float index = 0f; index <= 1f; index += tDef) { - x3D = tSpline.GetSplineValue(i); + x3D = tSpline.GetSplineValue(index); x2D = new Vector2(x3D.x, x3D.z); if (tRect.Contains(ref x2D)) { @@ -454,7 +461,9 @@ private static void ProcessRoad_Terrain_Hook1_Do(ref GSDSplineC tSpline, ref GSD //Heights: if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.BeginSample("Heights"); } + { + UnityEngine.Profiling.Profiler.BeginSample("Heights"); + } if (tRoad.opt_HeightModEnabled) { aSize = (int) tSpline.distance * ((int) (heightDistance * 1.65f * TTD.HMRatio) + 2); @@ -479,11 +488,15 @@ private static void ProcessRoad_Terrain_Hook1_Do(ref GSDSplineC tSpline, ref GSD } } if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.EndSample(); } + { + UnityEngine.Profiling.Profiler.EndSample(); + } //Details: if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.BeginSample("Details"); } + { + UnityEngine.Profiling.Profiler.BeginSample("Details"); + } if (tRoad.opt_DetailModEnabled) { // TTD.DetailValues = new Dictionary(); @@ -545,15 +558,15 @@ private static void ProcessRoad_Terrain_Hook1_Do(ref GSDSplineC tSpline, ref GSD TTD.OldDetailsValue = new List>(); // TTD.DetailHasProcessed = new List>(); - for (int i = 0; i < TTD.DetailLayersCount; i++) + for (int index = 0; index < TTD.DetailLayersCount; index++) { - // if(TTD.DetailLayersSkip.Contains(i)){ + // if(TTD.DetailLayersSkip.Contains(index)){ // TTD.DetailsX.Add(new ushort[0]); // TTD.DetailsY.Add(new ushort[0]); // TTD.OldDetailsValue.Add(new ushort[0]); // continue; // } - // int detailentrycount = (int)((float)mMinMaxDetailEntryCount[i] * 1.5f); + // int detailentrycount = (int)((float)mMinMaxDetailEntryCount[index] * 1.5f); // int d_temp_Size = dSize; // if(d_temp_Size > detailentrycount){ d_temp_Size = detailentrycount; } // if(d_temp_Size < 1){ d_temp_Size = 1; } @@ -578,11 +591,15 @@ private static void ProcessRoad_Terrain_Hook1_Do(ref GSDSplineC tSpline, ref GSD } if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.EndSample(); } + { + UnityEngine.Profiling.Profiler.EndSample(); + } //Trees: if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.BeginSample("Trees"); } + { + UnityEngine.Profiling.Profiler.BeginSample("Trees"); + } if (tRoad.opt_TreeModEnabled) { // TTD.TreesCurrent = tTerrain.terrainData.treeInstances; @@ -592,7 +609,9 @@ private static void ProcessRoad_Terrain_Hook1_Do(ref GSDSplineC tSpline, ref GSD TTD.TreesOld = new List(); } if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.EndSample(); } + { + UnityEngine.Profiling.Profiler.EndSample(); + } } } @@ -610,7 +629,9 @@ private static void ProcessRoad_Terrain_Hook1_Do(ref GSDSplineC tSpline, ref GSD } if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.EndSample(); } + { + UnityEngine.Profiling.Profiler.EndSample(); + } //Start job now, for each relevant TTD: tRoad.EditorTerrainCalcs(ref EditorTTDList); @@ -668,10 +689,14 @@ public static GSDRoadUtil.Construction2DRect GetTerrainBounds(Terrain tTerrain) public static void ProcessRoad_Terrain_Hook2(GSDSplineC tSpline, ref List TTDList) { if (tSpline.tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.BeginSample("ProcessRoad_Terrain_Hook2"); } + { + UnityEngine.Profiling.Profiler.BeginSample("ProcessRoad_Terrain_Hook2"); + } ProcessRoad_Terrain_Hook2_Do(ref tSpline, ref TTDList); if (tSpline.tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.EndSample(); } + { + UnityEngine.Profiling.Profiler.EndSample(); + } } @@ -701,16 +726,18 @@ private static void ProcessRoad_Terrain_Hook2_Do(ref GSDSplineC tSpline, ref Lis //Details: if (tSpline.tRoad.opt_DetailModEnabled) { - for (int i = 0; i < TTD.DetailLayersCount; i++) + for (int index = 0; index < TTD.DetailLayersCount; index++) { // if(TTD.DetailLayersSkip.Contains(i) || TTD.DetailValues[i] == null){ continue; } // if(TTD.DetailsI[i] > 0){ // tTerrain.terrainData.SetDetailLayer(0,0,i,TTD.DetailValues[i]); // } - if (TTD.DetailLayersSkip.Contains(i) || TTD.MainDetailsX == null || TTD.MainDetailsX.Count < 1) - { continue; } - tDetails = tTerrain.terrainData.GetDetailLayer(0, 0, TTD.DetailMaxIndex, TTD.DetailMaxIndex, i); + if (TTD.DetailLayersSkip.Contains(index) || TTD.MainDetailsX == null || TTD.MainDetailsX.Count < 1) + { + continue; + } + tDetails = tTerrain.terrainData.GetDetailLayer(0, 0, TTD.DetailMaxIndex, TTD.DetailMaxIndex, index); int MaxCount = TTD.MainDetailsX.Count; for (int j = 0; j < MaxCount; j++) @@ -720,15 +747,15 @@ private static void ProcessRoad_Terrain_Hook2_Do(ref GSDSplineC tSpline, ref Lis tVal = tDetails[IntBufferX, IntBufferY]; if (tVal > 0) { - TTD.DetailsX[i].Add((ushort) IntBufferX); - TTD.DetailsY[i].Add((ushort) IntBufferY); - TTD.OldDetailsValue[i].Add((ushort) tVal); + TTD.DetailsX[index].Add((ushort) IntBufferX); + TTD.DetailsY[index].Add((ushort) IntBufferY); + TTD.OldDetailsValue[index].Add((ushort) tVal); tDetails[IntBufferX, IntBufferY] = 0; } } - TTD.DetailsI[i] = TTD.DetailsX[i].Count; + TTD.DetailsI[index] = TTD.DetailsX[index].Count; - tTerrain.terrainData.SetDetailLayer(0, 0, i, tDetails); + tTerrain.terrainData.SetDetailLayer(0, 0, index, tDetails); tDetails = null; TTD.DetailHasProcessed = null; } @@ -763,9 +790,13 @@ public static void TerrainsReset(GSDRoad tRoad) private static void TerrainsReset_Do(ref GSDRoad tRoad) { if (tRoad.TerrainHistory == null) - { return; } + { + return; + } if (tRoad.TerrainHistory.Count < 1) - { return; } + { + return; + } Object[] TIDs = GameObject.FindObjectsOfType(typeof(GSDTerrain)); float[,] heights; @@ -791,9 +822,9 @@ private static void TerrainsReset_Do(ref GSDRoad tRoad) { heights = tTerrain.terrainData.GetHeights(0, 0, tTerrain.terrainData.heightmapWidth, tTerrain.terrainData.heightmapHeight); ArrayCount = TH.cI; - for (int i = 0; i < ArrayCount; i++) + for (int index = 0; index < ArrayCount; index++) { - heights[TH.x1[i], TH.y1[i]] = TH.h[i]; + heights[TH.x1[index], TH.y1[index]] = TH.h[index]; } tTerrain.terrainData.SetHeights(0, 0, heights); } @@ -803,30 +834,38 @@ private static void TerrainsReset_Do(ref GSDRoad tRoad) int RealLayerCount = tTerrain.terrainData.detailPrototypes.Length; int StartIndex = 0; int EndIndex = 0; - for (int i = 0; i < TH.DetailLayersCount; i++) - { - if (i >= RealLayerCount) - { break; } - if (TH.DetailsX.Length <= i) - { break; } - if (TH.DetailsY.Length <= i) - { break; } + for (int index = 0; index < TH.DetailLayersCount; index++) + { + if (index >= RealLayerCount) + { + break; + } + if (TH.DetailsX.Length <= index) + { + break; + } + if (TH.DetailsY.Length <= index) + { + break; + } if (TH.DetailsX == null || TH.DetailsY == null || TH.DetailsI == null || TH.DetailsX.Length < 1) { continue; } - tDetails = tTerrain.terrainData.GetDetailLayer(0, 0, tTerrain.terrainData.detailWidth, tTerrain.terrainData.detailHeight, i); - ArrayCount = TH.DetailsI[i]; + tDetails = tTerrain.terrainData.GetDetailLayer(0, 0, tTerrain.terrainData.detailWidth, tTerrain.terrainData.detailHeight, index); + ArrayCount = TH.DetailsI[index]; if (ArrayCount == 0) - { continue; } + { + continue; + } EndIndex += ArrayCount; for (int j = StartIndex; j < EndIndex; j++) { tDetails[TH.DetailsX[j], TH.DetailsY[j]] = TH.DetailsOldValue[j]; } StartIndex = EndIndex; - tTerrain.terrainData.SetDetailLayer(0, 0, i, tDetails); + tTerrain.terrainData.SetDetailLayer(0, 0, index, tDetails); tDetails = null; } } @@ -919,9 +958,9 @@ public void MakeGSDTrees(ref List tTrees) TreesOld = new GSDTreeInstance[tSize]; GSDTreeInstance tTree = null; TreeInstance xTree; - for (int i = 0; i < tSize; i++) + for (int index = 0; index < tSize; index++) { - xTree = tTrees[i]; + xTree = tTrees[index]; tTree = new GSDTreeInstance(); tTree.colorR = xTree.color.r; tTree.colorG = xTree.color.g; @@ -937,7 +976,7 @@ public void MakeGSDTrees(ref List tTrees) tTree.positionZ = xTree.position.z; tTree.prototypeIndex = xTree.prototypeIndex; tTree.widthScale = xTree.widthScale; - TreesOld[i] = tTree; + TreesOld[index] = tTree; } } @@ -945,14 +984,16 @@ public void MakeGSDTrees(ref List tTrees) public TreeInstance[] MakeTrees() { if (TreesOld == null || TreesOld.Length < 1) - { return null; } + { + return null; + } int tSize = TreesOld.Length; TreeInstance[] tTrees = new TreeInstance[tSize]; GSDTreeInstance tTree = null; TreeInstance xTree; - for (int i = 0; i < tSize; i++) + for (int index = 0; index < tSize; index++) { - tTree = TreesOld[i]; + tTree = TreesOld[index]; xTree = new TreeInstance(); xTree.color = new Color(tTree.colorR, tTree.colorG, tTree.colorB, tTree.colorA); xTree.heightScale = tTree.heightScale; @@ -960,7 +1001,7 @@ public TreeInstance[] MakeTrees() xTree.position = new Vector3(tTree.positionX, tTree.positionY, tTree.positionZ); xTree.prototypeIndex = tTree.prototypeIndex; xTree.widthScale = tTree.widthScale; - tTrees[i] = xTree; + tTrees[index] = xTree; } return tTrees; } @@ -970,27 +1011,51 @@ public int GetSize() { int tSize = 4; if (x1 != null) - { tSize += (x1.Length * 4); tSize += 20; } + { + tSize += (x1.Length * 4); + tSize += 20; + } if (y1 != null) - { tSize += (y1.Length * 4); tSize += 20; } + { + tSize += (y1.Length * 4); + tSize += 20; + } if (h != null) - { tSize += (h.Length * 4); tSize += 20; } + { + tSize += (h.Length * 4); + tSize += 20; + } tSize += 4; tSize += 1; //Details: tSize += 4; if (DetailsX != null) - { tSize += (DetailsX.Length * 4); tSize += 20; } + { + tSize += (DetailsX.Length * 4); + tSize += 20; + } if (DetailsY != null) - { tSize += (DetailsY.Length * 4); tSize += 20; } + { + tSize += (DetailsY.Length * 4); + tSize += 20; + } if (DetailsOldValue != null) - { tSize += (DetailsOldValue.Length * 4); tSize += 20; } + { + tSize += (DetailsOldValue.Length * 4); + tSize += 20; + } if (DetailsI != null) - { tSize += (DetailsI.Length * 4); tSize += 20; } + { + tSize += (DetailsI.Length * 4); + tSize += 20; + } tSize += 1; //Trees: if (TreesOld != null) - { tSize += (TreesOld.Length * 56); tSize += 20; } + { + tSize += (TreesOld.Length * 56); + tSize += 20; + } tSize += 4; tSize += 1; tSize += 1; @@ -1465,13 +1530,13 @@ private void InitGameObjects() int MFArrayCount = MFArray.Length; int MCArrayCount = MCArray.Length; - for (int i = (MFArrayCount - 1); i > -1; i--) + for (int index = (MFArrayCount - 1); index > -1; index--) { - MFArray[i].sharedMesh = null; + MFArray[index].sharedMesh = null; } - for (int i = (MCArrayCount - 1); i > -1; i--) + for (int index = (MCArrayCount - 1); index > -1; index--) { - MCArray[i].sharedMesh = null; + MCArray[index].sharedMesh = null; } Object.DestroyImmediate(tRoad.MainMeshes); @@ -1539,29 +1604,65 @@ public void Nullify() tMesh_SR = null; tMesh_SL = null; if (tMesh_iBLanes0 != null) - { tMesh_iBLanes0.Clear(); tMesh_iBLanes0 = null; } + { + tMesh_iBLanes0.Clear(); + tMesh_iBLanes0 = null; + } if (tMesh_iBLanes1 != null) - { tMesh_iBLanes1.Clear(); tMesh_iBLanes1 = null; } + { + tMesh_iBLanes1.Clear(); + tMesh_iBLanes1 = null; + } if (tMesh_iBLanes2 != null) - { tMesh_iBLanes2.Clear(); tMesh_iBLanes2 = null; } + { + tMesh_iBLanes2.Clear(); + tMesh_iBLanes2 = null; + } if (tMesh_iBLanes3 != null) - { tMesh_iBLanes3.Clear(); tMesh_iBLanes3 = null; } + { + tMesh_iBLanes3.Clear(); + tMesh_iBLanes3 = null; + } if (tMesh_iFLanes0 != null) - { tMesh_iFLanes0.Clear(); tMesh_iFLanes0 = null; } + { + tMesh_iFLanes0.Clear(); + tMesh_iFLanes0 = null; + } if (tMesh_iFLanes1 != null) - { tMesh_iFLanes1.Clear(); tMesh_iFLanes1 = null; } + { + tMesh_iFLanes1.Clear(); + tMesh_iFLanes1 = null; + } if (tMesh_iFLanes2 != null) - { tMesh_iFLanes2.Clear(); tMesh_iFLanes2 = null; } + { + tMesh_iFLanes2.Clear(); + tMesh_iFLanes2 = null; + } if (tMesh_iFLanes3 != null) - { tMesh_iFLanes3.Clear(); tMesh_iFLanes3 = null; } + { + tMesh_iFLanes3.Clear(); + tMesh_iFLanes3 = null; + } if (tMesh_iBMainPlates != null) - { tMesh_iBMainPlates.Clear(); tMesh_iBMainPlates = null; } + { + tMesh_iBMainPlates.Clear(); + tMesh_iBMainPlates = null; + } if (tMesh_iFMainPlates != null) - { tMesh_iFMainPlates.Clear(); tMesh_iFMainPlates = null; } + { + tMesh_iFMainPlates.Clear(); + tMesh_iFMainPlates = null; + } if (tMesh_iBMarkerPlates != null) - { tMesh_iBMarkerPlates.Clear(); tMesh_iBMarkerPlates = null; } + { + tMesh_iBMarkerPlates.Clear(); + tMesh_iBMarkerPlates = null; + } if (tMesh_iFMarkerPlates != null) - { tMesh_iFMarkerPlates.Clear(); tMesh_iFMarkerPlates = null; } + { + tMesh_iFMarkerPlates.Clear(); + tMesh_iFMarkerPlates = null; + } tMesh_RoadConnections = null; iFLane1s_IsMiddleLane = null; @@ -1574,17 +1675,35 @@ public void Nullify() RoadConnections_tangents = null; if (cut_uv_world != null) - { cut_uv_world.Clear(); cut_uv_world = null; } + { + cut_uv_world.Clear(); + cut_uv_world = null; + } if (cut_uv_SR_world != null) - { cut_uv_SR_world.Clear(); cut_uv_SR_world = null; } + { + cut_uv_SR_world.Clear(); + cut_uv_SR_world = null; + } if (cut_uv_SL_world != null) - { cut_uv_SL_world.Clear(); cut_uv_SL_world = null; } + { + cut_uv_SL_world.Clear(); + cut_uv_SL_world = null; + } if (cut_tangents_world != null) - { cut_tangents_world.Clear(); cut_tangents_world = null; } + { + cut_tangents_world.Clear(); + cut_tangents_world = null; + } if (cut_tangents_SR_world != null) - { cut_tangents_SR_world.Clear(); cut_tangents_SR_world = null; } + { + cut_tangents_SR_world.Clear(); + cut_tangents_SR_world = null; + } if (cut_tangents_SL_world != null) - { cut_tangents_SL_world.Clear(); cut_tangents_SL_world = null; } + { + cut_tangents_SL_world.Clear(); + cut_tangents_SL_world = null; + } tMesh = null; @@ -1627,7 +1746,9 @@ private void MeshSetup1_Do() if (RoadVectors.Count < 64000) { if (tMesh == null) - { tMesh = new Mesh(); } + { + tMesh = new Mesh(); + } tMesh = MeshSetup1_Helper(ref tMesh, RoadVectors.ToArray(), ref tris, ref normals); tMeshSkip = false; } @@ -1640,7 +1761,9 @@ private void MeshSetup1_Do() if (ShoulderR_Vectors.Count < 64000) { if (tMesh_SR == null) - { tMesh_SR = new Mesh(); } + { + tMesh_SR = new Mesh(); + } tMesh_SR = MeshSetup1_Helper(ref tMesh_SR, ShoulderR_Vectors.ToArray(), ref tris_ShoulderR, ref normals_ShoulderR); tMesh_SRSkip = false; } @@ -1653,7 +1776,9 @@ private void MeshSetup1_Do() if (ShoulderL_Vectors.Count < 64000) { if (tMesh_SL == null) - { tMesh_SL = new Mesh(); } + { + tMesh_SL = new Mesh(); + } tMesh_SL = MeshSetup1_Helper(ref tMesh_SL, ShoulderL_Vectors.ToArray(), ref tris_ShoulderL, ref normals_ShoulderL); tMesh_SLSkip = false; } @@ -1665,15 +1790,15 @@ private void MeshSetup1_Do() if (RoadConnections_verts.Count > 0) { Mesh qMesh = null; - for (int i = 0; i < RoadConnections_verts.Count; i++) + for (int index = 0; index < RoadConnections_verts.Count; index++) { qMesh = new Mesh(); - qMesh.vertices = RoadConnections_verts[i]; - qMesh.triangles = RoadConnections_tris[i]; - qMesh.normals = RoadConnections_normals[i]; - qMesh.uv = RoadConnections_uv[i]; + qMesh.vertices = RoadConnections_verts[index]; + qMesh.triangles = RoadConnections_tris[index]; + qMesh.normals = RoadConnections_normals[index]; + qMesh.uv = RoadConnections_uv[index]; qMesh.RecalculateNormals(); - RoadConnections_normals[i] = qMesh.normals; + RoadConnections_normals[index] = qMesh.normals; tMesh_RoadConnections.Add(qMesh); } } @@ -1684,15 +1809,15 @@ private void MeshSetup1_Do() int[] tTris = null; Vector3[] tNormals = null; int cCount = cut_RoadVectors.Count; - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - tTris = cut_tris[i]; - tNormals = cut_normals[i]; + tTris = cut_tris[index]; + tNormals = cut_normals[index]; MeshBuffer = new Mesh(); - tMesh_RoadCuts.Add(MeshSetup1_Helper(ref MeshBuffer, cut_RoadVectors[i].ToArray(), ref tTris, ref tNormals)); + tMesh_RoadCuts.Add(MeshSetup1_Helper(ref MeshBuffer, cut_RoadVectors[index].ToArray(), ref tTris, ref tNormals)); MeshBuffer = new Mesh(); - tMesh_RoadCuts_world.Add(MeshSetup1_Helper(ref MeshBuffer, cut_RoadVectors[i].ToArray(), ref tTris, ref tNormals)); - cut_normals[i] = tNormals; + tMesh_RoadCuts_world.Add(MeshSetup1_Helper(ref MeshBuffer, cut_RoadVectors[index].ToArray(), ref tTris, ref tNormals)); + cut_normals[index] = tNormals; tMeshSkip = true; } } @@ -1701,15 +1826,15 @@ private void MeshSetup1_Do() int[] tTris = null; Vector3[] tNormals = null; int rCount = cut_ShoulderR_Vectors.Count; - for (int i = 0; i < rCount; i++) + for (int index = 0; index < rCount; index++) { - tTris = cut_tris_ShoulderR[i]; - tNormals = cut_normals_ShoulderR[i]; + tTris = cut_tris_ShoulderR[index]; + tNormals = cut_normals_ShoulderR[index]; MeshBuffer = new Mesh(); - tMesh_SRCuts.Add(MeshSetup1_Helper(ref MeshBuffer, cut_ShoulderR_Vectors[i].ToArray(), ref tTris, ref tNormals)); + tMesh_SRCuts.Add(MeshSetup1_Helper(ref MeshBuffer, cut_ShoulderR_Vectors[index].ToArray(), ref tTris, ref tNormals)); MeshBuffer = new Mesh(); - tMesh_SRCuts_world.Add(MeshSetup1_Helper(ref MeshBuffer, cut_ShoulderR_Vectors[i].ToArray(), ref tTris, ref tNormals)); - cut_normals_ShoulderR[i] = tNormals; + tMesh_SRCuts_world.Add(MeshSetup1_Helper(ref MeshBuffer, cut_ShoulderR_Vectors[index].ToArray(), ref tTris, ref tNormals)); + cut_normals_ShoulderR[index] = tNormals; tMesh_SRSkip = true; } if (rCount <= 0) @@ -1717,15 +1842,15 @@ private void MeshSetup1_Do() tMesh_SRSkip = false; } int lCount = cut_ShoulderL_Vectors.Count; - for (int i = 0; i < lCount; i++) + for (int index = 0; index < lCount; index++) { - tTris = cut_tris_ShoulderL[i]; - tNormals = cut_normals_ShoulderL[i]; + tTris = cut_tris_ShoulderL[index]; + tNormals = cut_normals_ShoulderL[index]; MeshBuffer = new Mesh(); - tMesh_SLCuts.Add(MeshSetup1_Helper(ref MeshBuffer, cut_ShoulderL_Vectors[i].ToArray(), ref tTris, ref tNormals)); + tMesh_SLCuts.Add(MeshSetup1_Helper(ref MeshBuffer, cut_ShoulderL_Vectors[index].ToArray(), ref tTris, ref tNormals)); MeshBuffer = new Mesh(); - tMesh_SLCuts_world.Add(MeshSetup1_Helper(ref MeshBuffer, cut_ShoulderL_Vectors[i].ToArray(), ref tTris, ref tNormals)); - cut_normals_ShoulderL[i] = tNormals; + tMesh_SLCuts_world.Add(MeshSetup1_Helper(ref MeshBuffer, cut_ShoulderL_Vectors[index].ToArray(), ref tTris, ref tNormals)); + cut_normals_ShoulderL[index] = tNormals; tMesh_SLSkip = true; } if (lCount <= 0) @@ -1749,13 +1874,13 @@ private void MeshSetup1_IntersectionObjectsSetup() { int mCount = tRoad.GSDSpline.GetNodeCount(); List tGSDRIs = new List(); - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - if (tRoad.GSDSpline.mNodes[i].bIsIntersection) + if (tRoad.GSDSpline.mNodes[index].bIsIntersection) { - if (!tGSDRIs.Contains(tRoad.GSDSpline.mNodes[i].GSDRI)) + if (!tGSDRIs.Contains(tRoad.GSDSpline.mNodes[index].GSDRI)) { - tGSDRIs.Add(tRoad.GSDSpline.mNodes[i].GSDRI); + tGSDRIs.Add(tRoad.GSDSpline.mNodes[index].GSDRI); } } } @@ -1788,9 +1913,9 @@ private void MeshSetup1_IntersectionParts() { int mCount = tRoad.GSDSpline.GetNodeCount(); bool bHasInter = false; - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - if (tRoad.GSDSpline.mNodes[i].bIsIntersection) + if (tRoad.GSDSpline.mNodes[index].bIsIntersection) { bHasInter = true; break; @@ -1816,30 +1941,30 @@ private void MeshSetup1_IntersectionParts() tMesh_iBLanes0.Add(MeshBuffer); } vCount = iBLane1s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - tNormals = iBLane1s_normals[i]; - tTris = iBLane1s_tris[i]; + tNormals = iBLane1s_normals[index]; + tTris = iBLane1s_tris[index]; MeshBuffer = new Mesh(); - MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iBLane1s[i], ref tTris, ref tNormals); + MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iBLane1s[index], ref tTris, ref tNormals); tMesh_iBLanes1.Add(MeshBuffer); } vCount = iBLane2s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - tNormals = iBLane2s_normals[i]; - tTris = iBLane2s_tris[i]; + tNormals = iBLane2s_normals[index]; + tTris = iBLane2s_tris[index]; MeshBuffer = new Mesh(); - MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iBLane2s[i], ref tTris, ref tNormals); + MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iBLane2s[index], ref tTris, ref tNormals); tMesh_iBLanes2.Add(MeshBuffer); } vCount = iBLane3s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - tNormals = iBLane3s_normals[i]; - tTris = iBLane3s_tris[i]; + tNormals = iBLane3s_normals[index]; + tTris = iBLane3s_tris[index]; MeshBuffer = new Mesh(); - MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iBLane3s[i], ref tTris, ref tNormals); + MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iBLane3s[index], ref tTris, ref tNormals); tMesh_iBLanes3.Add(MeshBuffer); } //Front lanes: @@ -1853,49 +1978,49 @@ private void MeshSetup1_IntersectionParts() tMesh_iFLanes0.Add(MeshBuffer); } vCount = iFLane1s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - tNormals = iFLane1s_normals[i]; - tTris = iFLane1s_tris[i]; + tNormals = iFLane1s_normals[index]; + tTris = iFLane1s_tris[index]; MeshBuffer = new Mesh(); - MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iFLane1s[i], ref tTris, ref tNormals); + MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iFLane1s[index], ref tTris, ref tNormals); tMesh_iFLanes1.Add(MeshBuffer); } vCount = iFLane2s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - tNormals = iFLane2s_normals[i]; - tTris = iFLane2s_tris[i]; + tNormals = iFLane2s_normals[index]; + tTris = iFLane2s_tris[index]; MeshBuffer = new Mesh(); - MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iFLane2s[i], ref tTris, ref tNormals); + MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iFLane2s[index], ref tTris, ref tNormals); tMesh_iFLanes2.Add(MeshBuffer); } vCount = iFLane3s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - tNormals = iFLane3s_normals[i]; - tTris = iFLane3s_tris[i]; + tNormals = iFLane3s_normals[index]; + tTris = iFLane3s_tris[index]; MeshBuffer = new Mesh(); - MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iFLane3s[i], ref tTris, ref tNormals); + MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iFLane3s[index], ref tTris, ref tNormals); tMesh_iFLanes3.Add(MeshBuffer); } //Main plates: vCount = iBMainPlates.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - tNormals = iBMainPlates_normals[i]; - tTris = iBMainPlates_tris[i]; + tNormals = iBMainPlates_normals[index]; + tTris = iBMainPlates_tris[index]; MeshBuffer = new Mesh(); - MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iBMainPlates[i], ref tTris, ref tNormals); + MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iBMainPlates[index], ref tTris, ref tNormals); tMesh_iBMainPlates.Add(MeshBuffer); } vCount = iFMainPlates.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - tNormals = iFMainPlates_normals[i]; - tTris = iFMainPlates_tris[i]; + tNormals = iFMainPlates_normals[index]; + tTris = iFMainPlates_tris[index]; MeshBuffer = new Mesh(); - MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iFMainPlates[i], ref tTris, ref tNormals); + MeshBuffer = MeshSetup1_Helper(ref MeshBuffer, iFMainPlates[index], ref tTris, ref tNormals); tMesh_iFMainPlates.Add(MeshBuffer); } @@ -1923,6 +2048,7 @@ public void MeshSetup2() MeshSetup2_Do(); } + /// /// Assigns UV and tangents to meshes. If multithreading enabled, this occurs after the last threaded job since unity library can't be used in threads. /// @@ -2046,25 +2172,25 @@ private void MeshSetup2_Do() GameObject CreatedMainObj; GameObject CreatedMarkerObj; int rCount = cut_ShoulderR_Vectors.Count; - for (int i = 0; i < rCount; i++) + for (int index = 0; index < rCount; index++) { bool bHasMats = false; CreatedMainObj = null; - MeshMainBuffer = tMesh_SRCuts_world[i]; + MeshMainBuffer = tMesh_SRCuts_world[index]; if (MeshMainBuffer != null) { - MeshSetup2_Helper_CutsShoulder(i, ref MeshMainBuffer, cut_uv_SR_world[i], cut_tangents_SR_world[i], ref tRoad.MeshShoR, false, false, out CreatedMainObj); - SaveMesh(SaveMeshTypeEnum.SCut, MeshMainBuffer, tRoad, "SCutR" + i.ToString()); + MeshSetup2_Helper_CutsShoulder(index, ref MeshMainBuffer, cut_uv_SR_world[index], cut_tangents_SR_world[index], ref tRoad.MeshShoR, false, false, out CreatedMainObj); + SaveMesh(SaveMeshTypeEnum.SCut, MeshMainBuffer, tRoad, "SCutR" + index.ToString()); } CreatedMarkerObj = null; - MeshMarkerBuffer = tMesh_SRCuts[i]; + MeshMarkerBuffer = tMesh_SRCuts[index]; if (MeshMarkerBuffer != null) { - bHasMats = MeshSetup2_Helper_CutsShoulder(i, ref MeshMarkerBuffer, cut_uv_SR[i], cut_tangents_SR[i], ref CreatedMainObj, false, true, out CreatedMarkerObj); + bHasMats = MeshSetup2_Helper_CutsShoulder(index, ref MeshMarkerBuffer, cut_uv_SR[index], cut_tangents_SR[index], ref CreatedMainObj, false, true, out CreatedMarkerObj); if (bHasMats) { - SaveMesh(SaveMeshTypeEnum.SCut, MeshMarkerBuffer, tRoad, "SCutRMarker" + i.ToString()); + SaveMesh(SaveMeshTypeEnum.SCut, MeshMarkerBuffer, tRoad, "SCutRMarker" + index.ToString()); } else { @@ -2076,26 +2202,26 @@ private void MeshSetup2_Do() } int lCount = cut_ShoulderL_Vectors.Count; - for (int i = 0; i < lCount; i++) + for (int index = 0; index < lCount; index++) { bool bHasMats = false; CreatedMainObj = null; - MeshMainBuffer = tMesh_SLCuts_world[i]; + MeshMainBuffer = tMesh_SLCuts_world[index]; if (MeshMainBuffer != null) { - MeshSetup2_Helper_CutsShoulder(i, ref MeshMainBuffer, cut_uv_SL_world[i], cut_tangents_SL_world[i], ref tRoad.MeshShoL, true, false, out CreatedMainObj); - SaveMesh(SaveMeshTypeEnum.SCut, MeshMainBuffer, tRoad, "SCutL" + i.ToString()); + MeshSetup2_Helper_CutsShoulder(index, ref MeshMainBuffer, cut_uv_SL_world[index], cut_tangents_SL_world[index], ref tRoad.MeshShoL, true, false, out CreatedMainObj); + SaveMesh(SaveMeshTypeEnum.SCut, MeshMainBuffer, tRoad, "SCutL" + index.ToString()); } CreatedMarkerObj = null; - MeshMarkerBuffer = tMesh_SLCuts[i]; + MeshMarkerBuffer = tMesh_SLCuts[index]; if (MeshMarkerBuffer != null) { - bHasMats = MeshSetup2_Helper_CutsShoulder(i, ref MeshMarkerBuffer, cut_uv_SL[i], cut_tangents_SL[i], ref CreatedMainObj, true, true, out CreatedMarkerObj); + bHasMats = MeshSetup2_Helper_CutsShoulder(index, ref MeshMarkerBuffer, cut_uv_SL[index], cut_tangents_SL[index], ref CreatedMainObj, true, true, out CreatedMarkerObj); if (bHasMats) { - SaveMesh(SaveMeshTypeEnum.SCut, MeshMarkerBuffer, tRoad, "SCutLMarker" + i.ToString()); + SaveMesh(SaveMeshTypeEnum.SCut, MeshMarkerBuffer, tRoad, "SCutLMarker" + index.ToString()); } else { @@ -2126,18 +2252,26 @@ private void MeshSetup2_Do() MeshCollider tMC = tRoad.MeshShoR.GetComponent(); MeshRenderer tMR = tRoad.MeshShoR.GetComponent(); if (tMC != null) - { Object.DestroyImmediate(tMC); } + { + Object.DestroyImmediate(tMC); + } if (tMR != null) - { Object.DestroyImmediate(tMR); } + { + Object.DestroyImmediate(tMR); + } } if (tRoad.MeshShoL != null) { MeshCollider tMC = tRoad.MeshShoL.GetComponent(); MeshRenderer tMR = tRoad.MeshShoL.GetComponent(); if (tMC != null) - { Object.DestroyImmediate(tMC); } + { + Object.DestroyImmediate(tMC); + } if (tMR != null) - { Object.DestroyImmediate(tMR); } + { + Object.DestroyImmediate(tMR); + } } } } @@ -2158,48 +2292,56 @@ private void MeshSetup2_Do() MeshCollider tMC = tRoad.MeshShoR.GetComponent(); MeshRenderer tMR = tRoad.MeshShoR.GetComponent(); if (tMC != null) - { Object.DestroyImmediate(tMC); } + { + Object.DestroyImmediate(tMC); + } if (tMR != null) - { Object.DestroyImmediate(tMR); } + { + Object.DestroyImmediate(tMR); + } } if (tRoad.MeshShoL != null) { MeshCollider tMC = tRoad.MeshShoL.GetComponent(); MeshRenderer tMR = tRoad.MeshShoL.GetComponent(); if (tMC != null) - { Object.DestroyImmediate(tMC); } + { + Object.DestroyImmediate(tMC); + } if (tMR != null) - { Object.DestroyImmediate(tMR); } + { + Object.DestroyImmediate(tMR); + } } Mesh tBuffer = null; int xCount = tMesh_SRCuts_world.Count; - for (int i = 0; i < xCount; i++) + for (int index = 0; index < xCount; index++) { - tBuffer = tMesh_SRCuts_world[i]; + tBuffer = tMesh_SRCuts_world[index]; Object.DestroyImmediate(tBuffer); - tMesh_SRCuts_world[i] = null; + tMesh_SRCuts_world[index] = null; } xCount = tMesh_SRCuts.Count; - for (int i = 0; i < xCount; i++) + for (int index = 0; index < xCount; index++) { - tBuffer = tMesh_SRCuts[i]; + tBuffer = tMesh_SRCuts[index]; Object.DestroyImmediate(tBuffer); - tMesh_SRCuts[i] = null; + tMesh_SRCuts[index] = null; } xCount = tMesh_SLCuts_world.Count; - for (int i = 0; i < xCount; i++) + for (int index = 0; index < xCount; index++) { - tBuffer = tMesh_SLCuts_world[i]; + tBuffer = tMesh_SLCuts_world[index]; Object.DestroyImmediate(tBuffer); - tMesh_SLCuts_world[i] = null; + tMesh_SLCuts_world[index] = null; } xCount = tMesh_SLCuts.Count; - for (int i = 0; i < xCount; i++) + for (int index = 0; index < xCount; index++) { - tBuffer = tMesh_SLCuts[i]; + tBuffer = tMesh_SLCuts[index]; Object.DestroyImmediate(tBuffer); - tMesh_SLCuts[i] = null; + tMesh_SLCuts[index] = null; } if (tRoad.MeshShoR != null) @@ -2214,13 +2356,13 @@ private void MeshSetup2_Do() } - for (int i = 0; i < RoadConnections_tangents.Count; i++) + for (int index = 0; index < RoadConnections_tangents.Count; index++) { - tMesh_RoadConnections[i].tangents = RoadConnections_tangents[i]; + tMesh_RoadConnections[index].tangents = RoadConnections_tangents[index]; GameObject tObj = new GameObject("RoadConnectionMarker"); MeshFilter MF = tObj.AddComponent(); MeshRenderer MR = tObj.AddComponent(); - float fDist = Vector3.Distance(RoadConnections_verts[i][2], RoadConnections_verts[i][3]); + float fDist = Vector3.Distance(RoadConnections_verts[index][2], RoadConnections_verts[index][3]); fDist = Mathf.Round(fDist); if (tRoad.opt_Lanes == 2) { @@ -2240,21 +2382,21 @@ private void MeshSetup2_Do() GSD.Roads.GSDRoadUtilityEditor.SetRoadMaterial(GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDRoadConn-6L-4L.mat", MR); } } - MF.sharedMesh = tMesh_RoadConnections[i]; + MF.sharedMesh = tMesh_RoadConnections[index]; tObj.transform.parent = tRoad.MeshRoad.transform; Mesh vMesh = new Mesh(); - vMesh.vertices = RoadConnections_verts[i]; - vMesh.triangles = RoadConnections_tris[i]; - vMesh.normals = RoadConnections_normals[i]; + vMesh.vertices = RoadConnections_verts[index]; + vMesh.triangles = RoadConnections_tris[index]; + vMesh.normals = RoadConnections_normals[index]; Vector2[] vUV = new Vector2[4]; - vUV[0] = new Vector2(RoadConnections_verts[i][0].x / 5f, RoadConnections_verts[i][0].z / 5f); - vUV[1] = new Vector2(RoadConnections_verts[i][1].x / 5f, RoadConnections_verts[i][1].z / 5f); - vUV[2] = new Vector2(RoadConnections_verts[i][2].x / 5f, RoadConnections_verts[i][2].z / 5f); - vUV[3] = new Vector2(RoadConnections_verts[i][3].x / 5f, RoadConnections_verts[i][3].z / 5f); + vUV[0] = new Vector2(RoadConnections_verts[index][0].x / 5f, RoadConnections_verts[index][0].z / 5f); + vUV[1] = new Vector2(RoadConnections_verts[index][1].x / 5f, RoadConnections_verts[index][1].z / 5f); + vUV[2] = new Vector2(RoadConnections_verts[index][2].x / 5f, RoadConnections_verts[index][2].z / 5f); + vUV[3] = new Vector2(RoadConnections_verts[index][3].x / 5f, RoadConnections_verts[index][3].z / 5f); vMesh.uv = vUV; vMesh.RecalculateNormals(); - RoadConnections_normals[i] = vMesh.normals; + RoadConnections_normals[index] = vMesh.normals; vMesh.tangents = GSDRootUtil.ProcessTangents(vMesh.triangles, vMesh.normals, vMesh.uv, vMesh.vertices); tObj = new GameObject("RoadConnectionBase"); @@ -2266,7 +2408,7 @@ private void MeshSetup2_Do() GSD.Roads.GSDRoadUtilityEditor.SetRoadMaterial(GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/GSDRoad1.mat", MR); tObj.transform.parent = tRoad.MeshRoad.transform; - SaveMesh(SaveMeshTypeEnum.RoadConn, vMesh, tRoad, "RoadConn" + i.ToString()); + SaveMesh(SaveMeshTypeEnum.RoadConn, vMesh, tRoad, "RoadConn" + index.ToString()); } } @@ -2276,31 +2418,46 @@ private void MeshSetup2_Do() } if (tRoad.MeshiLanes != null) - { Object.DestroyImmediate(tRoad.MeshiLanes); } + { + Object.DestroyImmediate(tRoad.MeshiLanes); + } if (tRoad.MeshiLanes0 != null) - { Object.DestroyImmediate(tRoad.MeshiLanes0); } + { + Object.DestroyImmediate(tRoad.MeshiLanes0); + } if (tRoad.MeshiLanes1 != null) - { Object.DestroyImmediate(tRoad.MeshiLanes1); } + { + Object.DestroyImmediate(tRoad.MeshiLanes1); + } if (tRoad.MeshiLanes2 != null) - { Object.DestroyImmediate(tRoad.MeshiLanes2); } + { + Object.DestroyImmediate(tRoad.MeshiLanes2); + } if (tRoad.MeshiLanes3 != null) - { Object.DestroyImmediate(tRoad.MeshiLanes3); } + { + Object.DestroyImmediate(tRoad.MeshiLanes3); + } if (tRoad.MeshiMainPlates != null) - { Object.DestroyImmediate(tRoad.MeshiMainPlates); } + { + Object.DestroyImmediate(tRoad.MeshiMainPlates); + } if (tRoad.MeshiMarkerPlates != null) - { Object.DestroyImmediate(tRoad.MeshiMarkerPlates); } + { + Object.DestroyImmediate(tRoad.MeshiMarkerPlates); + } //Updates the road and shoulder cut materials if necessary. Note: Cycling through all nodes in case the road cuts and shoulder cut numbers don't match. if (tRoad.opt_bRoadCuts || tRoad.opt_bShoulderCuts || tRoad.opt_bDynamicCuts) { int mCount = tRoad.GSDSpline.GetNodeCount(); - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - tRoad.GSDSpline.mNodes[i].UpdateCuts(); + tRoad.GSDSpline.mNodes[index].UpdateCuts(); } } } + #region "MeshSetup2 - Intersections" // private void MeshSetup2_Intersections_FixNormals(){ // int mCount = tRoad.GSDSpline.GetNodeCount(); @@ -2354,9 +2511,9 @@ private void MeshSetup2_Intersections() { int mCount = tRoad.GSDSpline.GetNodeCount(); bool bHasInter = false; - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - if (tRoad.GSDSpline.mNodes[i].bIsIntersection) + if (tRoad.GSDSpline.mNodes[index].bIsIntersection) { bHasInter = true; break; @@ -2389,340 +2546,340 @@ private void MeshSetup2_Intersections() Dictionary> tCombineDict_Lane1_DisabledActive = new Dictionary>(); vCount = iBLane0s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - tUV = iBLane0s_uv[i]; - tTangents = iBLane0s_tangents[i]; - xMesh = tMesh_iBLanes0[i]; + tUV = iBLane0s_uv[index]; + tTangents = iBLane0s_tangents[index]; + xMesh = tMesh_iBLanes0[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes0, "Lane0B", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterWhiteLYellowR.mat"); - if (!tCombineDict_Lane0.ContainsKey(iBLane0s_tID[i])) + if (!tCombineDict_Lane0.ContainsKey(iBLane0s_tID[index])) { - tCombineDict_Lane0.Add(iBLane0s_tID[i], new List()); + tCombineDict_Lane0.Add(iBLane0s_tID[index], new List()); } - tCombineDict_Lane0[iBLane0s_tID[i]].Add(MF); + tCombineDict_Lane0[iBLane0s_tID[index]].Add(MF); } vCount = iBLane1s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - bool bPrimaryNode = (iBLane1s_tID[i].Node1 == iBLane1s_nID[i]); - if (!bPrimaryNode && iBLane1s_tID[i].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && (iBLane1s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.TurnLane || iBLane1s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) && !iBLane1s_tID[i].bNode2B_LeftTurnLane) + bool bPrimaryNode = (iBLane1s_tID[index].Node1 == iBLane1s_nID[index]); + if (!bPrimaryNode && iBLane1s_tID[index].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && (iBLane1s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.TurnLane || iBLane1s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) && !iBLane1s_tID[index].bNode2B_LeftTurnLane) { - tUV = iBLane1s_uv[i]; - tTangents = iBLane1s_tangents[i]; - xMesh = tMesh_iBLanes1[i]; + tUV = iBLane1s_uv[index]; + tTangents = iBLane1s_tangents[index]; + xMesh = tMesh_iBLanes1[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes1, "LaneD1B", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterLaneDisabled.mat"); - if (!tCombineDict_Lane1_Disabled.ContainsKey(iBLane1s_tID[i])) + if (!tCombineDict_Lane1_Disabled.ContainsKey(iBLane1s_tID[index])) { - tCombineDict_Lane1_Disabled.Add(iBLane1s_tID[i], new List()); + tCombineDict_Lane1_Disabled.Add(iBLane1s_tID[index], new List()); } - tCombineDict_Lane1_Disabled[iBLane1s_tID[i]].Add(MF); + tCombineDict_Lane1_Disabled[iBLane1s_tID[index]].Add(MF); } - else if (bPrimaryNode && iBLane1s_tID[i].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iBLane1s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) + else if (bPrimaryNode && iBLane1s_tID[index].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iBLane1s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) { - tUV = iBLane1s_uv[i]; - tTangents = iBLane1s_tangents[i]; - xMesh = tMesh_iBLanes1[i]; + tUV = iBLane1s_uv[index]; + tTangents = iBLane1s_tangents[index]; + xMesh = tMesh_iBLanes1[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes1, "LaneDA1B", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterLaneDisabledOuter.mat"); - if (!tCombineDict_Lane1_DisabledActive.ContainsKey(iBLane1s_tID[i])) + if (!tCombineDict_Lane1_DisabledActive.ContainsKey(iBLane1s_tID[index])) { - tCombineDict_Lane1_DisabledActive.Add(iBLane1s_tID[i], new List()); + tCombineDict_Lane1_DisabledActive.Add(iBLane1s_tID[index], new List()); } - tCombineDict_Lane1_DisabledActive[iBLane1s_tID[i]].Add(MF); + tCombineDict_Lane1_DisabledActive[iBLane1s_tID[index]].Add(MF); } else { - tUV = iBLane1s_uv[i]; - tTangents = iBLane1s_tangents[i]; - xMesh = tMesh_iBLanes1[i]; + tUV = iBLane1s_uv[index]; + tTangents = iBLane1s_tangents[index]; + xMesh = tMesh_iBLanes1[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes1, "Lane1B", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterYellowLWhiteR.mat"); - if (!tCombineDict_Lane1.ContainsKey(iBLane1s_tID[i])) + if (!tCombineDict_Lane1.ContainsKey(iBLane1s_tID[index])) { - tCombineDict_Lane1.Add(iBLane1s_tID[i], new List()); + tCombineDict_Lane1.Add(iBLane1s_tID[index], new List()); } - tCombineDict_Lane1[iBLane1s_tID[i]].Add(MF); + tCombineDict_Lane1[iBLane1s_tID[index]].Add(MF); } } vCount = iBLane2s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - bool bPrimaryNode = (iBLane2s_tID[i].Node1 == iBLane2s_nID[i]); - if (!bPrimaryNode && iBLane2s_tID[i].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && (iBLane2s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.TurnLane || iBLane2s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) && !iBLane2s_tID[i].bNode2B_LeftTurnLane) + bool bPrimaryNode = (iBLane2s_tID[index].Node1 == iBLane2s_nID[index]); + if (!bPrimaryNode && iBLane2s_tID[index].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && (iBLane2s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.TurnLane || iBLane2s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) && !iBLane2s_tID[index].bNode2B_LeftTurnLane) { - tUV = iBLane2s_uv[i]; - tTangents = iBLane2s_tangents[i]; - xMesh = tMesh_iBLanes2[i]; + tUV = iBLane2s_uv[index]; + tTangents = iBLane2s_tangents[index]; + xMesh = tMesh_iBLanes2[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes2, "LaneDA2B", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterLaneDisabledOuter.mat"); - if (!tCombineDict_Lane2_DisabledActive.ContainsKey(iBLane2s_tID[i])) + if (!tCombineDict_Lane2_DisabledActive.ContainsKey(iBLane2s_tID[index])) { - tCombineDict_Lane2_DisabledActive.Add(iBLane2s_tID[i], new List()); + tCombineDict_Lane2_DisabledActive.Add(iBLane2s_tID[index], new List()); } - tCombineDict_Lane2_DisabledActive[iBLane2s_tID[i]].Add(MF); + tCombineDict_Lane2_DisabledActive[iBLane2s_tID[index]].Add(MF); } - else if (!bPrimaryNode && iBLane2s_tID[i].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iBLane2s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes && !iBLane2s_tID[i].bNode2B_RightTurnLane) + else if (!bPrimaryNode && iBLane2s_tID[index].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iBLane2s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes && !iBLane2s_tID[index].bNode2B_RightTurnLane) { - tUV = iBLane2s_uv[i]; - tTangents = iBLane2s_tangents[i]; - xMesh = tMesh_iBLanes2[i]; + tUV = iBLane2s_uv[index]; + tTangents = iBLane2s_tangents[index]; + xMesh = tMesh_iBLanes2[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes2, "LaneDA2B", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterLaneDisabledOuterR.mat"); - if (!tCombineDict_Lane2_DisabledActiveR.ContainsKey(iBLane2s_tID[i])) + if (!tCombineDict_Lane2_DisabledActiveR.ContainsKey(iBLane2s_tID[index])) { - tCombineDict_Lane2_DisabledActiveR.Add(iBLane2s_tID[i], new List()); + tCombineDict_Lane2_DisabledActiveR.Add(iBLane2s_tID[index], new List()); } - tCombineDict_Lane2_DisabledActiveR[iBLane2s_tID[i]].Add(MF); + tCombineDict_Lane2_DisabledActiveR[iBLane2s_tID[index]].Add(MF); } - else if (bPrimaryNode && iBLane2s_tID[i].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iBLane2s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) + else if (bPrimaryNode && iBLane2s_tID[index].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iBLane2s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) { - tUV = iBLane2s_uv[i]; - tTangents = iBLane2s_tangents[i]; - xMesh = tMesh_iBLanes2[i]; + tUV = iBLane2s_uv[index]; + tTangents = iBLane2s_tangents[index]; + xMesh = tMesh_iBLanes2[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes2, "LaneD2B", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterLaneDisabled.mat"); - if (!tCombineDict_Lane2_Disabled.ContainsKey(iBLane2s_tID[i])) + if (!tCombineDict_Lane2_Disabled.ContainsKey(iBLane2s_tID[index])) { - tCombineDict_Lane2_Disabled.Add(iBLane2s_tID[i], new List()); + tCombineDict_Lane2_Disabled.Add(iBLane2s_tID[index], new List()); } - tCombineDict_Lane2_Disabled[iBLane2s_tID[i]].Add(MF); + tCombineDict_Lane2_Disabled[iBLane2s_tID[index]].Add(MF); } else { - tUV = iBLane2s_uv[i]; - tTangents = iBLane2s_tangents[i]; - xMesh = tMesh_iBLanes2[i]; + tUV = iBLane2s_uv[index]; + tTangents = iBLane2s_tangents[index]; + xMesh = tMesh_iBLanes2[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes2, "Lane2B", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterWhiteR.mat"); - if (!tCombineDict_Lane2.ContainsKey(iBLane2s_tID[i])) + if (!tCombineDict_Lane2.ContainsKey(iBLane2s_tID[index])) { - tCombineDict_Lane2.Add(iBLane2s_tID[i], new List()); + tCombineDict_Lane2.Add(iBLane2s_tID[index], new List()); } - tCombineDict_Lane2[iBLane2s_tID[i]].Add(MF); + tCombineDict_Lane2[iBLane2s_tID[index]].Add(MF); } } vCount = iBLane3s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - bool bPrimaryNode = (iBLane3s_tID[i].Node1 == iBLane3s_nID[i]); - if (!bPrimaryNode && iBLane3s_tID[i].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iBLane3s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes && !iBLane3s_tID[i].bNode2B_RightTurnLane) + bool bPrimaryNode = (iBLane3s_tID[index].Node1 == iBLane3s_nID[index]); + if (!bPrimaryNode && iBLane3s_tID[index].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iBLane3s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes && !iBLane3s_tID[index].bNode2B_RightTurnLane) { - tUV = iBLane3s_uv[i]; - tTangents = iBLane3s_tangents[i]; - xMesh = tMesh_iBLanes3[i]; + tUV = iBLane3s_uv[index]; + tTangents = iBLane3s_tangents[index]; + xMesh = tMesh_iBLanes3[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes3, "LaneD3B", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterLaneDisabled.mat"); - if (!tCombineDict_Lane3_Disabled.ContainsKey(iBLane3s_tID[i])) + if (!tCombineDict_Lane3_Disabled.ContainsKey(iBLane3s_tID[index])) { - tCombineDict_Lane3_Disabled.Add(iBLane3s_tID[i], new List()); + tCombineDict_Lane3_Disabled.Add(iBLane3s_tID[index], new List()); } - tCombineDict_Lane3_Disabled[iBLane3s_tID[i]].Add(MF); + tCombineDict_Lane3_Disabled[iBLane3s_tID[index]].Add(MF); } else { - tUV = iBLane3s_uv[i]; - tTangents = iBLane3s_tangents[i]; - xMesh = tMesh_iBLanes3[i]; + tUV = iBLane3s_uv[index]; + tTangents = iBLane3s_tangents[index]; + xMesh = tMesh_iBLanes3[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes3, "Lane3B", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterWhiteR.mat"); - if (!tCombineDict_Lane3.ContainsKey(iBLane3s_tID[i])) + if (!tCombineDict_Lane3.ContainsKey(iBLane3s_tID[index])) { - tCombineDict_Lane3.Add(iBLane3s_tID[i], new List()); + tCombineDict_Lane3.Add(iBLane3s_tID[index], new List()); } - tCombineDict_Lane3[iBLane3s_tID[i]].Add(MF); + tCombineDict_Lane3[iBLane3s_tID[index]].Add(MF); } } //Front lanes: vCount = iFLane0s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - tUV = iFLane0s_uv[i]; - tTangents = iFLane0s_tangents[i]; - xMesh = tMesh_iFLanes0[i]; + tUV = iFLane0s_uv[index]; + tTangents = iFLane0s_tangents[index]; + xMesh = tMesh_iFLanes0[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes0, "Lane0F", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterWhiteLYellowR.mat"); - if (!tCombineDict_Lane0.ContainsKey(iFLane0s_tID[i])) + if (!tCombineDict_Lane0.ContainsKey(iFLane0s_tID[index])) { - tCombineDict_Lane0.Add(iFLane0s_tID[i], new List()); + tCombineDict_Lane0.Add(iFLane0s_tID[index], new List()); } - tCombineDict_Lane0[iFLane0s_tID[i]].Add(MF); + tCombineDict_Lane0[iFLane0s_tID[index]].Add(MF); } vCount = iFLane1s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - bool bPrimaryNode = (iFLane1s_tID[i].Node1 == iFLane1s_nID[i]); - if (!bPrimaryNode && iFLane1s_tID[i].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && (iFLane1s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes || iFLane1s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.TurnLane) && !iFLane1s_tID[i].bNode2F_LeftTurnLane) + bool bPrimaryNode = (iFLane1s_tID[index].Node1 == iFLane1s_nID[index]); + if (!bPrimaryNode && iFLane1s_tID[index].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && (iFLane1s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes || iFLane1s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.TurnLane) && !iFLane1s_tID[index].bNode2F_LeftTurnLane) { - tUV = iFLane1s_uv[i]; - tTangents = iFLane1s_tangents[i]; - xMesh = tMesh_iFLanes1[i]; + tUV = iFLane1s_uv[index]; + tTangents = iFLane1s_tangents[index]; + xMesh = tMesh_iFLanes1[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes1, "LaneD1F", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterLaneDisabled.mat"); - if (!tCombineDict_Lane1_Disabled.ContainsKey(iFLane1s_tID[i])) + if (!tCombineDict_Lane1_Disabled.ContainsKey(iFLane1s_tID[index])) { - tCombineDict_Lane1_Disabled.Add(iFLane1s_tID[i], new List()); + tCombineDict_Lane1_Disabled.Add(iFLane1s_tID[index], new List()); } - tCombineDict_Lane1_Disabled[iFLane1s_tID[i]].Add(MF); + tCombineDict_Lane1_Disabled[iFLane1s_tID[index]].Add(MF); } - else if (bPrimaryNode && iFLane1s_tID[i].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iFLane1s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) + else if (bPrimaryNode && iFLane1s_tID[index].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iFLane1s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) { - tUV = iFLane1s_uv[i]; - tTangents = iFLane1s_tangents[i]; - xMesh = tMesh_iFLanes1[i]; + tUV = iFLane1s_uv[index]; + tTangents = iFLane1s_tangents[index]; + xMesh = tMesh_iFLanes1[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes1, "LaneDAR1F", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterLaneDisabledOuterR.mat"); - if (!tCombineDict_Lane1_DisabledActive.ContainsKey(iFLane1s_tID[i])) + if (!tCombineDict_Lane1_DisabledActive.ContainsKey(iFLane1s_tID[index])) { - tCombineDict_Lane1_DisabledActive.Add(iFLane1s_tID[i], new List()); + tCombineDict_Lane1_DisabledActive.Add(iFLane1s_tID[index], new List()); } - tCombineDict_Lane1_DisabledActive[iFLane1s_tID[i]].Add(MF); + tCombineDict_Lane1_DisabledActive[iFLane1s_tID[index]].Add(MF); } else { - tUV = iFLane1s_uv[i]; - tTangents = iFLane1s_tangents[i]; - xMesh = tMesh_iFLanes1[i]; + tUV = iFLane1s_uv[index]; + tTangents = iFLane1s_tangents[index]; + xMesh = tMesh_iFLanes1[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes1, "Lane1F", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterYellowLWhiteR.mat"); - if (!tCombineDict_Lane1.ContainsKey(iFLane1s_tID[i])) + if (!tCombineDict_Lane1.ContainsKey(iFLane1s_tID[index])) { - tCombineDict_Lane1.Add(iFLane1s_tID[i], new List()); + tCombineDict_Lane1.Add(iFLane1s_tID[index], new List()); } - tCombineDict_Lane1[iFLane1s_tID[i]].Add(MF); + tCombineDict_Lane1[iFLane1s_tID[index]].Add(MF); } } vCount = iFLane2s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - bool bPrimaryNode = (iFLane2s_tID[i].Node1 == iFLane2s_nID[i]); - if (!bPrimaryNode && iFLane2s_tID[i].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && (iFLane2s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes || iFLane2s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.TurnLane) && !iFLane2s_tID[i].bNode2F_LeftTurnLane) + bool bPrimaryNode = (iFLane2s_tID[index].Node1 == iFLane2s_nID[index]); + if (!bPrimaryNode && iFLane2s_tID[index].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && (iFLane2s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes || iFLane2s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.TurnLane) && !iFLane2s_tID[index].bNode2F_LeftTurnLane) { - tUV = iFLane2s_uv[i]; - tTangents = iFLane2s_tangents[i]; - xMesh = tMesh_iFLanes2[i]; + tUV = iFLane2s_uv[index]; + tTangents = iFLane2s_tangents[index]; + xMesh = tMesh_iFLanes2[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes2, "LaneDA2F", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterLaneDisabledOuter.mat"); - if (!tCombineDict_Lane2_DisabledActive.ContainsKey(iFLane2s_tID[i])) + if (!tCombineDict_Lane2_DisabledActive.ContainsKey(iFLane2s_tID[index])) { - tCombineDict_Lane2_DisabledActive.Add(iFLane2s_tID[i], new List()); + tCombineDict_Lane2_DisabledActive.Add(iFLane2s_tID[index], new List()); } - tCombineDict_Lane2_DisabledActive[iFLane2s_tID[i]].Add(MF); + tCombineDict_Lane2_DisabledActive[iFLane2s_tID[index]].Add(MF); } - else if (!bPrimaryNode && iFLane2s_tID[i].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iFLane2s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes && !iFLane2s_tID[i].bNode2F_RightTurnLane) + else if (!bPrimaryNode && iFLane2s_tID[index].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iFLane2s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes && !iFLane2s_tID[index].bNode2F_RightTurnLane) { - tUV = iFLane2s_uv[i]; - tTangents = iFLane2s_tangents[i]; - xMesh = tMesh_iFLanes2[i]; + tUV = iFLane2s_uv[index]; + tTangents = iFLane2s_tangents[index]; + xMesh = tMesh_iFLanes2[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes2, "LaneDAR2F", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterLaneDisabledOuterR.mat"); - if (!tCombineDict_Lane2_DisabledActiveR.ContainsKey(iFLane2s_tID[i])) + if (!tCombineDict_Lane2_DisabledActiveR.ContainsKey(iFLane2s_tID[index])) { - tCombineDict_Lane2_DisabledActiveR.Add(iFLane2s_tID[i], new List()); + tCombineDict_Lane2_DisabledActiveR.Add(iFLane2s_tID[index], new List()); } - tCombineDict_Lane2_DisabledActiveR[iFLane2s_tID[i]].Add(MF); + tCombineDict_Lane2_DisabledActiveR[iFLane2s_tID[index]].Add(MF); } - else if (bPrimaryNode && iFLane2s_tID[i].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iFLane2s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) + else if (bPrimaryNode && iFLane2s_tID[index].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iFLane2s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) { - tUV = iFLane2s_uv[i]; - tTangents = iFLane2s_tangents[i]; - xMesh = tMesh_iFLanes2[i]; + tUV = iFLane2s_uv[index]; + tTangents = iFLane2s_tangents[index]; + xMesh = tMesh_iFLanes2[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes2, "LaneD2F", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterLaneDisabled.mat"); - if (!tCombineDict_Lane2_Disabled.ContainsKey(iFLane2s_tID[i])) + if (!tCombineDict_Lane2_Disabled.ContainsKey(iFLane2s_tID[index])) { - tCombineDict_Lane2_Disabled.Add(iFLane2s_tID[i], new List()); + tCombineDict_Lane2_Disabled.Add(iFLane2s_tID[index], new List()); } - tCombineDict_Lane2_Disabled[iFLane2s_tID[i]].Add(MF); + tCombineDict_Lane2_Disabled[iFLane2s_tID[index]].Add(MF); } else { - tUV = iFLane2s_uv[i]; - tTangents = iFLane2s_tangents[i]; - xMesh = tMesh_iFLanes2[i]; + tUV = iFLane2s_uv[index]; + tTangents = iFLane2s_tangents[index]; + xMesh = tMesh_iFLanes2[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes2, "Lane2F", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterWhiteR.mat"); - if (!tCombineDict_Lane2.ContainsKey(iFLane2s_tID[i])) + if (!tCombineDict_Lane2.ContainsKey(iFLane2s_tID[index])) { - tCombineDict_Lane2.Add(iFLane2s_tID[i], new List()); + tCombineDict_Lane2.Add(iFLane2s_tID[index], new List()); } - tCombineDict_Lane2[iFLane2s_tID[i]].Add(MF); + tCombineDict_Lane2[iFLane2s_tID[index]].Add(MF); } } vCount = iFLane3s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - bool bPrimaryNode = (iFLane3s_tID[i].Node1 == iFLane3s_nID[i]); - if (!bPrimaryNode && iFLane3s_tID[i].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iFLane3s_tID[i].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes && !iFLane3s_tID[i].bNode2F_RightTurnLane) + bool bPrimaryNode = (iFLane3s_tID[index].Node1 == iFLane3s_nID[index]); + if (!bPrimaryNode && iFLane3s_tID[index].iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay && iFLane3s_tID[index].rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes && !iFLane3s_tID[index].bNode2F_RightTurnLane) { - tUV = iFLane3s_uv[i]; - tTangents = iFLane3s_tangents[i]; - xMesh = tMesh_iFLanes3[i]; + tUV = iFLane3s_uv[index]; + tTangents = iFLane3s_tangents[index]; + xMesh = tMesh_iFLanes3[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes3, "LaneD3F", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterWhiteR.mat"); - if (!tCombineDict_Lane3_Disabled.ContainsKey(iFLane3s_tID[i])) + if (!tCombineDict_Lane3_Disabled.ContainsKey(iFLane3s_tID[index])) { - tCombineDict_Lane3_Disabled.Add(iFLane3s_tID[i], new List()); + tCombineDict_Lane3_Disabled.Add(iFLane3s_tID[index], new List()); } - tCombineDict_Lane3_Disabled[iFLane3s_tID[i]].Add(MF); + tCombineDict_Lane3_Disabled[iFLane3s_tID[index]].Add(MF); } else { - tUV = iFLane3s_uv[i]; - tTangents = iFLane3s_tangents[i]; - xMesh = tMesh_iFLanes3[i]; + tUV = iFLane3s_uv[index]; + tTangents = iFLane3s_tangents[index]; + xMesh = tMesh_iFLanes3[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiLanes3, "Lane3F", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Markers/GSDInterWhiteR.mat"); - if (!tCombineDict_Lane3.ContainsKey(iFLane3s_tID[i])) + if (!tCombineDict_Lane3.ContainsKey(iFLane3s_tID[index])) { - tCombineDict_Lane3.Add(iFLane3s_tID[i], new List()); + tCombineDict_Lane3.Add(iFLane3s_tID[index], new List()); } - tCombineDict_Lane3[iFLane3s_tID[i]].Add(MF); + tCombineDict_Lane3[iFLane3s_tID[index]].Add(MF); } } //Main plates: vCount = iBMainPlates.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - tUV = iBMainPlates_uv[i]; - tTangents = iBMainPlates_tangents[i]; - xMesh = tMesh_iBMainPlates[i]; + tUV = iBMainPlates_uv[index]; + tTangents = iBMainPlates_tangents[index]; + xMesh = tMesh_iBMainPlates[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiMainPlates, "MainPlateB", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/GSDRoad1.mat", false); - if (!tCombineDict_MainPlate.ContainsKey(iBMainPlates_tID[i])) + if (!tCombineDict_MainPlate.ContainsKey(iBMainPlates_tID[index])) { - tCombineDict_MainPlate.Add(iBMainPlates_tID[i], new List()); + tCombineDict_MainPlate.Add(iBMainPlates_tID[index], new List()); } - tCombineDict_MainPlate[iBMainPlates_tID[i]].Add(MF); + tCombineDict_MainPlate[iBMainPlates_tID[index]].Add(MF); Mesh fMesh = new Mesh(); - fMesh.vertices = iBMainPlates[i]; - fMesh.triangles = iBMainPlates_tris[i]; - fMesh.normals = iBMainPlates_normals[i]; - tUV = iBMainPlates_uv2[i]; - tTangents = iBMainPlates_tangents2[i]; + fMesh.vertices = iBMainPlates[index]; + fMesh.triangles = iBMainPlates_tris[index]; + fMesh.normals = iBMainPlates_normals[index]; + tUV = iBMainPlates_uv2[index]; + tTangents = iBMainPlates_tangents2[index]; MF = MeshSetup2_Intersection_Helper(ref fMesh, ref tUV, ref tTangents, ref tRoad.MeshiMainPlates, "MainPlateBM", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/GSDInterMainPlate1.mat"); - if (!tCombineDict_MainPlateM.ContainsKey(iBMainPlates_tID[i])) + if (!tCombineDict_MainPlateM.ContainsKey(iBMainPlates_tID[index])) { - tCombineDict_MainPlateM.Add(iBMainPlates_tID[i], new List()); + tCombineDict_MainPlateM.Add(iBMainPlates_tID[index], new List()); } - tCombineDict_MainPlateM[iBMainPlates_tID[i]].Add(MF); + tCombineDict_MainPlateM[iBMainPlates_tID[index]].Add(MF); } vCount = iFMainPlates.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - tUV = iFMainPlates_uv[i]; - tTangents = iFMainPlates_tangents[i]; - xMesh = tMesh_iFMainPlates[i]; + tUV = iFMainPlates_uv[index]; + tTangents = iFMainPlates_tangents[index]; + xMesh = tMesh_iFMainPlates[index]; MF = MeshSetup2_Intersection_Helper(ref xMesh, ref tUV, ref tTangents, ref tRoad.MeshiMainPlates, "MainPlateFM", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/GSDRoad1.mat", false); - if (!tCombineDict_MainPlate.ContainsKey(iFMainPlates_tID[i])) + if (!tCombineDict_MainPlate.ContainsKey(iFMainPlates_tID[index])) { - tCombineDict_MainPlate.Add(iFMainPlates_tID[i], new List()); + tCombineDict_MainPlate.Add(iFMainPlates_tID[index], new List()); } - tCombineDict_MainPlate[iFMainPlates_tID[i]].Add(MF); + tCombineDict_MainPlate[iFMainPlates_tID[index]].Add(MF); Mesh tMesh = new Mesh(); - tMesh.vertices = iFMainPlates[i]; - tMesh.triangles = iFMainPlates_tris[i]; - tMesh.normals = iFMainPlates_normals[i]; - tUV = iFMainPlates_uv2[i]; - tTangents = iFMainPlates_tangents2[i]; + tMesh.vertices = iFMainPlates[index]; + tMesh.triangles = iFMainPlates_tris[index]; + tMesh.normals = iFMainPlates_normals[index]; + tUV = iFMainPlates_uv2[index]; + tTangents = iFMainPlates_tangents2[index]; MF = MeshSetup2_Intersection_Helper(ref tMesh, ref tUV, ref tTangents, ref tRoad.MeshiMainPlates, "MainPlateFM", GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/GSDInterMainPlate1.mat"); - if (!tCombineDict_MainPlateM.ContainsKey(iFMainPlates_tID[i])) + if (!tCombineDict_MainPlateM.ContainsKey(iFMainPlates_tID[index])) { - tCombineDict_MainPlateM.Add(iFMainPlates_tID[i], new List()); + tCombineDict_MainPlateM.Add(iFMainPlates_tID[index], new List()); } - tCombineDict_MainPlateM[iFMainPlates_tID[i]].Add(MF); + tCombineDict_MainPlateM[iFMainPlates_tID[index]].Add(MF); } vCount = tRoad.GSDSpline.GetNodeCount(); GSDSplineN tNode = null; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - tNode = tRoad.GSDSpline.mNodes[i]; + tNode = tRoad.GSDSpline.mNodes[index]; if (tNode.bIsIntersection && tNode.GSDRI != null && tNode.GSDRI.Node1 == tNode) { //Create center plate @@ -2862,73 +3019,97 @@ private void MeshSetup2_Intersections() foreach (KeyValuePair> KVP in tCombineDict_Lane0) { if (!UniqueGSDRI.Contains(KVP.Key)) - { UniqueGSDRI.Add(KVP.Key); } + { + UniqueGSDRI.Add(KVP.Key); + } MeshSetup2_CombineIntersections(KVP, KVP.Key.transform.name + "-" + "Lane0"); } foreach (KeyValuePair> KVP in tCombineDict_Lane1) { if (!UniqueGSDRI.Contains(KVP.Key)) - { UniqueGSDRI.Add(KVP.Key); } + { + UniqueGSDRI.Add(KVP.Key); + } MeshSetup2_CombineIntersections(KVP, KVP.Key.transform.name + "-" + "Lane1"); } foreach (KeyValuePair> KVP in tCombineDict_Lane2) { if (!UniqueGSDRI.Contains(KVP.Key)) - { UniqueGSDRI.Add(KVP.Key); } + { + UniqueGSDRI.Add(KVP.Key); + } MeshSetup2_CombineIntersections(KVP, KVP.Key.transform.name + "-" + "Lane2"); } foreach (KeyValuePair> KVP in tCombineDict_Lane3) { if (!UniqueGSDRI.Contains(KVP.Key)) - { UniqueGSDRI.Add(KVP.Key); } + { + UniqueGSDRI.Add(KVP.Key); + } MeshSetup2_CombineIntersections(KVP, KVP.Key.transform.name + "-" + "Lane3"); } foreach (KeyValuePair> KVP in tCombineDict_MainPlate) { if (!UniqueGSDRI.Contains(KVP.Key)) - { UniqueGSDRI.Add(KVP.Key); } + { + UniqueGSDRI.Add(KVP.Key); + } MeshSetup2_CombineIntersections(KVP, KVP.Key.transform.name + "-" + "TiledExt", true); } foreach (KeyValuePair> KVP in tCombineDict_MainPlateM) { if (!UniqueGSDRI.Contains(KVP.Key)) - { UniqueGSDRI.Add(KVP.Key); } + { + UniqueGSDRI.Add(KVP.Key); + } MeshSetup2_CombineIntersections(KVP, KVP.Key.transform.name + "-" + "StretchExt"); } foreach (KeyValuePair> KVP in tCombineDict_Lane1_Disabled) { if (!UniqueGSDRI.Contains(KVP.Key)) - { UniqueGSDRI.Add(KVP.Key); } + { + UniqueGSDRI.Add(KVP.Key); + } MeshSetup2_CombineIntersections(KVP, KVP.Key.transform.name + "-" + "LaneD1"); } foreach (KeyValuePair> KVP in tCombineDict_Lane3_Disabled) { if (!UniqueGSDRI.Contains(KVP.Key)) - { UniqueGSDRI.Add(KVP.Key); } + { + UniqueGSDRI.Add(KVP.Key); + } MeshSetup2_CombineIntersections(KVP, KVP.Key.transform.name + "-" + "LaneD3"); } foreach (KeyValuePair> KVP in tCombineDict_Lane2_DisabledActive) { if (!UniqueGSDRI.Contains(KVP.Key)) - { UniqueGSDRI.Add(KVP.Key); } + { + UniqueGSDRI.Add(KVP.Key); + } MeshSetup2_CombineIntersections(KVP, KVP.Key.transform.name + "-" + "LaneDA2"); } foreach (KeyValuePair> KVP in tCombineDict_Lane2_DisabledActiveR) { if (!UniqueGSDRI.Contains(KVP.Key)) - { UniqueGSDRI.Add(KVP.Key); } + { + UniqueGSDRI.Add(KVP.Key); + } MeshSetup2_CombineIntersections(KVP, KVP.Key.transform.name + "-" + "LaneDAR2"); } foreach (KeyValuePair> KVP in tCombineDict_Lane2_Disabled) { if (!UniqueGSDRI.Contains(KVP.Key)) - { UniqueGSDRI.Add(KVP.Key); } + { + UniqueGSDRI.Add(KVP.Key); + } MeshSetup2_CombineIntersections(KVP, KVP.Key.transform.name + "-" + "LaneD2"); } foreach (KeyValuePair> KVP in tCombineDict_Lane1_DisabledActive) { if (!UniqueGSDRI.Contains(KVP.Key)) - { UniqueGSDRI.Add(KVP.Key); } + { + UniqueGSDRI.Add(KVP.Key); + } MeshSetup2_CombineIntersections(KVP, KVP.Key.transform.name + "-" + "LaneDA1"); } @@ -2939,54 +3120,59 @@ private void MeshSetup2_Intersections() } + private void MeshSetup2_CombineIntersections(KeyValuePair> KVP, string tName, bool bMainPlates = false) { int vCount = KVP.Value.Count; if (vCount < 1) - { return; } + { + return; + } tName = tRoad.name + "-" + tName; GameObject tCenter = null; int cCount = KVP.Key.transform.childCount; List GOToDelete = new List(); - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - if (KVP.Key.transform.GetChild(i).name.ToLower() == tName.ToLower()) + if (KVP.Key.transform.GetChild(index).name.ToLower() == tName.ToLower()) { - GOToDelete.Add(KVP.Key.transform.GetChild(i).gameObject); + GOToDelete.Add(KVP.Key.transform.GetChild(index).gameObject); } - if (bMainPlates && KVP.Key.transform.GetChild(i).name.ToLower() == "tcenter") + if (bMainPlates && KVP.Key.transform.GetChild(index).name.ToLower() == "tcenter") { - tCenter = KVP.Key.transform.GetChild(i).gameObject; + tCenter = KVP.Key.transform.GetChild(index).gameObject; } } - for (int i = GOToDelete.Count - 1; i >= 0; i--) + for (int index = GOToDelete.Count - 1; index >= 0; index--) { - Object.DestroyImmediate(GOToDelete[i]); + Object.DestroyImmediate(GOToDelete[index]); } int CombineCount = vCount; if (tCenter != null) - { CombineCount += 1; } + { + CombineCount += 1; + } CombineInstance[] combine = new CombineInstance[CombineCount]; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - combine[i].mesh = KVP.Value[i].sharedMesh; - combine[i].transform = KVP.Value[i].transform.localToWorldMatrix; + combine[index].mesh = KVP.Value[index].sharedMesh; + combine[index].transform = KVP.Value[index].transform.localToWorldMatrix; } int SpecialVertCount = 0; if (tCenter != null) { - for (int i = 0; i < (CombineCount - 1); i++) + for (int index = 0; index < (CombineCount - 1); index++) { - SpecialVertCount += combine[i].mesh.vertexCount; + SpecialVertCount += combine[index].mesh.vertexCount; } MeshFilter tMF = tCenter.GetComponent(); Vector3[] xVerts = tMF.sharedMesh.vertices; float xHeight = combine[0].mesh.vertices[combine[0].mesh.vertexCount - 1].y; - for (int i = 0; i < xVerts.Length; i++) + for (int index = 0; index < xVerts.Length; index++) { - xVerts[i].y = xHeight; + xVerts[index].y = xHeight; } tMF.sharedMesh.vertices = xVerts; combine[CombineCount - 1].mesh = tMF.sharedMesh; @@ -3004,11 +3190,11 @@ private void MeshSetup2_CombineIntersections(KeyValuePair(); MR.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; GSD.Roads.GSDRoadUtilityEditor.SetRoadMaterial(tMat, MR); @@ -3082,6 +3273,7 @@ private MeshFilter MeshSetup2_Intersection_Helper(ref Mesh xMesh, ref Vector2[] } #endregion + private Mesh MeshSetup2_Helper(ref Mesh xMesh, Vector2[] uv, Vector4[] tangents, ref GameObject tObj, bool bMarker, bool bShoulder = false, bool bBridge = false) { xMesh.uv = uv; @@ -3228,7 +3420,9 @@ private Mesh MeshSetup2_Helper(ref Mesh xMesh, Vector2[] uv, Vector4[] tangents, } if (MC) - { MC.sharedMaterial = tRoad.RoadPhysicMaterial; } + { + MC.sharedMaterial = tRoad.RoadPhysicMaterial; + } } } @@ -3244,6 +3438,7 @@ private Mesh MeshSetup2_Helper(ref Mesh xMesh, Vector2[] uv, Vector4[] tangents, return xMesh; } + private bool MeshSetup2_Helper_RoadCuts(int i, ref Mesh zMesh, Vector2[] uv, Vector4[] tangents, ref GameObject MasterObj, bool bIsMarkers, out GameObject CreatedObj) { string tName = "RoadCut" + i.ToString(); @@ -3379,7 +3574,9 @@ private bool MeshSetup2_Helper_RoadCuts(int i, ref Mesh zMesh, Vector2[] uv, Vec CreatedObj.transform.parent = MasterObj.transform; if (!bIsMarkers && MC != null) - { MC.sharedMaterial = tRoad.RoadPhysicMaterial; } + { + MC.sharedMaterial = tRoad.RoadPhysicMaterial; + } if (tRoad.opt_bIsLightmapped) { UnityEditor.GameObjectUtility.SetStaticEditorFlags(CreatedObj, UnityEditor.StaticEditorFlags.LightmapStatic); @@ -3392,6 +3589,7 @@ private bool MeshSetup2_Helper_RoadCuts(int i, ref Mesh zMesh, Vector2[] uv, Vec return bHasMats; } + private bool MeshSetup2_Helper_CutsShoulder(int i, ref Mesh zMesh, Vector2[] uv, Vector4[] tangents, ref GameObject MasterObj, bool bIsLeft, bool bIsMarkers, out GameObject CreatedObj) { @@ -3561,7 +3759,9 @@ private bool MeshSetup2_Helper_CutsShoulder(int i, ref Mesh zMesh, Vector2[] uv, } if (!bIsMarkers && MC != null) - { MC.sharedMaterial = tRoad.ShoulderPhysicMaterial; } + { + MC.sharedMaterial = tRoad.ShoulderPhysicMaterial; + } CreatedObj.transform.parent = MasterObj.transform; if (tRoad.opt_bIsLightmapped) { @@ -3583,7 +3783,9 @@ private bool MeshSetup2_Helper_CutsShoulder(int i, ref Mesh zMesh, Vector2[] uv, private static void SaveMesh(SaveMeshTypeEnum SaveType, Mesh tMesh, GSDRoad tRoad, string tName) { if (!tRoad.GSDRS.opt_bSaveMeshes) - { return; } + { + return; + } //string tSceneName = System.IO.Path.GetFileName(UnityEditor.EditorApplication.currentScene).ToLower().Replace(".unity",""); string tSceneName = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name; @@ -3670,7 +3872,9 @@ public static void TerrainHistory_Save(List tObj, GSDRoa { string tPath = CheckNonAssetDirTH() + GetRoadTHFilename(ref tRoad); if (string.IsNullOrEmpty(tPath) || tPath.Length < 2) - { return; } + { + return; + } Stream stream = File.Open(tPath, FileMode.Create); BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Binder = new VersionDeserializationBinder(); @@ -3694,9 +3898,13 @@ public static List TerrainHistory_Load(GSDRoad tRoad) { string tPath = CheckNonAssetDirTH() + GetRoadTHFilename(ref tRoad); if (string.IsNullOrEmpty(tPath) || tPath.Length < 2) - { return null; } + { + return null; + } if (!File.Exists(tPath)) - { return null; } + { + return null; + } List result; Stream stream = File.Open(tPath, FileMode.Open); BinaryFormatter bFormatter = new BinaryFormatter(); @@ -3807,9 +4015,9 @@ private static Terrain GetTerrain_Do(ref Vector3 tVect) if (tColliders != null) { int tCollidersLength = tColliders.Length; - for (int i = 0; i < tCollidersLength; i++) + for (int index = 0; index < tCollidersLength; index++) { - Terrain tTerrain = tColliders[i].transform.GetComponent(); + Terrain tTerrain = tColliders[index].transform.GetComponent(); if (tTerrain) { tColliders = null; @@ -3825,9 +4033,9 @@ private static Terrain GetTerrain_Do(ref Vector3 tVect) if (tHits != null) { tHitsLength = tHits.Length; - for (int i = 0; i < tHitsLength; i++) + for (int index = 0; index < tHitsLength; index++) { - Terrain tTerrain = tHits[i].collider.transform.GetComponent(); + Terrain tTerrain = tHits[index].collider.transform.GetComponent(); if (tTerrain) { tHits = null; @@ -3886,20 +4094,24 @@ private static void ConstructRoad_DoStoreTerrainHistory(ref GSDRoad tRoad) } int hCount = tRoad.TerrainHistory.Count; - for (int i = hCount - 1; i >= 0; i--) + for (int index = hCount - 1; index >= 0; index--) { - if (tRoad.TerrainHistory[i].bDestroyMe) + if (tRoad.TerrainHistory[index].bDestroyMe) { - GSDTerrainHistoryMaker THf = tRoad.TerrainHistory[i]; - tRoad.TerrainHistory.RemoveAt(i); + GSDTerrainHistoryMaker THf = tRoad.TerrainHistory[index]; + tRoad.TerrainHistory.RemoveAt(index); if (THf != null) - { THf = null; } + { + THf = null; + } } } } if (tRoad.TerrainHistory == null) - { tRoad.TerrainHistory = new List(); } + { + tRoad.TerrainHistory = new List(); + } foreach (GSDTerraforming.TempTerrainData TTD in tRoad.EditorTTDList) { GSDTerrainHistoryMaker TH = null; @@ -3914,15 +4126,19 @@ private static void ConstructRoad_DoStoreTerrainHistory(ref GSDRoad tRoad) } if (tRoad.TerrainHistory == null) - { tRoad.TerrainHistory = new List(); } + { + tRoad.TerrainHistory = new List(); + } if (TID == null) - { continue; } + { + continue; + } int THCount = tRoad.TerrainHistory.Count; bool bContainsTID = false; - for (int i = 0; i < THCount; i++) + for (int index = 0; index < THCount; index++) { - if (tRoad.TerrainHistory[i].TID == TID.GSDID) + if (tRoad.TerrainHistory[index].TID == TID.GSDID) { bContainsTID = true; break; @@ -3937,16 +4153,18 @@ private static void ConstructRoad_DoStoreTerrainHistory(ref GSDRoad tRoad) } TH = null; - for (int i = 0; i < THCount; i++) + for (int index = 0; index < THCount; index++) { - if (tRoad.TerrainHistory[i].TID == TID.GSDID) + if (tRoad.TerrainHistory[index].TID == TID.GSDID) { - TH = tRoad.TerrainHistory[i]; + TH = tRoad.TerrainHistory[index]; break; } } if (TH == null) - { continue; } + { + continue; + } //Heights: if (tRoad.opt_HeightModEnabled) @@ -3987,15 +4205,17 @@ private static void ConstructRoad_DoStoreTerrainHistory(ref GSDRoad tRoad) int RunningIndex = 0; int cLength = 0; - for (int i = 0; i < TTD.DetailLayersCount; i++) + for (int index = 0; index < TTD.DetailLayersCount; index++) { - cLength = TTD.DetailsI[i]; + cLength = TTD.DetailsI[index]; if (cLength < 1) - { continue; } - System.Array.Copy(TTD.DetailsX[i].ToArray(), 0, TH.DetailsX, RunningIndex, cLength); - System.Array.Copy(TTD.DetailsY[i].ToArray(), 0, TH.DetailsY, RunningIndex, cLength); - System.Array.Copy(TTD.OldDetailsValue[i].ToArray(), 0, TH.DetailsOldValue, RunningIndex, cLength); - RunningIndex += TTD.DetailsI[i]; + { + continue; + } + System.Array.Copy(TTD.DetailsX[index].ToArray(), 0, TH.DetailsX, RunningIndex, cLength); + System.Array.Copy(TTD.DetailsY[index].ToArray(), 0, TH.DetailsY, RunningIndex, cLength); + System.Array.Copy(TTD.OldDetailsValue[index].ToArray(), 0, TH.DetailsOldValue, RunningIndex, cLength); + RunningIndex += TTD.DetailsI[index]; } // TH.DetailsX = TTD.DetailsX; @@ -4267,9 +4487,9 @@ public bool Contains2D(ref Vector2 p) inside = false; oldPoint = new Vector2(poly2D[3 - 1].x, poly2D[3 - 1].y); - for (int i = 0; i < 3; i++) + for (int index = 0; index < 3; index++) { - newPoint = new Vector2(poly2D[i].x, poly2D[i].y); + newPoint = new Vector2(poly2D[index].x, poly2D[index].y); if (newPoint.x > oldPoint.x) { x1 = oldPoint; @@ -4629,14 +4849,16 @@ public bool Contains(ref Vector2 p) { // if(Vector2.Distance(p,P1) > MaxDistance){ return false; } if (Vector2.SqrMagnitude(p - P1) > MaxDistanceSQ) - { return false; } + { + return false; + } // if(poly.Length != 4){ return false; } inside = false; oldPoint = new Vector2(poly[4 - 1].x, poly[4 - 1].y); - for (int i = 0; i < 4; i++) + for (int index = 0; index < 4; index++) { - newPoint = new Vector2(poly[i].x, poly[i].y); + newPoint = new Vector2(poly[index].x, poly[index].y); if (newPoint.x > oldPoint.x) { x1 = oldPoint; @@ -4721,9 +4943,9 @@ public static GSD.Threaded.GSDRoadCreationT.RoadTerrainInfo[] GetRoadTerrainInfo } GSD.Threaded.GSDRoadCreationT.RoadTerrainInfo[] fInfos = new GSD.Threaded.GSDRoadCreationT.RoadTerrainInfo[tInfos.Count]; int fInfosLength = fInfos.Length; - for (int i = 0; i < fInfosLength; i++) + for (int index = 0; index < fInfosLength; index++) { - fInfos[i] = tInfos[i]; + fInfos[index] = tInfos[index]; } tInfos = null; return fInfos; @@ -4793,17 +5015,17 @@ private static void SaveNodeObjects_DO(ref Splination.SplinatedMeshMaker[] tSpli builder.Append(WO.ConvertToString()); builder.Append(FileSepString); - for (int i = 0; i < sCount; i++) + for (int index = 0; index < sCount; index++) { - SMM = tSplinatedObjects[i]; + SMM = tSplinatedObjects[index]; builder.Append(SMM.ConvertToString()); builder.Append(FileSepString); } EdgeObjects.EdgeObjectMaker EOM = null; - for (int i = 0; i < eCount; i++) + for (int index = 0; index < eCount; index++) { - EOM = tEdgeObjects[i]; + EOM = tEdgeObjects[index]; builder.Append(EOM.ConvertToString()); builder.Append(FileSepString); } @@ -4846,10 +5068,10 @@ public static void LoadNodeObjects(string tFileName, GSDSplineN tNode, bool bIsD EdgeObjects.EdgeObjectMaker.EdgeObjectLibraryMaker ELM = null; int tSplitCount = tSplit.Length; - for (int i = 0; i < tSplitCount; i++) + for (int index = 0; index < tSplitCount; index++) { SLM = null; - SLM = Splination.SplinatedMeshMaker.SLMFromData(tSplit[i]); + SLM = Splination.SplinatedMeshMaker.SLMFromData(tSplit[index]); if (SLM != null) { SMM = tNode.AddSplinatedObject(); @@ -4866,7 +5088,7 @@ public static void LoadNodeObjects(string tFileName, GSDSplineN tNode, bool bIsD } ELM = null; - ELM = EdgeObjects.EdgeObjectMaker.ELMFromData(tSplit[i]); + ELM = EdgeObjects.EdgeObjectMaker.ELMFromData(tSplit[index]); if (ELM != null) { EOM = tNode.AddEdgeObject(); @@ -5195,22 +5417,24 @@ public static void CleanupIntersectionObjects(GameObject MasterGameObj) { int mCount = MasterGameObj.transform.childCount; if (mCount == 0) - { return; } + { + return; + } List tObjtoDelete = new List(); - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - if (MasterGameObj.transform.GetChild(i).name.ToLower().Contains("stopsign")) + if (MasterGameObj.transform.GetChild(index).name.ToLower().Contains("stopsign")) { - tObjtoDelete.Add(MasterGameObj.transform.GetChild(i).gameObject); + tObjtoDelete.Add(MasterGameObj.transform.GetChild(index).gameObject); } - if (MasterGameObj.transform.GetChild(i).name.ToLower().Contains("trafficlight")) + if (MasterGameObj.transform.GetChild(index).name.ToLower().Contains("trafficlight")) { - tObjtoDelete.Add(MasterGameObj.transform.GetChild(i).gameObject); + tObjtoDelete.Add(MasterGameObj.transform.GetChild(index).gameObject); } } - for (int i = (tObjtoDelete.Count - 1); i >= 0; i--) + for (int index = (tObjtoDelete.Count - 1); index >= 0; index--) { - Object.DestroyImmediate(tObjtoDelete[i]); + Object.DestroyImmediate(tObjtoDelete[index]); } } @@ -5274,7 +5498,9 @@ private static void CreateStopSignsAllWay_Do(ref GameObject MasterGameObj, bool tObj.name = "StopSignRR"; T_FixSigns(tObj); if (GSDRI.IgnoreCorner == 0) - { Object.DestroyImmediate(tObj); } + { + Object.DestroyImmediate(tObj); + } //LL: tSpline = GSDRI.Node1.GSDSpline; @@ -5293,7 +5519,9 @@ private static void CreateStopSignsAllWay_Do(ref GameObject MasterGameObj, bool tObj.name = "StopSignLL"; T_FixSigns(tObj); if (GSDRI.IgnoreCorner == 2) - { Object.DestroyImmediate(tObj); } + { + Object.DestroyImmediate(tObj); + } //RL: tSpline = GSDRI.Node2.GSDSpline; @@ -5312,7 +5540,9 @@ private static void CreateStopSignsAllWay_Do(ref GameObject MasterGameObj, bool tObj.name = "StopSignRL"; T_FixSigns(tObj); if (GSDRI.IgnoreCorner == 1) - { Object.DestroyImmediate(tObj); } + { + Object.DestroyImmediate(tObj); + } //LR: tSpline = GSDRI.Node2.GSDSpline; @@ -5331,14 +5561,15 @@ private static void CreateStopSignsAllWay_Do(ref GameObject MasterGameObj, bool tObj.name = "StopSignLR"; T_FixSigns(tObj); if (GSDRI.IgnoreCorner == 3) - { Object.DestroyImmediate(tObj); } + { + Object.DestroyImmediate(tObj); + } } private static Vector3 StopSign_GetRot_RR(GSDRoadIntersection GSDRI, GSDSplineC tSpline) { float tDist = ((Vector3.Distance(GSDRI.CornerRL, GSDRI.CornerRR) / 2f) + (0.025f * Vector3.Distance(GSDRI.CornerLL, GSDRI.CornerRR))) / tSpline.distance; - ; float p = Mathf.Clamp(GSDRI.Node1.tTime - tDist, 0f, 1f); Vector3 POS = tSpline.GetSplineValue(p, true); return (POS * -1); @@ -5348,7 +5579,6 @@ private static Vector3 StopSign_GetRot_RR(GSDRoadIntersection GSDRI, GSDSplineC private static Vector3 StopSign_GetRot_LL(GSDRoadIntersection GSDRI, GSDSplineC tSpline) { float tDist = ((Vector3.Distance(GSDRI.CornerLR, GSDRI.CornerLL) / 2f) + (0.025f * Vector3.Distance(GSDRI.CornerLL, GSDRI.CornerRR))) / tSpline.distance; - ; float p = Mathf.Clamp(GSDRI.Node1.tTime + tDist, 0f, 1f); Vector3 POS = tSpline.GetSplineValue(p, true); return POS; @@ -5358,7 +5588,6 @@ private static Vector3 StopSign_GetRot_LL(GSDRoadIntersection GSDRI, GSDSplineC private static Vector3 StopSign_GetRot_RL(GSDRoadIntersection GSDRI, GSDSplineC tSpline) { float tDist = ((Vector3.Distance(GSDRI.CornerLL, GSDRI.CornerRL) / 2f) + (0.025f * Vector3.Distance(GSDRI.CornerLR, GSDRI.CornerRL))) / tSpline.distance; - ; float p = -1f; if (GSDRI.bFlipped) { @@ -5384,7 +5613,6 @@ private static Vector3 StopSign_GetRot_RL(GSDRoadIntersection GSDRI, GSDSplineC private static Vector3 StopSign_GetRot_LR(GSDRoadIntersection GSDRI, GSDSplineC tSpline) { float tDist = ((Vector3.Distance(GSDRI.CornerRR, GSDRI.CornerLR) / 2f) + (0.025f * Vector3.Distance(GSDRI.CornerLR, GSDRI.CornerRL))) / tSpline.distance; - ; float p = -1f; if (GSDRI.bFlipped) { @@ -5483,7 +5711,9 @@ private static void CreateTrafficLightBases_Do(ref GameObject MasterGameObj, boo // xDir = (GSDRI.CornerRL - GSDRI.transform.position).normalized; tDir = TrafficLightBase_GetRot_RL(GSDRI, tSpline, DistFromCorner); if (tDir == zeroVect) - { tDir = new Vector3(0f, 0.0001f, 0f); } + { + tDir = new Vector3(0f, 0.0001f, 0f); + } tObjRL.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f); tObjRL.transform.parent = MasterGameObj.transform; StartVec = tPosRL; @@ -5493,7 +5723,9 @@ private static void CreateTrafficLightBases_Do(ref GameObject MasterGameObj, boo tObjRL.transform.parent = null; tDir = TrafficLightBase_GetRot_RL(GSDRI, tSpline, DistFromCorner, true); if (tDir == zeroVect) - { tDir = new Vector3(0f, 0.0001f, 0f); } + { + tDir = new Vector3(0f, 0.0001f, 0f); + } tObjRL.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f); tObjRL.transform.parent = MasterGameObj.transform; } @@ -5501,12 +5733,16 @@ private static void CreateTrafficLightBases_Do(ref GameObject MasterGameObj, boo { GSDRI.bRegularPoleAlignment = true; if (tObjRL != null) - { Object.DestroyImmediate(tObjRL); } + { + Object.DestroyImmediate(tObjRL); + } tObjRL = CreateTrafficLight(TLDistance, true, true, MaxDistanceStart, GSDRI.bTrafficPoleStreetLight, tSpline.tRoad.GSDRS.opt_bSaveMeshes); // xDir = (GSDRI.CornerRL - GSDRI.transform.position).normalized; tDir = TrafficLightBase_GetRot_RL(GSDRI, tSpline, DistFromCorner); if (tDir == zeroVect) - { tDir = new Vector3(0f, 0.0001f, 0f); } + { + tDir = new Vector3(0f, 0.0001f, 0f); + } tObjRL.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f); tObjRL.transform.parent = MasterGameObj.transform; StartVec = tPosRL; @@ -5527,7 +5763,9 @@ private static void CreateTrafficLightBases_Do(ref GameObject MasterGameObj, boo // xDir = (GSDRI.CornerLR - GSDRI.transform.position).normalized; tDir = TrafficLightBase_GetRot_LR(GSDRI, tSpline, DistFromCorner); if (tDir == zeroVect) - { tDir = new Vector3(0f, 0.0001f, 0f); } + { + tDir = new Vector3(0f, 0.0001f, 0f); + } tObjLR.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f); tObjLR.transform.parent = MasterGameObj.transform; StartVec = tPosLR; @@ -5537,7 +5775,9 @@ private static void CreateTrafficLightBases_Do(ref GameObject MasterGameObj, boo tObjLR.transform.parent = null; tDir = TrafficLightBase_GetRot_LR(GSDRI, tSpline, DistFromCorner, true); if (tDir == zeroVect) - { tDir = new Vector3(0f, 0.0001f, 0f); } + { + tDir = new Vector3(0f, 0.0001f, 0f); + } tObjLR.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f); tObjLR.transform.parent = MasterGameObj.transform; } @@ -5545,12 +5785,16 @@ private static void CreateTrafficLightBases_Do(ref GameObject MasterGameObj, boo { GSDRI.bRegularPoleAlignment = true; if (tObjLR != null) - { Object.DestroyImmediate(tObjLR); } + { + Object.DestroyImmediate(tObjLR); + } tObjLR = CreateTrafficLight(TLDistance, true, true, MaxDistanceStart, GSDRI.bTrafficPoleStreetLight, tSpline.tRoad.GSDRS.opt_bSaveMeshes); // xDir = (GSDRI.CornerLR - GSDRI.transform.position).normalized; tDir = TrafficLightBase_GetRot_LR(GSDRI, tSpline, DistFromCorner); if (tDir == zeroVect) - { tDir = new Vector3(0f, 0.0001f, 0f); } + { + tDir = new Vector3(0f, 0.0001f, 0f); + } tObjLR.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f); tObjLR.transform.parent = MasterGameObj.transform; StartVec = tPosLR; @@ -5572,7 +5816,9 @@ private static void CreateTrafficLightBases_Do(ref GameObject MasterGameObj, boo // xDir = (GSDRI.CornerRR - GSDRI.transform.position).normalized; tDir = TrafficLightBase_GetRot_RR(GSDRI, tSpline, DistFromCorner); if (tDir == zeroVect) - { tDir = new Vector3(0f, 0.0001f, 0f); } + { + tDir = new Vector3(0f, 0.0001f, 0f); + } tObjRR.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f); tObjRR.transform.parent = MasterGameObj.transform; StartVec = tPosRR; @@ -5582,7 +5828,9 @@ private static void CreateTrafficLightBases_Do(ref GameObject MasterGameObj, boo tObjRR.transform.parent = null; tDir = TrafficLightBase_GetRot_RR(GSDRI, tSpline, DistFromCorner, true); if (tDir == zeroVect) - { tDir = new Vector3(0f, 0.0001f, 0f); } + { + tDir = new Vector3(0f, 0.0001f, 0f); + } tObjRR.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, 0f, 0f); tObjRR.transform.parent = MasterGameObj.transform; } @@ -5595,7 +5843,9 @@ private static void CreateTrafficLightBases_Do(ref GameObject MasterGameObj, boo // xDir = (GSDRI.CornerRR - GSDRI.transform.position).normalized; tDir = TrafficLightBase_GetRot_RR(GSDRI, tSpline, DistFromCorner); if (tDir == zeroVect) - { tDir = new Vector3(0f, 0.0001f, 0f); } + { + tDir = new Vector3(0f, 0.0001f, 0f); + } tObjRR.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f); tObjRR.transform.parent = MasterGameObj.transform; StartVec = tPosRR; @@ -5617,7 +5867,9 @@ private static void CreateTrafficLightBases_Do(ref GameObject MasterGameObj, boo // xDir = (GSDRI.CornerLL - GSDRI.transform.position).normalized; tDir = TrafficLightBase_GetRot_LL(GSDRI, tSpline, DistFromCorner); if (tDir == zeroVect) - { tDir = new Vector3(0f, 0.0001f, 0f); } + { + tDir = new Vector3(0f, 0.0001f, 0f); + } tObjLL.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f); tObjLL.transform.parent = MasterGameObj.transform; StartVec = tPosLL; @@ -5627,7 +5879,9 @@ private static void CreateTrafficLightBases_Do(ref GameObject MasterGameObj, boo tObjLL.transform.parent = null; tDir = TrafficLightBase_GetRot_LL(GSDRI, tSpline, DistFromCorner, true); if (tDir == zeroVect) - { tDir = new Vector3(0f, 0.0001f, 0f); } + { + tDir = new Vector3(0f, 0.0001f, 0f); + } tObjLL.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, 0f, 0f); tObjLL.transform.parent = MasterGameObj.transform; } @@ -5635,12 +5889,16 @@ private static void CreateTrafficLightBases_Do(ref GameObject MasterGameObj, boo { GSDRI.bRegularPoleAlignment = true; if (tObjLL != null) - { Object.DestroyImmediate(tObjLL); } + { + Object.DestroyImmediate(tObjLL); + } tObjLL = CreateTrafficLight(TLDistance, true, true, MaxDistanceStart, GSDRI.bTrafficPoleStreetLight, tSpline.tRoad.GSDRS.opt_bSaveMeshes); // xDir = (GSDRI.CornerLL - GSDRI.transform.position).normalized; tDir = TrafficLightBase_GetRot_LL(GSDRI, tSpline, DistFromCorner); if (tDir == zeroVect) - { tDir = new Vector3(0f, 0.0001f, 0f); } + { + tDir = new Vector3(0f, 0.0001f, 0f); + } tObjLL.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f); tObjLL.transform.parent = MasterGameObj.transform; StartVec = tPosLL; @@ -5692,7 +5950,9 @@ private static GameObject CreateTrafficLight(float tDistance, bool bIsTrafficLig bool bXMod = false; if (!IsApproximately(xMod, 1f, 0.0001f)) - { bXMod = true; } + { + bXMod = true; + } Mesh xMesh = (Mesh) UnityEditor.AssetDatabase.LoadAssetAtPath(GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Mesh/RoadObj/Signs/TrafficLightBases/" + assetNameAsset, typeof(Mesh)); if (xMesh == null) @@ -5704,10 +5964,14 @@ private static GameObject CreateTrafficLight(float tDistance, bool bIsTrafficLig tObj = new GameObject("TempTrafficLight"); MeshFilter MF = tObj.GetComponent(); if (MF == null) - { MF = tObj.AddComponent(); } + { + MF = tObj.AddComponent(); + } MeshRenderer MR = tObj.GetComponent(); if (MR == null) - { MR = tObj.AddComponent(); } + { + MR = tObj.AddComponent(); + } GSD.Roads.GSDRoadUtilityEditor.SetRoadMaterial(GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/Signs/GSDInterTLB" + tTrafficLightNumber + ".mat", MR); if (!bDoCustom) @@ -5742,30 +6006,30 @@ private static GameObject CreateTrafficLight(float tDistance, bool bIsTrafficLig int mCount = tVerts.Length; Vector2[] uv = tMesh.uv; // List tUVInts = new List(); - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { bIgnoreMe = false; - if (IsApproximately(tVerts[i].y, 5f, 0.01f)) + if (IsApproximately(tVerts[index].y, 5f, 0.01f)) { - tVerts[i].y = tDistance; - if (uv[i].y > 3.5f) + tVerts[index].y = tDistance; + if (uv[index].y > 3.5f) { - uv[i].y *= tMod; + uv[index].y *= tMod; } bIgnoreMe = true; } - if (!bIgnoreMe && tVerts[i].z > 7.5f) + if (!bIgnoreMe && tVerts[index].z > 7.5f) { - tVerts[i].z *= hMod; - if (uv[i].y > 3.8f) + tVerts[index].z *= hMod; + if (uv[index].y > 3.8f) { - uv[i].y *= hMod; + uv[index].y *= hMod; } } - if (bXMod && tVerts[i].z > 4.8f && tVerts[i].z < 6.2f) + if (bXMod && tVerts[index].z > 4.8f && tVerts[index].z < 6.2f) { - tVerts[i].z += xValue; + tVerts[index].z += xValue; } } tMesh.vertices = tVerts; @@ -5809,8 +6073,10 @@ private static GameObject CreateTrafficLight(float tDistance, bool bIsTrafficLig //Bounds calcs: MeshFilter[] tMeshes = tObj.GetComponents(); - for (int i = 0; i < tMeshes.Length; i++) - { tMeshes[i].sharedMesh.RecalculateBounds(); } + for (int index = 0; index < tMeshes.Length; index++) + { + tMeshes[index].sharedMesh.RecalculateBounds(); + } return tObj; } @@ -5864,7 +6130,9 @@ private static Vector3 TrafficLightBase_GetRot_RR(GSDRoadIntersection GSDRI, GSD POS = tSpline.GetSplineValue(p, true); POS = Vector3.Cross(POS, Vector3.up); if (GSDRI.bFlipped) - { POS = POS * -1; } + { + POS = POS * -1; + } } else { @@ -5884,7 +6152,9 @@ private static Vector3 TrafficLightBase_GetRot_LL(GSDRoadIntersection GSDRI, GSD POS = tSpline.GetSplineValue(p, true); POS = Vector3.Cross(POS, Vector3.up); if (GSDRI.bFlipped) - { POS = POS * -1; } + { + POS = POS * -1; + } } else { @@ -5935,22 +6205,30 @@ private static void CreateTrafficLightMains(GameObject MasterGameObj, GameObject if (GSDRI.IgnoreCorner == 0) { if (tRR != null) - { Object.DestroyImmediate(tRR); } + { + Object.DestroyImmediate(tRR); + } } else if (GSDRI.IgnoreCorner == 1) { if (tRL != null) - { Object.DestroyImmediate(tRL); } + { + Object.DestroyImmediate(tRL); + } } else if (GSDRI.IgnoreCorner == 2) { if (tLL != null) - { Object.DestroyImmediate(tLL); } + { + Object.DestroyImmediate(tLL); + } } else if (GSDRI.IgnoreCorner == 3) { if (tLR != null) - { Object.DestroyImmediate(tLR); } + { + Object.DestroyImmediate(tLR); + } } } @@ -6013,9 +6291,9 @@ private static void ProcessPole(GameObject MasterGameObj, GameObject tObj, Vecto //7.5m = lane //12.5m = lane Vector3[] tLanePos = new Vector3[LanesHalf]; - for (int i = 0; i < LanesHalf; i++) + for (int index = 0; index < LanesHalf; index++) { - tLanePos[i] = (((EndVec - StartVec) * (((LaneWidth * 0.5f) + (i * LaneWidth)) / SmallerDist)) + StartVec); + tLanePos[index] = (((EndVec - StartVec) * (((LaneWidth * 0.5f) + (index * LaneWidth)) / SmallerDist)) + StartVec); } Vector3 tLanePosL = default(Vector3); Vector3 tLanePosL_Sign = default(Vector3); @@ -6051,29 +6329,39 @@ private static void ProcessPole(GameObject MasterGameObj, GameObject tObj, Vecto int mCount = tLanePos.Length; float mDistance = -50000f; float tDistance = 0f; - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - tDistance = Vector3.Distance(tObj.transform.TransformPoint(tLanePos[i]), tPos1); + tDistance = Vector3.Distance(tObj.transform.TransformPoint(tLanePos[index]), tPos1); if (tDistance > mDistance) - { mDistance = tDistance; } + { + mDistance = tDistance; + } } tDistance = Vector3.Distance(tObj.transform.TransformPoint(tLanePosL), tPos1); if (tDistance > mDistance) - { mDistance = tDistance; } + { + mDistance = tDistance; + } tDistance = Vector3.Distance(tObj.transform.TransformPoint(tLanePosR), tPos1); if (tDistance > mDistance) - { mDistance = tDistance; } + { + mDistance = tDistance; + } float tScaleSense = ((200f - GSDRI.ScalingSense) / 200f) * 200f; tScaleSense = Mathf.Clamp(tScaleSense * 0.1f, 0f, 20f); float ScaleMod = ((mDistance / 17f) + tScaleSense) * (1f / (tScaleSense + 1f)); if (IsApproximately(tScaleSense, 20f, 0.05f)) - { ScaleMod = 1f; } + { + ScaleMod = 1f; + } ScaleMod = Mathf.Clamp(ScaleMod, 1f, 1.5f); Vector3 tScale = new Vector3(ScaleMod, ScaleMod, ScaleMod); bool bScale = true; if (IsApproximately(ScaleMod, 1f, 0.001f)) - { bScale = false; } + { + bScale = false; + } //Debug.Log (mDistance + " " + ScaleMod + " " + tScaleSense); @@ -6104,11 +6392,11 @@ private static void ProcessPole(GameObject MasterGameObj, GameObject tObj, Vecto tLeft.transform.name = "LightLeft"; cCount = tLeft.transform.childCount; - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - if (tLeft.transform.GetChild(i).name.ToLower() == "lights") + if (tLeft.transform.GetChild(index).name.ToLower() == "lights") { - MR_Left = tLeft.transform.GetChild(i).GetComponent(); + MR_Left = tLeft.transform.GetChild(index).GetComponent(); } } @@ -6140,33 +6428,35 @@ private static void ProcessPole(GameObject MasterGameObj, GameObject tObj, Vecto { tRight.transform.localScale = tScale; } cCount = tRight.transform.childCount; - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - if (tRight.transform.GetChild(i).name.ToLower() == "lights") + if (tRight.transform.GetChild(index).name.ToLower() == "lights") { - MR_Right = tRight.transform.GetChild(i).GetComponent(); + MR_Right = tRight.transform.GetChild(index).GetComponent(); } } } GameObject[] tLanes = new GameObject[LanesHalf]; - for (int i = 0; i < LanesHalf; i++) + for (int index = 0; index < LanesHalf; index++) { prefab = UnityEditor.AssetDatabase.LoadAssetAtPath(GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Mesh/RoadObj/Signs/GSDTrafficLightMain.prefab", typeof(GameObject)); - tLanes[i] = (GameObject) GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity); - AdjustLightPrefab(tLanes[i]); - tLanes[i].transform.position = tObj.transform.TransformPoint(tLanePos[i]); - tLanes[i].transform.rotation = Quaternion.LookRotation(tan) * Quaternion.Euler(0f, 90f, 0f); - tLanes[i].transform.parent = tObj.transform; - tLanes[i].transform.name = "Light" + i.ToString(); + tLanes[index] = (GameObject) GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity); + AdjustLightPrefab(tLanes[index]); + tLanes[index].transform.position = tObj.transform.TransformPoint(tLanePos[index]); + tLanes[index].transform.rotation = Quaternion.LookRotation(tan) * Quaternion.Euler(0f, 90f, 0f); + tLanes[index].transform.parent = tObj.transform; + tLanes[index].transform.name = "Light" + index.ToString(); if (bScale) - { tLanes[i].transform.localScale = tScale; } + { + tLanes[index].transform.localScale = tScale; + } - cCount = tLanes[i].transform.childCount; + cCount = tLanes[index].transform.childCount; for (int j = 0; j < cCount; j++) { - if (tLanes[i].transform.GetChild(j).name.ToLower() == "lights") + if (tLanes[index].transform.GetChild(j).name.ToLower() == "lights") { - MR_Mains[i] = tLanes[i].transform.GetChild(j).GetComponent(); + MR_Mains[index] = tLanes[index].transform.GetChild(j).GetComponent(); } } } @@ -6235,7 +6525,9 @@ private static void GetFourPoints_Do(ref GSDRoadIntersection GSDRI, out Vector3 Node2Width = (Vector3.Distance(GSDRI.CornerRL, GSDRI.Node2.pos) + ShoulderWidth2) / GSDRI.Node2.GSDSpline.distance; tPos1 = GSDRI.Node1.tTime + Node1Width; if (GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay) - { tPos1 = GSDRI.Node1.tTime; } + { + tPos1 = GSDRI.Node1.tTime; + } tTan1 = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1, true); tPos2 = GSDRI.Node2.tTime + Node2Width; tTan2 = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2, true); @@ -6246,7 +6538,9 @@ private static void GetFourPoints_Do(ref GSDRoadIntersection GSDRI, out Vector3 Node2Width = (Vector3.Distance(GSDRI.CornerLL, GSDRI.Node2.pos) + ShoulderWidth2) / GSDRI.Node2.GSDSpline.distance; tPos1 = GSDRI.Node1.tTime + Node1Width; if (GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay) - { tPos1 = GSDRI.Node1.tTime; } + { + tPos1 = GSDRI.Node1.tTime; + } tTan1 = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1, true); tPos2 = GSDRI.Node2.tTime - Node2Width; tTan2 = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2, true) * -1f; @@ -6278,7 +6572,9 @@ private static void GetFourPoints_Do(ref GSDRoadIntersection GSDRI, out Vector3 Node2Width = (Vector3.Distance(GSDRI.CornerRL, GSDRI.Node2.pos) + ShoulderWidth2) / GSDRI.Node2.GSDSpline.distance; tPos1 = GSDRI.Node1.tTime + Node1Width; if (GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay) - { tPos1 = GSDRI.Node1.tTime; } + { + tPos1 = GSDRI.Node1.tTime; + } tTan1 = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1, true); tPos2 = GSDRI.Node2.tTime - Node2Width; tTan2 = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2, true) * -1f; @@ -6289,7 +6585,9 @@ private static void GetFourPoints_Do(ref GSDRoadIntersection GSDRI, out Vector3 Node2Width = (Vector3.Distance(GSDRI.CornerLL, GSDRI.Node2.pos) + ShoulderWidth2) / GSDRI.Node2.GSDSpline.distance; tPos1 = GSDRI.Node1.tTime + Node1Width; if (GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay) - { tPos1 = GSDRI.Node1.tTime; } + { + tPos1 = GSDRI.Node1.tTime; + } tTan1 = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1, true); tPos2 = GSDRI.Node2.tTime + Node2Width; tTan2 = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2, true); @@ -6697,59 +6995,135 @@ public void Nullify() //Intersection construction: if (iBLane0L != null) - { iBLane0L.Clear(); iBLane0L = null; } + { + iBLane0L.Clear(); + iBLane0L = null; + } if (iBLane0R != null) - { iBLane0R.Clear(); iBLane0R = null; } + { + iBLane0R.Clear(); + iBLane0R = null; + } if (iBLane1L != null) - { iBLane1L.Clear(); iBLane1L = null; } + { + iBLane1L.Clear(); + iBLane1L = null; + } if (iBLane1R != null) - { iBLane1R.Clear(); iBLane1R = null; } + { + iBLane1R.Clear(); + iBLane1R = null; + } if (iBLane2L != null) - { iBLane2L.Clear(); iBLane2L = null; } + { + iBLane2L.Clear(); + iBLane2L = null; + } if (iBLane2R != null) - { iBLane2R.Clear(); iBLane2R = null; } + { + iBLane2R.Clear(); + iBLane2R = null; + } if (iBLane3L != null) - { iBLane3L.Clear(); iBLane3L = null; } + { + iBLane3L.Clear(); + iBLane3L = null; + } if (iBLane3R != null) - { iBLane3R.Clear(); iBLane3R = null; } + { + iBLane3R.Clear(); + iBLane3R = null; + } if (iFLane0L != null) - { iFLane0L.Clear(); iFLane0L = null; } + { + iFLane0L.Clear(); + iFLane0L = null; + } if (iFLane0R != null) - { iFLane0R.Clear(); iFLane0R = null; } + { + iFLane0R.Clear(); + iFLane0R = null; + } if (iFLane1L != null) - { iFLane1L.Clear(); iFLane1L = null; } + { + iFLane1L.Clear(); + iFLane1L = null; + } if (iFLane1R != null) - { iFLane1R.Clear(); iFLane1R = null; } + { + iFLane1R.Clear(); + iFLane1R = null; + } if (iFLane2L != null) - { iFLane2L.Clear(); iFLane2L = null; } + { + iFLane2L.Clear(); + iFLane2L = null; + } if (iFLane2R != null) - { iFLane2R.Clear(); iFLane2R = null; } + { + iFLane2R.Clear(); + iFLane2R = null; + } if (iFLane3L != null) - { iFLane3L.Clear(); iFLane3L = null; } + { + iFLane3L.Clear(); + iFLane3L = null; + } if (iFLane3R != null) - { iFLane3R.Clear(); iFLane3R = null; } + { + iFLane3R.Clear(); + iFLane3R = null; + } if (iBMainPlateL != null) - { iBMainPlateL.Clear(); iBMainPlateL = null; } + { + iBMainPlateL.Clear(); + iBMainPlateL = null; + } if (iBMainPlateR != null) - { iBMainPlateR.Clear(); iBMainPlateR = null; } + { + iBMainPlateR.Clear(); + iBMainPlateR = null; + } if (iFMainPlateL != null) - { iFMainPlateL.Clear(); iFMainPlateL = null; } + { + iFMainPlateL.Clear(); + iFMainPlateL = null; + } if (iFMainPlateR != null) - { iFMainPlateR.Clear(); iFMainPlateR = null; } + { + iFMainPlateR.Clear(); + iFMainPlateR = null; + } if (iBMarkerPlateL != null) - { iBMarkerPlateL.Clear(); iBMarkerPlateL = null; } + { + iBMarkerPlateL.Clear(); + iBMarkerPlateL = null; + } if (iBMarkerPlateR != null) - { iBMarkerPlateR.Clear(); iBMarkerPlateR = null; } + { + iBMarkerPlateR.Clear(); + iBMarkerPlateR = null; + } if (iFMarkerPlateL != null) - { iFMarkerPlateL.Clear(); iFMarkerPlateL = null; } + { + iFMarkerPlateL.Clear(); + iFMarkerPlateL = null; + } if (iFMarkerPlateR != null) - { iFMarkerPlateR.Clear(); iFMarkerPlateR = null; } + { + iFMarkerPlateR.Clear(); + iFMarkerPlateR = null; + } if (tempconstruction_R != null) - { tempconstruction_R = null; } + { + tempconstruction_R = null; + } if (tempconstruction_L != null) - { tempconstruction_L = null; } + { + tempconstruction_L = null; + } } @@ -6821,7 +7195,10 @@ private static GameObject CreateIntersection_Do(GSDSplineN tNode, GSDSplineN xNo float RoadMod = 10f; GameObject SystemObj = tNode.transform.parent.parent.parent.gameObject; if (!SystemObj) - { Debug.LogWarning("Could not find GSD road system master object."); return null; } + { + Debug.LogWarning("Could not find GSD road system master object."); + return null; + } GameObject InterMaster = null; int cCount = SystemObj.transform.childCount; for (int i = 0; i < cCount; i++) @@ -7101,7 +7478,9 @@ public static void CreateIntersection(GSDRoadIntersection GSDRI) float iWidth = GSDRI.IntersectionWidth * 1.25f; Collider[] tColliders = Physics.OverlapSphere(GSDRI.transform.position, iWidth); if (tColliders == null || tColliders.Length < 1) - { return; } + { + return; + } List tRoads = new List(); foreach (Collider tCollider in tColliders) { @@ -7379,9 +7758,9 @@ private static void CreateIntersectionMesh_MainInternal(Vector3[] tVerts, GameOb // tObj = GameObject.Find("tInter3"); tObj.transform.position = tVerts[2]; // tObj = GameObject.Find("tInter4"); tObj.transform.position = tVerts[3]; - for (int i = 0; i < MVL; i++) + for (int index = 0; index < MVL; index++) { - tVerts[i] -= iObj.transform.position; + tVerts[index] -= iObj.transform.position; } tMesh.vertices = tVerts; tMesh.RecalculateBounds(); @@ -7415,19 +7794,25 @@ private static void CreateIntersectionMesh_MainInternal(Vector3[] tVerts, GameOb //Final processing: MeshFilter MF = iObj.GetComponent(); if (!MF) - { MF = iObj.AddComponent(); } + { + MF = iObj.AddComponent(); + } MF.sharedMesh = tMesh; // MeshToFile(MF,GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Mesh/Intersections/" + tName +".obj"); MeshCollider MC = iObj.GetComponent(); if (MC) - { Object.DestroyImmediate(MC); } + { + Object.DestroyImmediate(MC); + } //if(!MC){ MC = iObj.AddComponent(); } //MC.sharedMesh = MF.sharedMesh; MeshRenderer MR = iObj.GetComponent(); if (!MR) - { MR = iObj.AddComponent(); } + { + MR = iObj.AddComponent(); + } MR.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; MR.receiveShadows = true; GSD.Roads.GSDRoadUtilityEditor.SetRoadMaterial(GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/GSDRoadIntersection.mat", MR); @@ -7462,11 +7847,11 @@ private static void CreateIntersectionMesh_Outer(GSDRoadIntersection GSDRI, Vect int cCount = GSDRI.transform.childCount; // bool bOuter = false; GameObject tOuter = null; - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - if (GSDRI.transform.GetChild(i).transform.name == "outer") + if (GSDRI.transform.GetChild(index).transform.name == "outer") { - tOuter = GSDRI.transform.GetChild(i).transform.gameObject; + tOuter = GSDRI.transform.GetChild(index).transform.gameObject; } } if (!tOuter) @@ -7492,12 +7877,12 @@ private static void CreateIntersectionMesh_OuterInternal(Vector3[] tVerts, GameO int MVL = 16; int triCount = (int) (16f * 1.5f); - for (int i = 0; i < MVL; i += 4) + for (int index = 0; index < MVL; index += 4) { - // tVerts[i] += vOffset; - // tVerts[i+1] += vOffset; - tVerts[i + 2] -= vOffset; - tVerts[i + 3] -= vOffset; + // tVerts[index] += vOffset; + // tVerts[index+1] += vOffset; + tVerts[index + 2] -= vOffset; + tVerts[index + 3] -= vOffset; } tMesh.vertices = tVerts; tMesh.RecalculateBounds(); @@ -7549,20 +7934,26 @@ private static void CreateIntersectionMesh_OuterInternal(Vector3[] tVerts, GameO //Final processing: MeshFilter MF = iObj.GetComponent(); if (!MF) - { MF = iObj.AddComponent(); } + { + MF = iObj.AddComponent(); + } MF.sharedMesh = tMesh; // MeshToFile(MF,GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Mesh/Intersections/" + tName +"-overlay.obj"); MeshCollider MC = iObj.GetComponent(); if (MC) - { Object.DestroyImmediate(MC); } + { + Object.DestroyImmediate(MC); + } // if(!MC){ MC = iObj.AddComponent(); } // MC.sharedMesh = MF.sharedMesh; MeshRenderer MR = iObj.GetComponent(); if (!MR) - { MR = iObj.AddComponent(); } + { + MR = iObj.AddComponent(); + } MR.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; MR.receiveShadows = true; GSD.Roads.GSDRoadUtilityEditor.SetRoadMaterial(GSD.Roads.GSDRoadUtilityEditor.GetBasePath() + "/Materials/GSDInterText.mat", MR); @@ -7605,10 +7996,10 @@ private static void InitializeIntersectionObjects_Internal(GSDRoadIntersection G //Get all connected nodes on intersection node1: int cCount = GSDRI.Node1.id_connected.Count; GSDSplineN tNode; - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { //tNode = GetNodeByID(GSDRI.Node1.id_connected[i]); - tNode = GSDRI.Node1.node_connected[i]; + tNode = GSDRI.Node1.node_connected[index]; if (!tList.Contains(tNode)) { tList.Add(tNode); @@ -7616,10 +8007,10 @@ private static void InitializeIntersectionObjects_Internal(GSDRoadIntersection G } //Get all connected nodes on intersection node2: cCount = GSDRI.Node2.id_connected.Count; - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { //tNode = GetNodeByID(GSDRI.Node2.id_connected[i]); - tNode = GSDRI.Node2.node_connected[i]; + tNode = GSDRI.Node2.node_connected[index]; if (!tList.Contains(tNode)) { tList.Add(tNode); @@ -7632,7 +8023,9 @@ private static void InitializeIntersectionObjects_Internal(GSDRoadIntersection G n3 = tList[2]; n4 = null; if (tList.Count > 3) - { n4 = tList[3]; } + { + n4 = tList[3]; + } //Determine most relevant spline: GSDSplineC n1Spline = n1.GSDSpline; @@ -7640,7 +8033,9 @@ private static void InitializeIntersectionObjects_Internal(GSDRoadIntersection G GSDSplineC n3Spline = n3.GSDSpline; GSDSplineC n4Spline = null; if (n4 != null) - { n4Spline = n4.GSDSpline; } + { + n4Spline = n4.GSDSpline; + } //Get the point: Vector3 n1Point = GetFourCornerPoint(ref n1Spline, ref n1, GSDRI); @@ -7648,7 +8043,9 @@ private static void InitializeIntersectionObjects_Internal(GSDRoadIntersection G Vector3 n3Point = GetFourCornerPoint(ref n3Spline, ref n3, GSDRI); Vector3 n4Point = new Vector3(0f, 0f, 0f); if (n4Spline != null) - { n4Point = GetFourCornerPoint(ref n4Spline, ref n4, GSDRI); } + { + n4Point = GetFourCornerPoint(ref n4Spline, ref n4, GSDRI); + } //2. If 3 way, we know that 2 of the nodes have the same spline. if (1 == 1 && GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay) @@ -7699,12 +8096,12 @@ private static float GetLongestSplineDistance(GSDSplineC s1, GSDSplineC s2) } - private static GSDSplineN GetNodeByID(int i) + private static GSDSplineN GetNodeByID(int _ID) { Object[] SplineNodeObjects = GameObject.FindObjectsOfType(typeof(GSDSplineN)); foreach (GSDSplineN tNode in SplineNodeObjects) { - if (tNode.id == i) + if (tNode.id == _ID) { return tNode; } diff --git a/GSDRoadUtilityEditor.cs b/GSDRoadUtilityEditor.cs index d2c5c3fa..dd4d7dd1 100644 --- a/GSDRoadUtilityEditor.cs +++ b/GSDRoadUtilityEditor.cs @@ -1,9 +1,11 @@ +#region "Imports" using UnityEngine; using System.IO; using System; #if UNITY_EDITOR using UnityEditor; #endif +#endregion namespace GSD.Roads diff --git a/GSDRoadUtilityT.cs b/GSDRoadUtilityT.cs index 49499e0e..1fde3654 100644 --- a/GSDRoadUtilityT.cs +++ b/GSDRoadUtilityT.cs @@ -1,9 +1,11 @@ +#region "Imports" using UnityEngine; #if UNITY_EDITOR using System.Collections; using System.Collections.Generic; using GSD; #endif +#endregion namespace GSD.Threaded @@ -200,7 +202,9 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform Vector3 POS1 = default(Vector3); Vector3 POS2 = default(Vector3); if (FinalMax > 1f) - { FinalMax = 1f; } + { + FinalMax = 1f; + } float tNext = 0f; float fValue1, fValue2; @@ -228,20 +232,26 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform List tXYs = new List(); float TreeClearDist = tSpline.tRoad.opt_ClearTreesDistance; if (TreeClearDist < tSpline.tRoad.RoadWidth()) - { TreeClearDist = tSpline.tRoad.RoadWidth(); } + { + TreeClearDist = tSpline.tRoad.RoadWidth(); + } GSD.Roads.GSDRoadUtil.Construction2DRect tRect = null; float tGrade = 0f; - for (float i = StartMin; i < FinalMax; i += tStep) + for (float index = StartMin; index < FinalMax; index += tStep) { if (tSpline.tRoad.opt_HeightModEnabled) { - if (i > 1f) - { break; } - tNext = i + tStep; + if (index > 1f) + { + break; + } + tNext = index + tStep; if (tNext > 1f) - { break; } + { + break; + } - tSpline.GetSplineValue_Both(i, out tVect1, out POS1); + tSpline.GetSplineValue_Both(index, out tVect1, out POS1); if (tNext <= 1f) { @@ -254,7 +264,7 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform //Determine if intersection: bIsPastInter = false; //If past intersection - tIntStrength = tSpline.IntersectionStrength(ref tVect1, ref tIntHeight, ref GSDRI, ref bIsPastInter, ref i, ref xNode); + tIntStrength = tSpline.IntersectionStrength(ref tVect1, ref tIntHeight, ref GSDRI, ref bIsPastInter, ref index, ref xNode); // if(IsApproximately(tIntStrength,1f,0.001f) || tIntStrength > 1f){ // bMaxIntersection = true; // }else{ @@ -262,15 +272,19 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform // } // bFirstInterNode = false; - tIntStrength2 = tSpline.IntersectionStrength(ref tVect2, ref tIntHeight2, ref GSDRI, ref bIsPastInter, ref i, ref xNode); + tIntStrength2 = tSpline.IntersectionStrength(ref tVect2, ref tIntHeight2, ref GSDRI, ref bIsPastInter, ref index, ref xNode); if (tIntStrength2 > 1f) - { tIntStrength2 = 1f; } + { + tIntStrength2 = 1f; + } T1SUB = tVect1.y; T2SUB = tVect2.y; if (tIntStrength > 1f) - { tIntStrength = 1f; } + { + tIntStrength = 1f; + } if (tIntStrength >= 0f) {// || IsApproximately(tIntStrength,0f,0.01f)){ if (IsApproximately(tIntStrength, 1f, 0.01f)) @@ -284,13 +298,15 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform bIntStr1_Full = false; bIntStr1_FullNext = (tIntStrength2 >= 1f); if (!IsApproximately(tIntStrength, 0f, 0.01f)) - { T1SUB = (tIntStrength * tIntHeight) + ((1 - tIntStrength) * tVect1.y); } + { + T1SUB = (tIntStrength * tIntHeight) + ((1 - tIntStrength) * tVect1.y); + } // if(tIntStrength <= 0f){ T1SUB = (tIntStrength*tIntHeight) + ((1-tIntStrength)*tVect1.y); } } if ((bIntStr1_Full && !bIntStr1_FullPrev) || (!bIntStr1_Full && bIntStr1_FullNext)) { - tGrade = tSpline.GetCurrentNode(i).GradeToPrevValue; + tGrade = tSpline.GetCurrentNode(index).GradeToPrevValue; if (tGrade < 0f) { T1SUB -= Mathf.Lerp(0.02f, GSDRI.GradeMod, (tGrade / 20f) * -1f); @@ -306,7 +322,7 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform } else if (bIntStr1_Full && !bIntStr1_FullNext) { - tGrade = tSpline.GetCurrentNode(i).GradeToNextValue; + tGrade = tSpline.GetCurrentNode(index).GradeToNextValue; if (tGrade < 0f) { T1SUB -= Mathf.Lerp(0.02f, GSDRI.GradeMod, (tGrade / 20f) * -1f); @@ -344,7 +360,7 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform if ((bIntStr2_Full && !bIntStr2_FullPrev)) { - tGrade = tSpline.GetCurrentNode(i).GradeToPrevValue; + tGrade = tSpline.GetCurrentNode(index).GradeToPrevValue; if (tGrade < 0f) { T2SUB -= Mathf.Lerp(0.02f, GSDRI.GradeMod, (tGrade / 20f) * -1f); @@ -357,7 +373,7 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform } else if (bIntStr2_Full && !bIntStr2_FullNext) { - tGrade = tSpline.GetCurrentNode(i).GradeToNextValue; + tGrade = tSpline.GetCurrentNode(index).GradeToNextValue; if (tGrade < 0f) { T2SUB -= Mathf.Lerp(0.02f, GSDRI.GradeMod, (tGrade / 20f) * -1f); @@ -376,7 +392,7 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform if (tNext + tStep < 1f) { tVect3 = tSpline.GetSplineValue(tNext + tStep, false); - tIntStrength2 = tSpline.IntersectionStrength(ref tVect3, ref tIntHeight2, ref GSDRI, ref bIsPastInter, ref i, ref xNode); + tIntStrength2 = tSpline.IntersectionStrength(ref tVect3, ref tIntHeight2, ref GSDRI, ref bIsPastInter, ref index, ref xNode); } else { @@ -399,17 +415,21 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform bIntStr2_FullPrev = bIntStr2_Full; } - fValue1 = i - fValueMod; - fValue2 = i + fValueMod; + fValue1 = index - fValueMod; + fValue2 = index + fValueMod; if (fValue1 < 0) - { fValue1 = 0; } + { + fValue1 = 0; + } if (fValue2 > 1) - { fValue2 = 1; } + { + fValue2 = 1; + } tXYs.Add(CreateTris(fValue1, fValue2, ref tVect1, ref POS1, ref tVect2, ref POS2, Sep, ref TBMList, ref T1SUB, ref T2SUB, ref TTD, HeightSep)); //Details and trees: - tRect = SetDetailCoords(i, ref tVect1, ref POS1, ref tVect2, ref POS2, tSpline.tRoad.opt_ClearDetailsDistance, TreeClearDist, ref TTD, ref tSpline); + tRect = SetDetailCoords(index, ref tVect1, ref POS1, ref tVect2, ref POS2, tSpline.tRoad.opt_ClearDetailsDistance, TreeClearDist, ref TTD, ref tSpline); if (tSpline.tRoad.opt_TreeModEnabled && tRect != null) { TreerectList.Add(tRect); @@ -417,13 +437,17 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform } else { - if (i > 1f) - { break; } - tNext = i + tStep; + if (index > 1f) + { + break; + } + tNext = index + tStep; if (tNext > 1f) - { break; } + { + break; + } - tSpline.GetSplineValue_Both(i, out tVect1, out POS1); + tSpline.GetSplineValue_Both(index, out tVect1, out POS1); if (tNext <= 1f) { @@ -435,7 +459,7 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform } //Details and trees: - tRect = SetDetailCoords(i, ref tVect1, ref POS1, ref tVect2, ref POS2, tSpline.tRoad.opt_ClearDetailsDistance, TreeClearDist, ref TTD, ref tSpline); + tRect = SetDetailCoords(index, ref tVect1, ref POS1, ref tVect2, ref POS2, tSpline.tRoad.opt_ClearDetailsDistance, TreeClearDist, ref TTD, ref tSpline); if (tSpline.tRoad.opt_TreeModEnabled && tRect != null) { TreerectList.Add(tRect); @@ -507,13 +531,13 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform int tXYsCount = tXYs.Count; bool bIsBridge = false; bool bIsTunnel = false; - for (float i = StartMin; i < FinalMax; i += tStep) + for (float index = StartMin; index < FinalMax; index += tStep) { if (TBMList.Count > 0) { - if (TBMList[0].MaxI < i) + if (TBMList[0].MaxI < index) { - CleanupTris(i, ref TBMList); + CleanupTris(index, ref TBMList); } } else @@ -522,7 +546,7 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform } //If in bridg mode: - if (tSpline.IsInBridgeTerrain(i)) + if (tSpline.IsInBridgeTerrain(index)) { bIsBridge = true; } @@ -531,7 +555,7 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform bIsBridge = false; } //If in tunnel mode: - if (tSpline.IsInTunnelTerrain(i)) + if (tSpline.IsInTunnelTerrain(index)) { bIsTunnel = true; } @@ -543,10 +567,10 @@ private static void DoRectsDo(ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraform if (k < tXYsCount) { tXY = tXYs[k]; - tFloat = ProcessCoordinateGrabber(ref i, ref tSpline, ref TTD, ref TBMList, ref tXY, bIsBridge, bIsTunnel); + tFloat = ProcessCoordinateGrabber(ref index, ref tSpline, ref TTD, ref TBMList, ref tXY, bIsBridge, bIsTunnel); if (!IsApproximately(tFloat, 0f, 0.0001f)) { - tSpline.HeightHistory.Add(new KeyValuePair(i, tFloat)); + tSpline.HeightHistory.Add(new KeyValuePair(index, tFloat)); } } else @@ -562,11 +586,11 @@ private static void CleanupTris(float CurrentI, ref List tLi { int mCount = tList.Count; int LastIndexToRemove = -1; - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - if (tList[i].MaxI < CurrentI) + if (tList[index].MaxI < CurrentI) { - LastIndexToRemove = i; + LastIndexToRemove = index; } else { @@ -677,32 +701,56 @@ private static GSD.Roads.GSDRoadUtil.Construction2DRect SetDetailCoords(float pa int x2, y2, x3, y3; GetTempHeights_Coordinates(ref tVect1, ref TTD, out x2, out y2); if (x2 >= TTD.HM) - { x2 = -1; } + { + x2 = -1; + } if (y2 >= TTD.HM) - { y2 = -1; } + { + y2 = -1; + } if (x2 < 0) - { x2 = -1; } + { + x2 = -1; + } if (y2 < 0) - { y2 = -1; } + { + y2 = -1; + } if (x2 == -1) - { return null; } + { + return null; + } if (y2 == -1) - { return null; } + { + return null; + } float tDiff1 = ((TTD.heights[x2, y2] * (float) TTD.TerrainSize.y) - tVect1.y); GetTempHeights_Coordinates(ref tVect2, ref TTD, out x3, out y3); if (x3 >= TTD.HM) - { x3 = -1; } + { + x3 = -1; + } if (y3 >= TTD.HM) - { y3 = -1; } + { + y3 = -1; + } if (x3 < 0) - { x3 = -1; } + { + x3 = -1; + } if (y3 < 0) - { y3 = -1; } + { + y3 = -1; + } if (x3 == -1) - { return null; } + { + return null; + } if (y3 == -1) - { return null; } + { + return null; + } float tDiff2 = ((TTD.heights[x3, y3] * (float) TTD.TerrainSize.y) - tVect2.y); @@ -712,16 +760,24 @@ private static GSD.Roads.GSDRoadUtil.Construction2DRect SetDetailCoords(float pa { bool bQuit = false; if (x2 == -1) - { bQuit = true; } + { + bQuit = true; + } if (y2 == -1) - { bQuit = true; } + { + bQuit = true; + } if (bIsInBridge && !bQuit) { if (tDiff1 < 0f) - { tDiff1 *= -1f; } + { + tDiff1 *= -1f; + } if (tDiff2 < 0f) - { tDiff2 *= -1f; } + { + tDiff2 *= -1f; + } if (tDiff1 > tSpline.tRoad.opt_ClearTreesDistanceHeight) { bQuit = true; @@ -779,15 +835,23 @@ private static GSD.Roads.GSDRoadUtil.Construction2DRect SetDetailCoords(float pa if (bIsInBridge || bIsInTunnel) { if (tDiff1 < 0f) - { tDiff1 *= -1f; } + { + tDiff1 *= -1f; + } if (tDiff2 < 0f) - { tDiff2 *= -1f; } + { + tDiff2 *= -1f; + } bool bQuit = false; if (x2 == -1) - { bQuit = true; } + { + bQuit = true; + } if (y2 == -1) - { bQuit = true; } + { + bQuit = true; + } if (tDiff1 > tSpline.tRoad.opt_ClearDetailsDistanceHeight) { @@ -838,42 +902,60 @@ private static GSD.Roads.GSDRoadUtil.Construction2DRect SetDetailCoords(float pa int MaxY = Mathf.Max(Ys); if (MinX >= TTD.DetailMaxIndex) - { MinX = TTD.DetailMaxIndex - 1; } + { + MinX = TTD.DetailMaxIndex - 1; + } if (MinY >= TTD.DetailMaxIndex) - { MinY = TTD.DetailMaxIndex - 1; } + { + MinY = TTD.DetailMaxIndex - 1; + } if (MaxX >= TTD.DetailMaxIndex) - { MaxX = TTD.DetailMaxIndex - 1; } + { + MaxX = TTD.DetailMaxIndex - 1; + } if (MaxY >= TTD.DetailMaxIndex) - { MaxY = TTD.DetailMaxIndex - 1; } + { + MaxY = TTD.DetailMaxIndex - 1; + } if (MinX < 0) - { MinX = 0; } + { + MinX = 0; + } if (MinY < 0) - { MinY = 0; } + { + MinY = 0; + } if (MaxX < 0) - { MaxX = 0; } + { + MaxX = 0; + } if (MaxY < 0) - { MaxY = 0; } + { + MaxY = 0; + } // int DetailI = 0; if (tSpline.tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.BeginSample("Dorectsdetails"); } + { + UnityEngine.Profiling.Profiler.BeginSample("Dorectsdetails"); + } int tInt = 0; - for (int i = MinX; i <= MaxX; i++) + for (int index = MinX; index <= MaxX; index++) { for (int k = MinY; k <= MaxY; k++) { //Bitfield for identification: tInt = k; tInt = tInt << 16; - tInt = tInt | (ushort) i; + tInt = tInt | (ushort) index; if (!TTD.DetailHasProcessed.Contains(tInt)) { // for(int h=0;h 0){ - TTD.MainDetailsX.Add((ushort) i); + TTD.MainDetailsX.Add((ushort) index); TTD.MainDetailsY.Add((ushort) k); // DetailI = TTD.DetailsI[h]; @@ -909,22 +991,38 @@ private static float ProcessCoordinateGrabber(ref float param, ref GSDSplineC tS int MaxY = tXY[3]; if (MinX >= TTD.TerrainMaxIndex) - { MinX = TTD.TerrainMaxIndex - 1; } + { + MinX = TTD.TerrainMaxIndex - 1; + } if (MinY >= TTD.TerrainMaxIndex) - { MinY = TTD.TerrainMaxIndex - 1; } + { + MinY = TTD.TerrainMaxIndex - 1; + } if (MaxX >= TTD.TerrainMaxIndex) - { MaxX = TTD.TerrainMaxIndex - 1; } + { + MaxX = TTD.TerrainMaxIndex - 1; + } if (MaxY >= TTD.TerrainMaxIndex) - { MaxY = TTD.TerrainMaxIndex - 1; } + { + MaxY = TTD.TerrainMaxIndex - 1; + } if (MinX < 0) - { MinX = 0; } + { + MinX = 0; + } if (MinY < 0) - { MinY = 0; } + { + MinY = 0; + } if (MaxX < 0) - { MaxX = 0; } + { + MaxX = 0; + } if (MaxY < 0) - { MaxY = 0; } + { + MaxY = 0; + } Vector3 xVect = default(Vector3); bool bAdjusted = false; @@ -936,32 +1034,36 @@ private static float ProcessCoordinateGrabber(ref float param, ref GSDSplineC tS // int tdY = 0; // bool bOneHit = false; - for (int i = MinX; i <= MaxX; i++) + for (int index = MinX; index <= MaxX; index++) { for (int k = MinY; k <= MaxY; k++) { - if (TTD.tHeights[i, k] != true) + if (TTD.tHeights[index, k] != true) { if (TTD.cX.Length <= TTD.cI) - { break; } + { + break; + } - xVect = ConvertTerrainCoordToWorldVect(i, k, TTD.heights[i, k], ref TTD); + xVect = ConvertTerrainCoordToWorldVect(index, k, TTD.heights[index, k], ref TTD); AdjustedTerrainVect_Tri(ref param, out bAdjusted, out tHeight, ref xVect, ref tList, bIsBridge, bIsTunnel); if (bAdjusted) { tHeight -= tSpline.tRoad.opt_TerrainSubtract_Match; if (tHeight < 0f) - { tHeight = 0f; } + { + tHeight = 0f; + } xVect.y = tHeight; tHeight = ((tHeight) / TTD.TerrainSize.y); //Set height values: - TTD.tHeights[i, k] = true; - TTD.cX[TTD.cI] = (ushort) i; + TTD.tHeights[index, k] = true; + TTD.cX[TTD.cI] = (ushort) index; TTD.cY[TTD.cI] = (ushort) k; - TTD.oldH[TTD.cI] = TTD.heights[i, k]; - TTD.heights[i, k] = tHeight; + TTD.oldH[TTD.cI] = TTD.heights[index, k]; + TTD.heights[index, k] = tHeight; TTD.cI += 1; tReturnFloat = xVect.y; @@ -970,14 +1072,16 @@ private static float ProcessCoordinateGrabber(ref float param, ref GSDSplineC tS } else { - xVect = ConvertTerrainCoordToWorldVect(i, k, TTD.heights[i, k], ref TTD); + xVect = ConvertTerrainCoordToWorldVect(index, k, TTD.heights[index, k], ref TTD); AdjustedTerrainVect_Tri(ref param, out bAdjusted, out tHeight, ref xVect, ref tList, bIsBridge, bIsTunnel); if (bAdjusted) { tHeight -= tSpline.tRoad.opt_TerrainSubtract_Match; if (tHeight < 0f) - { tHeight = 0f; } + { + tHeight = 0f; + } tReturnFloat = tHeight; // bOneHit = true; } @@ -1022,9 +1126,9 @@ private static void AdjustedTerrainVect_Tri(ref float param, out bool bAdjusted, bAdjusted = false; tHeight = 0f; Vector2 t2D = new Vector2(xVect.x, xVect.z); - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - TBM = tList[i]; + TBM = tList[index]; if (param < TBM.MinI) { return; @@ -1421,18 +1525,24 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) //Prelim intersection construction and profiling: if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.BeginSample("RoadJob_Prelim_Inter"); } + { + UnityEngine.Profiling.Profiler.BeginSample("RoadJob_Prelim_Inter"); + } if (bInterseOn) { RoadJob_Prelim_Inter(ref tRoad); } if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.EndSample(); } + { + UnityEngine.Profiling.Profiler.EndSample(); + } if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.BeginSample("RoadPrelimForLoop"); } + { + UnityEngine.Profiling.Profiler.BeginSample("RoadPrelimForLoop"); + } //Road/shoulder cuts: Init necessary since a road cut is added for the last segment after this function: if (tRoad.opt_bRoadCuts || tRoad.opt_bDynamicCuts) @@ -1986,14 +2096,20 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) if (!xNode.iConstruction.bFLane1Done && !GSDRI.Contains(ref tempIVect) && !GSDRI.ContainsLine(tempIVect, rVect)) { if (f0LAdded) - { xNode.iConstruction.iFLane0R.Add(GVC(tempIVect, tIntHeight)); f0RAdded = true; } + { + xNode.iConstruction.iFLane0R.Add(GVC(tempIVect, tIntHeight)); + f0RAdded = true; + } xNode.iConstruction.iFLane1L.Add(GVC(tempIVect, tIntHeight)); f1LAdded = true; } else { if (f0LAdded) - { xNode.iConstruction.iFLane0L.RemoveAt(xNode.iConstruction.iFLane0L.Count - 1); f0LAdded = false; } + { + xNode.iConstruction.iFLane0L.RemoveAt(xNode.iConstruction.iFLane0L.Count - 1); + f0LAdded = false; + } } } else @@ -2002,14 +2118,20 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) if (!xNode.iConstruction.bFLane1Done && !GSDRI.Contains(ref tempIVect) && !GSDRI.ContainsLine(tempIVect, rVect)) { if (f0LAdded) - { xNode.iConstruction.iFLane0R.Add(GVC(tempIVect, tIntHeight)); f0RAdded = true; } + { + xNode.iConstruction.iFLane0R.Add(GVC(tempIVect, tIntHeight)); + f0RAdded = true; + } xNode.iConstruction.iFLane1L.Add(GVC(tempIVect, tIntHeight)); f1LAdded = true; } else { if (f0LAdded) - { xNode.iConstruction.iFLane0L.RemoveAt(xNode.iConstruction.iFLane0L.Count - 1); f0LAdded = false; } + { + xNode.iConstruction.iFLane0L.RemoveAt(xNode.iConstruction.iFLane0L.Count - 1); + f0LAdded = false; + } } } //} @@ -2024,12 +2146,18 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) if (!xNode.iConstruction.bFLane2Done && !GSDRI.Contains(ref tempIVect) && !GSDRI.ContainsLine(tempIVect, rVect)) { if (f1LAdded) - { xNode.iConstruction.iFLane1R.Add(GVC(tempIVect, tIntHeight)); f1RAdded = true; } + { + xNode.iConstruction.iFLane1R.Add(GVC(tempIVect, tIntHeight)); + f1RAdded = true; + } } else { if (f1LAdded && xNode.iConstruction.iFLane1L.Count > 1) - { xNode.iConstruction.iFLane1L.RemoveAt(xNode.iConstruction.iFLane1L.Count - 1); f1LAdded = false; } + { + xNode.iConstruction.iFLane1L.RemoveAt(xNode.iConstruction.iFLane1L.Count - 1); + f1LAdded = false; + } } } else @@ -2039,7 +2167,10 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) if (!xNode.iConstruction.bFLane2Done && !GSDRI.Contains(ref tempIVect) && !GSDRI.ContainsLine(tempIVect, rVect)) { if (f1LAdded) - { xNode.iConstruction.iFLane1R.Add(GVC(tempIVect, tIntHeight)); f1RAdded = true; } + { + xNode.iConstruction.iFLane1R.Add(GVC(tempIVect, tIntHeight)); + f1RAdded = true; + } xNode.iConstruction.iFLane2L.Add(GVC(tempIVect, tIntHeight)); f2LAdded = true; } @@ -2068,7 +2199,10 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) f3RAdded = true; // if(bIsNextInter && GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.FourWay){ if (f2LAdded) - { xNode.iConstruction.iFLane2R.Add(GVC(tempIVect, tIntHeight)); f2RAdded = true; } + { + xNode.iConstruction.iFLane2R.Add(GVC(tempIVect, tIntHeight)); + f2RAdded = true; + } // } } else @@ -2277,7 +2411,9 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) tempIVect_Prev = tempIVect; tempIVect = (tVect + new Vector3((LaneWidth * 0.5f) * -POS.normalized.z, 0, (LaneWidth * 0.5f) * POS.normalized.x)); if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane) - { tempIVect = tVect; } + { + tempIVect = tVect; + } bLine = false; if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) { @@ -2321,7 +2457,9 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) { tempIVect = (tVect + new Vector3((LaneWidth * 0.5f) * POS.normalized.z, 0, (LaneWidth * 0.5f) * -POS.normalized.x)); if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane) - { tempIVect = rVect; } + { + tempIVect = rVect; + } if (b1LAdded) { bLine = !GSDRI.ContainsLine(tempIVect, tempIVect_Prev); @@ -2333,7 +2471,10 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) if (!xNode.iConstruction.bBLane2Done && !GSDRI.Contains(ref tempIVect) && bLine) { if (b1LAdded) - { xNode.iConstruction.iBLane1R.Add(GVC(tempIVect, tIntHeight)); b1RAdded = true; } + { + xNode.iConstruction.iBLane1R.Add(GVC(tempIVect, tIntHeight)); + b1RAdded = true; + } xNode.iConstruction.iBLane2L.Add(GVC(tempIVect, tIntHeight)); b2LAdded = true; } @@ -2346,7 +2487,9 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) //Line 3 / 4: tempIVect = (tVect + new Vector3(((LaneWidth * 0.5f) + RoadSeperation) * POS.normalized.z, 0, ((LaneWidth * 0.5f) + RoadSeperation) * -POS.normalized.x)); if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane) - { tempIVect = rVect; } + { + tempIVect = rVect; + } if (!xNode.iConstruction.bBLane3Done && !GSDRI.ContainsLine(rVect, tempIVect) && !GSDRI.ContainsLine(rVect, lVect)) { xNode.iConstruction.iBLane3L.Add(GVC(tempIVect, tIntHeight)); @@ -2356,7 +2499,10 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) if (!bFirst123 && GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.FourWay) { if (b2LAdded) - { xNode.iConstruction.iBLane2R.Add(GVC(tempIVect, tIntHeight)); b2RAdded = true; } + { + xNode.iConstruction.iBLane2R.Add(GVC(tempIVect, tIntHeight)); + b2RAdded = true; + } } } else if (!xNode.iConstruction.bBLane3Done_Final) @@ -2536,9 +2682,13 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) //RR: if (GSDRI.EvenAngle > 90f) - { mCornerDist = tempRoadDef * bMod1; } + { + mCornerDist = tempRoadDef * bMod1; + } else - { mCornerDist = tempRoadDef * bMod2; } + { + mCornerDist = tempRoadDef * bMod2; + } mCornerDist *= mCornerDist; t2DDist = Vector2.SqrMagnitude(CornerRR - rVect2D); if (t2DDist < mCornerDist) @@ -2554,19 +2704,25 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) { vList = xNode.iConstruction.iBLane1R; if (xNode.iConstruction.bBLane1Done_Final_ThisRound) - { vList = null; } + { + vList = null; + } } else if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane) { vList = xNode.iConstruction.iBLane2R; if (xNode.iConstruction.bBLane2Done_Final_ThisRound) - { vList = null; } + { + vList = null; + } } else if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) { vList = xNode.iConstruction.iBLane3R; if (xNode.iConstruction.bBLane3Done_Final_ThisRound) - { vList = null; } + { + vList = null; + } } eList = new List(); @@ -2635,7 +2791,9 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) vList = null; vList = xNode.iConstruction.iBLane0L; if (xNode.iConstruction.bBLane0Done_Final_ThisRound) - { vList = null; } + { + vList = null; + } eList = new List(); if (vList != null) { @@ -2665,9 +2823,13 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) } //RL: if (GSDRI.OddAngle > 90f) - { mCornerDist = tempRoadDef * bMod1; } + { + mCornerDist = tempRoadDef * bMod1; + } else - { mCornerDist = tempRoadDef * bMod2; } + { + mCornerDist = tempRoadDef * bMod2; + } mCornerDist *= mCornerDist; t2DDist = Vector2.SqrMagnitude(CornerRL - rVect2D); if (t2DDist < mCornerDist) @@ -2777,19 +2939,25 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) { vList = xNode.iConstruction.iFLane1R; if (xNode.iConstruction.bFLane1Done_Final_ThisRound) - { vList = null; } + { + vList = null; + } } else if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane) { vList = xNode.iConstruction.iFLane2R; if (xNode.iConstruction.bFLane2Done_Final_ThisRound) - { vList = null; } + { + vList = null; + } } else if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) { vList = xNode.iConstruction.iFLane3R; if (xNode.iConstruction.bFLane3Done_Final_ThisRound) - { vList = null; } + { + vList = null; + } } eList = new List(); if (vList != null) @@ -2820,9 +2988,13 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) } //LR: if (GSDRI.OddAngle > 90f) - { mCornerDist = tempRoadDef * bMod1; } + { + mCornerDist = tempRoadDef * bMod1; + } else - { mCornerDist = tempRoadDef * bMod2; } + { + mCornerDist = tempRoadDef * bMod2; + } mCornerDist *= mCornerDist; t2DDist = Vector2.SqrMagnitude(CornerLR - rVect2D); if (t2DDist < mCornerDist) @@ -2838,19 +3010,25 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) { vList = xNode.iConstruction.iBLane1R; if (xNode.iConstruction.bBLane1Done_Final_ThisRound) - { vList = null; } + { + vList = null; + } } else if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane) { vList = xNode.iConstruction.iBLane2R; if (xNode.iConstruction.bBLane2Done_Final_ThisRound) - { vList = null; } + { + vList = null; + } } else if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) { vList = xNode.iConstruction.iBLane3R; if (xNode.iConstruction.bBLane3Done_Final_ThisRound) - { vList = null; } + { + vList = null; + } } eList = new List(); @@ -2893,7 +3071,9 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) vList = null; vList = xNode.iConstruction.iBLane0L; if (xNode.iConstruction.bBLane0Done_Final_ThisRound) - { vList = null; } + { + vList = null; + } eList = new List(); if (vList != null) { @@ -2959,9 +3139,13 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) } //LL: if (GSDRI.EvenAngle > 90f) - { mCornerDist = tempRoadDef * bMod1; } + { + mCornerDist = tempRoadDef * bMod1; + } else - { mCornerDist = tempRoadDef * bMod2; } + { + mCornerDist = tempRoadDef * bMod2; + } mCornerDist *= mCornerDist; t2DDist = Vector2.SqrMagnitude(CornerLL - rVect2D); if (t2DDist < mCornerDist) @@ -3050,7 +3234,9 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) vList = null; vList = xNode.iConstruction.iBLane0L; if (xNode.iConstruction.bBLane0Done_Final_ThisRound) - { vList = null; } + { + vList = null; + } eList = new List(); if (vList != null) { @@ -3083,17 +3269,25 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) { bOverrideRampR = true; if (!tRoad.RCS.ImmuneVects.Contains(ShoulderR_lVect)) - { tRoad.RCS.ImmuneVects.Add(ShoulderR_lVect); } + { + tRoad.RCS.ImmuneVects.Add(ShoulderR_lVect); + } if (!tRoad.RCS.ImmuneVects.Contains(ShoulderR_rVect)) - { tRoad.RCS.ImmuneVects.Add(ShoulderR_rVect); } + { + tRoad.RCS.ImmuneVects.Add(ShoulderR_rVect); + } } if (bImmuneL) { bOverrideRampL = true; if (!tRoad.RCS.ImmuneVects.Contains(ShoulderL_rVect)) - { tRoad.RCS.ImmuneVects.Add(ShoulderL_rVect); } + { + tRoad.RCS.ImmuneVects.Add(ShoulderL_rVect); + } if (!tRoad.RCS.ImmuneVects.Contains(ShoulderL_lVect)) - { tRoad.RCS.ImmuneVects.Add(ShoulderL_lVect); } + { + tRoad.RCS.ImmuneVects.Add(ShoulderL_lVect); + } } } @@ -3183,16 +3377,18 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) else { RampR_R = (tVect + new Vector3(RampOuterWidthR * POS.normalized.z, 0, RampOuterWidthR * -POS.normalized.x)) + gHeight; - ; if (bOverrideRampR) - { RampR_R = RampR_Override; } //Overrides will come from intersection. + { + RampR_R = RampR_Override; + } //Overrides will come from intersection. SetVectorHeight2(ref RampR_R, ref i, ref tSpline.HeightHistory, ref tSpline); RampR_R.y -= 0.35f; RampL_L = (tVect + new Vector3(RampOuterWidthL * -POS.normalized.z, 0, RampOuterWidthL * POS.normalized.x)) + gHeight; - ; if (bOverrideRampL) - { RampL_L = RampL_Override; } //Overrides will come from intersection. + { + RampL_L = RampL_Override; + } //Overrides will come from intersection. SetVectorHeight2(ref RampL_L, ref i, ref tSpline.HeightHistory, ref tSpline); RampL_L.y -= 0.35f; bOverrideRampR = false; @@ -3494,20 +3690,28 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) // i+=Step;//Master step incrementer. } if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.EndSample(); } + { + UnityEngine.Profiling.Profiler.EndSample(); + } if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.BeginSample("RoadJob_Prelim_FinalizeInter"); } + { + UnityEngine.Profiling.Profiler.BeginSample("RoadJob_Prelim_FinalizeInter"); + } //Finalize intersection vectors: if (bInterseOn) { RoadJob_Prelim_FinalizeInter(ref tRoad); } if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.EndSample(); } + { + UnityEngine.Profiling.Profiler.EndSample(); + } if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.BeginSample("RoadJob_Prelim_RoadConnections"); } + { + UnityEngine.Profiling.Profiler.BeginSample("RoadJob_Prelim_RoadConnections"); + } //Creates road connections if necessary: // float ExtraHeight = 0f; // float RampPercent = 0.2f; @@ -3723,7 +3927,9 @@ private static void RoadJob_DoPrelim(ref GSDRoad tRoad) tRoad.RCS.RoadConnections_uv.Add(RoadConn_uv); } if (tRoad.bProfiling) - { UnityEngine.Profiling.Profiler.EndSample(); } + { + UnityEngine.Profiling.Profiler.EndSample(); + } } @@ -5323,9 +5529,9 @@ private static void RoadJob_Prelim_FinalizeInter(ref GSDRoad tRoad) { int mCount = tRoad.GSDSpline.GetNodeCount(); GSDSplineN tNode; - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - tNode = tRoad.GSDSpline.mNodes[i]; + tNode = tRoad.GSDSpline.mNodes[index]; if (tNode.bIsIntersection) { Inter_OrganizeVertices(ref tNode, ref tRoad); @@ -5350,13 +5556,13 @@ private static bool Inter_OrganizeVerticesMatchEdges(ref List tList1, r { tList1New = new List(); tList2New = new List(); - for (int i = 1; i < tList1.Count; i++) + for (int index = 1; index < tList1.Count; index++) { - tList1New.Add(tList1[i]); + tList1New.Add(tList1[index]); } - for (int i = 1; i < tList2.Count; i++) + for (int index = 1; index < tList2.Count; index++) { - tList2New.Add(tList2[i]); + tList2New.Add(tList2[index]); } } else @@ -5364,18 +5570,18 @@ private static bool Inter_OrganizeVerticesMatchEdges(ref List tList1, r if (bSkipFirstListOne) { tList1New = new List(); - for (int i = 1; i < tList1.Count; i++) + for (int index = 1; index < tList1.Count; index++) { - tList1New.Add(tList1[i]); + tList1New.Add(tList1[index]); } tList2New = tList2; } else { tList2New = new List(); - for (int i = 1; i < tList2.Count; i++) + for (int index = 1; index < tList2.Count; index++) { - tList2New.Add(tList2[i]); + tList2New.Add(tList2[index]); } tList1New = tList1; } @@ -5390,7 +5596,9 @@ private static bool Inter_OrganizeVerticesMatchEdges(ref List tList1, r int tList1Count = tList1New.Count; int tList2Count = tList2New.Count; if (tList1Count == tList2Count) - { return false; } + { + return false; + } if (tList1Count > tList2Count) { @@ -5404,13 +5612,15 @@ private static bool Inter_OrganizeVerticesMatchEdges(ref List tList1, r } if (SecondaryList == null || SecondaryList.Count == 0) - { return true; } + { + return true; + } SecondaryList.Clear(); SecondaryList = null; SecondaryList = new List(); - for (int i = 0; i < PrimaryList.Count; i++) + for (int index = 0; index < PrimaryList.Count; index++) { - SecondaryList.Add(PrimaryList[i]); + SecondaryList.Add(PrimaryList[index]); } @@ -5431,9 +5641,9 @@ private static void Inter_OrganizeVerticesMatchShoulder(ref List tShoul { // return; List BackupList = new List(); - for (int i = 0; i < tToMatch.Count; i++) + for (int index = 0; index < tToMatch.Count; index++) { - BackupList.Add(tToMatch[i]); + BackupList.Add(tToMatch[index]); } Vector2 t2D = default(Vector2); Vector2 t2D_Start = ConvertVect3_To_Vect2(StartVec); @@ -5441,17 +5651,19 @@ private static void Inter_OrganizeVerticesMatchShoulder(ref List tShoul int RealStartID = -1; StartI = StartI - 30; if (StartI < 0) - { StartI = 0; } - for (int i = StartI; i < tShoulderList.Count; i++) { - t2D = ConvertVect3_To_Vect2(tShoulderList[i]); + StartI = 0; + } + for (int index = StartI; index < tShoulderList.Count; index++) + { + t2D = ConvertVect3_To_Vect2(tShoulderList[index]); // if(t2D.x > 745f && t2D.x < 755f && t2D.y > 1240f && t2D.y < 1250f){ // int agfsdajgsd = 1; // } if (t2D == t2D_Start) { //if(tShoulderList[i] == StartVec){ - RealStartID = i; + RealStartID = index; break; } } @@ -5471,10 +5683,10 @@ private static void Inter_OrganizeVerticesMatchShoulder(ref List tShoul { if (bIsF) { - for (int i = RealStartID; i > 0; i -= 8) + for (int index = RealStartID; index > 0; index -= 8) { - t2D = ConvertVect3_To_Vect2(tShoulderList[i]); - tToMatch.Add(tShoulderList[i]); + t2D = ConvertVect3_To_Vect2(tShoulderList[index]); + tToMatch.Add(tShoulderList[index]); if (t2D == t2D_End) { //if(tShoulderList[i] == EndVect){ @@ -5490,10 +5702,10 @@ private static void Inter_OrganizeVerticesMatchShoulder(ref List tShoul } else { - for (int i = RealStartID; i < tShoulderList.Count; i += 8) + for (int index = RealStartID; index < tShoulderList.Count; index += 8) { - t2D = ConvertVect3_To_Vect2(tShoulderList[i]); - tToMatch.Add(tShoulderList[i]); + t2D = ConvertVect3_To_Vect2(tShoulderList[index]); + tToMatch.Add(tShoulderList[index]); if (t2D == t2D_End) { //if(tShoulderList[i] == EndVect){ @@ -6217,20 +6429,26 @@ public static void RoadJob2(ref GSD.Roads.RoadConstructorBufferMaker RCS) if (RCS.bRoadOn) { if (!RCS.tMeshSkip) - { RCS.uv = ProcessRoad_UVs(RCS.RoadVectors.ToArray()); } + { + RCS.uv = ProcessRoad_UVs(RCS.RoadVectors.ToArray()); + } if (!RCS.tMesh_SRSkip) - { RCS.uv_SR = ProcessRoad_UVs_Shoulder(RCS.ShoulderR_Vectors.ToArray()); } + { + RCS.uv_SR = ProcessRoad_UVs_Shoulder(RCS.ShoulderR_Vectors.ToArray()); + } if (!RCS.tMesh_SLSkip) - { RCS.uv_SL = ProcessRoad_UVs_Shoulder(RCS.ShoulderL_Vectors.ToArray()); } + { + RCS.uv_SL = ProcessRoad_UVs_Shoulder(RCS.ShoulderL_Vectors.ToArray()); + } //UVs for pavement: if (!RCS.tMeshSkip) { int vCount = RCS.RoadVectors.Count; RCS.uv2 = new Vector2[vCount]; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - RCS.uv2[i] = new Vector2(RCS.RoadVectors[i].x * 0.2f, RCS.RoadVectors[i].z * 0.2f); + RCS.uv2[index] = new Vector2(RCS.RoadVectors[index].x * 0.2f, RCS.RoadVectors[index].z * 0.2f); } } } @@ -6240,27 +6458,27 @@ public static void RoadJob2(ref GSD.Roads.RoadConstructorBufferMaker RCS) { ProcessRoad_UVs_RoadCuts(ref RCS); int cCount = RCS.cut_RoadVectors.Count; - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - RCS.cut_tangents.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris[i], RCS.cut_normals[i], RCS.cut_uv[i], RCS.cut_RoadVectors[i].ToArray())); - RCS.cut_tangents_world.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris[i], RCS.cut_normals[i], RCS.cut_uv_world[i], RCS.cut_RoadVectors[i].ToArray())); + RCS.cut_tangents.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris[index], RCS.cut_normals[index], RCS.cut_uv[index], RCS.cut_RoadVectors[index].ToArray())); + RCS.cut_tangents_world.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris[index], RCS.cut_normals[index], RCS.cut_uv_world[index], RCS.cut_RoadVectors[index].ToArray())); } } if (RCS.tRoad.opt_bShoulderCuts || RCS.tRoad.opt_bDynamicCuts) { int rCount = RCS.cut_ShoulderR_Vectors.Count; - for (int i = 0; i < rCount; i++) + for (int index = 0; index < rCount; index++) { - ProcessRoad_UVs_ShoulderCut(ref RCS, false, i); - RCS.cut_tangents_SR.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris_ShoulderR[i], RCS.cut_normals_ShoulderR[i], RCS.cut_uv_SR[i], RCS.cut_ShoulderR_Vectors[i].ToArray())); - RCS.cut_tangents_SR_world.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris_ShoulderR[i], RCS.cut_normals_ShoulderR[i], RCS.cut_uv_SR_world[i], RCS.cut_ShoulderR_Vectors[i].ToArray())); + ProcessRoad_UVs_ShoulderCut(ref RCS, false, index); + RCS.cut_tangents_SR.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris_ShoulderR[index], RCS.cut_normals_ShoulderR[index], RCS.cut_uv_SR[index], RCS.cut_ShoulderR_Vectors[index].ToArray())); + RCS.cut_tangents_SR_world.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris_ShoulderR[index], RCS.cut_normals_ShoulderR[index], RCS.cut_uv_SR_world[index], RCS.cut_ShoulderR_Vectors[index].ToArray())); } int lCount = RCS.cut_ShoulderL_Vectors.Count; - for (int i = 0; i < lCount; i++) + for (int index = 0; index < lCount; index++) { - ProcessRoad_UVs_ShoulderCut(ref RCS, true, i); - RCS.cut_tangents_SL.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris_ShoulderL[i], RCS.cut_normals_ShoulderL[i], RCS.cut_uv_SL[i], RCS.cut_ShoulderL_Vectors[i].ToArray())); - RCS.cut_tangents_SL_world.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris_ShoulderL[i], RCS.cut_normals_ShoulderL[i], RCS.cut_uv_SL_world[i], RCS.cut_ShoulderL_Vectors[i].ToArray())); + ProcessRoad_UVs_ShoulderCut(ref RCS, true, index); + RCS.cut_tangents_SL.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris_ShoulderL[index], RCS.cut_normals_ShoulderL[index], RCS.cut_uv_SL[index], RCS.cut_ShoulderL_Vectors[index].ToArray())); + RCS.cut_tangents_SL_world.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris_ShoulderL[index], RCS.cut_normals_ShoulderL[index], RCS.cut_uv_SL_world[index], RCS.cut_ShoulderL_Vectors[index].ToArray())); } } if (RCS.bInterseOn) @@ -6273,16 +6491,24 @@ public static void RoadJob2(ref GSD.Roads.RoadConstructorBufferMaker RCS) if (RCS.bRoadOn) { if (!RCS.tMeshSkip) - { RCS.tangents = GSDRootUtil.ProcessTangents(RCS.tris, RCS.normals, RCS.uv, RCS.RoadVectors.ToArray()); } + { + RCS.tangents = GSDRootUtil.ProcessTangents(RCS.tris, RCS.normals, RCS.uv, RCS.RoadVectors.ToArray()); + } if (!RCS.tMeshSkip) - { RCS.tangents2 = GSDRootUtil.ProcessTangents(RCS.tris, RCS.normals, RCS.uv2, RCS.RoadVectors.ToArray()); } + { + RCS.tangents2 = GSDRootUtil.ProcessTangents(RCS.tris, RCS.normals, RCS.uv2, RCS.RoadVectors.ToArray()); + } if (!RCS.tMesh_SRSkip) - { RCS.tangents_SR = GSDRootUtil.ProcessTangents(RCS.tris_ShoulderR, RCS.normals_ShoulderR, RCS.uv_SR, RCS.ShoulderR_Vectors.ToArray()); } + { + RCS.tangents_SR = GSDRootUtil.ProcessTangents(RCS.tris_ShoulderR, RCS.normals_ShoulderR, RCS.uv_SR, RCS.ShoulderR_Vectors.ToArray()); + } if (!RCS.tMesh_SLSkip) - { RCS.tangents_SL = GSDRootUtil.ProcessTangents(RCS.tris_ShoulderL, RCS.normals_ShoulderL, RCS.uv_SL, RCS.ShoulderL_Vectors.ToArray()); } - for (int i = 0; i < RCS.tMesh_RoadConnections.Count; i++) { - RCS.RoadConnections_tangents.Add(GSDRootUtil.ProcessTangents(RCS.RoadConnections_tris[i], RCS.RoadConnections_normals[i], RCS.RoadConnections_uv[i], RCS.RoadConnections_verts[i])); + RCS.tangents_SL = GSDRootUtil.ProcessTangents(RCS.tris_ShoulderL, RCS.normals_ShoulderL, RCS.uv_SL, RCS.ShoulderL_Vectors.ToArray()); + } + for (int index = 0; index < RCS.tMesh_RoadConnections.Count; index++) + { + RCS.RoadConnections_tangents.Add(GSDRootUtil.ProcessTangents(RCS.RoadConnections_tris[index], RCS.RoadConnections_normals[index], RCS.RoadConnections_uv[index], RCS.RoadConnections_verts[index])); } } @@ -6290,66 +6516,66 @@ public static void RoadJob2(ref GSD.Roads.RoadConstructorBufferMaker RCS) { //Back lanes: int vCount = RCS.iBLane0s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - RCS.iBLane0s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBLane0s_tris[i], RCS.iBLane0s_normals[i], RCS.iBLane0s_uv[i], RCS.iBLane0s[i])); + RCS.iBLane0s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBLane0s_tris[index], RCS.iBLane0s_normals[index], RCS.iBLane0s_uv[index], RCS.iBLane0s[index])); } vCount = RCS.iBLane1s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - RCS.iBLane1s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBLane1s_tris[i], RCS.iBLane1s_normals[i], RCS.iBLane1s_uv[i], RCS.iBLane1s[i])); + RCS.iBLane1s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBLane1s_tris[index], RCS.iBLane1s_normals[index], RCS.iBLane1s_uv[index], RCS.iBLane1s[index])); } vCount = RCS.iBLane2s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - RCS.iBLane2s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBLane2s_tris[i], RCS.iBLane2s_normals[i], RCS.iBLane2s_uv[i], RCS.iBLane2s[i])); + RCS.iBLane2s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBLane2s_tris[index], RCS.iBLane2s_normals[index], RCS.iBLane2s_uv[index], RCS.iBLane2s[index])); } vCount = RCS.iBLane3s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - RCS.iBLane3s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBLane3s_tris[i], RCS.iBLane3s_normals[i], RCS.iBLane3s_uv[i], RCS.iBLane3s[i])); + RCS.iBLane3s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBLane3s_tris[index], RCS.iBLane3s_normals[index], RCS.iBLane3s_uv[index], RCS.iBLane3s[index])); } //Front lanes: vCount = RCS.iFLane0s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - RCS.iFLane0s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFLane0s_tris[i], RCS.iFLane0s_normals[i], RCS.iFLane0s_uv[i], RCS.iFLane0s[i])); + RCS.iFLane0s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFLane0s_tris[index], RCS.iFLane0s_normals[index], RCS.iFLane0s_uv[index], RCS.iFLane0s[index])); } vCount = RCS.iFLane1s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - RCS.iFLane1s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFLane1s_tris[i], RCS.iFLane1s_normals[i], RCS.iFLane1s_uv[i], RCS.iFLane1s[i])); + RCS.iFLane1s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFLane1s_tris[index], RCS.iFLane1s_normals[index], RCS.iFLane1s_uv[index], RCS.iFLane1s[index])); } vCount = RCS.iFLane2s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - RCS.iFLane2s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFLane2s_tris[i], RCS.iFLane2s_normals[i], RCS.iFLane2s_uv[i], RCS.iFLane2s[i])); + RCS.iFLane2s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFLane2s_tris[index], RCS.iFLane2s_normals[index], RCS.iFLane2s_uv[index], RCS.iFLane2s[index])); } vCount = RCS.iFLane3s.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - RCS.iFLane3s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFLane3s_tris[i], RCS.iFLane3s_normals[i], RCS.iFLane3s_uv[i], RCS.iFLane3s[i])); + RCS.iFLane3s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFLane3s_tris[index], RCS.iFLane3s_normals[index], RCS.iFLane3s_uv[index], RCS.iFLane3s[index])); } //Main plates: vCount = RCS.iBMainPlates.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - RCS.iBMainPlates_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBMainPlates_tris[i], RCS.iBMainPlates_normals[i], RCS.iBMainPlates_uv[i], RCS.iBMainPlates[i])); + RCS.iBMainPlates_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBMainPlates_tris[index], RCS.iBMainPlates_normals[index], RCS.iBMainPlates_uv[index], RCS.iBMainPlates[index])); } vCount = RCS.iBMainPlates.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - RCS.iBMainPlates_tangents2.Add(GSDRootUtil.ProcessTangents(RCS.iBMainPlates_tris[i], RCS.iBMainPlates_normals[i], RCS.iBMainPlates_uv2[i], RCS.iBMainPlates[i])); + RCS.iBMainPlates_tangents2.Add(GSDRootUtil.ProcessTangents(RCS.iBMainPlates_tris[index], RCS.iBMainPlates_normals[index], RCS.iBMainPlates_uv2[index], RCS.iBMainPlates[index])); } vCount = RCS.iFMainPlates.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - RCS.iFMainPlates_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFMainPlates_tris[i], RCS.iFMainPlates_normals[i], RCS.iFMainPlates_uv[i], RCS.iFMainPlates[i])); + RCS.iFMainPlates_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFMainPlates_tris[index], RCS.iFMainPlates_normals[index], RCS.iFMainPlates_uv[index], RCS.iFMainPlates[index])); } vCount = RCS.iFMainPlates.Count; - for (int i = 0; i < vCount; i++) + for (int index = 0; index < vCount; index++) { - RCS.iFMainPlates_tangents2.Add(GSDRootUtil.ProcessTangents(RCS.iFMainPlates_tris[i], RCS.iFMainPlates_normals[i], RCS.iFMainPlates_uv2[i], RCS.iFMainPlates[i])); + RCS.iFMainPlates_tangents2.Add(GSDRootUtil.ProcessTangents(RCS.iFMainPlates_tris[index], RCS.iFMainPlates_normals[index], RCS.iFMainPlates_uv2[index], RCS.iFMainPlates[index])); } } } @@ -6876,14 +7102,16 @@ private static void ProcessRoad_Normals_Shoulders(ref GSD.Roads.RoadConstructorB private static void ProcessRoad_Normals_iProcessor(ref List NormalList, ref List VertexList) { if (NormalList == null) - { NormalList = new List(); } + { + NormalList = new List(); + } int vListCount = VertexList.Count; Vector3[] normals; int MVL = -1; // Vector3 tVect = -Vector3.forward; - for (int i = 0; i < vListCount; i++) + for (int index = 0; index < vListCount; index++) { - MVL = VertexList[i].Length; + MVL = VertexList[index].Length; normals = new Vector3[MVL]; // for(int j=0;j> tList, ref GSDSplineC tSpline) { int mCount = tList.Count; - int i = 0; + int index = 0; if (mCount < 1) { @@ -7991,39 +8219,39 @@ private static void SetVectorHeight2(ref Vector3 tWorldVect, ref float p, ref Li } float cValue = 0f; - for (i = 0; i < (mCount - 1); i++) + for (index = 0; index < (mCount - 1); index++) { - if (p >= tList[i].Key && p < tList[i + 1].Key) + if (p >= tList[index].Key && p < tList[index + 1].Key) { - cValue = tList[i].Value; - if (i > 3) + cValue = tList[index].Value; + if (index > 3) { - if (tList[i - 1].Value < cValue) + if (tList[index - 1].Value < cValue) { - cValue = tList[i - 1].Value; + cValue = tList[index - 1].Value; } - if (tList[i - 2].Value < cValue) + if (tList[index - 2].Value < cValue) { - cValue = tList[i - 2].Value; + cValue = tList[index - 2].Value; } - if (tList[i - 3].Value < cValue) + if (tList[index - 3].Value < cValue) { - cValue = tList[i - 3].Value; + cValue = tList[index - 3].Value; } } - if (i < (mCount - 3)) + if (index < (mCount - 3)) { - if (tList[i + 1].Value < cValue) + if (tList[index + 1].Value < cValue) { - cValue = tList[i + 1].Value; + cValue = tList[index + 1].Value; } - if (tList[i + 2].Value < cValue) + if (tList[index + 2].Value < cValue) { - cValue = tList[i + 2].Value; + cValue = tList[index + 2].Value; } - if (tList[i + 3].Value < cValue) + if (tList[index + 3].Value < cValue) { - cValue = tList[i + 3].Value; + cValue = tList[index + 3].Value; } } break; @@ -8187,9 +8415,13 @@ protected override void ThreadFunction() { float Step = (tRoad.opt_RoadDefinition * 0.4f) / tSpline.distance; if (Step > 2f) - { Step = 2f; } + { + Step = 2f; + } if (Step < 1f) - { Step = 1f; } + { + Step = 1f; + } // float tDistance = tRoad.RoadWidth()*2f; // Vector3 tVect,POS; @@ -8267,9 +8499,13 @@ public static void RunMe(ref List TTD { float Step = (tRoad.opt_RoadDefinition * 0.4f) / tSpline.distance; if (Step > 2f) - { Step = 2f; } + { + Step = 2f; + } if (Step < 1f) - { Step = 1f; } + { + Step = 1f; + } // float tDistance = tRoad.RoadWidth()*2f; // Vector3 tVect,POS; @@ -8359,14 +8595,14 @@ protected override void ThreadFunction() GSDRoadCreationT.RoadJob_Prelim(ref tRoad); GSDRoadCreationT.RoadJob1(ref RCS); } - catch (System.Exception e) + catch (System.Exception exception) { lock (GSDm_Handle) { tRoad.bEditorError = true; - tRoad.tError = e; + tRoad.tError = exception; } - throw e; + throw exception; } } @@ -8410,12 +8646,12 @@ protected override void ThreadFunction() { GSDRoadCreationT.RoadJob2(ref RCS); } - catch (System.Exception e) + catch (System.Exception exception) { lock (GSDm_Handle) { RCS.tRoad.bEditorError = true; - RCS.tRoad.tError = e; + RCS.tRoad.tError = exception; } } } diff --git a/GSDRootUtil.cs b/GSDRootUtil.cs index a7d87a78..3555a8bf 100644 --- a/GSDRootUtil.cs +++ b/GSDRootUtil.cs @@ -1,9 +1,11 @@ +#region "Imports" using UnityEngine; using System.Collections; using System.Xml; using System.Xml.Serialization; using System.IO; using System.Text; +#endregion namespace GSD @@ -288,16 +290,16 @@ public static Vector4[] ProcessTangents(int[] tris, Vector3[] normals, Vector2[] } Vector3 n, t;//,tmp; - for (int i = 0; i < MVL; i++) + for (int index = 0; index < MVL; index++) { - n = normals[i]; - t = tan1[i]; + n = normals[index]; + t = tan1[index]; Vector3.OrthoNormalize(ref n, ref t); - tangents[i].x = t.x; - tangents[i].y = t.y; - tangents[i].z = t.z; - tangents[i].w = (Vector3.Dot(Vector3.Cross(n, t), tan2[i]) < 0.0f) ? -1.0f : 1.0f; + tangents[index].x = t.x; + tangents[index].y = t.y; + tangents[index].z = t.z; + tangents[index].w = (Vector3.Dot(Vector3.Cross(n, t), tan2[index]) < 0.0f) ? -1.0f : 1.0f; // tmp = (t - n * Vector3.Dot(n, t)).normalized; // tangents[i] = new Vector4(tmp.x, tmp.y, tmp.z); diff --git a/GSDTrafficLightController.cs b/GSDTrafficLightController.cs index 5571444a..4bedf72d 100644 --- a/GSDTrafficLightController.cs +++ b/GSDTrafficLightController.cs @@ -99,22 +99,22 @@ public GSDTrafficLightController(ref GameObject _LightLeft, ref GameObject _Ligh Lights_R = new Light[mCount]; Lights_Y = new Light[mCount]; Lights_G = new Light[mCount]; - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - tLights = LightsObj[i].transform.GetComponentsInChildren(); + tLights = LightsObj[index].transform.GetComponentsInChildren(); foreach (Light tLight in tLights) { if (tLight.transform.name.ToLower().Contains("redlight")) { - Lights_R[i] = tLight; + Lights_R[index] = tLight; } if (tLight.transform.name.ToLower().Contains("yellowlight")) { - Lights_Y[i] = tLight; + Lights_Y[index] = tLight; } if (tLight.transform.name.ToLower().Contains("greenl")) { - Lights_G[i] = tLight; + Lights_G[index] = tLight; } } } @@ -157,9 +157,9 @@ private void TriggerRegular() if (bMain) { MRChange(ref MR_Main, iLightSubStatus); - for (int i = 1; i < MR_MainsStorage.Length; i++) + for (int index = 1; index < MR_MainsStorage.Length; index++) { - MRChange(ref MR_MainsStorage[i], iLightSubStatus); + MRChange(ref MR_MainsStorage[index], iLightSubStatus); } LightChange(0, iLightSubStatus); } @@ -234,9 +234,9 @@ private void TriggerMasterLeft() if (bMain) { MRChange(ref MR_Main, iLightSubStatus); - for (int i = 1; i < MR_MainsStorage.Length; i++) + for (int index = 1; index < MR_MainsStorage.Length; index++) { - MRChange(ref MR_MainsStorage[i], iLightSubStatus); + MRChange(ref MR_MainsStorage[index], iLightSubStatus); } LightChange(0, iLightSubStatus); } @@ -265,9 +265,9 @@ private void TriggerRightTurn() if (bMain) { MRChange(ref MR_Main, iLightSubStatusEnum.Red); - for (int i = 1; i < MR_MainsStorage.Length; i++) + for (int index = 1; index < MR_MainsStorage.Length; index++) { - MRChange(ref MR_MainsStorage[i], iLightSubStatusEnum.Red); + MRChange(ref MR_MainsStorage[index], iLightSubStatusEnum.Red); } LightChange(0, iLightSubStatusEnum.Red); } @@ -289,9 +289,9 @@ private void TriggerRed() if (bMain) { MRChange(ref MR_Main, iLightSubStatusEnum.Red); - for (int i = 1; i < MR_MainsStorage.Length; i++) + for (int index = 1; index < MR_MainsStorage.Length; index++) { - MRChange(ref MR_MainsStorage[i], iLightSubStatusEnum.Red); + MRChange(ref MR_MainsStorage[index], iLightSubStatusEnum.Red); } LightChange(0, iLightSubStatusEnum.Red); } @@ -400,11 +400,11 @@ private void LightChange(int tIndex, iLightSubStatusEnum iLSSE) if (!bLightsEnabled) { int mCount = MR_MainsStorage.Length; - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - Lights_R[i].enabled = false; - Lights_Y[i].enabled = false; - Lights_G[i].enabled = false; + Lights_R[index].enabled = false; + Lights_Y[index].enabled = false; + Lights_G[index].enabled = false; } if (LightLeft_R != null) { @@ -437,9 +437,9 @@ private void LightChange(int tIndex, iLightSubStatusEnum iLSSE) { //Main: int mCount = MR_MainsStorage.Length; - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - LightChangeHelper(ref Lights_R[i], ref Lights_Y[i], ref Lights_G[i], iLSSE); + LightChangeHelper(ref Lights_R[index], ref Lights_Y[index], ref Lights_G[index], iLSSE); } } else if (tIndex == 1) @@ -494,24 +494,28 @@ public void Setup(bool bLeftYield) private void SetupMainObjects() { if (MR_Main == null) - { return; } + { + return; + } int mCount = MR_MainsStorage.Length; if (mCount == 0) - { return; } + { + return; + } SetupObject(MR_Main); if (mCount > 1) { - for (int i = 1; i < mCount; i++) + for (int index = 1; index < mCount; index++) { if (bUseSharedMaterial) { - MR_MainsStorage[i].sharedMaterial = MR_Main.sharedMaterial; + MR_MainsStorage[index].sharedMaterial = MR_Main.sharedMaterial; } else { Material[] materials = new Material[1]; materials[0] = MR_Main.materials[0]; - MR_MainsStorage[i].materials = materials; + MR_MainsStorage[index].materials = materials; } @@ -523,7 +527,9 @@ private void SetupMainObjects() private void SetupObject(MeshRenderer MR) { if (MR != null) - { MR.material = MR.material; } + { + MR.material = MR.material; + } } #endregion } diff --git a/GSDUnitTests.cs b/GSDUnitTests.cs index 9af9b0e0..b7bb5707 100644 --- a/GSDUnitTests.cs +++ b/GSDUnitTests.cs @@ -31,12 +31,12 @@ public static void RoadArchitectUnitTests() int numTests = 5; double totalTestTime = 0f; - for (int i = 1; i <= numTests; i++) + for (int index = 1; index <= numTests; index++) { - UnityEngine.Debug.Log("Running test " + i); - double testTime = RunTest(i); + UnityEngine.Debug.Log("Running test " + index); + double testTime = RunTest(index); totalTestTime += testTime; - UnityEngine.Debug.Log("Test " + i + " complete. Test time: " + testTime + "ms"); + UnityEngine.Debug.Log("Test " + index + " complete. Test time: " + testTime + "ms"); } UnityEngine.Debug.Log("All tests completed. Total test time: " + totalTestTime + "ms"); @@ -116,10 +116,10 @@ private static void RoadArchitectUnitTest1() int MaxCount = 18; float tMod = 100f; Vector3 xVect = new Vector3(50f, 40f, 50f); - for (int i = 0; i < MaxCount; i++) + for (int index = 0; index < MaxCount; index++) { //tLocs.Add(xVect + new Vector3(tMod * Mathf.Pow((float)i / ((float)MaxCount * 0.15f), 2f), 1f*((float)i*1.25f), tMod * i)); - nodeLocations.Add(xVect + new Vector3(tMod * Mathf.Pow((float) i / ((float) 25 * 0.15f), 2f), 0f, tMod * i)); + nodeLocations.Add(xVect + new Vector3(tMod * Mathf.Pow((float) index / ((float) 25 * 0.15f), 2f), 0f, tMod * index)); } //Get road system create road: @@ -178,53 +178,53 @@ private static void RoadArchitectUnitTest2() //Create base road: List nodeLocations = new List(); - for (int i = 0; i < 9; i++) + for (int index = 0; index < 9; index++) { - nodeLocations.Add(new Vector3(StartLocX + (i * 200f), tHeight, 600f)); + nodeLocations.Add(new Vector3(StartLocX + (index * 200f), tHeight, 600f)); } bRoad = GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); //Get road system, create road #1: nodeLocations.Clear(); - for (int i = 0; i < 5; i++) + for (int index = 0; index < 5; index++) { - nodeLocations.Add(new Vector3(StartLocX, tHeight, StartLocY + (i * StartLocYSep))); + nodeLocations.Add(new Vector3(StartLocX, tHeight, StartLocY + (index * StartLocYSep))); } tRoad = GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); //UnitTest_IntersectionHelper(bRoad, tRoad, GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.NoTurnLane); //Get road system, create road #2: nodeLocations.Clear(); - for (int i = 0; i < 5; i++) + for (int index = 0; index < 5; index++) { - nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 2f), tHeight, StartLocY + (i * StartLocYSep))); + nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 2f), tHeight, StartLocY + (index * StartLocYSep))); } tRoad = GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); //UnitTest_IntersectionHelper(bRoad, tRoad, GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.TurnLane); //Get road system, create road #3: nodeLocations.Clear(); - for (int i = 0; i < 5; i++) + for (int index = 0; index < 5; index++) { - nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 4f), tHeight, StartLocY + (i * StartLocYSep))); + nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 4f), tHeight, StartLocY + (index * StartLocYSep))); } tRoad = GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); //UnitTest_IntersectionHelper(bRoad, tRoad, GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.BothTurnLanes); //Get road system, create road #4: nodeLocations.Clear(); - for (int i = 0; i < 5; i++) + for (int index = 0; index < 5; index++) { - nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 6f), tHeight, StartLocY + (i * StartLocYSep))); + nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 6f), tHeight, StartLocY + (index * StartLocYSep))); } tRoad = GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); //UnitTest_IntersectionHelper(bRoad, tRoad, GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.TurnLane); //Get road system, create road #4: nodeLocations.Clear(); - for (int i = 0; i < 5; i++) + for (int index = 0; index < 5; index++) { - nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 8f), tHeight, StartLocY + (i * StartLocYSep))); + nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 8f), tHeight, StartLocY + (index * StartLocYSep))); } tRoad = GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); //UnitTest_IntersectionHelper(bRoad, tRoad, GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.TurnLane); @@ -294,9 +294,9 @@ private static void RoadArchitectUnitTest3() //Create base road: List nodeLocations = new List(); - for (int i = 0; i < 9; i++) + for (int index = 0; index < 9; index++) { - nodeLocations.Add(new Vector3(StartLocX + (i * StartLocYSep), tHeight, StartLocY + (StartLocYSep * 2f))); + nodeLocations.Add(new Vector3(StartLocX + (index * StartLocYSep), tHeight, StartLocY + (StartLocYSep * 2f))); } bRoad = GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); bRoad.opt_Lanes = 4; @@ -304,9 +304,9 @@ private static void RoadArchitectUnitTest3() //Get road system, create road #1: nodeLocations.Clear(); - for (int i = 0; i < 5; i++) + for (int index = 0; index < 5; index++) { - nodeLocations.Add(new Vector3(StartLocX, tHeight, StartLocY + (i * StartLocYSep))); + nodeLocations.Add(new Vector3(StartLocX, tHeight, StartLocY + (index * StartLocYSep))); } tRoad = GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); tRoad.opt_Lanes = 4; @@ -314,9 +314,9 @@ private static void RoadArchitectUnitTest3() //Get road system, create road #2: nodeLocations.Clear(); - for (int i = 0; i < 5; i++) + for (int index = 0; index < 5; index++) { - nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 2f), tHeight, StartLocY + (i * StartLocYSep))); + nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 2f), tHeight, StartLocY + (index * StartLocYSep))); } tRoad = GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); tRoad.opt_Lanes = 4; @@ -324,9 +324,9 @@ private static void RoadArchitectUnitTest3() //Get road system, create road #3: nodeLocations.Clear(); - for (int i = 0; i < 5; i++) + for (int index = 0; index < 5; index++) { - nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 4f), tHeight, StartLocY + (i * StartLocYSep))); + nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 4f), tHeight, StartLocY + (index * StartLocYSep))); } tRoad = GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); tRoad.opt_Lanes = 4; @@ -334,9 +334,9 @@ private static void RoadArchitectUnitTest3() //Get road system, create road #4: nodeLocations.Clear(); - for (int i = 0; i < 5; i++) + for (int index = 0; index < 5; index++) { - nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 6f), tHeight, StartLocY + (i * StartLocYSep))); + nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 6f), tHeight, StartLocY + (index * StartLocYSep))); } tRoad = GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); tRoad.opt_Lanes = 4; @@ -344,9 +344,9 @@ private static void RoadArchitectUnitTest3() //Get road system, create road #5: nodeLocations.Clear(); - for (int i = 0; i < 5; i++) + for (int index = 0; index < 5; index++) { - nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 8f), tHeight, StartLocY + (i * StartLocYSep))); + nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 8f), tHeight, StartLocY + (index * StartLocYSep))); } tRoad = GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); tRoad.opt_Lanes = 4; @@ -373,9 +373,9 @@ private static void RoadArchitectUnitTest4() { //Create base road: List nodeLocations = new List(); - for (int i = 0; i < 5; i++) + for (int index = 0; index < 5; index++) { - nodeLocations.Add(new Vector3(3500f, 90f, 200f + (800f * i))); + nodeLocations.Add(new Vector3(3500f, 90f, 200f + (800f * index))); } GSDRoad tRoad = GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); @@ -394,17 +394,17 @@ private static void RoadArchitectUnitTest5() { //Create base road: List nodeLocations = new List(); - for (int i = 0; i < 48; i++) + for (int index = 0; index < 48; index++) { - nodeLocations.Add(new Vector3(3000f, 40f, 10f + (79f * i))); + nodeLocations.Add(new Vector3(3000f, 40f, 10f + (79f * index))); } - for (int i = 0; i < 35; i++) + for (int index = 0; index < 35; index++) { - nodeLocations.Add(new Vector3(2900f - (79f * i), 30f, 3960f)); + nodeLocations.Add(new Vector3(2900f - (79f * index), 30f, 3960f)); } - for (int i = 0; i < 40; i++) + for (int index = 0; index < 40; index++) { - nodeLocations.Add(new Vector3(30, 30f, 3960f - (79f * i))); + nodeLocations.Add(new Vector3(30, 30f, 3960f - (79f * index))); } GSDRoadAutomation.CreateRoad_Programmatically(RoadSystem, ref nodeLocations); } diff --git a/Shaders.meta b/Shaders.meta new file mode 100644 index 00000000..82252e63 --- /dev/null +++ b/Shaders.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a6054d734a7c18a4c9608df817d3251f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Spline/GSDSplineC.cs b/Spline/GSDSplineC.cs index a7950200..12f214d3 100644 --- a/Spline/GSDSplineC.cs +++ b/Spline/GSDSplineC.cs @@ -555,9 +555,13 @@ private void RoadDefCalcs() float tempTotalDistance = 0f; float tempDistanceHolder = 0f; if (RoadDefKeysArray != null) - { RoadDefKeysArray = null; } + { + RoadDefKeysArray = null; + } if (RoadDefValuesArray != null) - { RoadDefValuesArray = null; } + { + RoadDefValuesArray = null; + } List RoadDefKeys = new List(); List RoadDefValues = new List(); @@ -565,16 +569,16 @@ private void RoadDefCalcs() RoadDefKeys.Add(0); RoadDefValues.Add(0f); - for (float i = 0f; i < 1f; i += step) + for (float index = 0f; index < 1f; index += step) { - cPos = GetSplineValue(i); + cPos = GetSplineValue(index); tempDistanceHolder = Vector3.Distance(cPos, prevPos); tempTotalDistance += tempDistanceHolder; tempDistanceMod += tempDistanceHolder; if (tempDistanceMod > tempDistanceModMax) { tempDistanceMod = 0f; - RoadDefKeys.Add(TranslateParamToInt(i)); + RoadDefKeys.Add(TranslateParamToInt(index)); RoadDefValues.Add(tempTotalDistance); } prevPos = cPos; @@ -640,9 +644,13 @@ public int GetClosestRoadDefIndex(float tX, bool bRoundUp = false, bool bRoundDo int x = TranslateParamToInt(tX); if (bRoundUp) - { return hiIndex; } + { + return hiIndex; + } if (bRoundDown) - { return loIndex; } + { + return loIndex; + } if ((x - lo) > (hi - x)) { @@ -782,10 +790,10 @@ public float TranslateParamToDist(float param) /// /// The relevant param (0-1) of the spline. /// - /// + /// /// True for is tangent, false (default) for vector3 position. /// - public Vector3 GetSplineValue(float _value, bool isTangent = false) // float _value, formerly f; Renamed boolb to reflect its use according to the summary of this function + public Vector3 GetSplineValue(float _value, bool _isTangent = false) // float _value, formerly f; Renamed boolb to reflect its use according to the summary of this function { int index; // index, formerly i int idx = -1; @@ -800,59 +808,74 @@ public float TranslateParamToDist(float param) return mNodes[0].pos; } - // if(GSDRootUtil.IsApproximately(f,0f,0.00001f)){ - // if(b){ - // return mNodes[0].tangent; - // }else{ - // return mNodes[0].pos; - // } - // }else - // if(GSDRootUtil.IsApproximately(f,1f,0.00001f) || f > 1f){ - // if(b){ - // return mNodes[mNodes.Count-1].tangent; - // }else{ - // return mNodes[mNodes.Count-1].pos; - // } - // }else{ - //GSDRootUtil.IsApproximately(f,1f,0.00001f) - for (index = 0; index < mNodes.Count; index++) + // FH 03.02.19 // This Code was outcommented, but it takes care about values above and below 0f and 1f and clamping them. + // This Fixes the Bug with 1f -> -0.0001f as descripted by embeddedt/RoadArchitect/issues/4 + if (GSDRootUtil.IsApproximately(_value, 0f, 0.00001f)) { - if (index == mNodes.Count - 1) + if (_isTangent) { - idx = index - 1; - break; + return mNodes[0].tangent; } - if (mNodes[index].tTime > _value) + else { - idx = index - 1; - break; + return mNodes[0].pos; } } - if (idx < 0) + else + if (GSDRootUtil.IsApproximately(_value, 1f, 0.00001f) || _value > 1f) { - idx = 0; + if (_isTangent) + { + return mNodes[mNodes.Count - 1].tangent; + } + else + { + return mNodes[mNodes.Count - 1].pos; + } } - // } + else + { + GSDRootUtil.IsApproximately(_value, 1f, 0.00001f); + // FH 03.02.19 // End of the former outcommented Code + + for (index = 0; index < mNodes.Count; index++) + { + if (index == mNodes.Count - 1) + { + idx = index - 1; + break; + } + if (mNodes[index].tTime > _value) + { + idx = index - 1; + break; + } + } + if (idx < 0) + { + idx = 0; + } + } // // FH 03.02.19 // also former outcommented Code, see above float param = (_value - mNodes[idx].tTime) / (mNodes[idx + 1].tTime - mNodes[idx].tTime); param = GSDRootUtil.Ease(param, mNodes[idx].EaseIO.x, mNodes[idx].EaseIO.y); - return GetHermiteInternal(idx, param, isTangent); + return GetHermiteInternal(idx, param, _isTangent); } - public void GetSplineValue_Both(float f, out Vector3 tVect1, out Vector3 tVect2) + public void GetSplineValue_Both(float _value, out Vector3 tVect1, out Vector3 tVect2) // former VarNames: f = _value { - int i; + int index; int idx = -1; int mCount = GetNodeCount(); - if (f < 0f) + if (_value < 0f) { - f = 0f; + _value = 0f; } - if (f > 1f) + if (_value > 1f) { - f = 1f; + _value = 1f; } @@ -878,34 +901,44 @@ public void GetSplineValue_Both(float f, out Vector3 tVect1, out Vector3 tVect2) return; } - // if(GSDRootUtil.IsApproximately(f,1f,0.0001f)){ - // tVect1 = mNodes[mNodes.Count-1].pos; - // tVect2 = mNodes[mNodes.Count-1].tangent; - // return; - // } - // else if(GSDRootUtil.IsApproximately(f,0f,0.0001f)){ - // tVect1 = mNodes[0].pos; - // tVect2 = mNodes[0].tangent; - // return; - // } - for (i = 1; i < mCount; i++) + // FH 03.02.19 // This Code was outcommented, but it takes care about values above and below 0f and 1f and clamping them. + // This code needs to be reevealuated if this isn't taken care of by the function above this one. GetSplineValue() + // Right now, I would say that it is not really a part of embeddedt/RoadArchitect/issues/4 + if (GSDRootUtil.IsApproximately(_value, 1f, 0.0001f)) { - if (i == mCount - 1) + tVect1 = mNodes[mNodes.Count - 1].pos; + tVect2 = mNodes[mNodes.Count - 1].tangent; + return; + } + else if (GSDRootUtil.IsApproximately(_value, 0f, 0.0001f)) + { + tVect1 = mNodes[0].pos; + tVect2 = mNodes[0].tangent; + return; + } + // FH 10.02.19 // Do Note: This does prevent EdgeObjects from being placed before or after 0f/1f on the Spline, but also causes the EdgeObject to be placed at the same Position at the End of the Spline. + // FH 03.02.19 // End of the former outcommented Code + + for (index = 1; index < mCount; index++) + { + if (index == mCount - 1) { - idx = i - 1; + idx = index - 1; break; } - if (mNodes[i].tTime > f) + if (mNodes[index].tTime > _value) { - idx = i - 1; + idx = index - 1; break; } } if (idx < 0) - { idx = 0; } + { + idx = 0; + } - float param = (f - mNodes[idx].tTime) / (mNodes[idx + 1].tTime - mNodes[idx].tTime); + float param = (_value - mNodes[idx].tTime) / (mNodes[idx + 1].tTime - mNodes[idx].tTime); param = GSDRootUtil.Ease(param, mNodes[idx].EaseIO.x, mNodes[idx].EaseIO.y); tVect1 = GetHermiteInternal(idx, param, false); @@ -915,7 +948,7 @@ public void GetSplineValue_Both(float f, out Vector3 tVect1, out Vector3 tVect2) public Vector3 GetSplineValue_SkipOpt(float f, bool b = false) { - int i; + int index; int idx = -1; if (mNodes.Count == 0) @@ -942,21 +975,23 @@ public Vector3 GetSplineValue_SkipOpt(float f, bool b = false) // return mNodes[mNodes.Count-1].pos; // } // }else{ - for (i = 1; i < mNodes.Count; i++) + for (index = 1; index < mNodes.Count; index++) { - if (i == mNodes.Count - 1) + if (index == mNodes.Count - 1) { - idx = i - 1; + idx = index - 1; break; } - if (mNodes[i].tTime > f) + if (mNodes[index].tTime > f) { - idx = i - 1; + idx = index - 1; break; } } if (idx < 0) - { idx = 0; } + { + idx = 0; + } // if(b && GSDRootUtil.IsApproximately(f,1f,0.00001f)){ // idx = mNodes.Count-2; // } @@ -1071,15 +1106,22 @@ private float GetClosestPoint_Helper(ref Vector3 tVect, float tStep, float BestV int jStart = (CachedIndex - Step1); if (jStart < 50) - { jStart = 0; } + { + jStart = 0; + } int jEnd = (CachedIndex + Step1); if (jEnd > (CachedPointsLength)) - { jEnd = CachedPointsLength; } + { + jEnd = CachedPointsLength; + } for (int j = jStart; j < jEnd; j++) { cVect = CachedPoints[j]; if (bSetBestValue) - { BestVect_n = cVect; bSetBestValue = false; } + { + BestVect_n = cVect; + bSetBestValue = false; + } tDistance = Vector3.Distance(tVect, cVect); if (tDistance < mDistance) { @@ -1104,16 +1146,19 @@ private float GetClosestPoint_Helper(ref Vector3 tVect, float tStep, float BestV } else { - for (float i = tMin; i <= tMax; i += tStep) + for (float index = tMin; index <= tMax; index += tStep) { - cVect = GetSplineValue(i); + cVect = GetSplineValue(index); if (bSetBestValue) - { BestVect_n = cVect; bSetBestValue = false; } + { + BestVect_n = cVect; + bSetBestValue = false; + } tDistance = Vector3.Distance(tVect, cVect); if (tDistance < mDistance) { mDistance = tDistance; - BestValue = i; + BestValue = index; if (!bFirstLoopHappened) { BestVect_p = cVect; @@ -1196,16 +1241,24 @@ private Vector3 GetHermiteInternal(int i, double t, bool bTangent = false) if (Vector3.Distance(P1, P3) > tMaxMag) { if (xVect1.magnitude > tMaxMag) - { xVect1 = Vector3.ClampMagnitude(xVect1, tMaxMag); } + { + xVect1 = Vector3.ClampMagnitude(xVect1, tMaxMag); + } if (xVect2.magnitude > tMaxMag) - { xVect2 = Vector3.ClampMagnitude(xVect2, tMaxMag); } + { + xVect2 = Vector3.ClampMagnitude(xVect2, tMaxMag); + } } else if (Vector3.Distance(P0, P2) > tMaxMag) { if (xVect1.magnitude > tMaxMag) - { xVect1 = Vector3.ClampMagnitude(xVect1, tMaxMag); } + { + xVect1 = Vector3.ClampMagnitude(xVect1, tMaxMag); + } if (xVect2.magnitude > tMaxMag) - { xVect2 = Vector3.ClampMagnitude(xVect2, tMaxMag); } + { + xVect2 = Vector3.ClampMagnitude(xVect2, tMaxMag); + } } @@ -1227,7 +1280,12 @@ private Vector3 GetHermiteInternal(int i, double t, bool bTangent = false) Vector3 tVect = BL0 * P0 + BL1 * P1 + BL2 * xVect1 + BL3 * xVect2; if (!bTangent) - { if (tVect.y < 0f) { tVect.y = 0f; } } + { + if (tVect.y < 0f) + { + tVect.y = 0f; + } + } return tVect; } @@ -1308,14 +1366,14 @@ void OnDrawGizmosSelected() float step = GizmoDrawMeters / distance; step = Mathf.Clamp(step, 0f, 1f); Gizmos.color = new Color(1f, 0f, 0f, 1f); - float i = 0f; + float index = 0f; Vector3 cPos; float tCheck = 0f; Vector3 camPos = Camera.current.transform.position; - for (i = 0f; i <= 1f; i += step) + for (index = 0f; index <= 1f; index += step) { tCheck += step; - cPos = GetSplineValue(i); + cPos = GetSplineValue(index); if (tCheck > 0.1f) { @@ -1355,7 +1413,7 @@ void OnDrawGizmosSelected() Gizmos.DrawLine(prevPos + tempVect, cPos + tempVect); prevPos = cPos; - if ((i + step) > 1f) + if ((index + step) > 1f) { cPos = GetSplineValue(1f); Gizmos.DrawLine(prevPos + tempVect, cPos + tempVect); @@ -1373,9 +1431,9 @@ public bool IsNearIntersection(ref Vector3 tPos, ref float nResult) GSDSplineN tNode; float MetersToCheck = 75f * ((tRoad.opt_LaneWidth / 5f) * (tRoad.opt_LaneWidth / 5f)); float tDist; - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - tNode = mNodes[i]; + tNode = mNodes[index]; if (tNode.bIsIntersection) { tNode.GSDRI.Height = tNode.pos.y; @@ -1393,7 +1451,6 @@ public bool IsNearIntersection(ref Vector3 tPos, ref float nResult) if (bUseSQ) { MetersToCheck = MetersToCheck_NoTurnLaneSQ * ((tRoad.opt_LaneWidth / 5f) * (tRoad.opt_LaneWidth / 5f)); - ; } // else{ // MetersToCheck = MetersToCheck_NoTurnLane; @@ -1452,9 +1509,9 @@ public float IntersectionStrength(ref Vector3 tPos, ref float nResult, ref GSDRo float MetersToCheck = 75f * ((tRoad.opt_LaneWidth / 5f) * (tRoad.opt_LaneWidth / 5f)); - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - tNode = mNodes[i]; + tNode = mNodes[index]; if (tNode.bIsIntersection) { tNode.GSDRI.Height = tNode.pos.y; @@ -1718,9 +1775,9 @@ public bool IsInBridge(float p) { return false; } - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - KVP = BridgeParams[i]; + KVP = BridgeParams[index]; if (GSDRootUtil.IsApproximately(KVP.Key, p, 0.0001f) || GSDRootUtil.IsApproximately(KVP.Value, p, 0.0001f)) { return true; @@ -1749,9 +1806,9 @@ public float BridgeUpComing(float p) { return 1f; } - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - KVP = BridgeParams[i]; + KVP = BridgeParams[index]; if (GSDRootUtil.IsApproximately(KVP.Key, p, 0.0001f) || GSDRootUtil.IsApproximately(KVP.Value, p, 0.0001f)) { @@ -1778,9 +1835,9 @@ public bool IsInBridgeTerrain(float p) { return false; } - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - KVP = BridgeParams[i]; + KVP = BridgeParams[index]; if (GSDRootUtil.IsApproximately(KVP.Key + (10f / distance), p, 0.0001f) || GSDRootUtil.IsApproximately(KVP.Value - (10f / distance), p, 0.0001f)) { return true; @@ -1806,9 +1863,9 @@ public float GetBridgeEnd(float p) { return -1f; } - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - KVP = BridgeParams[i]; + KVP = BridgeParams[index]; if (p >= KVP.Key && p <= KVP.Value) { return KVP.Value; @@ -1832,9 +1889,9 @@ public bool IsInTunnel(float p) { return false; } - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - KVP = TunnelParams[i]; + KVP = TunnelParams[index]; if (GSDRootUtil.IsApproximately(KVP.Key, p, 0.0001f) || GSDRootUtil.IsApproximately(KVP.Value, p, 0.0001f)) { return true; @@ -1863,9 +1920,9 @@ public float TunnelUpComing(float p) { return 1f; } - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - KVP = TunnelParams[i]; + KVP = TunnelParams[index]; if (GSDRootUtil.IsApproximately(KVP.Key, p, 0.0001f) || GSDRootUtil.IsApproximately(KVP.Value, p, 0.0001f)) { @@ -1892,9 +1949,9 @@ public bool IsInTunnelTerrain(float p) { return false; } - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - KVP = TunnelParams[i]; + KVP = TunnelParams[index]; if (GSDRootUtil.IsApproximately(KVP.Key + (10f / distance), p, 0.0001f) || GSDRootUtil.IsApproximately(KVP.Value - (10f / distance), p, 0.0001f)) { return true; @@ -1920,9 +1977,9 @@ public float GetTunnelEnd(float p) { return -1f; } - for (int i = 0; i < cCount; i++) + for (int index = 0; index < cCount; index++) { - KVP = TunnelParams[i]; + KVP = TunnelParams[index]; if (p >= KVP.Key && p <= KVP.Value) { return KVP.Value; @@ -2067,10 +2124,14 @@ private void ActivateEndNodeConnection_Do(GSDSplineN tNode1, GSDSplineN tNode2) tNode2.bSpecialRoadConnPrimary = true; NodeCreated2.bSpecialRoadConnPrimary = true; if (tNode2.GSDSpline.tRoad.opt_Lanes == 4) - { xWidth *= 2f; } + { + xWidth *= 2f; + } tDelay = (tNode1.GSDSpline.tRoad.opt_Lanes - tNode2.GSDSpline.tRoad.opt_Lanes) * xWidth; if (tDelay < 10f) - { tDelay = 10f; } + { + tDelay = 10f; + } if (bSecondNode_Start) { tNode2.GSDSpline.bSpecialEndNode_IsStart_Delay = true; @@ -2094,7 +2155,9 @@ private void ActivateEndNodeConnection_Do(GSDSplineN tNode1, GSDSplineN tNode2) { xWidth *= 2f; } tDelay = (tNode2.GSDSpline.tRoad.opt_Lanes - tNode1.GSDSpline.tRoad.opt_Lanes) * xWidth; if (tDelay < 10f) - { tDelay = 10f; } + { + tDelay = 10f; + } if (bFirstNode_Start) { tNode1.GSDSpline.bSpecialEndNode_IsStart_Delay = true; @@ -2174,14 +2237,14 @@ public int GetNodeCountNonNull() { int mCount = GetNodeCount(); int tCount = 0; - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - if (mNodes[i] != null) + if (mNodes[index] != null) { tCount += 1; - if (mNodes[i].bIsIntersection && mNodes[i].GSDRI == null) + if (mNodes[index].bIsIntersection && mNodes[index].GSDRI == null) { - DestroyIntersection(mNodes[i]); + DestroyIntersection(mNodes[index]); } } } @@ -2193,14 +2256,14 @@ public bool CheckInvalidNodeCount() { int mCount = GetNodeCount(); int tCount = 0; - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - if (mNodes[i] != null) + if (mNodes[index] != null) { tCount += 1; - if (mNodes[i].bIsIntersection && mNodes[i].GSDRI == null) + if (mNodes[index].bIsIntersection && mNodes[index].GSDRI == null) { - DestroyIntersection(mNodes[i]); + DestroyIntersection(mNodes[index]); } } else @@ -2223,12 +2286,12 @@ public GSDSplineN GetCurrentNode(float p) { int mCount = GetNodeCount(); GSDSplineN tNode = null; - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - tNode = mNodes[i]; + tNode = mNodes[index]; if (tNode.tTime > p) { - tNode = mNodes[i - 1]; + tNode = mNodes[index - 1]; return tNode; } } @@ -2240,9 +2303,9 @@ public GSDSplineN GetLastLegitimateNode() { int mCount = GetNodeCount(); GSDSplineN tNode = null; - for (int i = (mCount - 1); i >= 0; i--) + for (int index = (mCount - 1); index >= 0; index--) { - tNode = mNodes[i]; + tNode = mNodes[index]; if (tNode.IsLegitimate()) { return tNode; @@ -2280,9 +2343,9 @@ public GSDSplineN GetPrevLegitimateNode(int tIndex) try { GSDSplineN tNode = null; - for (int i = (tIndex - 1); i >= 0; i--) + for (int index = (tIndex - 1); index >= 0; index--) { - tNode = mNodes[i]; + tNode = mNodes[index]; if (tNode.IsLegitimateGrade()) { return tNode; @@ -2301,9 +2364,9 @@ public GSDSplineN GetNextLegitimateNode(int tIndex) { GSDSplineN tNode = null; int mCount = GetNodeCount(); - for (int i = (tIndex + 1); i < mCount; i++) + for (int index = (tIndex + 1); index < mCount; index++) { - tNode = mNodes[i]; + tNode = mNodes[index]; if (tNode.IsLegitimateGrade()) { return tNode; @@ -2311,13 +2374,15 @@ public GSDSplineN GetNextLegitimateNode(int tIndex) } return null; } + + #if UNITY_EDITOR public void ClearAllRoadCuts() { int mCount = GetNodeCount(); - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - mNodes[i].ClearCuts(); + mNodes[index].ClearCuts(); } } #endif diff --git a/Spline/GSDSplineF.cs b/Spline/GSDSplineF.cs index 2753e16b..25bb6f44 100644 --- a/Spline/GSDSplineF.cs +++ b/Spline/GSDSplineF.cs @@ -157,7 +157,7 @@ public void Setup(ref Vector3[] tVects) private void Setup_Nodes(ref Vector3[] tVects) { //Process nodes: - int i = 0; + int index = 0; if (mNodes != null) { mNodes.Clear(); @@ -166,30 +166,30 @@ private void Setup_Nodes(ref Vector3[] tVects) mNodes = new List(); GSDSplineFN tNode; - for (i = 0; i < tVects.Length; i++) + for (index = 0; index < tVects.Length; index++) { tNode = new GSDSplineFN(); - tNode.pos = tVects[i]; + tNode.pos = tVects[index]; mNodes.Add(tNode); } float step; Quaternion rot; step = (bClosed) ? 1f / mNodes.Count : 1f / (mNodes.Count - 1); - for (i = 0; i < mNodes.Count; i++) + for (index = 0; index < mNodes.Count; index++) { - tNode = mNodes[i]; + tNode = mNodes[index]; rot = Quaternion.identity; - if (i != mNodes.Count - 1) + if (index != mNodes.Count - 1) { - if (mNodes[i + 1].pos - tNode.pos == Vector3.zero) + if (mNodes[index + 1].pos - tNode.pos == Vector3.zero) { rot = Quaternion.identity; } else { - rot = Quaternion.LookRotation(mNodes[i + 1].pos - tNode.pos, transform.up); + rot = Quaternion.LookRotation(mNodes[index + 1].pos - tNode.pos, transform.up); } //rot = Quaternion.LookRotation(mNodes[i+1].pos - tNode.pos, transform.up); @@ -203,7 +203,7 @@ private void Setup_Nodes(ref Vector3[] tVects) rot = Quaternion.identity; } - tNode.Setup(tNode.pos, rot, new Vector2(0, 1), step * i, "pNode"); + tNode.Setup(tNode.pos, rot, new Vector2(0, 1), step * index, "pNode"); } tNode = null; tVects = null; @@ -256,15 +256,15 @@ private void Setup_SplineLength() /// /// Gets the spline value. /// - /// + /// /// The relevant param (0-1) of the spline. /// - /// + /// /// True for is tangent, false (default) for vector3 position. /// - public Vector3 GetSplineValue(float f, bool b = false) + public Vector3 GetSplineValue(float _value, bool _isTangent = false) // FH 03.02.19 // f is now _value // b is now_isTangent { - int i; + int index; int idx = -1; if (mNodes.Count == 0) @@ -278,9 +278,9 @@ public Vector3 GetSplineValue(float f, bool b = false) /* - if (GSDRootUtil.IsApproximately(f, 0f, 0.00001f)) + if (GSDRootUtil.IsApproximately(_value, 0f, 0.00001f)) { - if (b) + if (_isTangent) { return mNodes[0].tangent; } @@ -290,9 +290,9 @@ public Vector3 GetSplineValue(float f, bool b = false) } } else - if (GSDRootUtil.IsApproximately(f, 1f, 0.00001f) || f > 1f) + if (GSDRootUtil.IsApproximately(_value, 1f, 0.00001f) || f > 1f) { - if (b) + if (_isTangent) { return mNodes[mNodes.Count - 1].tangent; } @@ -306,16 +306,16 @@ public Vector3 GetSplineValue(float f, bool b = false) */ - for (i = 1; i < mNodes.Count; i++) + for (index = 1; index < mNodes.Count; index++) { - if (i == mNodes.Count - 1) + if (index == mNodes.Count - 1) { - idx = i - 1; + idx = index - 1; break; } - if (mNodes[i].tTime >= f) + if (mNodes[index].tTime >= _value) { - idx = i - 1; + idx = index - 1; break; } } @@ -325,9 +325,9 @@ public Vector3 GetSplineValue(float f, bool b = false) } // } - float param = (f - mNodes[idx].tTime) / (mNodes[idx + 1].tTime - mNodes[idx].tTime); + float param = (_value - mNodes[idx].tTime) / (mNodes[idx + 1].tTime - mNodes[idx].tTime); param = GSDRootUtil.Ease(param, mNodes[idx].EaseIO.x, mNodes[idx].EaseIO.y); - return GetHermiteInternal(idx, param, b); + return GetHermiteInternal(idx, param, _isTangent); } diff --git a/Spline/GSDSplineI.cs b/Spline/GSDSplineI.cs index eb3f0a4b..8347ea6d 100644 --- a/Spline/GSDSplineI.cs +++ b/Spline/GSDSplineI.cs @@ -43,6 +43,7 @@ public void Setup(Vector3 _p, Quaternion _q, Vector2 _io, float _tTime, string _ } } + public int tCount = 0; public List mNodes = new List(); public bool bClosed = false; @@ -56,7 +57,9 @@ public void DetermineInsertNodes() { int iCount = GSDSpline.mNodes.Count; if (iCount < 2) - { return; } + { + return; + } GSDSplineIN tNode; GSDSplineN xNode; mNodes.Clear(); @@ -74,9 +77,9 @@ public void DetermineInsertNodes() bEndInsert = true; } - for (int i = 0; i < iCount; i++) + for (int index = 0; index < iCount; index++) { - xNode = GSDSpline.mNodes[i]; + xNode = GSDSpline.mNodes[index]; tNode = new GSDSplineIN(); tNode.pos = xNode.pos; tNode.idOnSpline = xNode.idOnSpline; @@ -99,9 +102,9 @@ public void DetermineInsertNodes() } else { - for (int i = iStart; i < cCount; i++) + for (int index = iStart; index < cCount; index++) { - mNodes[i].idOnSpline += 1; + mNodes[index].idOnSpline += 1; } } tNode = new GSDSplineIN(); @@ -277,12 +280,12 @@ private void Setup_SplineLength() /// /// The relevant param (0-1) of the spline. /// - /// + /// /// True for is tangent, false (default) for vector3 position. /// - public Vector3 GetSplineValue(float f, bool b = false) + public Vector3 GetSplineValue(float _value, bool _isTangent = false) // FH 03.02.19 // formerly varNames: f = _value; b = _isTangent { - int i; + int index; int idx = -1; if (mNodes.Count == 0) @@ -295,10 +298,11 @@ public Vector3 GetSplineValue(float f, bool b = false) } + // FH 03.02.19 // Do note, that someone outcommented stuff here, for whatever Reason, but why? /* - if (GSDRootUtil.IsApproximately(f, 0f, 0.00001f)) + if (GSDRootUtil.IsApproximately(_value, 0f, 0.00001f)) { - if (b) + if (_isTangent) { return mNodes[0].tangent; } @@ -308,9 +312,9 @@ public Vector3 GetSplineValue(float f, bool b = false) } } else - if (GSDRootUtil.IsApproximately(f, 1f, 0.00001f) || f > 1f) + if (GSDRootUtil.IsApproximately(_value, 1f, 0.00001f) || _value > 1f) { - if (b) + if (_isTangent) { return mNodes[mNodes.Count - 1].tangent; } @@ -322,18 +326,19 @@ public Vector3 GetSplineValue(float f, bool b = false) else { */ + // FH 03.02.19 // Do note, that someone outcommented stuff here, for whatever Reason, but why? - for (i = 1; i < mNodes.Count; i++) + for (index = 1; index < mNodes.Count; index++) { - if (i == mNodes.Count - 1) + if (index == mNodes.Count - 1) { - idx = i - 1; + idx = index - 1; break; } - if (mNodes[i].tTime >= f) + if (mNodes[index].tTime >= _value) { - idx = i - 1; + idx = index - 1; break; } } @@ -341,118 +346,118 @@ public Vector3 GetSplineValue(float f, bool b = false) { idx = 0; } - // } + //} // FH 03.02.19 // Do note, that someone outcommented stuff here, for whatever Reason, but why? - float param = (f - mNodes[idx].tTime) / (mNodes[idx + 1].tTime - mNodes[idx].tTime); - param = GSDRootUtil.Ease(param, mNodes[idx].EaseIO.x, mNodes[idx].EaseIO.y); - return GetHermiteInternal(idx, param, b); - } + float param = (_value - mNodes[idx].tTime) / (mNodes[idx + 1].tTime - mNodes[idx].tTime); + param = GSDRootUtil.Ease(param, mNodes[idx].EaseIO.x, mNodes[idx].EaseIO.y); + return GetHermiteInternal(idx, param, _isTangent); +} - public Vector3 GetSplineValue_SkipOpt(float f, bool b = false) +public Vector3 GetSplineValue_SkipOpt(float _value, bool _isTangent = false) // FH 03.02.19 // former VarNames: f = _value; b = _isTangent +{ + int index; + int idx = -1; + + if (mNodes.Count == 0) { - int i; - int idx = -1; + return default(Vector3); + } + if (mNodes.Count == 1) + { + return mNodes[0].pos; + } - if (mNodes.Count == 0) - { - return default(Vector3); - } - if (mNodes.Count == 1) + // if(GSDRootUtil.IsApproximately(_value,0f,0.00001f)){ + // if(_isTangent){ + // return mNodes[0].tangent; + // }else{ + // return mNodes[0].pos; + // } + // }else + // if(GSDRootUtil.IsApproximately(_value,1f,0.00001f) || _value > 1f){ + // if(_isTangent){ + // return mNodes[mNodes.Count-1].tangent; + // }else{ + // return mNodes[mNodes.Count-1].pos; + // } + // }else{ + for (index = 1; index < mNodes.Count; index++) + { + if (index == mNodes.Count - 1) { - return mNodes[0].pos; - } - - // if(GSDRootUtil.IsApproximately(f,0f,0.00001f)){ - // if(b){ - // return mNodes[0].tangent; - // }else{ - // return mNodes[0].pos; - // } - // }else - // if(GSDRootUtil.IsApproximately(f,1f,0.00001f) || f > 1f){ - // if(b){ - // return mNodes[mNodes.Count-1].tangent; - // }else{ - // return mNodes[mNodes.Count-1].pos; - // } - // }else{ - for (i = 1; i < mNodes.Count; i++) - { - if (i == mNodes.Count - 1) - { - idx = i - 1; - break; - } - if (mNodes[i].tTime >= f) - { - idx = i - 1; - break; - } + idx = index - 1; + break; } - if (idx < 0) + if (mNodes[index].tTime >= _value) { - idx = 0; + idx = index - 1; + break; } - // } - - float param = (f - mNodes[idx].tTime) / (mNodes[idx + 1].tTime - mNodes[idx].tTime); - param = GSDRootUtil.Ease(param, mNodes[idx].EaseIO.x, mNodes[idx].EaseIO.y); - return GetHermiteInternal(idx, param, b); } + if (idx < 0) + { + idx = 0; + } + // } + float param = (_value - mNodes[idx].tTime) / (mNodes[idx + 1].tTime - mNodes[idx].tTime); + param = GSDRootUtil.Ease(param, mNodes[idx].EaseIO.x, mNodes[idx].EaseIO.y); + return GetHermiteInternal(idx, param, _isTangent); +} - private Vector3 GetHermiteInternal(int i, double t, bool bTangent = false) - { - double t2, t3; - float BL0, BL1, BL2, BL3, tension; - if (!bTangent) - { - t2 = t * t; - t3 = t2 * t; - } - else - { - t2 = t * t; - t = t * 2.0; - t2 = t2 * 3.0; - t3 = 0; //Necessary for compiler error. - } +private Vector3 GetHermiteInternal(int i, double t, bool bTangent = false) +{ + double t2, t3; + float BL0, BL1, BL2, BL3, tension; - //Vectors: - Vector3 P0 = mNodes[NGI(i, NI[0])].pos; - Vector3 P1 = mNodes[NGI(i, NI[1])].pos; - Vector3 P2 = mNodes[NGI(i, NI[2])].pos; - Vector3 P3 = mNodes[NGI(i, NI[3])].pos; + if (!bTangent) + { + t2 = t * t; + t3 = t2 * t; + } + else + { + t2 = t * t; + t = t * 2.0; + t2 = t2 * 3.0; + t3 = 0; //Necessary for compiler error. + } - //Tension: - tension = 0.5f; // 0.5 equivale a catmull-rom + //Vectors: + Vector3 P0 = mNodes[NGI(i, NI[0])].pos; + Vector3 P1 = mNodes[NGI(i, NI[1])].pos; + Vector3 P2 = mNodes[NGI(i, NI[2])].pos; + Vector3 P3 = mNodes[NGI(i, NI[3])].pos; - //Tangents: - P2 = (P1 - P2) * tension; - P3 = (P3 - P0) * tension; + //Tension: + tension = 0.5f; // 0.5 equivale a catmull-rom - if (!bTangent) - { - BL0 = (float) (CM[0] * t3 + CM[1] * t2 + CM[2] * t + CM[3]); - BL1 = (float) (CM[4] * t3 + CM[5] * t2 + CM[6] * t + CM[7]); - BL2 = (float) (CM[8] * t3 + CM[9] * t2 + CM[10] * t + CM[11]); - BL3 = (float) (CM[12] * t3 + CM[13] * t2 + CM[14] * t + CM[15]); - } - else - { - BL0 = (float) (CM[0] * t2 + CM[1] * t + CM[2]); - BL1 = (float) (CM[4] * t2 + CM[5] * t + CM[6]); - BL2 = (float) (CM[8] * t2 + CM[9] * t + CM[10]); - BL3 = (float) (CM[12] * t2 + CM[13] * t + CM[14]); - } + //Tangents: + P2 = (P1 - P2) * tension; + P3 = (P3 - P0) * tension; - return BL0 * P0 + BL1 * P1 + BL2 * P2 + BL3 * P3; + if (!bTangent) + { + BL0 = (float) (CM[0] * t3 + CM[1] * t2 + CM[2] * t + CM[3]); + BL1 = (float) (CM[4] * t3 + CM[5] * t2 + CM[6] * t + CM[7]); + BL2 = (float) (CM[8] * t3 + CM[9] * t2 + CM[10] * t + CM[11]); + BL3 = (float) (CM[12] * t3 + CM[13] * t2 + CM[14] * t + CM[15]); + } + else + { + BL0 = (float) (CM[0] * t2 + CM[1] * t + CM[2]); + BL1 = (float) (CM[4] * t2 + CM[5] * t + CM[6]); + BL2 = (float) (CM[8] * t2 + CM[9] * t + CM[10]); + BL3 = (float) (CM[12] * t2 + CM[13] * t + CM[14]); } + return BL0 * P0 + BL1 * P1 + BL2 * P2 + BL3 * P3; +} + - private static readonly double[] CM = new double[] { +private static readonly double[] CM = new double[] { 2.0, -3.0, 0.0, 1.0, -2.0, 3.0, 0.0, 0.0, 1.0, -2.0, 1.0, 0.0, @@ -460,39 +465,39 @@ private Vector3 GetHermiteInternal(int i, double t, bool bTangent = false) }; - private static readonly int[] NI = new int[] { 0, 1, -1, 2 }; +private static readonly int[] NI = new int[] { 0, 1, -1, 2 }; - private int NGI(int i, int o) +private int NGI(int i, int o) +{ + int NGITI = i + o; + if (bClosed) { - int NGITI = i + o; - if (bClosed) - { - return (NGITI % mNodes.Count + mNodes.Count) % mNodes.Count; - } - else - { - return Mathf.Clamp(NGITI, 0, mNodes.Count - 1); - } + return (NGITI % mNodes.Count + mNodes.Count) % mNodes.Count; } - #endregion - - - public int GetNodeCount() + else { - return mNodes.Count; + return Mathf.Clamp(NGITI, 0, mNodes.Count - 1); } +} +#endregion + + +public int GetNodeCount() +{ + return mNodes.Count; +} #endif - #region "Start" - void Start() - { +#region "Start" +void Start() +{ #if UNITY_EDITOR - //Do nothing. + //Do nothing. #else this.enabled = false; #endif - } +} #endregion } \ No newline at end of file diff --git a/Spline/GSDSplineN.cs b/Spline/GSDSplineN.cs index 343ab8d1..8577d617 100644 --- a/Spline/GSDSplineN.cs +++ b/Spline/GSDSplineN.cs @@ -103,12 +103,14 @@ public class GSDSplineN : MonoBehaviour public void SetupEdgeObjects(bool bCollect = true) { if (EdgeObjects == null) - { EdgeObjects = new List(); } + { + EdgeObjects = new List(); + } int eCount = EdgeObjects.Count; EdgeObjectMaker EOM = null; - for (int i = 0; i < eCount; i++) + for (int index = 0; index < eCount; index++) { - EOM = EdgeObjects[i]; + EOM = EdgeObjects[index]; EOM.tNode = this; EOM.Setup(bCollect); } @@ -212,17 +214,17 @@ public void DetectInvalidEdgeObjects() int mCount = EdgeObjects.Count; List InvalidList = new List(); - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - if (EdgeObjects[i].EdgeObject == null) + if (EdgeObjects[index].EdgeObject == null) { - InvalidList.Add(i); + InvalidList.Add(index); } } - for (int i = (InvalidList.Count - 1); i >= 0; i--) + for (int index = (InvalidList.Count - 1); index >= 0; index--) { - RemoveEdgeObject(InvalidList[i], true); + RemoveEdgeObject(InvalidList[index], true); } SetupEdgeObjects(); @@ -237,12 +239,14 @@ public void DetectInvalidEdgeObjects() public void SetupSplinatedMeshes(bool bCollect = true) { if (SplinatedObjects == null) - { SplinatedObjects = new List(); } + { + SplinatedObjects = new List(); + } int eCount = SplinatedObjects.Count; SplinatedMeshMaker SMM = null; - for (int i = 0; i < eCount; i++) + for (int index = 0; index < eCount; index++) { - SMM = SplinatedObjects[i]; + SMM = SplinatedObjects[index]; SMM.Setup(true, bCollect); } } @@ -251,15 +255,17 @@ public void SetupSplinatedMeshes(bool bCollect = true) public int SplinatedMeshGetIndex(ref string UID) { if (SplinatedObjects == null) - { SplinatedObjects = new List(); } + { + SplinatedObjects = new List(); + } int eCount = SplinatedObjects.Count; SplinatedMeshMaker SMM = null; - for (int i = 0; i < eCount; i++) + for (int index = 0; index < eCount; index++) { - SMM = SplinatedObjects[i]; + SMM = SplinatedObjects[index]; if (string.CompareOrdinal(SMM.UID, UID) == 0) { - return i; + return index; } } return -1; @@ -269,7 +275,9 @@ public int SplinatedMeshGetIndex(ref string UID) public void SetupSplinatedMesh(int i, bool bGetStrings = false) { if (SplinatedObjects == null) - { SplinatedObjects = new List(); } + { + SplinatedObjects = new List(); + } int eCount = SplinatedObjects.Count; if (i > -1 && i < eCount) { @@ -386,17 +394,17 @@ public void DetectInvalidSplinatedObjects() int mCount = SplinatedObjects.Count; List InvalidList = new List(); - for (int i = 0; i < mCount; i++) + for (int index = 0; index < mCount; index++) { - if (SplinatedObjects[i].Output == null) + if (SplinatedObjects[index].Output == null) { - InvalidList.Add(i); + InvalidList.Add(index); } } - for (int i = (InvalidList.Count - 1); i >= 0; i--) + for (int index = (InvalidList.Count - 1); index >= 0; index--) { - RemoveSplinatedObject(InvalidList[i], true); + RemoveSplinatedObject(InvalidList[index], true); } SetupSplinatedMeshes(); @@ -939,9 +947,9 @@ public void SetupSplinationLimits() //Figure out min splination: GSDSplineN tNode = null; MinSplination = tTime; - for (int i = idOnSpline; i >= 0; i--) + for (int index = idOnSpline; index >= 0; index--) { - tNode = GSDSpline.mNodes[i]; + tNode = GSDSpline.mNodes[index]; if (tNode.CanSplinate()) { MinSplination = tNode.tTime; @@ -955,9 +963,9 @@ public void SetupSplinationLimits() //Figure out max splination: MaxSplination = tTime; int mCount = GSDSpline.GetNodeCount(); - for (int i = idOnSpline; i < mCount; i++) + for (int index = idOnSpline; index < mCount; index++) { - tNode = GSDSpline.mNodes[i]; + tNode = GSDSpline.mNodes[index]; if (tNode.CanSplinate()) { MaxSplination = tNode.tTime; @@ -1478,14 +1486,16 @@ public void TunnelToggleEnd() { int mCount = GSDSpline.GetNodeCount(); GSDSplineN tNode = null; - for (int i = 1; i < (mCount - 1); i++) + for (int index = 1; index < (mCount - 1); index++) { - tNode = GSDSpline.mNodes[i]; + tNode = GSDSpline.mNodes[index]; if (tNode.bIsTunnelStart && !tNode.bIsTunnelMatched) { tNode.TunnelToggleStart(); if (tNode.bIsTunnelMatched && tNode.TunnelCounterpartNode == this) - { return; } + { + return; + } } } } @@ -1738,6 +1748,8 @@ private static bool IsApproxTwoThirds(ref Vector3 V1, Vector3 V2) } #endregion #endif + + #region "Non-editor util" public bool CanSplinate() {