Skip to content

Commit 1ec007d

Browse files
committed
Moved editor specific code into EngineIntegration
1 parent 8573a0f commit 1ec007d

21 files changed

+287
-260
lines changed

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Improvements
1010

1111

12+
## [Version: 2.5.0] - 2023.09.14
13+
### Improvements
14+
- Refactored DestroyImmediate usage
15+
- Changed temporary material variables to private
16+
- Added an option to disable road updates
17+
- Refactored NullifyList method
18+
- Refactored clamping of construction values
19+
- Refactored setup of edge object maker
20+
- Refactored deletion in road constructor
21+
- Refactored deletion in intersection cleanup
22+
- Removed redundant EdgeObjectEditorMaker
23+
- Removed redundant SplinatedMeshEditorMaker
24+
- Removed gizmo toggle on nodes
25+
- Refactored road materials reset
26+
- Refactored ToggleWireframes
27+
- Removed editorDisplayString in node
28+
- Removed isEditorSelected in node
29+
- Removed unused intersection gizmos
30+
- Refactored wizard window type
31+
- Refactored node dragging in editor
32+
- Added unit test 10
33+
- Removed unused ProgressBar
34+
- Changed Remove all button
35+
- Refactored RemoveAllEdgeObjects
36+
- Refactored RemoveAllSplinatedObjects
37+
- Added OnDrawGizmosSelected for intersections
38+
- Refactored ConstructRoadStoreTerrainHistory
39+
- Simplified ConstructRoadStoreTerrainHistory
40+
- Removed sortID code
41+
- Moved editor specific code into EngineIntegration
42+
43+
1244
## [Version: 2.4.0] - 2021.09.22
1345
### Improvements
1446
- Added automatic rename of edge objects (Feature #29)

Scripts/Construction.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ public static class Construction
1111
Object[] worldNodeCount = GameObject.FindObjectsOfType<SplineN>();
1212
GameObject nodeObj = new GameObject("Node" + worldNodeCount.Length.ToString());
1313

14-
#if UNITY_EDITOR
1514
if (!_isInterNode)
1615
{
17-
UnityEditor.Undo.RegisterCreatedObjectUndo(nodeObj, "Created node");
16+
EngineIntegration.RegisterUndo(nodeObj, "Created node");
1817
}
19-
#endif
2018

2119

2220
SplineN node = nodeObj.AddComponent<SplineN>();
@@ -91,12 +89,10 @@ public static class Construction
9189
}
9290

9391

94-
#if UNITY_EDITOR
9592
if (!_isInterNode)
9693
{
97-
UnityEditor.Undo.RegisterCreatedObjectUndo(nodeObj, "Inserted node");
94+
EngineIntegration.RegisterUndo(nodeObj, "Inserted node");
9895
}
99-
#endif
10096

10197

10298
if (!_isForcedLoc)

Scripts/EdgeObjectMaker.cs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ public EdgeObjectMaker Copy()
133133

134134
EOM.edgeObjectString = edgeObjectString;
135135

136-
#if UNITY_EDITOR
137-
EOM.edgeObject = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(edgeObjectString);
138-
#endif
136+
EOM.edgeObject = EngineIntegration.LoadAssetFromPath<GameObject>(edgeObjectString);
139137

140138
EOM.isDefault = isDefault;
141139

@@ -367,15 +365,9 @@ private void SaveMesh(Mesh _mesh, bool _isCollider)
367365
Directory.CreateDirectory(path);
368366
}
369367

370-
371-
#if UNITY_EDITOR
372-
// Unity works with forward slash so we convert
373-
// If you want to implement your own Asset creation and saving you should just use finalName
374-
finalName = finalName.Replace(Path.DirectorySeparatorChar, '/');
375-
finalName = finalName.Replace(Path.AltDirectorySeparatorChar, '/');
376-
UnityEditor.AssetDatabase.CreateAsset(_mesh, finalName);
377-
UnityEditor.AssetDatabase.SaveAssets();
378-
#endif
368+
finalName = EngineIntegration.GetUnityFilePath(finalName);
369+
EngineIntegration.CreateAsset(_mesh, finalName);
370+
EngineIntegration.SaveAssets();
379371
}
380372

381373

