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