Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. /*
  2.  * Copyright (c) UserJoy Technology
  3.  * All Rights Reserved.
  4.  */
  5.  
  6. using UnityEditor;
  7. using UnityEngine;
  8. using System.Reflection;
  9.  
  10. namespace Edit.Postprocessor {
  11.     public sealed class TextureReviewer : AssetPostprocessor {
  12.         #region AssetPostprocessor Hooks
  13.         void OnPreprocessTexture() {
  14.             // Unity Code Snippet: Getting the original size of a Texture2D
  15.             // http://philippseifried.com/blog/2012/07/30/unity3d-code-original-texture-siz/
  16.  
  17.             var textureImporter = (TextureImporter) assetImporter;
  18.             if (textureImporter != null) {
  19.                 var args = new object[2] { 0, 0 };
  20.                 MethodInfo mi = typeof(TextureImporter).GetMethod("GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Instance);
  21.                 mi.Invoke(textureImporter, args);
  22.  
  23.                 int width = (int) args[0];
  24.                 int height = (int) args[1];
  25.  
  26.                 if (width > 2048 || height > 2048) {
  27.                     Debug.LogError(string.Format("texture width or height must small than 4096, width:{0}, height:{1}", width, height));
  28.                 }
  29.             }
  30.         }
  31.         #endregion
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement