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.

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