Ejemplo n.º 1
0
        public MarkerTrack(Timeline owner) : base(owner)
        {
            name = "Markers";
            AddToClassList("markerTrack");

            RegisterCallback <AttachToPanelEvent>(OnAttachToPanel);
            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel);

            m_MarkerOverlapIndicators = new List <MarkerOverlapIndicator>();
            var manipulator = new ContextualMenuManipulator(evt =>
            {
                DropdownMenu menu = evt.menu;
                float time        = m_Owner.WorldPositionToTime(evt.mousePosition.x);
                if (m_Owner.ViewMode == TimelineViewMode.frames)
                {
                    time = (float)TimelineUtility.RoundToFrame(time, Clip.SampleRate);
                }

                string timeStr = TimelineUtility.GetTimeString(m_Owner.ViewMode, time, (int)Clip.SampleRate);

                menu.AppendAction($"Add Marker at {timeStr}", null, DropdownMenuAction.Status.Disabled);
                menu.AppendSeparator();
                var menuStatus = EditorApplication.isPlaying ? DropdownMenuAction.Status.Disabled : DropdownMenuAction.Status.Normal;
                foreach (Type markerType in MarkerAttribute.GetMarkerTypes())
                {
                    evt.menu.AppendAction(MarkerAttribute.GetDescription(markerType), action => OnAddAnnotationSelection(markerType, time), a => menuStatus, markerType);
                }
            });

            this.AddManipulator(manipulator);
        }
        public static void AddCopyValue <TValue>(this DropdownMenu menu, TValue value)
        {
            menu.AppendAction($"{k_CopyPrefix}All", action => { EditorGUIUtility.systemCopyBuffer = JsonSerialization.ToJson(value); });
            menu.AppendSeparator(k_CopyPrefix);
            var visitor = new DropdownMenuCopyVisitor(menu);

            PropertyContainer.Visit(value, visitor);
        }
Ejemplo n.º 3
0
        private void Start()
        {
            var root = uiDoc.rootVisualElement;

            dropdown = new Dropdown(root);

            //setup button menu;
            btnMenu = new DropdownMenu();
            btnMenu.AppendAction("Action 1", DoMenuAction);
            btnMenu.AppendAction("Action 2", DoMenuAction);
            btnMenu.AppendAction("Action 3", DoMenuAction);
            btnMenu.AppendAction("DisabledAction", DoMenuAction, DropdownMenuAction.AlwaysDisabled);
            btnMenu.AppendSeparator();
            btnMenu.AppendAction("Sub Menu/Action 4", DoMenuAction);
            btnMenu.AppendSeparator("Sub Menu/");
            btnMenu.AppendAction("Sub Menu/Action 5", DoMenuAction);
            btnMenu.AppendAction("Sub Menu/Another Sub Menu/Action 6", DoMenuAction);
            btnMenu.AppendAction("Sub Menu/Another Sub Menu/Action 7", DoMenuAction);
            btnMenu.AppendAction("Deep/Nested/Menu/That/Would/Annoy/Anyone/That/Has/To/Click/Through/It/But/Atleast/It/Wraps/Around/Nicely/When/It/Reaches/The/End/Of/The/Screen", DoMenuAction);

            var btn = root.Q <Button>(name: "dropdown-btn");

            btn.clickable.clicked += () => dropdown.Open(btnMenu, btn.worldBound);

            //setup pointer menu;
            pointerMenu = new DropdownMenu();
            pointerMenu.AppendAction("Koala", ToggleOption, GetOptionStatus);
            pointerMenu.AppendAction("Kangaroo", ToggleOption, GetOptionStatus);
            pointerMenu.AppendAction("Platypus", ToggleOption, GetOptionStatus);
            pointerMenu.AppendAction("Wombat", ToggleOption, GetOptionStatus);


            root.Q <VisualElement>(name: "dropdown-area").RegisterCallback <PointerDownEvent>(evt =>
            {
                if (evt.button == 1)
                {
                    Debug.Log("Click");
                    dropdown.Open(pointerMenu, evt.position);
                }
            });
        }
