123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- // Amplify Shader Editor - Visual Shader Editing Tool
- // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
- using UnityEngine;
- using UnityEditor;
- namespace AmplifyShaderEditor
- {
- public class NodeUtils
- {
- public delegate void DrawPropertySection();
- public static void DrawPropertyGroup( string sectionName, DrawPropertySection DrawSection )
- {
- Color cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
- EditorGUILayout.BeginHorizontal( UIUtils.MenuItemToolbarStyle );
- GUI.color = cachedColor;
- GUILayout.Label( sectionName, UIUtils.MenuItemToggleStyle );
- EditorGUILayout.EndHorizontal();
- cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
- EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
- GUI.color = cachedColor;
- DrawSection();
- EditorGUILayout.Separator();
- EditorGUILayout.EndVertical();
- }
- public static void DrawNestedPropertyGroup( ref bool foldoutValue, string sectionName, DrawPropertySection DrawSection, int horizontalSpacing = 15 )
- {
- GUILayout.BeginHorizontal();
- {
- GUILayout.Space( horizontalSpacing );
- EditorGUILayout.BeginVertical( EditorStyles.helpBox );
- {
- Color cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
- EditorGUILayout.BeginHorizontal();
- {
- GUI.color = cachedColor;
- bool value = GUILayout.Toggle( foldoutValue, sectionName, UIUtils.MenuItemToggleStyle );
- if( Event.current.button == Constants.FoldoutMouseId )
- {
- foldoutValue = value;
- }
- }
- EditorGUILayout.EndHorizontal();
- EditorGUI.indentLevel--;
- if( foldoutValue )
- {
- cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
- {
- EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
- {
- GUI.color = cachedColor;
- DrawSection();
- }
- EditorGUILayout.EndVertical();
- EditorGUILayout.Separator();
- }
- }
- EditorGUI.indentLevel++;
- }
- EditorGUILayout.EndVertical();
- }
- GUILayout.EndHorizontal();
- }
- public static void DrawNestedPropertyGroup( ref bool foldoutValue, Rect rect, string sectionName, DrawPropertySection DrawSection, int horizontalSpacing = 15 )
- {
- var box = rect;
- box.height -= 2;
- GUI.Label( box, string.Empty, EditorStyles.helpBox );
- var tog = rect;
- tog.y -= ( tog.height - ( EditorGUIUtility.singleLineHeight + 5 ) ) * 0.5f;
- tog.xMin += 2;
- tog.xMax -= 2;
- tog.yMin += 2;
- bool value = GUI.Toggle( tog, foldoutValue, sectionName, UIUtils.MenuItemToggleStyle );
- if( Event.current.button == Constants.FoldoutMouseId )
- {
- foldoutValue = value;
- }
- if( foldoutValue )
- {
- DrawSection();
- }
- }
- public static void DrawNestedPropertyGroup( ref bool foldoutValue, string sectionName, DrawPropertySection DrawSection, DrawPropertySection HeaderSection )
- {
- GUILayout.BeginHorizontal();
- {
- GUILayout.Space( 15 );
- EditorGUILayout.BeginVertical( EditorStyles.helpBox );
- Color cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
- EditorGUILayout.BeginHorizontal();
- GUI.color = cachedColor;
- bool value = GUILayout.Toggle( foldoutValue, sectionName, UIUtils.MenuItemToggleStyle );
- if( Event.current.button == Constants.FoldoutMouseId )
- {
- foldoutValue = value;
- }
- HeaderSection();
- EditorGUILayout.EndHorizontal();
- EditorGUI.indentLevel--;
- if( foldoutValue )
- {
- cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
- EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
- GUI.color = cachedColor;
- DrawSection();
- EditorGUILayout.EndVertical();
- EditorGUILayout.Separator();
- }
- EditorGUI.indentLevel++;
- EditorGUILayout.EndVertical();
- }
- GUILayout.EndHorizontal();
- }
- public static void DrawNestedPropertyGroup( UndoParentNode owner, ref bool foldoutValue, ref bool enabledValue, string sectionName, DrawPropertySection DrawSection )
- {
- GUILayout.BeginHorizontal();
- {
- GUILayout.Space( 15 );
- EditorGUILayout.BeginVertical( EditorStyles.helpBox );
- Color cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
- EditorGUILayout.BeginHorizontal();
- GUI.color = cachedColor;
- bool value = GUILayout.Toggle( foldoutValue, sectionName, UIUtils.MenuItemToggleStyle );
- if( Event.current.button == Constants.FoldoutMouseId )
- {
- foldoutValue = value;
- }
-
- value = ( (object)owner != null ) ? owner.GUILayoutToggle( enabledValue, string.Empty,UIUtils.MenuItemEnableStyle, GUILayout.Width( 16 ) ) :
- GUILayout.Toggle( enabledValue, string.Empty, UIUtils.MenuItemEnableStyle, GUILayout.Width( 16 ) );
- if( Event.current.button == Constants.FoldoutMouseId )
- {
- enabledValue = value;
- }
-
- EditorGUILayout.EndHorizontal();
- EditorGUI.indentLevel--;
- if( foldoutValue )
- {
- cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
- EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
- GUI.color = cachedColor;
- DrawSection();
- EditorGUILayout.EndVertical();
- EditorGUILayout.Separator();
- }
- EditorGUI.indentLevel++;
- EditorGUILayout.EndVertical();
- }
- GUILayout.EndHorizontal();
- }
- public static void DrawPropertyGroup( ref bool foldoutValue, string sectionName, DrawPropertySection DrawSection )
- {
- Color cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
- EditorGUILayout.BeginHorizontal( UIUtils.MenuItemToolbarStyle );
- GUI.color = cachedColor;
- bool value = GUILayout.Toggle( foldoutValue, sectionName, UIUtils.MenuItemToggleStyle );
- if( Event.current.button == Constants.FoldoutMouseId )
- {
- foldoutValue = value;
- }
- EditorGUILayout.EndHorizontal();
- if( foldoutValue )
- {
- cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
- EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
- {
- GUI.color = cachedColor;
- EditorGUI.indentLevel++;
- DrawSection();
- EditorGUI.indentLevel--;
- EditorGUILayout.Separator();
- }
- EditorGUILayout.EndVertical();
- }
- }
- public static void DrawPropertyGroup( ref bool foldoutValue, string sectionName, DrawPropertySection DrawSection, DrawPropertySection HeaderSection )
- {
- Color cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
- EditorGUILayout.BeginHorizontal( UIUtils.MenuItemToolbarStyle );
- GUI.color = cachedColor;
- bool value = GUILayout.Toggle( foldoutValue, sectionName, UIUtils.MenuItemToggleStyle );
- if( Event.current.button == Constants.FoldoutMouseId )
- {
- foldoutValue = value;
- }
- HeaderSection();
- EditorGUILayout.EndHorizontal();
- if( foldoutValue )
- {
- cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
- EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
- {
- GUI.color = cachedColor;
- EditorGUI.indentLevel++;
- DrawSection();
- EditorGUI.indentLevel--;
- EditorGUILayout.Separator();
- }
- EditorGUILayout.EndVertical();
- }
- }
- public static bool DrawPropertyGroup( UndoParentNode owner, ref bool foldoutValue, ref bool enabledValue, string sectionName, DrawPropertySection DrawSection )
- {
- bool enableChanged = false;
- Color cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, 0.5f );
- EditorGUILayout.BeginHorizontal( UIUtils.MenuItemToolbarStyle );
- GUI.color = cachedColor;
- bool value = GUILayout.Toggle( foldoutValue, sectionName, UIUtils.MenuItemToggleStyle, GUILayout.ExpandWidth( true ) );
- if( Event.current.button == Constants.FoldoutMouseId )
- {
- foldoutValue = value;
- }
- EditorGUI.BeginChangeCheck();
- value = ( (object)owner != null ) ? owner.EditorGUILayoutToggle( string.Empty, enabledValue, UIUtils.MenuItemEnableStyle, GUILayout.Width( 16 ) ) :
- EditorGUILayout.Toggle( string.Empty, enabledValue, UIUtils.MenuItemEnableStyle, GUILayout.Width( 16 ) );
- if( Event.current.button == Constants.FoldoutMouseId )
- {
- enabledValue = value;
- }
- if( EditorGUI.EndChangeCheck() )
- {
- enableChanged = true;
- }
- EditorGUILayout.EndHorizontal();
- if( foldoutValue )
- {
- cachedColor = GUI.color;
- GUI.color = new Color( cachedColor.r, cachedColor.g, cachedColor.b, ( EditorGUIUtility.isProSkin ? 0.5f : 0.25f ) );
- EditorGUILayout.BeginVertical( UIUtils.MenuItemBackgroundStyle );
- GUI.color = cachedColor;
- EditorGUILayout.Separator();
- EditorGUI.BeginDisabledGroup( !enabledValue );
- EditorGUI.indentLevel += 1;
- DrawSection();
- EditorGUI.indentLevel -= 1;
- EditorGUI.EndDisabledGroup();
- EditorGUILayout.Separator();
- EditorGUILayout.EndVertical();
- }
- return enableChanged;
- }
- }
- }
|