@@ -508,18 +500,16 @@ public void Setup(EdgeObjectMaker _EOM)
508500
public void LoadTo(EdgeObjectMaker _EOM)
509501
{
510502
_EOM.edgeObjectString = edgeObjectString;
511-
#if UNITY_EDITOR
512-
_EOM.edgeObject = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(edgeObjectString);
503+
_EOM.edgeObject = EngineIntegration.LoadAssetFromPath<GameObject>(edgeObjectString);
513504

514505
if (edgeMaterial1String.Length > 0)
515506
{
516-
_EOM.edgeMaterial1 = UnityEditor.AssetDatabase.LoadAssetAtPath<Material>(edgeMaterial1String);
507+
_EOM.edgeMaterial1 = EngineIntegration.LoadAssetFromPath<Material>(edgeMaterial1String);
517508
}
518509
if (edgeMaterial2String.Length > 0)
519510
{
520-
_EOM.edgeMaterial2 = UnityEditor.AssetDatabase.LoadAssetAtPath<Material>(edgeMaterial2String);
511+
_EOM.edgeMaterial2 = EngineIntegration.LoadAssetFromPath<Material>(edgeMaterial2String);
521512
}
522-
#endif
523513

524514
_EOM.isMaterialOverriden = isMaterialOverriden;
525515

@@ -611,16 +601,14 @@ private void SetupDo(ref List<GameObject> _errorObjs)
611601

612602
edgeObjectString = RootUtils.GetPrefabString(edgeObject);
613603

614-
#if UNITY_EDITOR
615604
if (edgeMaterial1 != null)
616605
{
617-
edgeMaterial1String = UnityEditor.AssetDatabase.GetAssetPath(edgeMaterial1);
606+
edgeMaterial1String = EngineIntegration.GetAssetPath(edgeMaterial1);
618607
}
619608
if (edgeMaterial2 != null)
620609
{
621-
edgeMaterial2String = UnityEditor.AssetDatabase.GetAssetPath(edgeMaterial2);
610+
edgeMaterial2String = EngineIntegration.GetAssetPath(edgeMaterial2);
622611
}
623-
#endif
624612

625613
edgeObjects = new List<GameObject>();
626614

@@ -644,13 +632,7 @@ private void SetupDo(ref List<GameObject> _errorObjs)
644632
MeshRenderer OrigMR = edgeObject.GetComponent<MeshRenderer>();
645633
for (int j = 0; j < lCount; j++)
646634
{
647-
#if UNITY_EDITOR
648-
// Instantiate prefab instead of object
649-
tObj = (GameObject)UnityEditor.PrefabUtility.InstantiatePrefab(edgeObject);
650-
#else
651-
// Line to instantiate the object instead of an prefab
652-
tObj = GameObject.Instantiate(edgeObject);
653-
#endif
635+
tObj = EngineIntegration.InstantiatePrefab(edgeObject);
654636
tObj.transform.position = edgeObjectLocations[j];
655637

656638
if (edgeObjectRotations[j] == default(Vector3))

Scripts/Editor/EditorProgressWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private void OnGUI()
4444
}
4545
else
4646
{
47-
EditorUtility.ClearProgressBar();
47+
EngineIntegration.ClearProgressBar();
4848
}
4949

5050
progress = (float)(EditorApplication.timeSinceStartup - startValue);

Scripts/Editor/EditorUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void OpenOfflineManual()
1616
/// <summary> Loads the _texture from _path if necessary </summary>
1717
public static void LoadTexture<T>(ref T _texture, string _path) where T : Texture
1818
{
19-
_texture = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(_path);
19+
_texture = EngineIntegration.LoadAssetFromPath<T>(_path);
2020
}
2121

2222

Scripts/Editor/ObjExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private static string MeshToString(MeshFilter _meshFilter, Dictionary<string, Ob
8787

8888
if (materials[material].mainTexture)
8989
{
90-
objMaterial.textureName = AssetDatabase.GetAssetPath(materials[material].mainTexture);
90+
objMaterial.textureName = EngineIntegration.GetAssetPath(materials[material].mainTexture);
9191
}
9292
else
9393
{

Scripts/Editor/RoadIntersectionEditor.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,9 +1072,7 @@ public override void OnInspectorGUI()
10721072
int count = meshRenderers.Length;
10731073
for (int i = 0; i < count; i++)
10741074
{
1075-
//EditorUtility.SetSelectedWireframeHidden(tMRs[i], !tInter.bDrawGizmo);
1076-
EditorUtility.SetSelectedRenderState(meshRenderers[i], intersection.isDrawingGizmo ? EditorSelectedRenderState.Wireframe : EditorSelectedRenderState.Hidden);
1077-
1075+
EngineIntegration.SetSelectedRenderState(meshRenderers[i], intersection.isDrawingGizmo);
10781076
}
10791077
SceneView.RepaintAll();
10801078
}

Scripts/Editor/SaveWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private void OnGUI()
5050
if (temp2D2 != temp2D)
5151
{
5252
temp2D = temp2D2;
53-
thumbString = AssetDatabase.GetAssetPath(temp2D);
53+
thumbString = EngineIntegration.GetAssetPath(temp2D);
5454
}
5555

5656
if (path.Length < 5)

Scripts/Editor/SplineNEditor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ private void BridgeAddTopBase(float _horizSep = 0f, float _vertRaise = -0.01f, s
17131713
}
17141714

17151715
SMM.objectName = tName;
1716-
SMM.currentSplination = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(tBridgeTopBaseToAdd);
1716+
SMM.currentSplination = EngineIntegration.LoadAssetFromPath<GameObject>(tBridgeTopBaseToAdd);
17171717
SMM.horizontalSep = _horizSep;
17181718
SMM.verticalRaise = _vertRaise;
17191719
SMM.isMaterialOverriden = true;
@@ -1893,7 +1893,7 @@ private void BridgeAddBottomBase(float _horizSep = 0f, float _vertRaise = -1.01f
18931893
tBridgeBottomBaseToAdd = _overridePrefab;
18941894
}
18951895

1896-
SMM.currentSplination = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(tBridgeBottomBaseToAdd);
1896+
SMM.currentSplination = EngineIntegration.LoadAssetFromPath<GameObject>(tBridgeBottomBaseToAdd);
18971897
SMM.horizontalSep = _horizSep;
18981898
SMM.verticalRaise = _vertRaise;
18991899
SMM.isMaterialOverriden = true;
@@ -1976,7 +1976,7 @@ private void ExtrusionQuickAddDo()
19761976
private void ExtrudeHelper(string _path, string _name, float DefaultHoriz, Splination.AxisTypeEnum _axisType = Splination.AxisTypeEnum.Z, bool _isHorizOverriden = false, float _horizSep = 0f, bool _isVertOverriden = false, float _vertRaise = 0f, bool _isFlippingRot = false)
19771977
{
19781978
SMM = node.AddSplinatedObject();
1979-
SMM.currentSplination = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(_path);
1979+
SMM.currentSplination = EngineIntegration.LoadAssetFromPath<GameObject>(_path);
19801980

19811981
if (_isHorizOverriden)
19821982
{
@@ -2257,7 +2257,7 @@ private GameObject GetEndObjectQuickAdd()
22572257
return null;
22582258
}
22592259

2260-
return UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
2260+
return EngineIntegration.LoadAssetFromPath<GameObject>(path);
22612261
}
22622262
}
22632263
}

