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.

189 lines
4.9 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. [SerializeField]
  89. private bool m_hidden = false;
  90. public bool Hidden
  91. {
  92. get { return m_hidden; }
  93. set { m_hidden = value; }
  94. }
  95. public void UpdateDirectivesList()
  96. {
  97. m_additionalDirectives.CleanNullDirectives();
  98. m_additionalDirectives.UpdateDirectivesFromSaveItems();
  99. if( m_additionalIncludes.IncludeList.Count > 0 )
  100. {
  101. m_additionalDirectives.AddItems( AdditionalLineType.Include, m_additionalIncludes.IncludeList );
  102. m_additionalIncludes.IncludeList.Clear();
  103. }
  104. if( m_additionalPragmas.PragmaList.Count > 0 )
  105. {
  106. m_additionalDirectives.AddItems( AdditionalLineType.Pragma, m_additionalPragmas.PragmaList );
  107. m_additionalPragmas.PragmaList.Clear();
  108. }
  109. }
  110. public void ResetDirectivesOrigin()
  111. {
  112. //if( UIUtils.CurrentShaderVersion() < 16807 )
  113. // Although the correct version was 1.6.7 rev 07 this issue was only detected on v1.7.1. rev 00
  114. // So to avoid potential incorrect saves over shader functions, I decided to broaden up the version range
  115. if( UIUtils.CurrentShaderVersion() < 17101 )
  116. {
  117. m_additionalDirectives.ResetDirectivesOrigin();
  118. }
  119. }
  120. }
  121. public class ShaderFunctionDetector : AssetPostprocessor
  122. {
  123. static void OnPostprocessAllAssets( string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths )
  124. {
  125. if( UIUtils.CurrentWindow == null )
  126. return;
  127. bool markForRefresh = false;
  128. AmplifyShaderFunction function = null;
  129. for( int i = 0; i < importedAssets.Length; i++ )
  130. {
  131. function = AssetDatabase.LoadAssetAtPath<AmplifyShaderFunction>( importedAssets[ i ] );
  132. if( function != null )
  133. {
  134. markForRefresh = true;
  135. break;
  136. }
  137. }
  138. if( deletedAssets.Length > 0 )
  139. markForRefresh = true;
  140. for( int i = 0; i < movedAssets.Length; i++ )
  141. {
  142. function = AssetDatabase.LoadAssetAtPath<AmplifyShaderFunction>( movedAssets[ i ] );
  143. if( function != null )
  144. {
  145. markForRefresh = true;
  146. break;
  147. }
  148. }
  149. for( int i = 0; i < movedFromAssetPaths.Length; i++ )
  150. {
  151. function = AssetDatabase.LoadAssetAtPath<AmplifyShaderFunction>( movedFromAssetPaths[ i ] );
  152. if( function != null )
  153. {
  154. markForRefresh = true;
  155. break;
  156. }
  157. }
  158. if( markForRefresh )
  159. {
  160. markForRefresh = false;
  161. if( function != null )
  162. {
  163. IOUtils.UpdateSFandRefreshWindows( function );
  164. }
  165. UIUtils.CurrentWindow.LateRefreshAvailableNodes();
  166. }
  167. }
  168. }