DropDownList with string array in Editor Inspector

I understand that you can do the dropdownlist with enums already automatically, but I have a dynamic list of strings from file/game/input/etc stored into a List that I want to be selectable in the editor. How would I go about doing that? Any specifics into the correct direction would be greatly appreciated!

You should look at EditorGUILayout.Popup. This sounds like exactly what you’re looking for. You’d use it as follows,

[CustomEditor(typeof(SomeClass))]
public class SomeEditor : Editor
{
  string[] _choices = new [] { "foo", "foobar" };
  int _choiceIndex = 0;

  public override void OnInspectorGUI ()
  {
    // Draw the default inspector
    DrawDefaultInspector();
    _choiceIndex = EditorGUILayout.Popup(_choiceIndex, _choices);
    var someClass = target as SomeClass;
    // Update the selected choice in the underlying object
    someClass.choice = _choices[_choiceIndex];
    // Save the changes back to the object
    EditorUtility.SetDirty(target);
  }
}

I got around the problem of the _choice index resetting by setting the _choice index to the value in my array.

public override void OnInspectorGUI()
        {
            // Draw the default inspector
            DrawDefaultInspector();

            // Set the choice index to the previously selected index
            _choiceIndex = Array.IndexOf(_choices, sameClass.choice);

            // If the choice is not in the array then the _choiceIndex will be -1 so set back to 0
            if (_choiceIndex < 0)
                _choiceIndex = 0;

            _choiceIndex = EditorGUILayout.Popup(_choiceIndex, _choices);
            
            var someClass = target as SomeClass;
            // Update the selected choice in the underlying object
            someClass.choice = _choices[_choiceIndex];
            // Save the changes back to the object
             EditorUtility.SetDirty(target);
        }

Found this gist that creates an attribute allowing you to create a dropdown out of any string field using.

[StringInList("Cat","Dog")]
public string Animal;

.

For dynamic lists he uses reflection to call a function that returns a string.

[StringInList(typeof(PropertyDrawersHelper), "AllSceneNames")]
public string SceneName;

I just came across this post, to learn how to to customize the editor. However some of the information here no longer works with the current Unity version(5.5). For this, I followed the Scripting API: Editor page and also used some of the code available here.
Here is how I achieved the results with the new version:

using UnityEditor;
using UnityEngine;
using System.Collections;
using System;
// Custom Editor using SerializedProperties.
// Automatic handling of multi-object editing, undo, and prefab overrides.
[CustomEditor(typeof(MyPlayer))]
[CanEditMultipleObjects]
public class MyPlayerEditor : Editor
{

    SerializedProperty orientationProp;
    string[] _choices = new[] { "Up", "Down" , "Left" , "Right" };
    int _choiceIndex = 0;

    void OnEnable()
    {
        // Setup the SerializedProperties.
        orientationProp = serializedObject.FindProperty("gameOrientation");
        // Set the choice index to the previously selected index
        _choiceIndex = Array.IndexOf(_choices, orientationProp.stringValue);
    
    }

    public override void OnInspectorGUI()
    {
        // Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
        serializedObject.Update();

        //doing the orientation thing
        _choiceIndex = EditorGUILayout.Popup("Orientation", _choiceIndex, _choices);
        if (_choiceIndex < 0)
            _choiceIndex = 0;
        orientationProp.stringValue = _choices[_choiceIndex];


      
        // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
        serializedObject.ApplyModifiedProperties();
    }

and the class MyPlayer example class simply has the public declaration.

public class MyPlayer : MonoBehaviour
{

    public string gameOrientation;

}

for those who need to quickly add custom dropdown to their project,
you can download this folder from my repo.

https://github.com/datsfain/EditorCools/tree/main/Assets/Tools/DropdownStringAttribute
Add:

[Dropdown(nameof(MethodThatReturnsOptionsStringArray))]
public string options;

or

[Dropdown(nameof("NameOfMethodThatReturnsOptionsStringArray"))]
public string options;

If you’re doing an inspector and you want that inspector to have it’s own custom gui style without messing with the others, you could do something like this:

//save as Editor_Inspectors_MyScript.cs in the Editor folder...Works if you //attach a 'MyInspectorScript.cs' to an object. Then look at it in the //inspector to see the changes.

using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(MyInspectorScript))]
public class Editor_Inspectors_MyScript : Editor {

	GUIStyle guiStyle;
	MyInspectorScript myInspectorScript;

	void OnEnable()  {
		myInspectorScript = (MyInspectorScript)target;
		guiStyle = new GUIStyle ();
	}

	public override void OnInspectorGUI() { 
		guiStyle.fontSize = 50;
            guiStyle.font = "Arial"; //or whatever
		EditorGUILayout.Label ("Hello world", choices,guiStyle);
	}
}