Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Contextual Overlay

Discussion in '2021.2 Beta' started by DeanJGrey, Jun 23, 2021.

  1. DeanJGrey

    DeanJGrey

    Joined:
    Sep 16, 2015
    Posts:
    5
    Is it possible to create an overlay like the one shown here?

    upload_2021-6-23_23-12-37.png

    This is an overlay shown when a Tilemap component is in the scene.

    When you deactivate the GameObject the tile map component is on, it disappears:

    upload_2021-6-23_23-14-17.png

    Additionally, it doesn't appear in the overlay List:
    upload_2021-6-23_23-15-14.png
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    GamerXP, DeanJGrey and mariandev like this.
  3. DeanJGrey

    DeanJGrey

    Joined:
    Sep 16, 2015
    Posts:
    5
    Thank you, ChuanXin.

    I'm have a bit of trouble getting it to work.

    Could you please show me a bit of code?
     
  4. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    You could implement ITransientOverlay.visible with something like below where your overlay would only show if your GameObject selection was enabled. You can modify it to check for other criteria, such as if it has a Tilemap component or otherwise.

    Code (CSharp):
    1. public bool visible
    2. {
    3.     get
    4.     {
    5.         return Selection.activeGameObject != null && Selection.activeGameObject.activeSelf;
    6.     }
    7. }
     
  5. DeanJGrey

    DeanJGrey

    Joined:
    Sep 16, 2015
    Posts:
    5
    You're the best, ChuanXin.
    Thank you!

    For anyone else looking, this is how you do it:

    Code (CSharp):
    1.  
    2.     [Overlay (typeof (SceneView), "MyOverlay", true)]
    3.     public class MyOverlay : Overlay, ITransientOverlay
    4.     {
    5.         // This bit is what makes it visible or not, based on whether this returns true or false
    6.         public bool visible
    7.         {
    8.             get
    9.             {
    10.                 return
    11.                     Selection.activeGameObject != null &&
    12.                     Selection.activeGameObject.GetComponent <TileMaster> () != null; // Or whatever logic you want to dictate true or false
    13.             }
    14.         }
    15.  
    16.         public override VisualElement CreatePanelContent ()
    17.         {
    18.             return new Button (); // Or whatever visual elects you want
    19.         }
    20.     }
    21.