Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by adsilcott · Apr 16, 2017 at 12:32 AM · guieditorspritesceneviewdrawtexture

strange results with GUI.DrawTexture() in the editor scene

I'm creating a quick prototype to test an idea, and working on some editor tools for it. I want to display a sprite over certain points on a grid to indicate where a creature will spawn when the game runs. But when I use GUI.DrawTexture(), I get strange results:

alt text

As you can see, the textures only render in the upper right quadrant of the scene view. As I scroll the scene view around, the textures disappear as they cross the center point.

Another odd thing is that if I add a 0.5f vector offset to the position in the code below, the position of the creature textures don't change. And if I half the size of the Rect they disappear.

Here's the code:

 [DrawGizmo(GizmoType.NotInSelectionHierarchy | GizmoType.InSelectionHierarchy)]
 static void DrawSprite(GridObject gridObject, GizmoType gizmoType)
 {
     if (gridObject.spawnType == GridProperties.SpawnType.Basic)
     {
         Sprite sprite = gridObject.properties.spawns [((int)gridObject.spawnType) - 1].GetComponentInChildren <SpriteRenderer> ().sprite;
         Rect texRect = new Rect (gridObject.transform.position, new Vector2 (1f, -1f));
         GUI.DrawTexture (texRect, sprite.texture);
     }
 }

The only think I can think is that I'm doing something fundamentally wrong with the GUI.DrawTexture method.

texturedrawweird.png (24.1 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by adsilcott · Apr 16, 2017 at 06:00 PM

I made a test scene and tried it again but with:

 GUI.DrawTextureWithTexCoords ()
 EditorGUI.DrawTextureTransparent ()
 EditorGUI.DrawPreviewTexture ()
 EditorGUI.DrawTextureAlpha ()

They all do the same thing, clipping to the upper right corner of the scene view, even in 3d view. I'm wondering if this should be a bug report.

Anyway, what finally worked for me was:

Gizmos.DrawGUITexture(texRect, sprite.texture);

The new code is:

 [DrawGizmo(GizmoType.NotInSelectionHierarchy | GizmoType.InSelectionHierarchy)]
 static void DrawSprite(GridObject gridObject, GizmoType gizmoType)
 {
     Rect texRect = new Rect (gridObject.transform.position, new Vector2 (1f, -1f));
     if (!Application.isPlaying)
         Gizmos.DrawGUITexture(texRect, gridObject.sprite.texture);
 }

However I still can't seem to offset the position of the Rect. It always snaps to the nearest 1 unit grid lines. For example if I change it to:

 Rect texRect = new Rect ((Vector2) gridObject.transform.position + new Vector2(.5f, .5f), new Vector2 (1f, -1f));

They all jump over one unit space, rather than half a unit as expected. I might start a new question for this.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jennal · Feb 13, 2019 at 07:04 AM 0
Share

I stucked on the same problem when Gizmos.DrawGUITexture jump over units, did you find a solution yet?

avatar image adsilcott jennal · Feb 13, 2019 at 07:39 AM 0
Share

I'm afraid not, I moved on to another project and haven't used Gizmos.DrawGUITexture much since then.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

128 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

texCoords rect for GUI.DrawTextureWithTexCoords 3 Answers

Displaying single sprite from spritesheet on GUI 1 Answer

Using sprites as GUI 1 Answer

Extending editor without script on GameObject? 1 Answer

Hide all objects except selected object in scene view 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges