Esempio n. 1
0
        private static TextureDetails GetAllTexturesFromAssets()
        {
            var details = new TextureDetails();

            var assetGuidStrings = AssetDatabase.FindAssets("t:texture2D", new[] { "Assets" });

            var assetsLength = assetGuidStrings.Length;

            for (var i = 0; i < assetsLength; i++)
            {
                var path = AssetDatabase.GUIDToAssetPath(assetGuidStrings[i]);

                if (EditorUtility.DisplayCancelableProgressBar("Getting All Textures from Assets", Path.GetFileName(path), (float)i / assetsLength))
                {
                    break;
                }

                var texture         = AssetDatabase.LoadAssetAtPath <Texture>(path);
                var textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;

                details.AddTexture(textureImporter, texture);
            }

            EditorUtility.ClearProgressBar();
            return(details);
        }
Esempio n. 2
0
        private static TextureDetails GetAllTexturesFromScene()
        {
            var details          = new TextureDetails();
            var checkedMaterials = new List <Material>();

            var allGameObjects       = Resources.FindObjectsOfTypeAll(typeof(GameObject));
            var allGameObjectsLength = allGameObjects.Length;

            for (var i = 0; i < allGameObjectsLength; i++)
            {
                var gameObject = allGameObjects[i] as GameObject;

                if (gameObject.hideFlags != HideFlags.None || EditorUtility.IsPersistent(gameObject.transform.root.gameObject))
                {
                    continue;
                }

                if (EditorUtility.DisplayCancelableProgressBar("Getting All Textures from Scene", gameObject.name, (float)i / allGameObjectsLength))
                {
                    break;
                }

                var renderers = gameObject.GetComponents <Renderer>();
                for (var j = 0; j < renderers.Length; j++)
                {
                    var renderer = renderers[j];
                    for (var k = 0; k < renderer.sharedMaterials.Length; k++)
                    {
                        var material = renderer.sharedMaterials[k];

                        if (material == null || checkedMaterials.Contains(material))
                        {
                            continue;
                        }

                        checkedMaterials.Add(material);

                        var shader = material.shader;

                        for (var l = 0; l < ShaderUtil.GetPropertyCount(shader); l++)
                        {
                            if (ShaderUtil.GetPropertyType(shader, l) == ShaderUtil.ShaderPropertyType.TexEnv)
                            {
                                var texture = material.GetTexture(ShaderUtil.GetPropertyName(shader, l));

                                var textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture)) as TextureImporter;

                                if (textureImporter != null)
                                {
                                    details.AddTexture(textureImporter, texture);
                                }
                            }
                        }
                    }
                }
            }

            EditorUtility.ClearProgressBar();
            return(details);
        }