Ejemplo n.º 4
0
        public void OnAdvancedMenuCreate(DropdownMenu menu)
        {
            if (!Unsupported.IsDeveloperMode())
            {
                return;
            }

            menu.AppendSeparator();
            menu.AppendAction("Internal/Always show development tools", a =>
            {
                OnDevelopmentToolToggle();
            }, a => !Unsupported.IsDeveloperMode() ? DropdownMenuAction.Status.Hidden :
                              AlwaysShowDevTools?DropdownMenuAction.Status.Checked: DropdownMenuAction.Status.Normal);
        }
Ejemplo n.º 5
0
        void AppendWorldMenu(DropdownMenu menu, bool showAdvancedWorlds)
        {
            var worldCategories = WorldCategoryHelper.Categories;

            foreach (var category in worldCategories)
            {
                if (showAdvancedWorlds)
                {
                    menu.AppendAction(category.Name.ToUpper(), null, DropdownMenuAction.Status.Disabled);
                    AppendWorlds(menu, category);
                    menu.AppendSeparator();
                }
                else if (category.Flag == WorldFlags.Live)
                {
                    AppendWorlds(menu, category);
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        public void RefreshDropdown()
        {
            if (m_NeedRefresh || m_DropdownItems.Any(item => item.needRefresh))
            {
                m_BuiltInItems.Sort(ExtensionManager.CompareExtensions);
                m_DropdownItems.Sort(ExtensionManager.CompareExtensions);

                var newDropdownMenu = new DropdownMenu();
                foreach (var item in m_BuiltInItems.Concat(m_DropdownItems))
                {
                    if (item.insertSeparatorBefore)
                    {
                        newDropdownMenu.AppendSeparator();
                    }

                    newDropdownMenu.AppendAction(item.text, a => { item.action?.Invoke(); }, item.statusCallback, item.userData);
                    item.needRefresh = false;
                }
                menu          = newDropdownMenu;
                m_NeedRefresh = false;
            }
        }
Ejemplo n.º 7
0
        public void OnAddMenuCreate(DropdownMenu menu)
        {
            menu.AppendSeparator("");

            menu.AppendAction("Create Package...", a =>
            {
                var defaultName              = PackageCreator.GenerateUniquePackageDisplayName("New Package");
                var createPackage            = new PackagesAction("Create", defaultName);
                createPackage.actionClicked += displayName =>
                {
                    createPackage.Hide();
                    var packagePath = PackageCreator.CreatePackage("Packages/" + displayName);
                    PackageManagerWindowAnalytics.SendEvent("createPackage");
                    AssetDatabase.Refresh();
#if UNITY_2020_1_OR_NEWER
                    EditorApplication.delayCall += () => Window.Open(displayName);
#else
                    EditorApplication.delayCall += () =>
                    {
                        var path = Path.Combine(packagePath, "package.json");
                        var o    = AssetDatabase.LoadMainAssetAtPath(path);
                        if (o != null)
                        {
                            Selection.activeObject = o;
                        }

                        PackageManagerWindow.SelectPackageAndFilter(displayName, PackageFilterTab.InDevelopment, true);
                    };
#endif
                };

                var parent = EditorWindow.GetWindow <PackageManagerWindow>()
                             .rootVisualElement.Q <PackageManagerToolbar>("topMenuToolbar")
                             .parent;
                parent.Add(createPackage);
                createPackage.Show();
            }, a => DropdownMenuAction.Status.Normal);
        }
 public override void OnCreateContextMenu(DropdownMenu dropdownMenu)
 {
     dropdownMenu.AppendSeparator();
     dropdownMenu.AppendAction("Add input", action => AddInput());
     dropdownMenu.AppendAction("Remove input", action => RemoveInput());
 }