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.

212 lines
5.0 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. namespace AmplifyShaderEditor
  7. {
  8. public enum TemplateDataType
  9. {
  10. LegacySinglePass,
  11. MultiPass
  12. }
  13. [Serializable]
  14. public class TemplateIncludePragmaContainter
  15. {
  16. [SerializeField]
  17. private List<string> m_nativeDirectivesList = new List<string>();
  18. [SerializeField]
  19. private List<string> m_includesList = new List<string>();
  20. private Dictionary<string,string> m_includesDict = new Dictionary<string,string>();
  21. [SerializeField]
  22. private List<string> m_pragmasList = new List<string>();
  23. private Dictionary<string, string> m_pragmasDict = new Dictionary<string, string>();
  24. [SerializeField]
  25. private List<string> m_definesList = new List<string>();
  26. private Dictionary<string, string> m_definesDict = new Dictionary<string, string>();
  27. public void RefreshIncludesList()
  28. {
  29. if ( m_includesDict.Count != m_includesList.Count )
  30. {
  31. m_includesDict.Clear();
  32. int count = m_includesList.Count;
  33. for ( int i = 0; i < count; i++ )
  34. {
  35. m_includesDict.Add( m_includesList[ i ], m_includesList[ i ] );
  36. }
  37. }
  38. }
  39. public void RefreshPragmasList()
  40. {
  41. if ( m_pragmasDict.Count != m_pragmasList.Count )
  42. {
  43. m_pragmasDict.Clear();
  44. int count = m_pragmasList.Count;
  45. for ( int i = 0; i < count; i++ )
  46. {
  47. m_pragmasDict.Add( m_pragmasList[ i ], m_pragmasList[ i ] );
  48. }
  49. }
  50. }
  51. public void RefreshDefinesList()
  52. {
  53. if ( m_definesDict.Count != m_definesList.Count )
  54. {
  55. m_definesDict.Clear();
  56. int count = m_definesList.Count;
  57. for ( int i = 0; i < count; i++ )
  58. {
  59. m_definesDict.Add( m_definesList[ i ], m_definesList[ i ] );
  60. }
  61. }
  62. }
  63. public bool HasInclude( string include )
  64. {
  65. RefreshIncludesList();
  66. return m_includesDict.ContainsKey( include );
  67. }
  68. public bool HasPragma( string pragma )
  69. {
  70. RefreshPragmasList();
  71. return m_pragmasDict.ContainsKey( pragma );
  72. }
  73. public bool HasDefine( string pragma )
  74. {
  75. RefreshDefinesList();
  76. return m_definesDict.ContainsKey( pragma );
  77. }
  78. public void AddInclude( string include )
  79. {
  80. RefreshIncludesList();
  81. if ( !m_includesDict.ContainsKey( include ) )
  82. {
  83. m_includesList.Add( include );
  84. m_includesDict.Add( include, include );
  85. }
  86. }
  87. public void AddPragma( string pragma )
  88. {
  89. RefreshPragmasList();
  90. if ( !m_pragmasDict.ContainsKey( pragma ) )
  91. {
  92. m_pragmasList.Add( pragma );
  93. m_pragmasDict.Add( pragma, pragma );
  94. }
  95. }
  96. public void AddDefine( string define )
  97. {
  98. RefreshDefinesList();
  99. if ( !m_definesDict.ContainsKey( define ) )
  100. {
  101. m_definesList.Add( define );
  102. m_definesDict.Add( define, define );
  103. }
  104. }
  105. public void AddNativeDirective( string native )
  106. {
  107. m_nativeDirectivesList.Add( native );
  108. }
  109. public void Destroy()
  110. {
  111. m_nativeDirectivesList.Clear();
  112. m_nativeDirectivesList = null;
  113. m_includesList.Clear();
  114. m_includesDict.Clear();
  115. m_includesList = null;
  116. m_includesDict = null;
  117. m_pragmasList.Clear();
  118. m_pragmasDict.Clear();
  119. m_pragmasList = null;
  120. m_pragmasDict = null;
  121. m_definesList.Clear();
  122. m_definesDict.Clear();
  123. m_definesList = null;
  124. m_definesDict = null;
  125. }
  126. public List<string> IncludesList { get { return m_includesList; } }
  127. public List<string> PragmasList { get { return m_pragmasList; } }
  128. public List<string> DefinesList { get { return m_definesList; } }
  129. public List<string> NativeDirectivesList { get { return m_nativeDirectivesList; } }
  130. }
  131. [Serializable]
  132. public class TemplateInfoContainer
  133. {
  134. public string Id = string.Empty;
  135. public string Data = string.Empty;
  136. public int Index = -1;
  137. public bool IsValid { get { return Index > -1; } }
  138. public void Reset()
  139. {
  140. Id = string.Empty;
  141. Data = string.Empty;
  142. Index = -1;
  143. }
  144. }
  145. [Serializable]
  146. public class TemplateDataParent : ScriptableObject
  147. {
  148. [SerializeField]
  149. protected TemplateDataType m_templateType;
  150. [SerializeField]
  151. protected string m_name;
  152. [SerializeField]
  153. protected string m_guid;
  154. [SerializeField]
  155. protected int m_orderId;
  156. [SerializeField]
  157. protected string m_defaultShaderName = string.Empty;
  158. [SerializeField]
  159. protected bool m_isValid = true;
  160. [SerializeField]
  161. protected bool m_communityTemplate = false;
  162. public virtual void Destroy() { }
  163. public virtual bool Reload() { return true; }
  164. public string Name
  165. {
  166. get { return m_name; }
  167. set
  168. {
  169. m_name = value.StartsWith( "Hidden/" ) ? value.Replace( "Hidden/", string.Empty ) : value;
  170. }
  171. }
  172. public string GUID { get { return m_guid; } set { m_guid = value; } }
  173. public int OrderId { get { return m_orderId; } set { m_orderId = value; } }
  174. public string DefaultShaderName { get { return m_defaultShaderName; } set { m_defaultShaderName = value; } }
  175. public bool IsValid { get { return m_isValid; } }
  176. public TemplateDataType TemplateType { get { return m_templateType; } }
  177. public virtual void Init( string name, string guid, bool isCommunity ) { m_communityTemplate = isCommunity; }
  178. }
  179. }