Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

[Flags] attribute for 'UnityEditor.GizmoType'

Discussion in '2018.3 Beta' started by Rallix, Oct 10, 2018.

  1. Rallix

    Rallix

    Joined:
    Mar 17, 2016
    Posts:
    139
    I encountered a minor problem when creating custom gizmos in the Editor. It's reproducible in the 2018.3b04 version I'm using right now but it was likely present in the earlier versions as well.

    The DrawGizmo attribute uses the GizmoType enum, e.g. in this example from the documentation:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. public class MyScript : MonoBehaviour { }
    5.  
    6. public class MyScriptGizmoDrawer
    7. {
    8.     [DrawGizmo(GizmoType.Selected | GizmoType.Active)]
    9.     static void DrawGizmoForMyScript(MyScript scr, GizmoType gizmoType)
    10.     {
    11.         Vector3 position = scr.transform.position;
    12.  
    13.         if (Vector3.Distance(position, Camera.current.transform.position) > 10f)
    14.             Gizmos.DrawIcon(position, "MyScript Gizmo.tiff");
    15.     }
    16. }
    From this, it's clear that GizmoType is intended to be used as bit flags rather than single constants.
    However, if UnityCsReference is to be believed, the GizmoType enum isn't marked with FlagsAttribute which causes the code editor to complain.

    Warning.png
    "Bitwise operation on enum which is not marked by [Flags] attribute."

    It's not exactly a bug – it works the same way without the attribute – just a cosmetic change to let the users (and the compiler) know a combination of multiple values is possible.
     
    Last edited: Oct 10, 2018
  2. j-h-a

    j-h-a

    Joined:
    Oct 31, 2015
    Posts:
    2
    Yeah, this is a bug.
    I also consider it wrong that C# compiles it - it should be a compile error.