public static void UpdateCallbacklist(bool selectedOBject, string search)
    {
        callbackList.Clear();

        var callbacks = allMethodRecieveWithText.Select(item => item.callback).Distinct();
        var objects   = Selection.gameObjects;

        foreach (var callback in callbacks)
        {
            var callbackviewinfo = new CallbackViewerInfo();
            callbackviewinfo.callback = callback;
            foreach (var monoScript in allMethodCallWithText.Where(item => item.callback == callback).Select(item => item.type).Distinct())
            {
                if (selectedOBject && objects != null)
                {
                    callbackviewinfo.senderList.AddRange(ReferenceExplorerData.allSelectedComponent
                                                         .Where(item => item.GetType() == monoScript));
                }
                else
                {
                    callbackviewinfo.senderList.AddRange(ReferenceExplorerData.allComponents
                                                         .Where(item => item.GetType() == monoScript));
                }
            }

            foreach (var type in allMethodRecieveWithText
                     .Where(item => item.callback == callback)
                     .Select(item => item.monoScript.GetClass())
                     .Distinct())
            {
                if (selectedOBject && objects != null)
                {
                    var collection = ReferenceExplorerData.allSelectedComponent
                                     .Where(item => item.GetType() == type);
                    callbackviewinfo.recieverList.AddRange(collection);
                }
                else
                {
                    callbackviewinfo.recieverList.AddRange(ReferenceExplorerData.allComponents
                                                           .Where(item => item.GetType() == type));
                }
            }
            callbackList.Add(callbackviewinfo);
        }
        if (!string.IsNullOrEmpty(search))
        {
            var dic = ReferenceExplorerUtility.GetTExtCommand(search);

            if (dic.ContainsKey("type"))
            {
                var typeText = dic["type"];
                foreach (var callback in callbackList)
                {
                    callback.recieverList = callback.recieverList
                                            .Where(item => item.GetType().FullName.ToLower().IndexOf(typeText) != -1)
                                            .ToList();

                    callback.senderList = callback.senderList
                                          .Where(item => item.GetType().FullName.ToLower().IndexOf(typeText) != -1)
                                          .ToList();
                }
            }

            if (dic.ContainsKey("obj"))
            {
                var objName = dic["obj"];

                foreach (var callback in callbackList)
                {
                    callback.recieverList = callback.recieverList.Where(item => item.name.ToLower().IndexOf(objName) != -1).ToList();
                    callback.senderList   = callback.senderList.Where(item => item.name.ToLower().IndexOf(objName) != -1).ToList();
                }
            }
        }

        foreach (var callback in callbackList)
        {
            callback.recieverTypeList = callback.recieverList.Select(item => item.GetType()).Distinct().ToList();
            callback.senderTypeList   = callback.senderList.Select(item => item.GetType()).Distinct().ToList();
        }
    }
