Advertisement
Guest User

Feature Request: TextureImporter.GetWidthAndHeight

a guest
Jan 7th, 2013
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. public static bool GetImageSize(Texture2D asset, out int width, out int height) {
  2.     if (asset != null) {
  3.         string assetPath = AssetDatabase.GetAssetPath(asset);
  4.         TextureImporter importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;
  5.  
  6.         if (importer != null) {
  7.             object[] args = new object[2] { 0, 0 };
  8.             MethodInfo mi = typeof(TextureImporter).GetMethod("GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Instance);
  9.             mi.Invoke(importer, args);
  10.  
  11.             width = (int)args[0];
  12.             height = (int)args[1];
  13.  
  14.             return true;
  15.         }
  16.     }
  17.  
  18.     height = width = 0;
  19.     return false;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement