Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by DriesVienne · Jul 02, 2013 at 07:50 PM · c#guieditortexture

Editor scripting: Part of a texture as button content

Hello guys!

Since I want to get the hang of creating custom editor tools, I've been working on a tile based map editor. It's quite simple, and allows me to focus on creating editor tools.

I create a mesh out of quads, and assign a sprite sheet (or atlas if you will) as the main texture. By switching around the UV coordinates of my vertices, I have a basic functioning tilemap.

I also have the basic controls down for creating this mesh through my editing window, and some simple tile picking code for in-editor tile changing.

Since I have all the information about what tiles are present in my main texture (sprite sheet/atlas), I would like to create a toggle button for each tile. The user would be able to select a tile in the editor window (similar to the unity texture bowser), and "paint" it on the plane by mouse picking.

I've found different ways of drawing textures as controls or on controls, but in this particular case I need only a part of the texture. I am aware that I could take the pixel data of my sheet, and create a new texture for each tile to use in my controls. While this could be done once, when assigning a texture to my mesh, I figure it still creates a lot of overhead.

So I was wondering if I could utilize the same technique as when i draw on my quads: pass some UV coordinates. That way, only part of the texture will be rendered on my buttons. The last solution i tried was reserving the spaces in the editor where my tiles should be by using GUILayoutUtility.GetRect(), saving these rects in a list, and later draw my texture using Graphics.DrawTexture(), which allows for UV's as parameters. This, in effect, draws only the needed tile on the correct position while maintaining my layout. While this works, it goes against the GUILayout's principle of assigning "content" to buttons, in fact, it doesn't create buttons at all ^^. I'm kind of all over the place trying to make this work, and getting it right would give me much more insight in creating decent editor windows.

So what should be the best practice when creating a "grid" of buttons (similar to the unity texture bowser), each with a part of a texture as content? Any thoughts on this? Or should I conclude that creating a seperate texture for each tile in advance is the best course of action?

Thanks in advance!

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
1
Best Answer

Answer by TonyLi · Jul 03, 2013 at 12:06 AM

Try GUI.DrawTextureWithTexCoords().

Comment
Add comment · Show 1 · 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 DriesVienne · Jul 03, 2013 at 06:48 PM 0
Share

How in the world did I miss that? Very much appreciated!

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

16 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

Related Questions

Texture2D not showing in build, but shows up in editor 1 Answer

Why are all my GUITexture elements semi-transparent? 0 Answers

GUI Label "flash a Arrow" 1 Answer

Unity Editor script arrows to display a variable 2 Answers

What does the code behind BeginHorizontal() and EndHorizontal() look like or is presumed to look like ? 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