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.

254 lines
14 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEditor;
  4. using System;
  5. using UnityEngine;
  6. namespace AmplifyShaderEditor
  7. {
  8. public class EditorVariable<T>
  9. {
  10. protected string m_labelName;
  11. protected string m_name;
  12. protected T m_value;
  13. protected T m_defaultValue;
  14. public EditorVariable( string name, string labelName, T defaultValue ) { m_name = name; m_labelName = labelName; m_defaultValue = defaultValue; m_value = defaultValue; }
  15. public string Name { get { return m_name; } }
  16. public virtual T Value
  17. {
  18. get { return m_value; }
  19. set
  20. {
  21. m_value = value;
  22. }
  23. }
  24. public string LabelName { get { return m_labelName; } }
  25. }
  26. public sealed class EditorVariableFloat : EditorVariable<float>
  27. {
  28. public EditorVariableFloat( string name, string labelName, float defaultValue ) : base( name, labelName, defaultValue )
  29. {
  30. m_value = EditorPrefs.GetFloat( name, m_defaultValue );
  31. }
  32. public override float Value
  33. {
  34. get { return m_value; }
  35. set
  36. {
  37. if( m_value != value )
  38. {
  39. m_value = value;
  40. EditorPrefs.SetFloat( m_name, m_value );
  41. }
  42. }
  43. }
  44. }
  45. public sealed class EditorVariableBool : EditorVariable<bool>
  46. {
  47. public EditorVariableBool( string name, string labelName, bool defaultValue ) : base( name, labelName, defaultValue )
  48. {
  49. m_value = EditorPrefs.GetBool( name, m_defaultValue );
  50. }
  51. public override bool Value
  52. {
  53. get { return m_value; }
  54. set
  55. {
  56. if( m_value != value )
  57. {
  58. m_value = value;
  59. EditorPrefs.SetBool( m_name, m_value );
  60. }
  61. }
  62. }
  63. }
  64. public sealed class EditorVariableInt : EditorVariable<int>
  65. {
  66. public EditorVariableInt( string name, string labelName, int defaultValue ) : base( name, labelName, defaultValue )
  67. {
  68. m_value = EditorPrefs.GetInt( name, m_defaultValue );
  69. }
  70. public override int Value
  71. {
  72. get { return m_value; }
  73. set
  74. {
  75. if( m_value != value )
  76. {
  77. m_value = value;
  78. EditorPrefs.SetInt( m_name, m_value );
  79. }
  80. }
  81. }
  82. }
  83. public sealed class EditorVariableString : EditorVariable<string>
  84. {
  85. public EditorVariableString( string name, string labelName, string defaultValue ) : base( name, labelName, defaultValue )
  86. {
  87. m_value = EditorPrefs.GetString( name, m_defaultValue );
  88. }
  89. public override string Value
  90. {
  91. get { return m_value; }
  92. set
  93. {
  94. if( !m_value.Equals( value ) )
  95. {
  96. m_value = value;
  97. EditorPrefs.SetString( m_name, m_value );
  98. }
  99. }
  100. }
  101. }
  102. public class EditorVariablesManager
  103. {
  104. public static EditorVariableBool LiveMode = new EditorVariableBool( "ASELiveMode", "LiveMode", false );
  105. public static EditorVariableBool OutlineActiveMode = new EditorVariableBool( "ASEOutlineActiveMode", " Outline", false );
  106. public static EditorVariableBool NodeParametersMaximized = new EditorVariableBool( "ASENodeParametersVisible", " NodeParameters", true );
  107. public static EditorVariableBool NodePaletteMaximized = new EditorVariableBool( "ASENodePaletteVisible", " NodePalette", true );
  108. public static EditorVariableBool ExpandedRenderingPlatforms = new EditorVariableBool( "ASEExpandedRenderingPlatforms", " ExpandedRenderingPlatforms", false );
  109. public static EditorVariableBool ExpandedRenderingOptions = new EditorVariableBool( "ASEExpandedRenderingOptions", " ExpandedRenderingPlatforms", false );
  110. public static EditorVariableBool ExpandedGeneralShaderOptions = new EditorVariableBool( "ASEExpandedGeneralShaderOptions", " ExpandedGeneralShaderOptions", false );
  111. public static EditorVariableBool ExpandedBlendOptions = new EditorVariableBool( "ASEExpandedBlendOptions", " ExpandedBlendOptions", false );
  112. public static EditorVariableBool ExpandedStencilOptions = new EditorVariableBool( "ASEExpandedStencilOptions", " ExpandedStencilOptions", false );
  113. public static EditorVariableBool ExpandedVertexOptions = new EditorVariableBool( "ASEExpandedVertexOptions", " ExpandedVertexOptions", false );
  114. public static EditorVariableBool ExpandedFunctionInputs = new EditorVariableBool( "ASEExpandedFunctionInputs", " ExpandedFunctionInputs", false );
  115. public static EditorVariableBool ExpandedFunctionSwitches = new EditorVariableBool( "ASEExpandedFunctionSwitches", " ExpandedFunctionSwitches", false );
  116. public static EditorVariableBool ExpandedFunctionOutputs = new EditorVariableBool( "ASEExpandedFunctionOutputs", " ExpandedFunctionOutputs", false );
  117. public static EditorVariableBool ExpandedAdditionalIncludes = new EditorVariableBool( "ASEExpandedAdditionalIncludes", " ExpandedAdditionalIncludes", false );
  118. public static EditorVariableBool ExpandedAdditionalDefines = new EditorVariableBool( "ASEExpandedAdditionalDefines", " ExpandedAdditionalDefines", false );
  119. public static EditorVariableBool ExpandedAdditionalDirectives = new EditorVariableBool( "ASEExpandedAdditionalDirectives", " ExpandedAdditionalDirectives", false );
  120. public static EditorVariableBool ExpandedCustomTags = new EditorVariableBool( "ASEExpandedCustomTags", " ExpandedCustomTags", false );
  121. public static EditorVariableBool ExpandedAdditionalSurfaceOptions = new EditorVariableBool( "ASEExpandedAdditionalSurfaceOptions", " ExpandedAdditionalSurfaceOptions", false );
  122. public static EditorVariableBool ExpandedAdditionalPragmas = new EditorVariableBool( "ASEExpandedAdditionalPragmas", " ExpandedAdditionalPragmas", false );
  123. public static EditorVariableBool ExpandedDependencies = new EditorVariableBool( "ASEExpandedDependencies", " ExpandedDependencies", false );
  124. public static EditorVariableBool ExpandedDepth = new EditorVariableBool( "ASEExpandedDepth", " ExpandedDepth", false );
  125. public static EditorVariableBool ExpandedTesselation = new EditorVariableBool( "ASEExpandedTesselation", " ExpandedTesselation", false );
  126. public static EditorVariableBool ExpandedProperties = new EditorVariableBool( "ASEExpandedProperties", " ExpandedProperties", false );
  127. public static EditorVariableBool ExpandedUsePass = new EditorVariableBool( "ASEUsePass", " UsePass", false );
  128. //Templates
  129. public static EditorVariableBool ExpandedBlendModeModule = new EditorVariableBool( "ASEExpandedBlendModeModule", " ExpandedBlendModeModule", false );
  130. }
  131. [Serializable]
  132. public class InnerWindowEditorVariables
  133. {
  134. [SerializeField]
  135. private bool m_liveMode = false;
  136. [SerializeField]
  137. private bool m_outlineActiveMode = false;
  138. [SerializeField]
  139. private bool m_nodeParametersMaximized = false;
  140. [SerializeField]
  141. private bool m_nodePaletteMaximized = false;
  142. [SerializeField]
  143. private bool m_expandedRenderingPlatforms = false;
  144. [SerializeField]
  145. private bool m_expandedRenderingOptions = false;
  146. [SerializeField]
  147. private bool m_expandedGeneralShaderOptions = false;
  148. [SerializeField]
  149. private bool m_expandedBlendOptions = false;
  150. [SerializeField]
  151. private bool m_expandedStencilOptions = false;
  152. [SerializeField]
  153. private bool m_expandedVertexOptions = false;
  154. [SerializeField]
  155. private bool m_expandedFunctionInputs = false;
  156. [SerializeField]
  157. private bool m_expandedFunctionSwitches = false;
  158. [SerializeField]
  159. private bool m_expandedFunctionOutputs = false;
  160. [SerializeField]
  161. private bool m_expandedAdditionalIncludes = false;
  162. [SerializeField]
  163. private bool m_expandedAdditionalDefines = false;
  164. [SerializeField]
  165. private bool m_expandedAdditionalDirectives = false;
  166. [SerializeField]
  167. private bool m_expandedCustomTags = false;
  168. [SerializeField]
  169. private bool m_expandedAdditionalSurfaceOptions = false;
  170. [SerializeField]
  171. private bool m_expandedAdditionalPragmas = false;
  172. [SerializeField]
  173. private bool m_expandedDependencies = false;
  174. [SerializeField]
  175. private bool m_expandedBlendModeModule = false;
  176. [SerializeField]
  177. private bool m_expandedDepth = false;
  178. [SerializeField]
  179. private bool m_expandedTesselation = false;
  180. [SerializeField]
  181. private bool m_expandedProperties = false;
  182. [SerializeField]
  183. private bool m_expandedUsePass = false;
  184. public void Initialize()
  185. {
  186. m_liveMode = EditorVariablesManager.LiveMode.Value;
  187. m_outlineActiveMode = EditorVariablesManager.OutlineActiveMode.Value;
  188. m_nodeParametersMaximized = EditorVariablesManager.NodeParametersMaximized.Value;
  189. m_nodePaletteMaximized = EditorVariablesManager.NodePaletteMaximized.Value;
  190. m_expandedRenderingPlatforms = EditorVariablesManager.ExpandedRenderingPlatforms.Value;
  191. m_expandedRenderingOptions = EditorVariablesManager.ExpandedRenderingOptions.Value;
  192. m_expandedGeneralShaderOptions = EditorVariablesManager.ExpandedGeneralShaderOptions.Value;
  193. m_expandedBlendOptions = EditorVariablesManager.ExpandedBlendOptions.Value;
  194. m_expandedStencilOptions = EditorVariablesManager.ExpandedStencilOptions.Value;
  195. m_expandedVertexOptions = EditorVariablesManager.ExpandedVertexOptions.Value;
  196. m_expandedFunctionInputs = EditorVariablesManager.ExpandedFunctionInputs.Value;
  197. m_expandedFunctionSwitches = EditorVariablesManager.ExpandedFunctionSwitches.Value;
  198. m_expandedFunctionOutputs = EditorVariablesManager.ExpandedFunctionOutputs.Value;
  199. m_expandedAdditionalIncludes = EditorVariablesManager.ExpandedAdditionalIncludes.Value;
  200. m_expandedAdditionalDefines = EditorVariablesManager.ExpandedAdditionalDefines.Value;
  201. m_expandedAdditionalDirectives = EditorVariablesManager.ExpandedAdditionalDirectives.Value;
  202. m_expandedCustomTags = EditorVariablesManager.ExpandedCustomTags.Value;
  203. m_expandedAdditionalSurfaceOptions = EditorVariablesManager.ExpandedAdditionalSurfaceOptions.Value;
  204. m_expandedAdditionalPragmas = EditorVariablesManager.ExpandedAdditionalPragmas.Value;
  205. m_expandedDependencies = EditorVariablesManager.ExpandedDependencies.Value;
  206. m_expandedBlendModeModule = EditorVariablesManager.ExpandedBlendModeModule.Value;
  207. m_expandedDepth = EditorVariablesManager.ExpandedDepth.Value;
  208. m_expandedTesselation = EditorVariablesManager.ExpandedTesselation.Value;
  209. m_expandedProperties = EditorVariablesManager.ExpandedProperties.Value;
  210. m_expandedUsePass = EditorVariablesManager.ExpandedUsePass.Value;
  211. }
  212. public bool LiveMode{ get { return m_liveMode; } set { m_liveMode = value; EditorVariablesManager.LiveMode.Value = value; } }
  213. public bool OutlineActiveMode { get { return m_outlineActiveMode; } set { m_outlineActiveMode = value; EditorVariablesManager.OutlineActiveMode.Value = value; } }
  214. public bool NodeParametersMaximized { get { return m_nodeParametersMaximized; } set { m_nodeParametersMaximized = value; EditorVariablesManager.NodeParametersMaximized.Value = value; } }
  215. public bool NodePaletteMaximized { get { return m_nodePaletteMaximized; } set { m_nodePaletteMaximized = value; EditorVariablesManager.NodePaletteMaximized.Value = value; } }
  216. public bool ExpandedRenderingPlatforms { get { return m_expandedRenderingPlatforms; } set { m_expandedRenderingPlatforms = value; EditorVariablesManager.ExpandedRenderingPlatforms.Value = value; } }
  217. public bool ExpandedRenderingOptions { get { return m_expandedRenderingOptions; } set { m_expandedRenderingOptions = value; EditorVariablesManager.ExpandedRenderingOptions.Value = value; } }
  218. public bool ExpandedGeneralShaderOptions { get { return m_expandedGeneralShaderOptions; } set { m_expandedGeneralShaderOptions = value; EditorVariablesManager.ExpandedGeneralShaderOptions.Value = value; } }
  219. public bool ExpandedBlendOptions { get { return m_expandedBlendOptions; } set { m_expandedBlendOptions = value; EditorVariablesManager.ExpandedBlendOptions.Value = value; } }
  220. public bool ExpandedStencilOptions { get { return m_expandedStencilOptions; } set { m_expandedStencilOptions = value; EditorVariablesManager.ExpandedStencilOptions.Value = value; } }
  221. public bool ExpandedVertexOptions { get { return m_expandedVertexOptions; } set { m_expandedVertexOptions = value; EditorVariablesManager.ExpandedVertexOptions.Value = value; } }
  222. public bool ExpandedFunctionInputs { get { return m_expandedFunctionInputs; } set { m_expandedFunctionInputs = value; EditorVariablesManager.ExpandedFunctionInputs.Value = value; } }
  223. public bool ExpandedFunctionSwitches { get { return m_expandedFunctionSwitches; } set { m_expandedFunctionSwitches = value; EditorVariablesManager.ExpandedFunctionSwitches.Value = value; } }
  224. public bool ExpandedFunctionOutputs { get { return m_expandedFunctionOutputs; } set { m_expandedFunctionOutputs = value; EditorVariablesManager.ExpandedFunctionOutputs.Value = value; } }
  225. public bool ExpandedAdditionalIncludes { get { return m_expandedAdditionalIncludes; } set { m_expandedAdditionalIncludes = value; EditorVariablesManager.ExpandedAdditionalIncludes.Value = value; } }
  226. public bool ExpandedAdditionalDefines { get { return m_expandedAdditionalDefines; } set { m_expandedAdditionalDefines = value; EditorVariablesManager.ExpandedAdditionalDefines.Value = value; } }
  227. public bool ExpandedAdditionalDirectives { get { return m_expandedAdditionalDirectives; } set { m_expandedAdditionalDirectives = value; EditorVariablesManager.ExpandedAdditionalDirectives.Value = value; } }
  228. public bool ExpandedCustomTags { get { return m_expandedCustomTags; } set { m_expandedCustomTags = value; EditorVariablesManager.ExpandedCustomTags.Value = value; } }
  229. public bool ExpandedAdditionalSurfaceOptions { get { return m_expandedAdditionalSurfaceOptions; } set { m_expandedAdditionalSurfaceOptions = value; EditorVariablesManager.ExpandedAdditionalSurfaceOptions.Value = value; } }
  230. public bool ExpandedAdditionalPragmas { get { return m_expandedAdditionalPragmas; } set { m_expandedAdditionalPragmas = value; EditorVariablesManager.ExpandedAdditionalPragmas.Value = value; } }
  231. public bool ExpandedDependencies { get { return m_expandedDependencies; } set { m_expandedDependencies = value; EditorVariablesManager.ExpandedDependencies.Value = value; } }
  232. public bool ExpandedBlendModeModule { get { return m_expandedBlendModeModule; } set { m_expandedBlendModeModule = value; EditorVariablesManager.ExpandedBlendModeModule.Value = value; } }
  233. public bool ExpandedDepth { get { return m_expandedDepth; } set { m_expandedDepth = value; EditorVariablesManager.ExpandedDepth.Value = value; } }
  234. public bool ExpandedTesselation { get { return m_expandedTesselation; } set { m_expandedTesselation = value; EditorVariablesManager.ExpandedTesselation.Value = value; } }
  235. public bool ExpandedProperties { get { return m_expandedProperties; } set { m_expandedProperties = value; EditorVariablesManager.ExpandedProperties.Value = value; } }
  236. public bool ExpandedUsePass { get { return m_expandedUsePass; } set { m_expandedUsePass = value; EditorVariablesManager.ExpandedUsePass.Value = value; } }
  237. }
  238. }