Хорошо, я пытаюсь написать скрипт, который просматривает все сцены и обнаруживает, что у объектов ведьм есть более одного 2D коллайдера. Я уже написал сценарий, и он отлично работает, пока игра не находится в режиме игры, но некоторые сценарии добавляют компонент коллайдера в Start () или в других местах, и существует более 100 сцен.
Есть ли способ что сценарий редактора может запустить режим воспроизведения, l oop через все сцены (загрузить сцену 0, дождаться ее загрузки, проверить все объекты и перейти к следующей сцене).
Здесь уже написан сценарий:
14 public class SearchForDoubleColliders : EditorWindow
15 {
16 [MenuItem("CustomTools/Search For Double Colliders")]
17 static void Init()
18 {
19 SearchForDoubleColliders window = (SearchForDoubleColliders)EditorWindow.GetWindow(typeof(SearchForDoubleColliders));
20 window.titleContent = new GUIContent("Search For Double Colliders");
21 window.Show();
22 window.position = new Rect(50, 80, 1200, 500);
23
24
25 }
26
27 Vector2 scroll;
28 List<string> listResult = new List<string>();
29 static string[] scenesPathNames;
30 string[] scenesNames;
31 public List<GameObject> objectsList;
32
33
34 void OnGUI()
35 {
36 GUILayout.Space(3);
37 int oldValue = GUI.skin.window.padding.bottom;
38 GUI.skin.window.padding.bottom = -20;
39 Rect windowRect = GUILayoutUtility.GetRect(1, 17);
40 windowRect.x += 4;
41 windowRect.width -= 7;
42 GUI.skin.window.padding.bottom = oldValue;
43 GUILayout.Label("Make sure to build the project before running the search!");
44 GUILayout.Space(10);
45 GUILayout.BeginVertical();
46 GUILayout.BeginHorizontal();
47 //createLog = GUILayout.Toggle(createLog, "Create build asset log in /Assets/Assets_in_build.txt?");
48 GUILayout.EndHorizontal();
49 GUILayout.EndVertical();
50 GUILayout.Space(10);
51 if (GUILayout.Button("Search!"))
52 {
53 Debug.LogWarning("Searching... Will take some time...");
54 //EditorApplication.isPlaying = true;
55 DoSearch();
56 }
57
58 if (listResult != null)
59 {
60 GUILayout.BeginVertical();
61 GUILayout.Space(10);
62 GUILayout.Label("Found " + listResult.Count + " objects with double colliders in the build");
63
64 GUILayout.Space(10);
65 GUILayout.EndVertical();
66
67 scroll = GUILayout.BeginScrollView(scroll);
68 for (int i = 0; i < listResult.Count; i++)
69 {
70 GUILayout.BeginHorizontal();
71 GUILayout.Label(listResult[i], GUILayout.Width(position.width * 0.68f));
72 GUILayout.FlexibleSpace();
73 if (GUILayout.Button("Open Scene", GUILayout.Width(position.width * 0.30f)))
74 {
75 string[] tokens = listResult[i].Split(' ');
76 EditorSceneManager.OpenScene(scenesPathNames[int.Parse(tokens[0])], OpenSceneMode.Single);
77 //Selection.activeGameObject = objectsList[i];
78 }
79 GUILayout.EndHorizontal();
80 }
81 GUILayout.EndScrollView();
82 }
83 }
84
85
86 void DoSearch()
87 {
88 scenesPathNames = GetAllScenesPaths(ref scenesNames);
89 StringBuilder builder = new StringBuilder();
90
91 for (int i = 0; i < scenesPathNames.Length; i++)
92 {
93 GetSceneObjects(ref objectsList, scenesPathNames[i], OpenSceneMode.Single);
94
95 foreach (GameObject obj in objectsList)
96 {
97
98 int numOfColl = 0;
99 foreach (Collider2D collider in obj.GetComponents<Collider2D>())
100 {
101 numOfColl++;
102
103 }
104
105
106 //simulating scene load
107 numOfColl += CheckForAdditionalRuntimeColliders(obj);
108
109
110
111 if (numOfColl > 1)
112 {
113 builder.Clear();
114 builder.Append($"{i} Scene Name: {scenesNames[i]}\t\t");
115 builder.Append($"Object Name: {obj.name}");
116 builder.Append($"\t\tColliders:{numOfColl}");
117 listResult.Add(builder.ToString());
118 }
119 }
120 }
121 }
122
123
124 private void GetSceneObjects(ref List<GameObject> objectsList, string sceneName, OpenSceneMode open_mode)
125 {
126 List<GameObject> temp_list = new List<GameObject>();
127 objectsList = new List<GameObject>();
128
129 Scene scene = EditorSceneManager.OpenScene(sceneName, open_mode);
130 scene.GetRootGameObjects(temp_list);
131 for (int i = 0; i < temp_list.Count; i++)
132 {
133 objectsList.Add(temp_list[i]);
134 }
135
136 }
137
138 private static string[] GetAllScenesPaths(ref string[] sceneNames)
139 {
140 List<string> temp = new List<string>();
141 List<string> tempNames = new List<string>();
142 foreach (UnityEditor.EditorBuildSettingsScene S in UnityEditor.EditorBuildSettings.scenes)
143 {
144 if (S.enabled)
145 {
146 string path = S.path;
147 string name = S.path.Substring(S.path.LastIndexOf('/') + 1);
148 name = name.Substring(0, name.Length - 6);
149 temp.Add(path);
150 tempNames.Add(name);
151 }
152 }
153 sceneNames = tempNames.ToArray();
154 return temp.ToArray();
155 }
156
229 }