Version: 2023.1
言語: 日本語
public Overlays.OverlayToolbar CreateVerticalToolbarContent ();

戻り値

OverlayToolbar The content of your overlay in vertical toolbar layout form.

説明

Implement this to return your visual element representing the vertical toolbar layout of your overlay.

using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Overlays;
using UnityEditor.Toolbars;
using UnityEngine;
using UnityEngine.UIElements;

[Overlay(typeof(SceneView), "Custom Toolbar Overlay")]
class CustomOverlay : Overlay, ICreateHorizontalToolbar, ICreateVerticalToolbar
{
    public override VisualElement CreatePanelContent()
    {
        return new Label("I'm the content shown in panel mode!");
    }

    // Setup horizontal layout to only have CustomToolbarItem visual element.
    public OverlayToolbar CreateHorizontalToolbarContent()
    {
        var horizontalOverlayToolbar = new OverlayToolbar();
        horizontalOverlayToolbar.Add(new CustomToolbarItem());

        return horizontalOverlayToolbar;
    }

    // Setup vertical layout to only have OtherToolbarItem visual element.
    public OverlayToolbar CreateVerticalToolbarContent()
    {
        var verticalOverlayToolbar = new OverlayToolbar();
        verticalOverlayToolbar.Add(new OtherToolbarItem());

        return verticalOverlayToolbar;
    }
}

[EditorToolbarElement("SomeOtherToolbarItem", typeof(SceneView))]
class OtherToolbarItem : EditorToolbarToggle
{
    public OtherToolbarItem()
    {
        icon = EditorGUIUtility.FindTexture("CustomTool");
    }
}

[EditorToolbarElement("MyToolbarItem", typeof(SceneView))]
class CustomToolbarItem : OverlayToolbar
{
    public CustomToolbarItem()
    {
        var icon = AssetDatabase.LoadAssetAtPath<Texture2D>("MyIcon");
        Add(new EditorToolbarButton(icon, () => { Debug.Log("Hello!"); }));
        Add(new EditorToolbarButton(icon, () => { Debug.Log("Hello again!"); }));
        SetupChildrenAsButtonStrip();
    }
}
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961