Creating a SerializedProperty for type

I have an editor script that needs to store and display some data. It should work the same way public variables do for monobehaviours. Normally this could just be done using EditorGUI.SomethingField(something); but in my case, I don’t know the type of object that will be stored until runtime.

I know that SerializedProperty can hold any sort of object I need, so I’m trying to use that. Problem is, how can I create a SerializedProperty for a given type? For example, I want to do something like this:

		private SerializedProperty property;

		private void CreateProperty(Type type)
		{
			property = new SerializedProperty(type);
		}

		private void OnGUI()
		{
			EditorGUILayout.PropertyField(property);
		}

There will also need to be some way to actually serialize that property for persistence.

How can something like this be done?

Hey Stuffses

Unfortunately you can’t store a Type in a SerializedProperty, but you CAN store a string!

/// <summary>
/// 	Provides util methods for working with Types.
/// </summary>
public static class TypeUtils
{
	/// <summary>
	/// 	Converts the input string to a Type.
	/// </summary>
	/// <returns>The Type.</returns>
	/// <param name="typeString">Type string.</param>
	public static Type FromString(string typeString)
	{
		return Type.GetType(typeString);
	}

	/// <summary>
	/// 	Converts the input Type to a string.
	/// </summary>
	/// <returns>The string.</returns>
	/// <param name="type">Type.</param>
	public static string ToString(Type type)
	{
		return type.AssemblyQualifiedName;
	}
}