Ejemplo n.º 1
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);
        }