0

Hi I have a small problem with a funccion. I need some help

public static void BuildContentEnum<T>(string label, string toolTip, SerializedProperty property) 
{
    EditorGUILayout.BeginHorizontal();

    property.enumValueIndex = (T)EditorGUILayout.EnumPopup(BuildContentBasic(label, toolTip), (T)Enum.GetValues(typeof(T)).GetValue(property.enumValueIndex));

    EditorGUILayout.EndHorizontal();
}

error CS1503: Argument #2' cannot convertT' expression to type `System.Enum'

Fredrik Widerberg
  • 3,068
  • 10
  • 30
  • 42
Fran
  • 1
  • 1
  • `EditorGUILayout.EnumPopup` returns `Enum` so can not use it with a generic/template `T`, I guess. use something like this: http://stackoverflow.com/questions/79126/create-generic-method-constraining-t-to-an-enum – Umair M Jul 18 '16 at 12:22

1 Answers1

0

You are missing a closing parenthesis.

 (T) EditorGUILayout.EnumPopup(
          BuildContentBasic(label, toolTip), 
          (T)Enum.GetValues(typeof(T)) // here should be an extra parenthesis
          .GetValue(property.enumValueIndex)); // Here you should remove one

At least this is how I understand it, enumValueIndex is an integer but EnumPopup returns and enum, that won't do. So you want to get the value of the enum.

But I would think there is an easier way:

int value = property.enumValueIndex;
Fredrik Widerberg
  • 3,068
  • 10
  • 30
  • 42
Everts
  • 10,408
  • 2
  • 34
  • 45