GeeItSomeLaldy

Draw Texture Gizmo

May 10th, 2021 (edited)
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. #if UNITY_EDITOR
  2.         private void OnDrawGizmos()
  3.         {
  4.             if (Prefab != null)
  5.             {
  6.                 var icon = UnityEditor.AssetPreview.GetAssetPreview(Prefab);
  7.                 var matrix = GL.modelview; //Get the current View Matrix
  8.  
  9.                 //Begin Insanity
  10.                 GL.PushMatrix();
  11.                
  12.                 //Downscale the previous view matrix by 100
  13.                 GL.modelview = matrix * Matrix4x4.Scale(Vector3.one / 100f);
  14.  
  15.                 //Center the icon bounds on the Game Object. Flip the Y-scale because.
  16.                 var rect = new Rect(transform.position - new Vector3(.5f, -.5f, 0), new Vector2(1, -1));
  17.  
  18.                 //Upscale the rectangle bounds by 100
  19.                 rect.x *= 100;
  20.                 rect.y *= 100;
  21.                 rect.width *= 100;
  22.                 rect.height *= 100;
  23.  
  24.                 //Draw the rest of the Owl
  25.                 Gizmos.DrawGUITexture(rect, icon);
  26.  
  27.                 //End Insanity?
  28.                 GL.PopMatrix();
  29.  
  30.                 Gizmos.color = Color.green;
  31.                 Gizmos.DrawWireCube(this.transform.position, Vector2.one);
  32.             } else
  33.             {
  34.                 Gizmos.color = Color.red;
  35.                 Gizmos.DrawCube(this.transform.position, Vector2.one);
  36.             }
  37.         }
  38.     }
  39. #endif
Add Comment
Please, Sign In to add comment