SimpleSpritePackerEditor.SPTools.GetDirectoryAssets C# (CSharp) Method

GetDirectoryAssets() public static method

Gets the assets in the specified directory.
public static GetDirectoryAssets ( string path ) : Object[]
path string Path.
return Object[]
        public static Object[] GetDirectoryAssets(string path)
        {
            List<Object> assets = new List<Object>();

            // Get the file paths of all the files in the specified directory
            string[] assetPaths = System.IO.Directory.GetFiles(path);

            // Enumerate through the list of files loading the assets they represent
            foreach (string assetPath in assetPaths)
            {
                // Check if it's a meta file
                if (assetPath.Contains(".meta"))
                    continue;

                Object objAsset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object));

                if (objAsset != null)
                    assets.Add(objAsset);
            }

            // Return the array of objects
            return assets.ToArray();
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Filters the resources for atlas import.
        /// </summary>
        /// <returns>The resources for atlas import.</returns>
        /// <param name="resources">Resources.</param>
        public static Object[] FilterResourcesForAtlasImport(Object[] resources)
        {
            List <Object> tempList = new List <Object>();

            foreach (Object resource in resources)
            {
                string resourcePath = SPTools.GetAssetPath(resource);

                // Check if this is a main asset and queue all it's sub assets
                if (SPTools.IsMainAsset(resource) && SPTools.HasSubAssets(resource))
                {
                    Object[] subAssets = SPTools.FilterResourcesForAtlasImport(SPTools.GetSubAssets(resource));

                    foreach (Object a in subAssets)
                    {
                        tempList.Add(a);
                    }
                }
                else if (resource is Texture2D || resource is Sprite)
                {
                    tempList.Add(resource);
                }
                else if (SPTools.IsDirectory(resourcePath))
                {
                    Object[] subAssets = SPTools.FilterResourcesForAtlasImport(SPTools.GetDirectoryAssets(resourcePath));

                    foreach (Object a in subAssets)
                    {
                        tempList.Add(a);
                    }
                }
            }

            return(tempList.ToArray());
        }