Editor/ShaderGraphPlus/Widgets/ControlWidgets/PortTypeControlWidget.cs

An editor control widget for selecting a shader port type, implemented as a dropdown bound to a SerializedProperty. It initializes the property to "float" if unset and provides a fixed list of shader data types (bool, int, float, vectors, matrices, textures, sampler).

using Editor;
using static ShaderGraphPlus.ShaderGraphPlusGlobals;

namespace ShaderGraphPlus;

[CustomEditor( typeof( string ), NamedEditor = ControlWidgetCustomEditors.PortTypeChoiceEditor )]
sealed class PortTypeControlWidget : DropdownControlWidget<string>
{
	public PortTypeControlWidget( SerializedProperty property ) : base( property )
	{
		var currentValue = SerializedProperty.GetValue<object>()?.ToString();
		SerializedProperty.SetValue<string>( currentValue ?? "float" );
	}

	protected override IEnumerable<object> GetDropdownValues()
	{
		return new List<object>()
		{
			"bool",
			"int",
			"float",
			"Vector2",
			"Vector3",
			"Vector4",
			"float2x2",
			"float3x3",
			"float4x4",
			"Texture2D",
			"TextureCube",
			"SamplerState",
		};
	}
}