public List <MonoBehaviour> FindReference(CustomEvent e) { List <MonoBehaviour> result = new List <MonoBehaviour>(); for (int i = 0; i < SceneManager.sceneCount; i++) { var scene = SceneManager.GetSceneAt(i); var allObjects = scene.GetRootGameObjects(); for (int j = 0; j < allObjects.Length; j++) { var obj = allObjects[j]; var comps = obj.GetComponentsInChildren <MonoBehaviour>(true); foreach (var comp in comps) { FieldInfo[] fields = comp.GetType().GetFields(); foreach (var field in fields) { CustomEventAttribute attrib = Attribute.GetCustomAttribute(field, typeof(CustomEventAttribute)) as CustomEventAttribute; if (attrib != null) { if (field.GetValue(comp) as CustomEvent != null && (field.GetValue(comp) as CustomEvent).name.Equals(e.name)) { result.Add(comp); } } } } } } return(result); }
public void RefreshReference(EventReference er) { if (er != null) { er.ReferenceNames = new List <string>(); er.Events = new List <CustomEvent>(); er.Fields = new List <FieldInfo>(); { FieldInfo[] fields = er.Reference.GetType().GetFields(); foreach (var field in fields) { CustomEventAttribute attrib = Attribute.GetCustomAttribute(field, typeof(CustomEventAttribute)) as CustomEventAttribute; if (attrib != null) { er.Events.Add(field.GetValue(er.Reference) as CustomEvent); er.ReferenceNames.Add(field.Name); er.Fields.Add(field); } } } } }
private EventTrackBarContextMenu() { // find all event class List <EventInfo> events = new List <EventInfo>(); Type baseType = typeof(EventKey); foreach (System.Reflection.Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Type objType in assembly.GetTypes()) { if ((objType.IsPublic && ((objType.Attributes & System.Reflection.TypeAttributes.Abstract) != System.Reflection.TypeAttributes.Abstract)) && objType.IsSubclassOf(baseType)) { object[] customEventAttributes = objType.GetCustomAttributes(typeof(CustomEventAttribute), true); if (customEventAttributes != null && customEventAttributes.Length > 0) { CustomEventAttribute att = (CustomEventAttribute)customEventAttributes[0]; EventInfo info = new EventInfo(); info.DisplayName = att.DisplayName; info.Path = string.IsNullOrEmpty(att.Path) ? "Custom" : att.Path.Trim(' ', '/', '\\', ',', '.').Replace('\\', '/'); info.Type = objType; info.Assembly = assembly; events.Add(info); } } } } List <MenuItemData> itemList = new List <MenuItemData>(); foreach (var e in events) { Skill.Editor.UI.MenuItem pathItem = FindItem(itemList, e.Path); if (pathItem == null) { string[] pathParts = e.Path.Split('/'); if (pathParts == null || pathParts.Length == 0) { pathParts = new string[] { "Custom" } } ; string path = string.Empty; Skill.Editor.UI.MenuItemBase parentItem = this; for (int i = 0; i < pathParts.Length; i++) { path += pathParts[i]; pathItem = FindItem(itemList, path); if (pathItem == null) { pathItem = new UI.MenuItem(pathParts[i]); itemList.Add(new MenuItemData() { Path = path, Item = pathItem }); parentItem.Add(pathItem); } parentItem = pathItem; path += "/"; } } if (pathItem != null) { Skill.Editor.UI.MenuItem addItem = new UI.MenuItem(e.DisplayName) { UserData = e }; addItem.Click += addItem_Click; pathItem.Add(addItem); } } }
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) { CustomEventAttribute attrib = Attribute.GetCustomAttribute(field, typeof(CustomEventAttribute)) as CustomEventAttribute; 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); }
public void FindAllReferences(List <string> scenes) { References = new List <EventReference>(); if (scenes.Count > 0) { var activeScene = EditorSceneManager.GetActiveScene(); for (int i = 0; i < EditorSceneManager.sceneCount; i++) { if (EditorSceneManager.GetSceneAt(i) != activeScene && EditorSceneManager.GetSceneAt(i).isLoaded) { if (EditorSceneManager.GetSceneAt(i).isLoaded) { EditorSceneManager.SaveScene(EditorSceneManager.GetSceneAt(i)); } else { EditorSceneManager.LoadScene(EditorSceneManager.GetSceneAt(i).path, LoadSceneMode.Additive); } EditorSceneManager.SetActiveScene(activeScene); } } for (int i = 0; i < scenes.Count; i++) { for (int j = 0; j < _Scenes.Count; j++) { { var guid1 = AssetDatabase.AssetPathToGUID(scenes[i]); var guid2 = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(_Scenes[j])); if (guid1.Equals(guid2)) { var scene = EditorSceneManager.OpenScene(scenes[i], OpenSceneMode.Additive); { if (scene.IsValid() && scene.isLoaded) { var allObjects = scene.GetRootGameObjects(); for (int k = 0; k < allObjects.Length; k++) { var obj = allObjects[k]; var comps = obj.GetComponentsInChildren <MonoBehaviour>(true); foreach (var comp in comps) { FieldInfo[] fields = comp.GetType().GetFields(); var eventReference = new EventReference(); eventReference.Reference = comp; bool add = false; foreach (var field in fields) { CustomEventAttribute attrib = Attribute.GetCustomAttribute(field, typeof(CustomEventAttribute)) as CustomEventAttribute; if (attrib != null) { eventReference.Events.Add(field.GetValue(comp) as CustomEvent); eventReference.ReferenceNames.Add(field.Name); eventReference.Fields.Add(field); add = true; } } if (add) { References.Add(eventReference); } } } } } } } } } } }