Esempio n. 1
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 OnGUI()
        {
            EditorGUI.BeginChangeCheck();

            using (var hedder = new GUILayout.HorizontalScope()) {
                EditorGUI.BeginChangeCheck();
                var isHide     = GUILayout.Toggle(isHideNoReferenceObjects, "hide no reference object", EditorStyles.toolbarButton, GUILayout.Width(125));
                var ignoreType = (ReferenceIgnoreType)EditorGUILayout.EnumPopup(ignoreReferenceType, EditorStyles.toolbarPopup, GUILayout.Width(85));



                search = EditorGUILayout.TextField(search);

                isLocked = GUILayout.Toggle(isLocked, "Locked", EditorStyles.toolbarButton, GUILayout.Width(40));

                if (isHide != isHideNoReferenceObjects || ignoreType != ignoreReferenceType)
                {
                    isHideNoReferenceObjects = isHide;
                    ignoreReferenceType      = ignoreType;

                    if (isHideNoReferenceObjects)
                    {
                        switch (ignoreReferenceType)
                        {
                        case ReferenceIgnoreType.None:
                            ObjectOrganize.AppearObjects();
                            break;

                        case ReferenceIgnoreType.IgnoreSelf:
                            ObjectOrganize.DisappearObjects();
                            break;

                        case ReferenceIgnoreType.IgnoreFamilly:
                            ObjectOrganize.DisappearObjectsWithFamillyReference();
                            break;
                        }
                    }
                    else
                    {
                        ObjectOrganize.AppearObjects();
                    }
                }
            }

            using (var title = new GUILayout.HorizontalScope("box")) {
                GUILayout.Label("Reference scene objecsts");
            }

            using (var scrollViewLayout = new GUILayout.ScrollViewScope(scrollViewPosition)) {
                scrollViewPosition = scrollViewLayout.scrollPosition;

                if (referenceList.Count() > 0 && referenceList.Sum(item => item.referenceInfoList.Count) > 0)
                {
                    var color = GUI.backgroundColor;
                    GUI.backgroundColor = new Color(1f, 0.8f, 0.8f);

                    using (var referencedByBlockLayout = new GUILayout.VerticalScope("box")) {
                        EditorGUI.indentLevel = 0;
                        isOpenReferenceList   = EditorGUILayout.Foldout(isOpenReferenceList, "reference");

                        if (isOpenReferenceList)
                        {
                            OnGUIReference(referenceList);
                        }
                    }
                    GUI.backgroundColor = color;
                }

                if (referencedByList.Count() > 0 && referencedByList.Sum(item => item.referenceInfoList.Count) > 0)
                {
                    var color = GUI.backgroundColor;
                    GUI.backgroundColor = new Color(0.8f, 0.8f, 1f);
                    using (var referencedByBlockLayout = new GUILayout.VerticalScope("box")) {
                        EditorGUI.indentLevel  = 0;
                        isOpenReferencedByList = EditorGUILayout.Foldout(isOpenReferencedByList, "referenced by");

                        if (isOpenReferencedByList)
                        {
                            OnGUIReferencedBy(referencedByList);
                        }
                    }
                    GUI.backgroundColor = color;
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                UpdateReferenceInfomation();
                SceneView.RepaintAll();
                Repaint();
            }
        }