-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectSoundFinder.cs
62 lines (53 loc) · 1.87 KB
/
ObjectSoundFinder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
using System.IO;
// Find sounds that are not in the sound manager
public class ObjectSoundFinder : EditorWindow
{
[MenuItem("Window/Object Sound Finder")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(ObjectSoundFinder));
}
void OnGUI()
{
if (GUILayout.Button("Find Object Sounds"))
{
FindObjectSounds();
}
}
private static void FindObjectSounds()
{
string[] scenePaths = AssetDatabase.GetAllAssetPaths();
string logFilePath = "Assets/ObjectSound.log";
// Clear the log file if it already exists
if (File.Exists(logFilePath))
{
File.Delete(logFilePath);
}
foreach (string scenePath in scenePaths)
{
if (scenePath.EndsWith(".unity"))
{
Scene scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);
GameObject[] allObjects = Resources.FindObjectsOfTypeAll<GameObject>();
foreach (GameObject go in allObjects)
{
if (PrefabUtility.GetPrefabAssetType(go) == PrefabAssetType.NotAPrefab)
{
if (go.GetComponent<ObjectSound>() != null)
{
string logMessage = "Found Object Sound on GameObject '" + go.name + "' in scene '" + scene.name + "'";
Debug.Log(logMessage);
File.AppendAllText(logFilePath, logMessage + "\n");
}
}
}
EditorSceneManager.CloseScene(scene, true);
}
}
Debug.Log("Object Sound search complete. Results saved to: " + logFilePath);
}
}