Esempio n. 1
0
        static HashSet <string> LibraryReferences()
        {
            var libraryReferences = new HashSet <string>();
            var type = typeof(PlayerSettings);

            foreach (var property in type.GetProperties(BindingFlags.Static | BindingFlags.Public))
            {
                if (property.PropertyType == typeof(Object) || property.PropertyType.IsSubclassOf(typeof(Object)))
                {
                    var val = type.InvokeMember(property.Name, BindingFlags.Public | BindingFlags.Static | BindingFlags.GetProperty, null, property.PropertyType, null) as Object;
                    if (val != null)
                    {
                        libraryReferences.Add(AssetDatabase.GetAssetPath(val));
                    }
                }
            }

            foreach (var nestedClass in type.GetNestedTypes(BindingFlags.Static | BindingFlags.Public))
            {
                foreach (var property in nestedClass.GetProperties(BindingFlags.Static | BindingFlags.Public))
                {
                    if (property.PropertyType == typeof(Object) || property.PropertyType.IsSubclassOf(typeof(Object)))
                    {
                        var val = nestedClass.InvokeMember(property.Name, BindingFlags.Public | BindingFlags.Static | BindingFlags.GetProperty, null, property.PropertyType, null) as Object;
                        if (val != null)
                        {
                            libraryReferences.Add(AssetDatabase.GetAssetPath(val));
                        }
                    }
                }
            }

            foreach (var target in EnumUtil.GetValues <BuildTargetGroup>())
            {
                foreach (var icon in PlayerSettings.GetIconsForTargetGroup(target))
                {
                    if (icon != null)
                    {
                        libraryReferences.Add(AssetDatabase.GetAssetPath(icon));
                    }
                }
            }

            var editor = PlayerSettingsEditor;

            foreach (var field in editor.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (field.FieldType == typeof(SerializedProperty))
                {
                    var prop = field.GetValue(editor) as SerializedProperty;
                    if (prop != null)
                    {
                        if (prop.type.StartsWith("PPtr") && prop.objectReferenceValue != null)
                        {
                            libraryReferences.Add(AssetDatabase.GetAssetPath(prop.objectReferenceValue));
                        }
                    }
                }
            }
            Object.DestroyImmediate(editor);

            return(libraryReferences);
        }
Esempio n. 2
0
        static HashSet <string> LibraryReferences(Object obj)
        {
            const string libraryPath            = "ProjectSettings/ProjectSettings.asset";
            var          foundLibraryReferences = new HashSet <string>();
            var          type = typeof(PlayerSettings);

            foreach (var property in type.GetProperties(BindingFlags.Static | BindingFlags.Public))
            {
                if (property.PropertyType == typeof(Object) || property.PropertyType.IsSubclassOf(typeof(Object)))
                {
                    var val = type.InvokeMember(property.Name, BindingFlags.Public | BindingFlags.Static | BindingFlags.GetProperty, null, property.PropertyType, null) as Object;
                    if (val == obj)
                    {
                        foundLibraryReferences.Add(libraryPath + "/" + type.Name + "/" + property.Name);
                    }
                }
            }

            foreach (var nestedClass in type.GetNestedTypes(BindingFlags.Static | BindingFlags.Public))
            {
                foreach (var property in nestedClass.GetProperties(BindingFlags.Static | BindingFlags.Public))
                {
                    if (property.PropertyType == typeof(Object) || property.PropertyType.IsSubclassOf(typeof(Object)))
                    {
                        var val = nestedClass.InvokeMember(property.Name, BindingFlags.Public | BindingFlags.Static | BindingFlags.GetProperty, null, property.PropertyType, null) as Object;
                        if (val == obj)
                        {
                            foundLibraryReferences.Add(libraryPath + "/" + type.Name + "/" + nestedClass.Name + "/" + property.Name);
                        }
                    }
                }
            }

            if (obj is Texture2D)
            {
                foreach (var target in EnumUtil.GetValues <BuildTargetGroup>())
                {
                    foreach (var icon in  PlayerSettings.GetIconsForTargetGroup(target))
                    {
                        if (obj == icon)
                        {
                            foundLibraryReferences.Add(libraryPath + "/" + target + "/Icons");
                        }
                    }
                }
            }

            var editor = PlayerSettingsEditor;

            foreach (var field in editor.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (field.FieldType == typeof(SerializedProperty))
                {
                    var prop = field.GetValue(editor) as SerializedProperty;
                    if (prop != null)
                    {
                        if (prop.type.StartsWith("PPtr") && prop.objectReferenceValue == obj)
                        {
                            foundLibraryReferences.Add(libraryPath + "/PlayerSettings/" + field.Name.Replace("m_", ""));
                        }
                    }
                }
            }
            Object.DestroyImmediate(editor);

            return(foundLibraryReferences);
        }