Exemplo n.º 1
0
        /// <summary>
        /// Adds a command to the <see cref="EditorMenu"/>.
        /// </summary>
        /// <example>
        /// <para>Add command with a straightforward action:</para>
        /// <code language="csharp"><![CDATA[
        /// var menu = new EditorMenu();
        /// menu.AddCommand("Do Something!")
        ///     .Action(() => {
        ///         Debug.Log("Woot!");
        ///     });
        /// ]]></code>
        ///
        /// <para>Add a command that is always disabled:</para>
        /// <code language="csharp"><![CDATA[
        /// var menu = new EditorMenu();
        /// menu.AddCommand("Disabled Command - No Action");
        /// ]]></code>
        ///
        /// <para>Add a command that is conditionally disabled:</para>
        /// <code language="csharp"><![CDATA[
        /// var menu = new EditorMenu();
        /// menu.AddCommand("Delete Selected")
        ///     .Enabled(selectedObject != null)
        ///     .Action(() => {
        ///         Undo.DestroyObjectImmediate(selectedObject);
        ///     });
        /// ]]></code>
        ///
        /// <para>Add a command that is conditionally visible:</para>
        /// <code language="csharp"><![CDATA[
        /// var menu = new EditorMenu();
        /// menu.AddCommand("Edit Tileset...")
        ///     .Visible(selectedObject is TilesetBrush)
        ///     .Action(() => {
        ///         var tilesetBrush = selectedObject as TilesetBrush;
        ///         ToolUtility.ShowTilesetInDesigner(tilesetBrush.Tileset);
        ///     });
        /// ]]></code>
        ///
        /// <para>Add commands to a sub-menu:</para>
        /// <code language="csharp"><![CDATA[
        /// var menu = new EditorMenu();
        /// menu.AddCommand("Sort/Ascending")
        ///     .Checked(this.SortMode == SortMode.Ascending)
        ///     .Action(() => this.SortMode = SortMode.Ascending);
        /// menu.AddCommand("Sort/Descending")
        ///     .Checked(this.SortMode == SortMode.Descending)
        ///     .Action(() => this.SortMode = SortMode.Descending);
        /// ]]></code>
        /// </example>
        /// <param name="fullPath">Full path of the menu command.</param>
        /// <returns>
        /// Fluid style API to further define the new command entry.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="fullPath"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// If <paramref name="fullPath"/> is an empty string or starts with a slash.
        /// </exception>
        /// <seealso cref="AddSeparator(string)"/>
        public virtual EditorMenuCommandBinder AddCommand(string fullPath)
        {
            var entry = new EditorMenuCommandEntry(fullPath);

            this.entries.Add(entry);
            return(new EditorMenuCommandBinder(entry));
        }
        /// <summary>
        /// Adds a command entry to the <see cref="GenericMenu"/>.
        /// </summary>
        /// <example>
        /// <para>Can be overriden to provide special <see cref="EditorMenuCommandEntry"/>
        /// implementations:</para>
        /// <code language="csharp"><![CDATA[
        /// protected override void AddCommandEntryToMenu(GenericMenu menu, EditorMenuCommandEntry entry)
        /// {
        ///     var specialCommandEntry = entry as EditorMenuSpecialCommandEntry;
        ///     if (specialCommandEntry != null) {
        ///         this.AddSpecialCommandEntryToMenu(menu, specialCommandEntry);
        ///         return;
        ///     }
        ///
        ///     // Assume the default implementation.
        ///     base.AddCommandEntryToMenu(menu, entry);
        /// }
        /// ]]></code>
        /// </example>
        /// <param name="genericMenu">Input menu data structure.</param>
        /// <param name="entry">Menu entry that is currently being added.</param>
        protected virtual void AddCommandEntryToMenu(GenericMenu genericMenu, EditorMenuCommandEntry entry)
        {
            var content = new GUIContent(entry.FullPath);

            if (entry.EvaluateIsEnabled())
            {
                genericMenu.AddItem(content, entry.EvaluateIsChecked(), () => entry.InvokeAction());
            }
            else
            {
                genericMenu.AddDisabledItem(content);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorMenuCommandBinder"/> class.
        /// </summary>
        /// <param name="entry">The associated command entry.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="entry"/> is <c>null</c>.
        /// </exception>
        public EditorMenuCommandBinder(EditorMenuCommandEntry entry)
        {
            ExceptionUtility.CheckArgumentNotNull(entry, "entry");

            this.Entry = entry;
        }