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.

91 lines
2.5 KiB

  1. using System;
  2. using UnityEngine;
  3. using UnityEditor;
  4. namespace AmplifyShaderEditor
  5. {
  6. public class UpperLeftWidgetHelper
  7. {
  8. public int DrawWidget( ParentNode owner, int selectedIndex, GUIContent[] displayedOptions )
  9. {
  10. if( owner.DropdownEditing )
  11. {
  12. int newValue = owner.EditorGUIPopup( owner.DropdownRect, selectedIndex, displayedOptions, UIUtils.PropertyPopUp );
  13. if( newValue != selectedIndex )
  14. {
  15. owner.DropdownEditing = false;
  16. }
  17. return newValue;
  18. }
  19. return selectedIndex;
  20. }
  21. public int DrawWidget( ParentNode owner, int selectedIndex, string[] displayedOptions )
  22. {
  23. if( owner.DropdownEditing )
  24. {
  25. int newValue = owner.EditorGUIPopup( owner.DropdownRect, selectedIndex, displayedOptions, UIUtils.PropertyPopUp );
  26. if( newValue != selectedIndex )
  27. {
  28. owner.DropdownEditing = false;
  29. }
  30. return newValue;
  31. }
  32. return selectedIndex;
  33. }
  34. public int DrawWidget( ParentNode owner, int selectedIndex, string[] displayedOptions, int[] optionValues )
  35. {
  36. if( owner.DropdownEditing )
  37. {
  38. int newValue = owner.EditorGUIIntPopup( owner.DropdownRect, selectedIndex, displayedOptions, optionValues, UIUtils.PropertyPopUp );
  39. if( newValue != selectedIndex )
  40. {
  41. owner.DropdownEditing = false;
  42. }
  43. return newValue;
  44. }
  45. return selectedIndex;
  46. }
  47. // GC free version
  48. public void DrawWidget<TEnum>( ref TEnum selectedIndex, ParentNode owner, Action<ParentNode> callback ) where TEnum : struct
  49. {
  50. if( owner.DropdownEditing )
  51. {
  52. Enum asEnumType = selectedIndex as Enum;
  53. if( asEnumType != null )
  54. {
  55. EditorGUI.BeginChangeCheck();
  56. selectedIndex = ( owner.EditorGUIEnumPopup( owner.DropdownRect, asEnumType, UIUtils.PropertyPopUp ) as TEnum? ).Value;
  57. if( EditorGUI.EndChangeCheck() )
  58. {
  59. owner.DropdownEditing = false;
  60. if( callback != null )
  61. callback( owner );
  62. }
  63. }
  64. }
  65. }
  66. /*
  67. * USE THIS OVERRIDE IN CASE THE NODE DOESN'T HAVE PREVIEW
  68. */
  69. //public override void AfterCommonInit()
  70. //{
  71. // base.AfterCommonInit();
  72. // if( PaddingTitleLeft == 0 )
  73. // {
  74. // PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
  75. // if( PaddingTitleRight == 0 )
  76. // PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
  77. // }
  78. //}
  79. /*
  80. * USE THE SOURCE CODE BELOW INTO THE NODE YOU WANT THE WIDGET TO SHOW
  81. */
  82. //private UpperLeftWidgetHelper m_upperLeftWidget = new UpperLeftWidgetHelper();
  83. }
  84. }