Exemple #2
0
    public static IEnumerable <ReferenceViewerClassbase> AllReferencedByComponent(GameObject[] currentObjects, ReferenceIgnoreType ignoreType, string search = null)
    {
        var list = new List <ReferenceViewerClassbase> ();

        foreach (var currentObject in currentObjects)
        {
            var referencedByList = allReferenceInfo
                                   .Where(item => currentObject == ReferenceExplorerUtility.GetGameObject(item.referenceTarget));

            if (string.IsNullOrEmpty(search) == false)
            {
                var dic = ReferenceExplorerUtility.GetTExtCommand(search);

                if (dic.ContainsKey("type"))
                {
                    var typeText = dic ["type"];
                    referencedByList = referencedByList
                                       .Where(item =>
                                              item.referenceName.ToLower().IndexOf(typeText) != -1 ||
                                              item.referenceTarget.GetType().FullName.ToLower().IndexOf(typeText) != -1 ||
                                              item.fromObject.GetType().FullName.ToLower().IndexOf(typeText) != -1 ||
                                              ReferenceExplorerUtility.GetGameObject(item.fromObject).name.ToLower().IndexOf(typeText) != -1);
                }
                if (dic.ContainsKey("obj"))
                {
                    var objName = dic ["obj"];
                    referencedByList = referencedByList
                                       .Where(item =>
                                              ReferenceExplorerUtility.GetGameObject(item.fromObject).name.ToLower().IndexOf(objName) != -1);
                }

                if (dic.ContainsKey("param"))
                {
                    var param = dic ["param"];
                    referencedByList = referencedByList
                                       .Where(item => item.referenceName.IndexOf(param) != -1);
                }
            }

            if (ignoreType == ReferenceIgnoreType.IgnoreSelf)
            {
                referencedByList = referencedByList.Where(item => currentObject != ReferenceExplorerUtility.GetGameObject(item.fromObject))
                                   .Where(item => currentObjects.Contains(ReferenceExplorerUtility.GetGameObject(item.fromObject)) == false);
            }
            else if (ignoreType == ReferenceIgnoreType.IgnoreFamilly)
            {
                referencedByList = referencedByList.Where(item => ReferenceExplorerUtility.IsFamilly(item.fromObject, currentObject) == false)
                                   .Where(item => currentObjects.Contains(ReferenceExplorerUtility.GetGameObject(item.fromObject)) == false);
            }

            var allComponentType = referencedByList
                                   .Select(item => item.fromObject.GetType())
                                   .Distinct().OrderBy(item => item.FullName);

            foreach (var uniqueComponentType in allComponentType)
            {
                var componentItme = new ReferenceViewerClassbase();
                componentItme.type = uniqueComponentType;
                componentItme.referenceInfoList = referencedByList
                                                  .Where(item => item.fromObject.GetType() == uniqueComponentType)
                                                  .OrderBy(item => ReferenceExplorerUtility.GetGameObject(item.fromObject).name)
                                                  .ToList();
                list.Add(componentItme);
            }
        }

        return(list.Where(item => item.referenceInfoList.Count > 0));
    }
    void OnGUIClass()
    {
        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);
            }
            orderType = (OrderType)EditorGUILayout.EnumPopup(orderType, EditorStyles.toolbarPopup, GUILayout.Width(95));
        }

        using (var scrollRectLayout = new GUILayout.ScrollViewScope(classSroll)) {
            classSroll = scrollRectLayout.scrollPosition;


            var componentTypeList     = ReferenceExplorerData.allComponentTypes.AsEnumerable();
            var animatorBehaviourList = ReferenceExplorerData.animatorBehaviourList.AsEnumerable();

            var doc = ReferenceExplorerUtility.GetTExtCommand(searchText);
            if (doc.ContainsKey("type"))
            {
                var typeText = doc["type"];
                componentTypeList = componentTypeList.
                                    Where(item => item.FullName.ToLower().IndexOf(typeText) != -1 ||
                                          item.GetInterfaces()
                                          .Any(interfaces => interfaces.FullName.ToLower().IndexOf(typeText) != -1));

                animatorBehaviourList = animatorBehaviourList
                                        .Where(item => item.behaviour.GetType().FullName.ToLower().IndexOf(typeText) != -1);
            }

            if (orderType == OrderType.Names)
            {
                componentTypeList = componentTypeList
                                    .OrderBy(t1 => t1.FullName).ToList();
            }
            else
            {
                componentTypeList = componentTypeList
                                    .OrderBy(t1 => ReferenceExplorerData.allComponents.Count(t2 => t1 == t2.GetType()) * -1).ToList();
            }


            foreach (var type in componentTypeList)
            {
                Component component;
                int       count;

                if (isSelectedObject)
                {
                    component = ReferenceExplorerData.allSelectedComponent.Find(item => item.GetType() == type);
                    count     = ReferenceExplorerData.allSelectedComponent.Count(item => item.GetType() == type);
                }
                else
                {
                    component = ReferenceExplorerData.allComponents.Find(item => item.GetType() == type);
                    count     = ReferenceExplorerData.allComponents.Count(item => item.GetType() == type);
                }

                if (count == 0)
                {
                    continue;
                }

                var color = GUI.backgroundColor;
                if (type == currentType)
                {
                    GUI.backgroundColor = new Color(1f, 0.8f, 0.8f);
                }

                using (var classViewLayout = new GUILayout.VerticalScope("box")) {
                    using (var itemLayout = new GUILayout.HorizontalScope()) {
                        string buttontext = (currentType == type) ? "▼" :  "▶";
                        if (GUILayout.Button(buttontext, EditorStyles.miniLabel, GUILayout.Width(12)))
                        {
                            if (currentType == type)
                            {
                                currentType = null;
                            }
                            else
                            {
                                currentType = type;
                            }
                        }

                        if (component == null)
                        {
                            continue;
                        }

                        if (component is MonoBehaviour)
                        {
                            var monoscript = MonoScript.FromMonoBehaviour((MonoBehaviour)component);
                            EditorGUILayout.ObjectField(monoscript, type, false);
                        }
                        else
                        {
                            GUILayout.Label(type.ToString());
                        }

                        EditorGUILayout.LabelField(count.ToString(), GUILayout.ExpandWidth(false), GUILayout.Width(40));
                        if (GUILayout.Button("F", EditorStyles.toolbarButton, GUILayout.Width(20)))
                        {
                            var components = ReferenceExplorerData.allComponents.FindAll(item => item.GetType() == type).Select(item => item.gameObject).ToArray();
                            Selection.objects = components;
                        }
                    }

                    GUILayout.Space(5);
                    EditorGUI.indentLevel = 1;

                    if (type == currentType)
                    {
                        var components = isSelectedObject ? ReferenceExplorerData.allSelectedComponent : ReferenceExplorerData.allComponents;

                        foreach (var obj in components
                                 .FindAll(item => item.GetType() == type)
                                 .OrderBy(item => item.name)
                                 .AsEnumerable())
                        {
                            EditorGUILayout.ObjectField(obj, type, true);
                        }
                    }

                    EditorGUI.indentLevel = 0;
                }
                GUI.backgroundColor = color;
            }

            foreach (var type in animatorBehaviourList.Select(item => item.behaviour.GetType()).Distinct())
            {
                if (type == null)
                {
                    continue;
                }

                var animators = animatorBehaviourList
                                .Where(item => item.behaviour.GetType() == type)
                                .Distinct();

                if (animators.Count() == 0)
                {
                    continue;
                }


                var color = GUI.backgroundColor;
                if (type == currentType)
                {
                    GUI.backgroundColor = new Color(1f, 0.8f, 0.8f);
                }

                using (var classViewLayout = new GUILayout.VerticalScope("box")) {
                    using (var componentHeader = new GUILayout.HorizontalScope())
                    {
                        string buttontext = (currentType == type) ? "▼" :  "▶";
                        if (GUILayout.Button(buttontext, EditorStyles.miniLabel, GUILayout.Width(12)))
                        {
                            if (currentType == type)
                            {
                                currentType = null;
                            }
                            else
                            {
                                currentType = type;
                            }
                        }

                        var code = MonoScript.FromScriptableObject(animators.First().behaviour);
                        EditorGUILayout.ObjectField(code, typeof(MonoScript), false);
                    }

                    if (type != currentType)
                    {
                        continue;
                    }

                    EditorGUI.indentLevel = 1;
                    using (var animatotrLayouts = new GUILayout.VerticalScope()){
                        foreach (var anim in animators)
                        {
                            EditorGUILayout.ObjectField(anim.animator, typeof(Animator), true);
                        }
                    }
                    EditorGUI.indentLevel = 0;
                }
                GUI.backgroundColor = color;
            }
        }
    }