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.

267 lines
8.7 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. namespace AmplifyShaderEditor
  6. {
  7. public class NodeUtils
  8. {
  9. public delegate void DrawPropertySection();
  10. public static void DrawPropertyGroup( string sectionName, DrawPropertySection DrawSection )
  11. {
  12. Color cachedColor = GUI.color;
  13. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
  14. EditorGUILayout.BeginHorizontal( UIUtils.MenuItemToolbarStyle );
  15. GUI.color = cachedColor;
  16. GUILayout.Label( sectionName, UIUtils.MenuItemToggleStyle );
  17. EditorGUILayout.EndHorizontal();
  18. cachedColor = GUI.color;
  19. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
  20. EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
  21. GUI.color = cachedColor;
  22. DrawSection();
  23. EditorGUILayout.Separator();
  24. EditorGUILayout.EndVertical();
  25. }
  26. public static void DrawNestedPropertyGroup( ref bool foldoutValue, string sectionName, DrawPropertySection DrawSection, int horizontalSpacing = 15 )
  27. {
  28. GUILayout.BeginHorizontal();
  29. {
  30. GUILayout.Space( horizontalSpacing );
  31. EditorGUILayout.BeginVertical( EditorStyles.helpBox );
  32. {
  33. Color cachedColor = GUI.color;
  34. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
  35. EditorGUILayout.BeginHorizontal();
  36. {
  37. GUI.color = cachedColor;
  38. bool value = GUILayout.Toggle( foldoutValue, sectionName, UIUtils.MenuItemToggleStyle );
  39. if( Event.current.button == Constants.FoldoutMouseId )
  40. {
  41. foldoutValue = value;
  42. }
  43. }
  44. EditorGUILayout.EndHorizontal();
  45. EditorGUI.indentLevel--;
  46. if( foldoutValue )
  47. {
  48. cachedColor = GUI.color;
  49. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
  50. {
  51. EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
  52. {
  53. GUI.color = cachedColor;
  54. DrawSection();
  55. }
  56. EditorGUILayout.EndVertical();
  57. EditorGUILayout.Separator();
  58. }
  59. }
  60. EditorGUI.indentLevel++;
  61. }
  62. EditorGUILayout.EndVertical();
  63. }
  64. GUILayout.EndHorizontal();
  65. }
  66. public static void DrawNestedPropertyGroup( ref bool foldoutValue, string sectionName, DrawPropertySection DrawSection, DrawPropertySection HeaderSection )
  67. {
  68. GUILayout.BeginHorizontal();
  69. {
  70. GUILayout.Space( 15 );
  71. EditorGUILayout.BeginVertical( EditorStyles.helpBox );
  72. Color cachedColor = GUI.color;
  73. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
  74. EditorGUILayout.BeginHorizontal();
  75. GUI.color = cachedColor;
  76. bool value = GUILayout.Toggle( foldoutValue, sectionName, UIUtils.MenuItemToggleStyle );
  77. if( Event.current.button == Constants.FoldoutMouseId )
  78. {
  79. foldoutValue = value;
  80. }
  81. HeaderSection();
  82. EditorGUILayout.EndHorizontal();
  83. EditorGUI.indentLevel--;
  84. if( foldoutValue )
  85. {
  86. cachedColor = GUI.color;
  87. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
  88. EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
  89. GUI.color = cachedColor;
  90. DrawSection();
  91. EditorGUILayout.EndVertical();
  92. EditorGUILayout.Separator();
  93. }
  94. EditorGUI.indentLevel++;
  95. EditorGUILayout.EndVertical();
  96. }
  97. GUILayout.EndHorizontal();
  98. }
  99. public static void DrawNestedPropertyGroup( UndoParentNode owner, ref bool foldoutValue, ref bool enabledValue, string sectionName, DrawPropertySection DrawSection )
  100. {
  101. GUILayout.BeginHorizontal();
  102. {
  103. GUILayout.Space( 15 );
  104. EditorGUILayout.BeginVertical( EditorStyles.helpBox );
  105. Color cachedColor = GUI.color;
  106. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
  107. EditorGUILayout.BeginHorizontal();
  108. GUI.color = cachedColor;
  109. bool value = GUILayout.Toggle( foldoutValue, sectionName, UIUtils.MenuItemToggleStyle );
  110. if( Event.current.button == Constants.FoldoutMouseId )
  111. {
  112. foldoutValue = value;
  113. }
  114. value = ( (object)owner != null ) ? owner.GUILayoutToggle( enabledValue, string.Empty,UIUtils.MenuItemEnableStyle, GUILayout.Width( 16 ) ) :
  115. GUILayout.Toggle( enabledValue, string.Empty, UIUtils.MenuItemEnableStyle, GUILayout.Width( 16 ) );
  116. if( Event.current.button == Constants.FoldoutMouseId )
  117. {
  118. enabledValue = value;
  119. }
  120. EditorGUILayout.EndHorizontal();
  121. EditorGUI.indentLevel--;
  122. if( foldoutValue )
  123. {
  124. cachedColor = GUI.color;
  125. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
  126. EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
  127. GUI.color = cachedColor;
  128. DrawSection();
  129. EditorGUILayout.EndVertical();
  130. EditorGUILayout.Separator();
  131. }
  132. EditorGUI.indentLevel++;
  133. EditorGUILayout.EndVertical();
  134. }
  135. GUILayout.EndHorizontal();
  136. }
  137. public static void DrawPropertyGroup( ref bool foldoutValue, string sectionName, DrawPropertySection DrawSection )
  138. {
  139. Color cachedColor = GUI.color;
  140. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
  141. EditorGUILayout.BeginHorizontal( UIUtils.MenuItemToolbarStyle );
  142. GUI.color = cachedColor;
  143. bool value = GUILayout.Toggle( foldoutValue, sectionName, UIUtils.MenuItemToggleStyle );
  144. if( Event.current.button == Constants.FoldoutMouseId )
  145. {
  146. foldoutValue = value;
  147. }
  148. EditorGUILayout.EndHorizontal();
  149. if( foldoutValue )
  150. {
  151. cachedColor = GUI.color;
  152. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
  153. EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
  154. {
  155. GUI.color = cachedColor;
  156. EditorGUI.indentLevel++;
  157. DrawSection();
  158. EditorGUI.indentLevel--;
  159. EditorGUILayout.Separator();
  160. }
  161. EditorGUILayout.EndVertical();
  162. }
  163. }
  164. public static void DrawPropertyGroup( ref bool foldoutValue, string sectionName, DrawPropertySection DrawSection, DrawPropertySection HeaderSection )
  165. {
  166. Color cachedColor = GUI.color;
  167. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
  168. EditorGUILayout.BeginHorizontal( UIUtils.MenuItemToolbarStyle );
  169. GUI.color = cachedColor;
  170. bool value = GUILayout.Toggle( foldoutValue, sectionName, UIUtils.MenuItemToggleStyle );
  171. if( Event.current.button == Constants.FoldoutMouseId )
  172. {
  173. foldoutValue = value;
  174. }
  175. HeaderSection();
  176. EditorGUILayout.EndHorizontal();
  177. if( foldoutValue )
  178. {
  179. cachedColor = GUI.color;
  180. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
  181. EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
  182. {
  183. GUI.color = cachedColor;
  184. EditorGUI.indentLevel++;
  185. DrawSection();
  186. EditorGUI.indentLevel--;
  187. EditorGUILayout.Separator();
  188. }
  189. EditorGUILayout.EndVertical();
  190. }
  191. }
  192. public static bool DrawPropertyGroup( UndoParentNode owner, ref bool foldoutValue, ref bool enabledValue, string sectionName, DrawPropertySection DrawSection )
  193. {
  194. bool enableChanged = false;
  195. Color cachedColor = GUI.color;
  196. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
  197. EditorGUILayout.BeginHorizontal( UIUtils.MenuItemToolbarStyle );
  198. GUI.color = cachedColor;
  199. bool value = GUILayout.Toggle( foldoutValue, sectionName, UIUtils.MenuItemToggleStyle, GUILayout.ExpandWidth( true ) );
  200. if( Event.current.button == Constants.FoldoutMouseId )
  201. {
  202. foldoutValue = value;
  203. }
  204. EditorGUI.BeginChangeCheck();
  205. value = ( (object)owner != null ) ? owner.EditorGUILayoutToggle( string.Empty, enabledValue, UIUtils.MenuItemEnableStyle, GUILayout.Width( 16 ) ) :
  206. EditorGUILayout.Toggle( string.Empty, enabledValue, UIUtils.MenuItemEnableStyle, GUILayout.Width( 16 ) );
  207. if( Event.current.button == Constants.FoldoutMouseId )
  208. {
  209. enabledValue = value;
  210. }
  211. if( EditorGUI.EndChangeCheck() )
  212. {
  213. enableChanged = true;
  214. }
  215. EditorGUILayout.EndHorizontal();
  216. if( foldoutValue )
  217. {
  218. cachedColor = GUI.color;
  219. GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
  220. EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
  221. GUI.color = cachedColor;
  222. EditorGUILayout.Separator();
  223. EditorGUI.BeginDisabledGroup( !enabledValue );
  224. EditorGUI.indentLevel += 1;
  225. DrawSection();
  226. EditorGUI.indentLevel -= 1;
  227. EditorGUI.EndDisabledGroup();
  228. EditorGUILayout.Separator();
  229. EditorGUILayout.EndVertical();
  230. }
  231. return enableChanged;
  232. }
  233. }
  234. }