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.

171 lines
4.3 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System;
  6. using System.Collections.Generic;
  7. using AmplifyShaderEditor;
  8. [Serializable]
  9. public class AmplifyShaderFunction : ScriptableObject
  10. {
  11. [SerializeField]
  12. private string m_functionInfo = string.Empty;
  13. public string FunctionInfo
  14. {
  15. get { return m_functionInfo; }
  16. set { m_functionInfo = value; }
  17. }
  18. [SerializeField]
  19. private string m_functionName = string.Empty;
  20. public string FunctionName
  21. {
  22. get { if( m_functionName.Length == 0 ) return name; else return m_functionName; }
  23. set { m_functionName = value; }
  24. }
  25. [SerializeField]
  26. [TextArea( 5, 15 )]
  27. private string m_description = string.Empty;
  28. public string Description
  29. {
  30. get { return m_description; }
  31. set { m_description = value; }
  32. }
  33. [SerializeField]
  34. private AdditionalIncludesHelper m_additionalIncludes = new AdditionalIncludesHelper();
  35. //public AdditionalIncludesHelper AdditionalIncludes
  36. //{
  37. // get { return m_additionalIncludes; }
  38. // set { m_additionalIncludes = value; }
  39. //}
  40. [SerializeField]
  41. private AdditionalPragmasHelper m_additionalPragmas = new AdditionalPragmasHelper();
  42. //public AdditionalPragmasHelper AdditionalPragmas
  43. //{
  44. // get { return m_additionalPragmas; }
  45. // set { m_additionalPragmas = value; }
  46. //}
  47. [SerializeField]
  48. private TemplateAdditionalDirectivesHelper m_additionalDirectives = new TemplateAdditionalDirectivesHelper( " Additional Directives" );
  49. public TemplateAdditionalDirectivesHelper AdditionalDirectives
  50. {
  51. get { return m_additionalDirectives; }
  52. set { m_additionalDirectives = value; }
  53. }
  54. [SerializeField]
  55. private FunctionNodeCategories m_nodeCategory = FunctionNodeCategories.Functions;
  56. public FunctionNodeCategories NodeCategory
  57. {
  58. get { return m_nodeCategory; }
  59. set { m_nodeCategory = value; }
  60. }
  61. [SerializeField]
  62. private string m_customNodeCategory = string.Empty;
  63. public string CustomNodeCategory
  64. {
  65. get
  66. {
  67. if( m_nodeCategory == FunctionNodeCategories.Custom )
  68. {
  69. if( string.IsNullOrEmpty( m_customNodeCategory ) )
  70. return "Functions";
  71. else
  72. return m_customNodeCategory;
  73. }
  74. else
  75. {
  76. return UIUtils.CategoryPresets[ (int)m_nodeCategory ];
  77. //return new SerializedObject( this ).FindProperty( "m_nodeCategory" ).enumDisplayNames[ (int)m_nodeCategory ];
  78. }
  79. }
  80. }
  81. [SerializeField]
  82. private PreviewLocation m_previewPosition = PreviewLocation.Auto;
  83. public PreviewLocation PreviewPosition
  84. {
  85. get { return m_previewPosition; }
  86. set { m_previewPosition = value; }
  87. }
  88. public void UpdateDirectivesList()
  89. {
  90. m_additionalDirectives.CleanNullDirectives();
  91. m_additionalDirectives.UpdateDirectivesFromSaveItems();
  92. if( m_additionalIncludes.IncludeList.Count > 0 )
  93. {
  94. m_additionalDirectives.AddItems( AdditionalLineType.Include, m_additionalIncludes.IncludeList );
  95. m_additionalIncludes.IncludeList.Clear();
  96. }
  97. if( m_additionalPragmas.PragmaList.Count > 0 )
  98. {
  99. m_additionalDirectives.AddItems( AdditionalLineType.Pragma, m_additionalPragmas.PragmaList );
  100. m_additionalPragmas.PragmaList.Clear();
  101. }
  102. }
  103. }
  104. public class ShaderFunctionDetector : AssetPostprocessor
  105. {
  106. static void OnPostprocessAllAssets( string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths )
  107. {
  108. if( UIUtils.CurrentWindow == null )
  109. return;
  110. bool markForRefresh = false;
  111. AmplifyShaderFunction function = null;
  112. for( int i = 0; i < importedAssets.Length; i++ )
  113. {
  114. function = AssetDatabase.LoadAssetAtPath<AmplifyShaderFunction>( importedAssets[ i ] );
  115. if( function != null )
  116. {
  117. markForRefresh = true;
  118. break;
  119. }
  120. }
  121. if( deletedAssets.Length > 0 )
  122. markForRefresh = true;
  123. for( int i = 0; i < movedAssets.Length; i++ )
  124. {
  125. function = AssetDatabase.LoadAssetAtPath<AmplifyShaderFunction>( movedAssets[ i ] );
  126. if( function != null )
  127. {
  128. markForRefresh = true;
  129. break;
  130. }
  131. }
  132. for( int i = 0; i < movedFromAssetPaths.Length; i++ )
  133. {
  134. function = AssetDatabase.LoadAssetAtPath<AmplifyShaderFunction>( movedFromAssetPaths[ i ] );
  135. if( function != null )
  136. {
  137. markForRefresh = true;
  138. break;
  139. }
  140. }
  141. if( markForRefresh )
  142. {
  143. markForRefresh = false;
  144. if( function != null )
  145. {
  146. IOUtils.UpdateSFandRefreshWindows( function );
  147. }
  148. UIUtils.CurrentWindow.LateRefreshAvailableNodes();
  149. }
  150. }
  151. }