暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

MenuEntryAttribute.cs 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.Timeline.Actions
  4. {
  5. /// <summary>
  6. /// Use this attribute to add a menu item to a context menu.
  7. /// Used to indicate path and priority that are auto added to the menu
  8. /// (examples can be found on <see href="https://docs.unity3d.com/ScriptReference/MenuItem.html"/>).
  9. /// </summary>
  10. /// <example>
  11. /// <code source="../../DocCodeExamples/TimelineAttributesExamples.cs" region="declare-menuEntryAttribute" title="menuEntryAttr"/>
  12. /// </example>
  13. /// <remarks>
  14. /// Unlike Menu item, MenuEntryAttribute doesn't handle shortcuts in the menu name. See <see cref="TimelineShortcutAttribute"/>.
  15. /// </remarks>
  16. [AttributeUsage(AttributeTargets.Class)]
  17. public class MenuEntryAttribute : Attribute
  18. {
  19. internal readonly int priority;
  20. internal readonly string name;
  21. internal readonly string subMenuPath;
  22. /// <summary>
  23. /// Constructor for Menu Entry Attribute to define information about the menu item for an action.
  24. /// </summary>
  25. /// <param name="path">Path to the menu. If there is a "/" in the path, it will create one (or multiple) submenu items.</param>
  26. /// <param name="priority">Priority to decide where the menu will be positioned in the menu.
  27. /// The lower the priority, the higher the menu item will be in the context menu.
  28. /// </param>
  29. /// <seealso cref="MenuPriority"/>
  30. public MenuEntryAttribute(string path = default, int priority = MenuPriority.defaultPriority)
  31. {
  32. path = path ?? string.Empty;
  33. path = L10n.Tr(path);
  34. this.priority = priority;
  35. var index = path.LastIndexOf('/');
  36. if (index >= 0)
  37. {
  38. name = (index == path.Length - 1) ? string.Empty : path.Substring(index + 1);
  39. subMenuPath = path.Substring(0, index + 1);
  40. }
  41. else
  42. {
  43. name = path;
  44. subMenuPath = string.Empty;
  45. }
  46. }
  47. }
  48. }