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 DaveA · Mar 02, 2012 at 09:05 AM · editortexturecustomgizmo

How to draw a textured plane in Editor?

I want to make a custom editor which draws a textured plane in 3-space (not like a billboard icon). Think of it as a reference object. Is this possible, and which API's would be involved?

Comment
Add comment · Show 4
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 syclamoth · Mar 02, 2012 at 09:08 AM 1
Share

Good one. Usually I just use Graphics.Draw (and its variants) with a plane mesh, but it's a bit of a hack.

avatar image DaveA · Mar 02, 2012 at 09:15 AM 0
Share

Interesting. So I'm guessing Draw$$anonymous$$eshNow in LateUpdate on script marked to run in edit mode?

avatar image DaveA · Mar 02, 2012 at 10:23 PM 0
Share

Would you be able to post any working code? $$anonymous$$y attempts at this produce nothing. No Update or OnGUI seems to draw anything, using this as a basis (and setting mat and mesh in inspector): http://unity3d.com/support/documentation/ScriptReference/Graphics.Draw$$anonymous$$eshNow.html

avatar image DaveA · Mar 02, 2012 at 10:28 PM 0
Share

OnDrawGizmos seems to be working....

2 Replies

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

Answer by DaveA · Mar 02, 2012 at 10:38 PM

This is what's working for me. Props to Bunny83 and syclamoth!

 @script ExecuteInEditMode()
 var aMesh : Mesh;
 var mat : Material;
 
 function Start () {
     hideFlags = HideFlags.HideAndDontSave;
 }
 
 function OnDrawGizmos() {
     // SetPass to 0 if the material doesnt have a texture.
     mat.SetPass(1);
     Graphics.DrawMeshNow(aMesh, Matrix4x4.Scale(transform.localScale));
 }
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 Bunny83 · Mar 03, 2012 at 12:32 PM 0
Share

;) Ok a combination, but keep in $$anonymous$$d that Graphics.Draw$$anonymous$$eshNow is a pro only feature.

avatar image
1

Answer by Bunny83 · Mar 02, 2012 at 10:07 AM

You can use the usual procedure. Just use GameObjects and a camera. Make sure you use a seperate unused layer so it's seperated from the actual scene.

The next important thing is that you set the hideFlags of all objects you create for your editor to at least "DontSave" or "HideAndDontSave", otherwise the object get saved into the current scene.

If you want to use an EditorWindow, you can use Camera.Render in OnGUI() to render the camera into the editor window. Note: make sure you only call it in the repaint step.

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 DaveA · Mar 02, 2012 at 08:32 PM 0
Share

" and a camera" - not sure what you mean. Can I access the editor's 3D view camera(s)? What I'm shooting for is like a gizmo, but that renders an image, presumably on a planar mesh (any mesh would be interesting too). It would be seen and perhaps manipulated in the Editor's 3D views, but not seen at runtime.

avatar image Bunny83 · Mar 02, 2012 at 10:49 PM 1
Share

Well, the editor uses GameObjects and Cameras exactly like you do at runtime. The editors camera has hideflags set so it won't show up in the scenes hierarchy panel and it's not saved along with the scene.

I thought you talk about a custom editorwindow, but you can also draw something in the "normal" sceneview. If you have ILSpy, take a look into the UnityEditor.dll assembly. The SceneView class isn't documented, but it can be accessed. With SceneView.lastActiveSceneView.camera you can access the camera used by the scene view.

There's also the function Resources.FindObjectsOfTypeAll which can also "find" those internal objects.

You can do exactly the same. You can create a temporary gameobject with a mesh (plane, cube, ...) and display it right along with your usual scene objects. The hideflags also have a NotEditable flag so the object can't be edited. There's even an example with a plane mesh ^^

But be careful. You have to take care of destroing the objects when you don't need them anymore. They can cause memory leaks in the editor if you just forget about them. Some are caught by the editor, some are not.

Final note: Never use Destroy() in the editor. You always have to use DestroyImmediate() in the editor.

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

6 People are following this question.

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

Related Questions

How would I make a custom editor for texture swatches like Terrain editor? 2 Answers

Are textured/z-clipped gizmos possible? 0 Answers

Draw texture in editor with size less than a single unit 2 Answers

Blending edges of textures in the Terrain Editor 0 Answers

Unity editor and inspector header 0 Answers


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