SHARE
TWEET

Feature Request: TextureImporter.GetWidthAndHeight

a guest Jan 7th, 2013 695 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top