AssetBundleGraph.TypeUtility.GetTypeOfAsset C# (CSharp) Method

GetTypeOfAsset() public static method

public static GetTypeOfAsset ( string assetPath ) : Type
assetPath string
return System.Type
        public static Type GetTypeOfAsset(string assetPath)
        {
            if (assetPath.EndsWith(AssetBundleGraphSettings.UNITY_METAFILE_EXTENSION)) return typeof(string);

            var asset = AssetDatabase.LoadMainAssetAtPath(assetPath);

            // If asset is null, this asset is not imported yet, or unsupported type of file
            // so we set this to object type.
            if (asset == null) {
                return typeof(object);
            }
            return asset.GetType();
        }

Usage Example

 public static AssetReference CreateReference(string importFrom)
 {
     return(new AssetReference(
                guid: Guid.NewGuid(),
                assetDatabaseId: AssetDatabase.AssetPathToGUID(importFrom),
                importFrom: importFrom,
                assetType: TypeUtility.GetTypeOfAsset(importFrom)
                ));
 }
All Usage Examples Of AssetBundleGraph.TypeUtility::GetTypeOfAsset