From b82da95b5181ac8bbae38efb13e950d5e88a4caa Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 23 Oct 2020 13:08:43 +0800 Subject: =?UTF-8?q?*=E7=A7=BB=E5=8A=A8amplify=20shader=20editor=E5=88=B0th?= =?UTF-8?q?ird=20party=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Plugins/Editor/Utils/UpperLeftWidgetHelper.cs | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Utils/UpperLeftWidgetHelper.cs (limited to 'Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Utils/UpperLeftWidgetHelper.cs') diff --git a/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Utils/UpperLeftWidgetHelper.cs b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Utils/UpperLeftWidgetHelper.cs new file mode 100644 index 00000000..9e92fe2d --- /dev/null +++ b/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Utils/UpperLeftWidgetHelper.cs @@ -0,0 +1,91 @@ +using System; +using UnityEngine; +using UnityEditor; + +namespace AmplifyShaderEditor +{ + public class UpperLeftWidgetHelper + { + public int DrawWidget( ParentNode owner, int selectedIndex, GUIContent[] displayedOptions ) + { + if( owner.DropdownEditing ) + { + int newValue = owner.EditorGUIPopup( owner.DropdownRect, selectedIndex, displayedOptions, UIUtils.PropertyPopUp ); + if( newValue != selectedIndex ) + { + owner.DropdownEditing = false; + } + return newValue; + } + return selectedIndex; + } + + public int DrawWidget( ParentNode owner, int selectedIndex, string[] displayedOptions ) + { + if( owner.DropdownEditing ) + { + int newValue = owner.EditorGUIPopup( owner.DropdownRect, selectedIndex, displayedOptions, UIUtils.PropertyPopUp ); + if( newValue != selectedIndex ) + { + owner.DropdownEditing = false; + } + return newValue; + } + return selectedIndex; + } + + public int DrawWidget( ParentNode owner, int selectedIndex, string[] displayedOptions, int[] optionValues ) + { + if( owner.DropdownEditing ) + { + int newValue = owner.EditorGUIIntPopup( owner.DropdownRect, selectedIndex, displayedOptions, optionValues, UIUtils.PropertyPopUp ); + if( newValue != selectedIndex ) + { + owner.DropdownEditing = false; + } + return newValue; + } + return selectedIndex; + } + + // GC free version + public void DrawWidget( ref TEnum selectedIndex, ParentNode owner, Action callback ) where TEnum : struct + { + if( owner.DropdownEditing ) + { + Enum asEnumType = selectedIndex as Enum; + if( asEnumType != null ) + { + EditorGUI.BeginChangeCheck(); + selectedIndex = ( owner.EditorGUIEnumPopup( owner.DropdownRect, asEnumType, UIUtils.PropertyPopUp ) as TEnum? ).Value; + if( EditorGUI.EndChangeCheck() ) + { + owner.DropdownEditing = false; + if( callback != null ) + callback( owner ); + } + } + } + } + + /* + * USE THIS OVERRIDE IN CASE THE NODE DOESN'T HAVE PREVIEW + */ + //public override void AfterCommonInit() + //{ + // base.AfterCommonInit(); + // if( PaddingTitleLeft == 0 ) + // { + // PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + // if( PaddingTitleRight == 0 ) + // PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin; + // } + //} + + + /* + * USE THE SOURCE CODE BELOW INTO THE NODE YOU WANT THE WIDGET TO SHOW + */ + //private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper(); + } +} -- cgit v1.1-26-g67d0