title: EditorGUILayout.EnumPopup resetting value in custom editor
body: <p>I have an editor script which is supposed to allow me to change the texture of a tile (I'm making a game board). It works by creating a drop down menu with different "tile types", and then when I select a new tile type from the menu it will change the texture to the appropriate type.</p>
  
  <pre><code>[CustomEditor(typeof(Tile))]
  public class TileEditor : Editor {
  
      enum Type {
          Blank,
          Portal
      }
  
      // Represents the type of tile this is
      Type type;
  
      public override void OnInspectorGUI() {
          Tile tile = (Tile)target;
  
          // Create a dropdown list of tile types
          type = (Type)EditorGUILayout.EnumPopup ("Type", type);
  
          switch (type) {
          case Type.Blank:
              tile.GetComponent&lt;Renderer&gt; ().material = Resources.Load ("Materials/Blank Tile", typeof(Material)) as Material;
              break;
          case Type.Portal:
              tile.GetComponent&lt;Renderer&gt; ().material = Resources.Load("Materials/Portal Tile", typeof(Material)) as Material;
              break;
          }
      }
  }
  </code></pre>
  
  <p>If I remove the lines where I set the materials, the drop down menu works as expected, but with those lines included, when I select Portal from the drop down it will change the texture for just a moment, and then both the texture and the menu will reset themselves back to the first item in the enum (Blank).</p>
  
  <p>What is going on here, and how do I make my selections persist?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I've narrowed down the issue slightly. When I select the Portal type it executes the <code>Type.Portal</code> case, but then immediately <code>type</code> changes back to <code>Type.Blank</code> and it executes the <code>Type.Blank</code> case. So it seems something is changing my <code>type</code> variable between calls to <code>OnInspectorGUI()</code>.</p>