1.获取相对于存储资源的项目文件的路径名称
使用AssetDatabase类中的静态方法:
public static string GetAssetPath (int instanceID );
public static string GetAssetPath ( Object assetObject );
举例:
Material mat = new Material(Shader.Find("Specular"));
AssetDatabase.CreateAsset(mat, "Assets/MyMaterial.mat");
string assetPath = AssetDatabase.GetAssetPath(mat);
Debug.Log(assetPath);
2.获取与.meta文件关联的资源文件路径
方法:
public static string GetAssetPathFromTextMetaFilePath (string path );
举例:
Material mat = new Material(Shader.Find("Specular"));
AssetDatabase.CreateAsset(mat, "Assets/MyMaterial.mat");
string assetPath = AssetDatabase.GetAssetPathFromTextMetaFilePath ("Assets/MyMaterial.mat.meta");
Debug.Log(assetPath);
|