/// <summary> /// Collects the field reference. /// </summary> /// <param name="component">Component.</param> /// <param name="referenceInfoList">Reference info list.</param> static void CollectFieldReference(System.Object component, ref List <ReferenceInfo> referenceInfoList, System.Object baseObject, int depth) { if (component == null) { return; } Type type = component.GetType(); foreach (var field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly)) { var value = ReferenceExplorerUtility.GetObject(field.GetValue(component)); if (value == null) { continue; } if (value is Component || value is GameObject) { referenceInfoList.Add(new ReferenceInfo() { fromObject = (System.Object)baseObject, referenceName = field.Name, referenceTarget = (System.Object)value }); continue; } if (value is IEnumerable) { foreach (var element in value as IEnumerable) { if (element is GameObject || element is Component) { referenceInfoList.Add(new ReferenceInfo() { fromObject = (System.Object)baseObject, referenceName = field.Name, referenceTarget = (System.Object)element }); } else if (IgnoreComponents.IsNotAnalyticsTypes(element)) { referenceInfoList.AddRange(FindReferenceInfo(element, baseObject, depth)); } } continue; } else if (value is System.Object) { referenceInfoList.AddRange(FindReferenceInfo(value, baseObject, depth)); continue; } } }
/// <summary> /// Collects the event reference. /// </summary> /// <param name="component">Component.</param> /// <param name="referenceInfoList">Reference info list.</param> static void CollectEventReference(System.Object component, ref List <ReferenceInfo> referenceInfoList) { if (component == null) { return; } Type type = component.GetType(); foreach (var eventType in type.GetEvents()) { var eventField = type.GetField(eventType.Name, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy); var eventValue = (System.Delegate)eventField.GetValue(component); if (eventValue == null) { continue; } var invocationList = eventValue.GetInvocationList(); foreach (var ev in invocationList) { var connectedMethod = ReferenceExplorerUtility.GetObject(ev.Target); if (connectedMethod == null || connectedMethod is Component == false || connectedMethod is GameObject == false) { continue; } referenceInfoList.Add(new ReferenceInfo() { fromObject = (System.Object)component, referenceName = eventType.Name, referenceTarget = (System.Object)connectedMethod }); } } }
/// <summary> /// Raises the GUI callback event. /// </summary> void OnGUICallback() { using (var header = new GUILayout.HorizontalScope("box")){ EditorGUI.BeginChangeCheck(); isSelectedObject = GUILayout.Toggle(isSelectedObject, "selected", EditorStyles.toolbarButton, GUILayout.Width(70)); searchText = EditorGUILayout.TextField(searchText); if (EditorGUI.EndChangeCheck()) { CallbackData.UpdateCallbacklist(isSelectedObject, searchText); } } EditorGUI.BeginChangeCheck(); callbackScroll = EditorGUILayout.BeginScrollView(callbackScroll); var width = position.width * 0.48f; foreach (var callback in CallbackData.callbackList) { if (callback.recieverList.Count == 0 && callback.senderList.Count == 0) { continue; } if (GUILayout.Button(callback.callback, EditorStyles.toolbarButton)) { opendCallbackList = callback.callback; } if (opendCallbackList != callback.callback) { continue; } if (callback.senderList.Where(item => ReferenceExplorerUtility.GetObject(item) != null).Count() != 0) { EditorGUILayout.LabelField("Sender", EditorStyles.boldLabel); foreach (var type in callback.senderTypeList) { using (var componentLayout = new EditorGUILayout.HorizontalScope()) { var senders = callback.senderList.Where(item => item.GetType() == type); if (type.IsSubclassOf(typeof(MonoBehaviour))) { var monoscript = MonoScript.FromMonoBehaviour((MonoBehaviour)callback.senderList.First()); EditorGUILayout.ObjectField(monoscript, typeof(MonoScript), true, GUILayout.Width(width)); using (var referencecomponentLayout = new EditorGUILayout.VerticalScope()){ foreach (var sender in senders) { EditorGUILayout.ObjectField(sender, typeof(Component), true, GUILayout.Width(width)); } } } } var animationSender = CallbackData.allAnimatorSender.Where(item => item.callback == callback.callback); foreach (var sender in animationSender) { using (var animatorLayout = new GUILayout.HorizontalScope()) { EditorGUILayout.ObjectField(sender.clip, typeof(AnimationClip), true, GUILayout.Width(width)); EditorGUILayout.ObjectField(sender.sender, typeof(Animator), true, GUILayout.Width(width)); } } } } if (callback.recieverList.Count != 0) { EditorGUILayout.LabelField("Reciever", EditorStyles.boldLabel); var types = callback.recieverTypeList; foreach (var type in types) { using (var componentLayout = new EditorGUILayout.HorizontalScope()) { var recievers = callback.recieverList.Where(item => item.GetType() == type); if (recievers.Count() == 0) { continue; } var monoscript = MonoScript.FromMonoBehaviour((MonoBehaviour)recievers.First()); EditorGUILayout.ObjectField(monoscript, typeof(MonoScript), true, GUILayout.Width(width)); using (var referenceComponentLayout = new EditorGUILayout.VerticalScope()) { foreach (var reciever in recievers) { EditorGUILayout.ObjectField(reciever, typeof(MonoScript), true, GUILayout.Width(width)); } } } GUILayout.Space(5); } } } EditorGUILayout.EndScrollView(); EditorGUI.EndChangeCheck(); }