Search Unity

Handles.DotHandleCap ztest issue

Discussion in 'Scripting' started by ErrorX, Jun 10, 2018.

  1. ErrorX

    ErrorX

    Joined:
    May 21, 2014
    Posts:
    22
    If you set "Handles.zTest = CompareFunction.Less" this has no effect on "Handles.DotHandleCap" it only works with "Handles.DotCap" but this function is obsolete.
    So how can I solve this or is this a bug in Unity?


    My test code:
    Code (CSharp):
    1.  [CustomEditor(typeof(MyTestCode))]
    2. public class DotHandleTestEditor : Editor
    3. {
    4.      protected virtual void OnSceneGUI()
    5.      {
    6.          Handles.zTest = CompareFunction.Less;
    7.  
    8.          Quaternion lookAtRot = Quaternion.LookRotation(Camera.current.transform.position);
    9.          float size = HandleUtility.GetHandleSize(Vector3.zero);
    10.          if (Handles.Button(Vector3.zero, lookAtRot, size * 0.05f, size * 0.07f, Handles.DotCap))
    11.              Debug.Log("zTest works fine on this one");
    12.          lookAtRot = Quaternion.LookRotation(new Vector3(20, 0, 0) - Camera.current.transform.position);
    13.          if (Handles.Button(new Vector3(1,0,0), lookAtRot, size * 0.05f, size * 0.07f, Handles.DotHandleCap))
    14.              Debug.Log("zTest is not working on this one");
    15.      }
    16. }
     
    Last edited: Jun 11, 2018
    1nterstellar and t2g4 like this.
  2. ErrorX

    ErrorX

    Joined:
    May 21, 2014
    Posts:
    22
    Okey I dit some more research and I looked in de source code and I found this.

    Code (CSharp):
    1. //Unity 2018.1
    2. public sealed class Handles
    3. ...
    4.  
    5. [Obsolete("Use DotHandleCap instead")]
    6. public static void DotCap(int controlID, Vector3 position, Quaternion rotation, float size)
    7. {
    8.     if (Event.current.type == EventType.Repaint)
    9.     {
    10.         position = Handles.matrix.MultiplyPoint(position);
    11.         Vector3 b = Camera.current.transform.right * size;
    12.         Vector3 b2 = Camera.current.transform.up * size;
    13.         Color c = Handles.color * new Color(1f, 1f, 1f, 0.99f);
    14.         HandleUtility.ApplyWireMaterial(Handles.zTest);
    15.         GL.Begin(7);
    16.         GL.Color(c);
    17.         GL.Vertex(position + b + b2);
    18.         GL.Vertex(position + b - b2);
    19.         GL.Vertex(position - b - b2);
    20.         GL.Vertex(position - b + b2);
    21.         GL.End();
    22.     }
    23. }
    24.  
    25. public static void DotHandleCap(int controlID, Vector3 position, Quaternion rotation, float size, EventType eventType)
    26. {
    27.     if (eventType != EventType.Layout)
    28.     {
    29.         if (eventType == EventType.Repaint)
    30.         {
    31.             position = Handles.matrix.MultiplyPoint(position);
    32.             Vector3 b = Camera.current.transform.right * size;
    33.             Vector3 b2 = Camera.current.transform.up * size;
    34.             Color c = Handles.color * new Color(1f, 1f, 1f, 0.99f);
    35.             HandleUtility.ApplyWireMaterial();
    36.             GL.Begin(7);
    37.             GL.Color(c);
    38.             GL.Vertex(position + b + b2);
    39.             GL.Vertex(position + b - b2);
    40.             GL.Vertex(position - b - b2);
    41.             GL.Vertex(position - b + b2);
    42.             GL.End();
    43.         }
    44.     }
    45.     else
    46.     {
    47.         HandleUtility.AddControl(controlID, HandleUtility.DistanceToRectangle(position, rotation, size));
    48.     }
    49. }
    As you can see DotCap uses the zTest
    Code (CSharp):
    1. HandleUtility.ApplyWireMaterial(Handles.zTest);
    And DotHandleCap does not use the zTest
    Code (CSharp):
    1. HandleUtility.ApplyWireMaterial();
    So I think the Unity team forgot to put it in there.
     
    Last edited: Jun 11, 2018
    1nterstellar and t2g4 like this.