Ejemplo n.º 1
0
        public static IEnumerable <ResultRow> InScenePro(SearchTarget target)
        {
            var referencedBy = new List <ResultRow>();

            for (int ii = 0; ii < SceneManager.sceneCount; ii++)
            {
                var currentScene = SceneManager.GetSceneAt(ii);
                if (!currentScene.IsValid() || !currentScene.isLoaded)
                {
                    continue;
                }
                var allObjects = currentScene
                                 .GetRootGameObjects()
                                 .SelectMany(g => g.GetComponentsInChildren <Component>(true).Where(c => c && !(c is Transform)).OfType <Object>()
                                             .Union(AsEnumerable(g as Object))).ToArray();
                var total = allObjects.Length;
                for (int i = 0; i < total; i++)
                {
                    var comp = allObjects[i];
                    var res  = CheckObject(target, comp);
                    if (res == null)
                    {
                        continue;
                    }
                    referencedBy.Add(res);

                    if (EditorUtility.DisplayCancelableProgressBar("Searching for file usages in current scene..", target.Target.name, (float)i / total))
                    {
                        break;
                    }
                }
                EditorUtility.ClearProgressBar();
            }

            return(referencedBy);
        }
Ejemplo n.º 2
0
        private static ResultRow CheckObject(SearchTarget target, Object c, bool scene = true)
        {
            if (target.Check(c))
            {
                return(null);
            }
            if (target.Root == c)
            {
                return(null);
            }
            var       so  = new SerializedObject(c);
            var       sp  = so.GetIterator();
            ResultRow row = null;

            while (sp.Next(true))
            {
                if (sp.propertyType != SerializedPropertyType.ObjectReference || !target.Check(sp.objectReferenceValue))
                {
                    continue;
                }
                if (row == null)
                {
                    row = new ResultRow
                    {
                        Root             = c,
                        Target           = c,
                        SerializedObject = so
                    };

                    if (scene)
                    {
                        var component = c as Component;
                        if (component)
                        {
                            row.Main = component.gameObject;
                        }
                        else
                        {
                            var o = c as GameObject;
                            if (o != null)
                            {
                                row.Main = o;
                            }
                        }
                        var go = row.Main as GameObject;
                        Assert.NotNull(go);
                        row.LabelContent.text  = AnimationUtility.CalculateTransformPath(go.transform, null);
                        row.LabelContent.image = AssetPreview.GetMiniThumbnail(go);
                        ;
                    }
                    else
                    {
                        var path = AssetDatabase.GetAssetPath(c);
                        row.Main = AssetDatabase.LoadMainAssetAtPath(path);
                        row.LabelContent.text  = path.Replace(AssetsRootPath, string.Empty);
                        row.LabelContent.image = AssetDatabase.GetCachedIcon(path);
                        ;
                    }
                }

                Texture2D miniTypeThumbnail = row.Main == c ? null : AssetPreview.GetMiniThumbnail(c);

                row.Properties.Add(new ResultRow.PropertyData
                {
                    Property = sp.Copy(),
                    Content  = new GUIContent
                    {
                        image   = miniTypeThumbnail,
                        text    = Nicify(sp, sp.serializedObject.targetObject),
                        tooltip = string.Format("{0}.{1}", sp.serializedObject.targetObject.GetType().Name, sp.propertyPath)
                    }
                });
            }

            if (row == null)
            {
                so.Dispose();
            }
            return(row);
        }