#if UNITY_EDITOR #region "Imports" using UnityEngine; using UnityEditor; using RoadArchitect; #endregion namespace RoadArchitect { /// Provides the menu items inside the editor public class EditorMenu { /// Creates the road system. [MenuItem("Window/Road Architect/Create road system")] public static void CreateRoadSystem() { Object[] allRoadSystemObjects = GameObject.FindObjectsOfType(); int nextCount = (allRoadSystemObjects.Length + 1); allRoadSystemObjects = null; GameObject newRoadSystemObject = new GameObject("RoadArchitectSystem" + nextCount.ToString()); RoadSystem newRoadSystem = newRoadSystemObject.AddComponent(); //Add road for new road system. newRoadSystem.AddRoad(true); GameObject masterIntersectionsObject = new GameObject("Intersections"); masterIntersectionsObject.transform.parent = newRoadSystemObject.transform; } /// Add road to gameobject. Not sure if this is necessary. [MenuItem("Window/Road Architect/Add road")] public static void AddRoad() { Object[] allRoadSystemObjects = GameObject.FindObjectsOfType(); if (allRoadSystemObjects != null && allRoadSystemObjects.Length == 0) { CreateRoadSystem(); return; } else { RoadSystem firstRoadSystem = (RoadSystem)allRoadSystemObjects[0]; Selection.activeGameObject = firstRoadSystem.AddRoad(); } } /// Updates all roads. Used when things get out of sync. [MenuItem("Window/Road Architect/Update All Roads")] public static void UpdateAllRoads() { Road[] allRoadObjects = GameObject.FindObjectsOfType(); int roadCount = allRoadObjects.Length; Road singleRoad = null; SplineC[] tPiggys = null; if (roadCount > 1) { tPiggys = new SplineC[roadCount - 1]; } for (int count = 0; count < roadCount; count++) { singleRoad = allRoadObjects[count]; if (count > 0) { tPiggys[count - 1] = singleRoad.spline; } } singleRoad = allRoadObjects[0]; if (tPiggys != null && tPiggys.Length > 0) { singleRoad.PiggyBacks = tPiggys; } singleRoad.UpdateRoad(); } /// Show the help screen. [MenuItem("Window/Road Architect/Help")] public static void ShowHelpWindow() { HelpWindow helpWindow = EditorWindow.GetWindow(); helpWindow.Initialize(); } /// WARNING: Only call this on an empty scene that has some terrains on it. We are not responsbile for data loss if this function is called by the user. [MenuItem("Window/Road Architect/Testing/Run all unit tests (caution)")] public static void TestProgram() { if (EditorUtility.DisplayDialog("Warning !", "This will delete your RoadSystem 1, 6, 7, 8 and 9 and will create a lot of test roads.", "OK", "Cancel")) { RoadArchitect.Tests.UnitTests.RoadArchitectUnitTests(); } } [MenuItem("Window/Road Architect/Testing/Run unit test 1-5 (caution)")] public static void Test1To5() { if (EditorUtility.DisplayDialog("Warning !", "This will delete your first RoadSystem and will create a lot of test roads.", "OK", "Cancel")) { RoadArchitect.Tests.UnitTests.RoadArchitectUnitTest1To5(); } } [MenuItem("Window/Road Architect/Testing/Run unit test 6 (caution)")] public static void Test6() { if (EditorUtility.DisplayDialog("Warning !", "This will delete your sixth RoadSystem and will create a lot of test roads.", "OK", "Cancel")) { RoadArchitect.Tests.UnitTests.RoadArchitectUnitTest6(); } } [MenuItem("Window/Road Architect/Testing/Run unit test 7 (caution)")] public static void Test7() { if (EditorUtility.DisplayDialog("Warning !", "This will delete your seventh RoadSystem and will create a lot of test roads.", "OK", "Cancel")) { RoadArchitect.Tests.UnitTests.RoadArchitectUnitTest7(); } } [MenuItem("Window/Road Architect/Testing/Run unit test 8 (caution)")] public static void Test8() { if (EditorUtility.DisplayDialog("Warning !", "This will delete your eigth RoadSystem and will create a test roads.", "OK", "Cancel")) { RoadArchitect.Tests.UnitTests.RoadArchitectUnitTest8(); } } [MenuItem("Window/Road Architect/Testing/Run unit test 9 (caution)")] public static void Test9() { if (EditorUtility.DisplayDialog("Warning !", "This will delete your RoadArchitectSystem9 and will create test roads.", "OK", "Cancel")) { RoadArchitect.Tests.UnitTests.RoadArchitectUnitTest9(); } } [MenuItem("Window/Road Architect/Testing/Run unit test 10 (caution)")] public static void Test10() { if (EditorUtility.DisplayDialog("Warning !", "This will delete your RoadArchitectSystem10 and will create test roads.", "OK", "Cancel")) { RoadArchitect.Tests.UnitTests.RoadArchitectUnitTest10(); } } /// WARNING: Only call this on an empty scene that has some terrains on it. We are not responsbile for data loss if this function is called by the user. [MenuItem("Window/Road Architect/Testing/Clean up tests (caution)")] public static void TestCleanup() { if (EditorUtility.DisplayDialog("Warning !", "This will delete your RoadSystem 1, 6, 7, 8 and 9", "OK", "Cancel")) { RoadArchitect.Tests.UnitTests.CleanupAllTests(); } } /// Get code line count for RA project [MenuItem("Window/Road Architect/Testing/Get line count of RA")] public static void TestCodeCount() { string mainDir = System.IO.Path.Combine(System.Environment.CurrentDirectory, RoadEditorUtility.GetBasePathForIO()); string[] files = System.IO.Directory.GetFiles(mainDir, "*.cs", System.IO.SearchOption.AllDirectories); int lineCount = 0; foreach (string file in files) { lineCount += System.IO.File.ReadAllLines(file).Length; } Debug.Log(string.Format("{0:n0}", lineCount) + " lines of code in Road Architect."); } [MenuItem("Window/Road Architect/Report a Bug")] public static void ReportBug() { Application.OpenURL("https://github.com/FritzsHero/RoadArchitect/issues"); } } } #endif