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 /
  • Help Room /
avatar image
1
Question by julian_weltenbauer · Oct 19, 2017 at 11:11 AM · custom editorocclusionhandles

How to draw Handles transparent occluded by geometry

I've build a custom Editor for Setting Up specific Systems in our game world. I want my Handles to be transparent when occluded by any objects (especially my colliders to see if they intersect with the terrain).

Right now they're just drawn on top of erverything else, whereas Unity's BoxColliderEditor for example switches to draw transparent lines when the collider is stuck in or hidden by any geometry.

My OnSceneGUI is registered to SceneView.onSceneGUIDelegate and within that i call DrawCollider():

 private void DrawCollider(BoxCollider col, bool selected) {
 
             Color clr = Handles.color;
 
             if (selected) {
                 Handles.color = Color.magenta;
             }
 
             Vector3 center = col.center;
             Vector3 size = col.size;
             Vector3 minPos = center - size * 0.5f;
             Vector3 maxPos = center + size * 0.5f;
 
             Matrix4x4 matrix = Handles.matrix;
             Handles.matrix = Matrix4x4.TRS(col.transform.position, col.transform.rotation, Vector3.one);
 
             //Draw Box
             Handles.DrawWireCube(center, size);
 
             if (selected) {
 
                 Vector3 topRight = this.DrawMovementHandler(new Vector3(maxPos.x, center.y + size.y * 0.5f, maxPos.z));
                 Vector3 botLeft = this.DrawMovementHandler(new Vector3(minPos.x, center.y - size.y * 0.5f, minPos.z));
 
                 if (topRight.z > botLeft.z && topRight.x > botLeft.x && topRight.y > botLeft.y) {
 
                     col.center = (topRight + botLeft) * 0.5f;
                     col.size = topRight - botLeft;
 
                 }
             }
 
             Handles.matrix = matrix;
             Handles.color = clr;
         }

I just don't understand how Unity's BoxColliders are drawn differently. As far as i figured out Unity is also just calling Handles.DrawWireCube internally in it's OnSceneGUI Method (from BoxEditor.cs):

       Color color = Handles.color;
       Handles.color = boxColor;
       Vector3 minPos = center - size * 0.5f;
       Vector3 maxPos = center + size * 0.5f;
       Matrix4x4 matrix = Handles.matrix;
       Handles.matrix = transform;
       int hotControl = GUIUtility.hotControl;
       if (!handlesOnly)
         Handles.DrawWireCube(center, size);
       Vector3 point = transform.inverse.MultiplyPoint(Camera.current.transform.position);
       bool isCameraInsideBox = new Bounds(center, size).Contains(point);
       Handles.color = midPointHandleColor;
       this.MidpointHandles(ref minPos, ref maxPos, Handles.matrix, isCameraInsideBox);
       if (hotControl != GUIUtility.hotControl && GUIUtility.hotControl != 0)
         this.m_HandleControlID = GUIUtility.hotControl;
       bool changed = GUI.changed;
       if (changed)
       {
         center = (maxPos + minPos) * 0.5f;
         size = maxPos - minPos;
       }
       Handles.color = color;
       Handles.matrix = matrix;


So i was just wondering where the magic happens and how the depth value is conscidered for drawing these handles.

Unity Box: alt text

My Box: alt text

unityboxcollider.jpg (286.2 kB)
myboxcollider.jpg (307.5 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
1

Answer by Haderer · Jan 21, 2018 at 10:02 PM

try this ;-)

https://docs.unity3d.com/ScriptReference/Handles-zTest.html

Comment
Add comment · 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

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

119 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

Related Questions

Progrid with custom handle 1 Answer

How to fix Emission maps that aren't cooperating with other maps? 0 Answers

Do Unity Editor GUI Utilities (Handles.DrawLine & EditorGUI.DrawRect) have limitations? 2 Answers

UnityEvent referens to custom editor from inside array of class and editor losing settings 1 Answer

How can I color a PrefixLabel? 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