List instances names of a class

Hi everybody

I have a class that contains list of other class instances :

List< Sections > Anims;  // 'Sections'  is a class

i need a property “CurrentAnim” that point to number of “Sections” Instances , defined in List<> Anims .

(In Inspector) for example if Anims contains 3 items(3 instance of classes) with names : walk , run , idle :

in the CurrentAnim , i should have that 3 names Selectable .

i am thinking , can i create a ENUM from list of instances of a class ? and i think it must created in EDITOR while Level Designer is working with unity inspectors & …

how can i finish it ?

Thanks for your answers.

Yes, you can create an enum and then have one of those values selectable in the inspector.

public enum Animations{
	Walk,
	Run
}

public class MyScript{
	public Animations thisAnimation;
}

You can use a switch-case to choose which Sections-instance in your list should be used. Though I suggest coming up with a better solution, because I don’t like switch-cases.

seems you didn’t get what i want my friend.
i wanted to create an Enum from List of Instances of a class . not a constant list.

By the way , i found the solution my self :

I had this list item in my class :

public Sections[] section;

and actually “Sectuions” class described here :

public class Sections {
	public string name;
	public Texture2D[] frames;
}

so, i wanted to Show “section” items in a Drop-Down Popup. first i created my editor script and said:

private SerializedProperty _Section ;
void OnEnable () {
		objClass = new SerializedObject(target); 
        _Section = objClass.FindProperty("section");
    }
public override void OnInspectorGUI()
	{
		string[] _names=new string[_Section.arraySize];
		_values=new int[_Section.arraySize];
		
		for (int i = 0; i < _Section.arraySize; i++) {
			SerializedProperty _tmp= _Section.GetArrayElementAtIndex(i);
			_names*=_tmp.FindPropertyRelative("name").stringValue;*

values*=i;
_
}*

* serializedObject.Update ();*
* flag=EditorGUILayout.IntPopup(“Current Animation”,flag,_names,values);
_
serializedObject.ApplyModifiedProperties ();*

* }*
and it’s done !
thanks every one .