summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/AmplifyShaderEditor/Plugins/Editor/Utils/UpperLeftWidgetHelper.cs
blob: 9e92fe2d379d11196c23142f2d1a9621028824e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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<TEnum>( ref TEnum selectedIndex, ParentNode owner, Action<ParentNode> 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();
	}
}