private void DrawRightSceneSection(Rect rightDataArea) { SceneStatistics statistics = EventManager.GetSceneStatistics(selectedScene); float labelTitleWidth = rightDataArea.width / 4; float labelDataWidth = (rightDataArea.width * 3 / 4) - 20; string eventsText = "This scene is using " + statistics.NumberOfEvents + " referenced across all scripts in the scene."; GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Event Details", EditorStyles.helpBox, GUILayout.Width(labelTitleWidth)); EditorGUILayout.LabelField(eventsText, EditorStyles.helpBox, GUILayout.Width(labelDataWidth)); GUILayout.EndHorizontal(); EditorStyles.helpBox.fontSize = 12; EditorStyles.helpBox.fontStyle = FontStyle.Bold; EditorGUILayout.Space(); EditorGUILayout.Space(); string listenersText = "This scene is using " + statistics.NumberOfListeners; GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Event Listener Details", EditorStyles.helpBox, GUILayout.Width(labelTitleWidth)); EditorGUILayout.LabelField(listenersText, EditorStyles.helpBox, GUILayout.Width(labelDataWidth)); GUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); string referencesText = "This scene is using " + statistics.NumberOfReferences + " across all scripts in the scene."; GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Event Reference Details", EditorStyles.helpBox, GUILayout.Width(labelTitleWidth)); EditorGUILayout.LabelField(referencesText, EditorStyles.helpBox, GUILayout.Width(labelDataWidth)); GUILayout.EndHorizontal(); }
public SceneStatistics GetSceneStatistics(SceneAsset s) { SceneStatistics result = new SceneStatistics(); if (s == null) { return(result); } for (int j = 0; j < _Scenes.Count; j++) { var guid1 = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(_Scenes[j])); var guid2 = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(s)); if (guid1.Equals(guid2)) { { EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(_Scenes[j]), OpenSceneMode.Additive); } } } var scene = EditorSceneManager.GetSceneByPath(AssetDatabase.GetAssetPath(s)); if (scene.IsValid() && !scene.isLoaded) { EditorSceneManager.LoadScene(scene.path); } if (scene.IsValid() && scene.isLoaded) { var allObjects = scene.GetRootGameObjects(); int eventCount = 0; int referenceCount = 0; int listenerCount = 0; Dictionary <string, CustomEvent> events = new Dictionary <string, CustomEvent>(); for (int j = 0; j < allObjects.Length; j++) { var obj = allObjects[j]; var listenerComps = obj.GetComponentsInChildren <GameEventListener>(true); var AllComps = obj.GetComponentsInChildren <MonoBehaviour>(true); listenerCount += listenerComps.Length; foreach (var comp in AllComps) { FieldInfo[] fields = comp.GetType().GetFields(); foreach (var field in fields) { KAIEvent attrib = Attribute.GetCustomAttribute(field, typeof(KAIEvent)) as KAIEvent; if (attrib != null) { referenceCount++; if (field.GetValue(comp) as CustomEvent != null) { if (events.ContainsKey((field.GetValue(comp) as CustomEvent).GetInstanceID().ToString()) == false) { events.Add((field.GetValue(comp) as CustomEvent).GetInstanceID().ToString(), field.GetValue(comp) as CustomEvent); } //eventCount++; } } } } } result.NumberOfListeners = listenerCount.ToString() + " Listeners"; result.NumberOfEvents = events.Count.ToString() + " Events"; result.NumberOfReferences = referenceCount.ToString() + " Event References"; } return(result); }