title: How to make an enum-like Unity inspector drop-down menu from a string array with C#?
body: <p>I'm making a Unity C# script that is meant to be used by other people as a character dialog tool to write out conversations between multiple game characters.</p>
  
  <p>I have a <code>DialogueElement</code> class and then I create a list of <code>DialogueElement</code> objects. Each object represents a line of dialogue.</p>
  
  <pre><code>[System.Serializable] //needed to make ScriptableObject out of this class
  public class DialogueElement
  {
      public enum Characters {CharacterA, CharacterB};
      public Characters Character; //Which characters is saying the line of dialog
      public string DialogueText; //What the character is saying
  }
  </code></pre>
  
  <pre><code>public class Dialogue : ScriptableObject
  {
      public string[] CharactersList; //defined by the user in the Unity inspector
      public List&lt;DialogueElement&gt; DialogueItems; //each element represents a line of dialogue
  }
  </code></pre>
  
  <p>I want the user to be able to use the dialog tool by only interacting with the Unity inspector (so no editing code). The problem with this setup then is that the user of the dialogue tool cannot specify their own custom names (such as Felix or Wendy) for the characters in the <code>Characters</code> enum since they are hardcoded as "CharacterA" and "CharacterB" in the <code>DialogueElement</code> class.</p>
  
  <p>For those not familiar with Unity, it is a game creation program. Unity lets users create physical files (known as scriptable objects) that acts as containers for class objects. The public variables of the scriptable object can be defined through a visual interface called the "inspector" as you can see below:<br>
  <a href="https://i.stack.imgur.com/9y2sK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9y2sK.png" alt="Unity inspector"></a></p>
  
  <p>I want to use an enum to specify which characters is the one saying the line of dialog because using an enum creates a nice drop-down menu in the inspector where the user can easily select the character without having to manually type the name of the character for each line of dialogue.</p>
  
  <p><strong>How can I allow the user to define the elements of the <code>Characters</code> enum?</strong> In this case I was trying to use a string array variable where the player can type the name of all the possible characters and then use that array to define the enum.</p>
  
  <p>I don't know if solving the problem this way is possible. I'm open to <strong>ANY</strong> ideas that will allow the user to specify a list of names that can then be used to create a drop down menu in the inspector where the user selects one of the names as seen in the image above.</p>
  
  <p>The solution doesn't need to specifically declare a new enum from a string array. I just want to find a way to make this work. One solution I thought of is to write a separate script that would edit the text of the C# script that contains the Character enum. I think this would technically work since Unity automatically recompiles scripts every time it detects they were changed and updates the scriptable objects in the inspector, but I was hoping to find a cleaner way.  </p>
  
  <p>Link to repository for reference:<br>
  <a href="https://github.com/guitarjorge24/DialogueTool" rel="nofollow noreferrer">https://github.com/guitarjorge24/DialogueTool</a></p>