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.

93 lines
3.2 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 enum NodeAvailability
  8. {
  9. SurfaceShader = 1 << 0,
  10. ShaderFunction = 1 << 1,
  11. CustomLighting = 1 << 2,
  12. TemplateShader = 1 << 3
  13. }
  14. [AttributeUsage( AttributeTargets.Class )]
  15. public class NodeAttributes : Attribute
  16. {
  17. public string Name;
  18. public string Description;
  19. public string Category;
  20. public KeyCode ShortcutKey;
  21. public bool Available;
  22. public System.Type[] CastType; // Type that will be converted to AttribType if dropped on the canvas ... p.e. dropping a texture2d on the canvas will generate a sampler2d node
  23. public bool Deprecated;
  24. public string DeprecatedAlternative;
  25. public System.Type DeprecatedAlternativeType;
  26. public bool FromCommunity;
  27. public string CustomCategoryColor; // Color created via a string containing its hexadecimal representation
  28. public int SortOrderPriority; // to be used when name comparing on sorting
  29. public int NodeAvailabilityFlags;// used to define where this node can be used
  30. private string m_nodeUrl;
  31. public string Community;
  32. public NodeAttributes( string name, string category, string description, System.Type castType = null, KeyCode shortcutKey = KeyCode.None, bool available = true, bool deprecated = false, string deprecatedAlternative = null, System.Type deprecatedAlternativeType = null, string community = null, string customCategoryColor = null, int sortOrderPriority = -1, int nodeAvailabilityFlags = int.MaxValue )
  33. {
  34. Name = name;
  35. Description = description;
  36. Category = category;
  37. if( castType != null )
  38. CastType = new System.Type[] { castType };
  39. ShortcutKey = shortcutKey;
  40. Available = available;
  41. Deprecated = deprecated;
  42. DeprecatedAlternative = deprecatedAlternative;
  43. Community = community;
  44. if( string.IsNullOrEmpty( Community ) )
  45. Community = string.Empty;
  46. else
  47. FromCommunity = true;
  48. if( !string.IsNullOrEmpty( customCategoryColor ) )
  49. CustomCategoryColor = customCategoryColor;
  50. DeprecatedAlternativeType = deprecatedAlternativeType;
  51. SortOrderPriority = sortOrderPriority;
  52. NodeAvailabilityFlags = nodeAvailabilityFlags;
  53. //m_nodeUrl = ( FromCommunity ? Constants.CommunityNodeCommonUrl : Constants.NodeCommonUrl ) + UIUtils.UrlReplaceInvalidStrings( Name );
  54. }
  55. public NodeAttributes( string name, string category, string description, KeyCode shortcutKey, bool available, int sortOrderPriority, int nodeAvailabilityFlags, params System.Type[] castTypes )
  56. {
  57. Name = name;
  58. Description = description;
  59. Category = category;
  60. if( castTypes != null && castTypes.Length > 0 )
  61. {
  62. CastType = castTypes;
  63. }
  64. ShortcutKey = shortcutKey;
  65. Available = available;
  66. SortOrderPriority = sortOrderPriority;
  67. NodeAvailabilityFlags = nodeAvailabilityFlags;
  68. //m_nodeUrl = ( FromCommunity ? Constants.CommunityNodeCommonUrl : Constants.NodeCommonUrl ) + UIUtils.UrlReplaceInvalidStrings( Name );
  69. }
  70. public string NodeUrl
  71. {
  72. get
  73. {
  74. if( string.IsNullOrEmpty( m_nodeUrl ) )
  75. {
  76. m_nodeUrl = ( FromCommunity ? Constants.CommunityNodeCommonUrl : Constants.NodeCommonUrl ) + UIUtils.UrlReplaceInvalidStrings( Name );
  77. }
  78. return m_nodeUrl;
  79. }
  80. }
  81. }
  82. }