Assignment for RMIT Mixed Reality in 2020
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.

81 lines
2.6 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_tags;
  13. private string m_category;
  14. private string m_description;
  15. private System.Type m_type;
  16. private GUIContent m_guiContent;
  17. private string m_nameWithShortcut;
  18. private AmplifyShaderFunction m_function;
  19. private NodeAttributes m_nodeAttributes;
  20. public ContextMenuItem( NodeAttributes nodeAttributes, System.Type type, string name, string tags, string category, string description, AmplifyShaderFunction function, KeyCode shortcut )
  21. {
  22. m_nodeAttributes = nodeAttributes;
  23. m_name = name;
  24. m_tags = name + ( string.IsNullOrEmpty( tags ) ? "" : " " + tags );
  25. m_tags = m_tags.ToLower();
  26. m_nameWithShortcut = shortcut != KeyCode.None ? ( name + " [ " + UIUtils.KeyCodeToString( shortcut ) + " ]" ) : name;
  27. m_paletteName = PALETTE_NAME_MOD_STR + m_name;
  28. m_type = type;
  29. m_category = category;
  30. m_description = description;
  31. m_function = function;
  32. m_guiContent = new GUIContent( m_nameWithShortcut, m_description );
  33. }
  34. public int CompareTo( ContextMenuItem item , bool useWeights )
  35. {
  36. if ( useWeights && NodeAttributes.SortOrderPriority > -1 && item.NodeAttributes.SortOrderPriority > -1 )
  37. {
  38. if ( NodeAttributes.SortOrderPriority > item.NodeAttributes.SortOrderPriority )
  39. {
  40. return 1;
  41. }
  42. else if ( NodeAttributes.SortOrderPriority == item.NodeAttributes.SortOrderPriority )
  43. {
  44. return m_name.CompareTo( item.Name );
  45. }
  46. else
  47. {
  48. return -1;
  49. }
  50. }
  51. return m_name.CompareTo( item.Name );
  52. }
  53. public string PaletteName { get { return m_paletteName; } }
  54. public string Name { get { return m_name; } }
  55. public string Tags { get { return m_tags; } }
  56. public string NameWithShortcut { get { return m_nameWithShortcut; } }
  57. public string Category { get { return m_category; } }
  58. public string Description { get { return m_description; } }
  59. public AmplifyShaderFunction Function { get { return m_function; } }
  60. public System.Type NodeType { get { return m_type; } }
  61. public GUIContent ItemUIContent { get { return m_guiContent; } }
  62. public NodeAttributes NodeAttributes { get { return m_nodeAttributes; } }
  63. public override string ToString()
  64. {
  65. return m_name + ":" + m_category + ":" + m_description;
  66. }
  67. public void Destroy()
  68. {
  69. m_guiContent = null;
  70. m_nodeAttributes = null;
  71. }
  72. }
  73. }