Contextual Overlay

Is it possible to create an overlay like the one shown here?

7264147--876631--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:

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

Additionally, it doesn’t appear in the overlay List:
7264147--876637--upload_2021-6-23_23-15-14.png

Your overlay needs to inherit from this interface:
https://docs.unity3d.com/2021.2/Documentation/ScriptReference/Overlays.ITransientOverlay.html

3 Likes

Thank you, ChuanXin.

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

Could you please show me a bit of code?

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.

public bool visible
{
    get
    {
        return Selection.activeGameObject != null && Selection.activeGameObject.activeSelf;
    }
}
4 Likes

You’re the best, ChuanXin.
Thank you!

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

    [Overlay (typeof (SceneView), "MyOverlay", true)]
    public class MyOverlay : Overlay, ITransientOverlay
    {
        // This bit is what makes it visible or not, based on whether this returns true or false
        public bool visible
        {
            get
            {
                return
                    Selection.activeGameObject != null &&
                    Selection.activeGameObject.GetComponent <TileMaster> () != null; // Or whatever logic you want to dictate true or false
            }
        }

        public override VisualElement CreatePanelContent ()
        {
            return new Button (); // Or whatever visual elects you want
        }
    }
4 Likes