You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.4 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. using UnityEngine;
  5. namespace AmplifyShaderEditor
  6. {
  7. public class ContextMenuItem
  8. {
  9. private const string PALETTE_NAME_MOD_STR = " ";
  10. private string m_paletteName;
  11. private string m_name;
  12. private string m_category;
  13. private string m_description;
  14. private System.Type m_type;
  15. private GUIContent m_guiContent;
  16. private string m_nameWithShortcut;
  17. private AmplifyShaderFunction m_function;
  18. private NodeAttributes m_nodeAttributes;
  19. public ContextMenuItem( NodeAttributes nodeAttributes, System.Type type, string name, string category, string description, AmplifyShaderFunction function, KeyCode shortcut )
  20. {
  21. m_nodeAttributes = nodeAttributes;
  22. m_name = name;
  23. m_nameWithShortcut = shortcut != KeyCode.None ? ( name + " [ " + UIUtils.KeyCodeToString( shortcut ) + " ]" ) : name;
  24. m_paletteName = PALETTE_NAME_MOD_STR + m_name;
  25. m_type = type;
  26. m_category = category;
  27. m_description = description;
  28. m_function = function;
  29. m_guiContent = new GUIContent( m_nameWithShortcut, m_description );
  30. }
  31. public int CompareTo( ContextMenuItem item , bool useWeights )
  32. {
  33. if ( useWeights && NodeAttributes.SortOrderPriority > -1 && item.NodeAttributes.SortOrderPriority > -1 )
  34. {
  35. if ( NodeAttributes.SortOrderPriority > item.NodeAttributes.SortOrderPriority )
  36. {
  37. return 1;
  38. }
  39. else if ( NodeAttributes.SortOrderPriority == item.NodeAttributes.SortOrderPriority )
  40. {
  41. return m_name.CompareTo( item.Name );
  42. }
  43. else
  44. {
  45. return -1;
  46. }
  47. }
  48. return m_name.CompareTo( item.Name );
  49. }
  50. public string PaletteName { get { return m_paletteName; } }
  51. public string Name { get { return m_name; } }
  52. public string NameWithShortcut { get { return m_nameWithShortcut; } }
  53. public string Category { get { return m_category; } }
  54. public string Description { get { return m_description; } }
  55. public AmplifyShaderFunction Function { get { return m_function; } }
  56. public System.Type NodeType { get { return m_type; } }
  57. public GUIContent ItemUIContent { get { return m_guiContent; } }
  58. public NodeAttributes NodeAttributes { get { return m_nodeAttributes; } }
  59. public override string ToString()
  60. {
  61. return m_name + ":" + m_category + ":" + m_description;
  62. }
  63. public void Destroy()
  64. {
  65. m_guiContent = null;
  66. m_nodeAttributes = null;
  67. }
  68. }
  69. }