Scripts/Editor/Wizard.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ private void LoadGroupObjs(ref string[] _names, ref string[] _paths, bool _isBri
326326
}
327327
try
328328
{
329-
tO.thumb = AssetDatabase.LoadAssetAtPath<Texture2D>(tO.thumbString);
329+
tO.thumb = EngineIntegration.LoadAssetFromPath<Texture2D>(tO.thumbString);
330330
}
331331
catch
332332
{
@@ -500,7 +500,7 @@ private void LoadObjs(ref string[] _names, ref string[] _paths, bool _isDefault
500500
#region "Image"
501501
try
502502
{
503-
tO.thumb = AssetDatabase.LoadAssetAtPath<Texture2D>(thumbString);
503+
tO.thumb = EngineIntegration.LoadAssetFromPath<Texture2D>(thumbString);
504504
}
505505
catch
506506
{
@@ -512,7 +512,7 @@ private void LoadObjs(ref string[] _names, ref string[] _paths, bool _isDefault
512512
{
513513
try
514514
{
515-
GameObject xObj = AssetDatabase.LoadAssetAtPath<GameObject>(stringPath);
515+
GameObject xObj = EngineIntegration.LoadAssetFromPath<GameObject>(stringPath);
516516
tO.thumb = AssetPreview.GetAssetPreview(xObj);
517517
}
518518
catch

0 commit comments

Comments
 (0)