context: using UnityEngine;
  using UnityEditor;
  using System.Collections;
  using System.Collections.Generic;
  using System;
  
  public class AMOptions : EditorWindow {
      public static AMOptions window = null;
  
      public AMOptionsFile oData;
  
      private AnimatorData __aData;
  
      public AnimatorData aData {
          get {
              if(AMTimeline.window != null && __aData != AMTimeline.window.aData) {
                  reloadAnimatorData();
              }
  
              return __aData;
          }
      }
  
      string version = "1.53";
      Vector2 scrollView = new Vector2(0f, 0f);
      private int playOnStartIndex = 0;
      private int exportTakeIndex = 0;
      private bool exportAllTakes = false;
      public static int tabIndex = 0;
  
      private enum tabType {
          General = 0,
          QuickAdd = 1,
          ImportExport = 2,
          About = 3
      }
  
      string[] tabNames = new string[] { "General", "Quick Add", "Import / Export", "About" };
  
      // skin names
      private string[] skin_names = new string[] { "Dark", "Classic Blue" };
      private string[] skin_ids = new string[] { "am_skin_dark", "am_skin_blue" };
      private int skinIndex = 0;
  
      // skins
      private GUISkin skin = null;
      private string cachedSkinName = null;
  
      private float width_indent = 5f;
  
      void OnEnable() {
          window = this;
          this.title = "Options";
          this.minSize = new Vector2(545f, 365f);
          this.maxSize = new Vector2(1000f, this.minSize.y);
  
          loadAnimatorData();
          oData = AMOptionsFile.loadFile();
          // setup skin popup
          skinIndex = 0;
          for(int i = 1; i < skin_ids.Length; i++) {
              if(skin_ids[i] == oData.skin) {
                  skinIndex = i;
                  break;
              }
          }
  
          if(aData) exportTakeIndex = aData.getTakeIndex(aData.getCurrentTake());
      }
      void OnDisable() {
          window = null;
      }
      void OnHierarchyChange() {
          if(!aData) loadAnimatorData();
      }
      void OnGUI() {
          AMTimeline.loadSkin(oData, ref skin, ref cachedSkinName, position);
          if(!aData) {
              AMTimeline.MessageBox("Animator requires an AnimatorData component in your scene. Launch Animator to add the component.", AMTimeline.MessageBoxType.Warning);
              return;
          }
          if(!oData) oData = AMOptionsFile.loadFile();
          GUILayout.BeginHorizontal();
          #region tab selection
          //GUI.DrawTexture(new Rect(0f,0f,120f,position.height),GUI.skin.GetStyle("GroupElementBG")/*GUI.skin.GetStyle("GroupElementBG").onNormal.background*/);
          GUIStyle styleTabSelectionBG = new GUIStyle(GUI.skin.GetStyle("GroupElementBG"));
          styleTabSelectionBG.normal.background = EditorStyles.toolbar.normal.background;
          GUILayout.BeginVertical(/*GUI.skin.GetStyle("GroupElementBG")*/styleTabSelectionBG, GUILayout.Width(121f));
          EditorGUIUtility.LookLikeControls();
          GUIStyle styleTabButton = new GUIStyle(EditorStyles.toolbarButton);
          styleTabButton.fontSize = 12;
          styleTabButton.fixedHeight = 30;
          styleTabButton.onNormal.background = styleTabButton.onActive.background;
          styleTabButton.onFocused.background = null;
          styleTabButton.onHover.background = null;
          tabIndex = GUILayout.SelectionGrid(tabIndex, tabNames, 1, styleTabButton);
          GUILayout.EndVertical();
          #endregion
          #region options
          GUILayout.BeginVertical();
          EditorGUIUtility.LookLikeControls();
  
          GUIStyle styleArea = new GUIStyle(GUI.skin.textArea);
          scrollView = GUILayout.BeginScrollView(scrollView, styleArea);
          List<string> takeNames = getTakeNames();
  
          GUIStyle styleTitle = new GUIStyle(GUI.skin.label);
          styleTitle.fontSize = 20;
          styleTitle.fontStyle = FontStyle.Bold;
  
          // tab title
          GUILayout.BeginHorizontal();
          GUILayout.Space(width_indent);
          GUILayout.Label(tabNames[tabIndex], styleTitle);
          GUILayout.EndHorizontal();
          GUILayout.Space(10f);
  
          #region general
          if(tabIndex == (int)tabType.General) {
              List<string> takeNamesWithNone = new List<string>(takeNames);
              takeNamesWithNone.Insert(0, "None");
              // play on start
              GUILayout.BeginHorizontal();
              GUILayout.Space(width_indent);
              GUILayout.BeginVertical(GUILayout.Height(26f));
              GUILayout.Space(1f);
              GUILayout.Label("Play On Start");
              GUILayout.FlexibleSpace();
              GUILayout.EndVertical();
              if(setPlayOnStartIndex(EditorGUILayout.Popup(playOnStartIndex, takeNamesWithNone.ToArray(), GUILayout.Width(200f)))) {
                  if(playOnStartIndex == 0) aData.playOnStart = null;
                  else aData.playOnStart = aData.getTake(takeNames[playOnStartIndex - 1]);
              }
              GUILayout.EndHorizontal();
              // gizmo size
              GUILayout.BeginHorizontal();
              GUILayout.Space(width_indent);
              GUILayout.BeginVertical(GUILayout.Height(26f), GUILayout.Width(80f));
              GUILayout.FlexibleSpace();
              GUILayout.Label("Gizmo size", GUILayout.Width(80f));
              GUILayout.FlexibleSpace();
              GUILayout.EndVertical();
              if(aData.setGizmoSize(GUILayout.HorizontalSlider(aData.gizmo_size, 0f, 0.1f, GUILayout.ExpandWidth(true)))) {
                  GUIUtility.keyboardControl = 0;
                  EditorUtility.SetDirty(aData);
              }
              GUILayout.BeginVertical(GUILayout.Height(26f), GUILayout.Width(75f));
              GUILayout.FlexibleSpace();
              if(aData.setGizmoSize(EditorGUILayout.FloatField(aData.gizmo_size, GUI.skin.textField, GUILayout.Width(75f)))) {
                  EditorUtility.SetDirty(aData);
              }
              GUILayout.FlexibleSpace();
              GUILayout.EndVertical();
              GUILayout.EndHorizontal();
              // time instead of frame numbers
              GUILayout.BeginHorizontal();
              GUILayout.Space(width_indent);
              GUILayout.BeginVertical(GUILayout.Height(26f));
              GUILayout.FlexibleSpace();
              GUILayout.Label("Show time instead of frame numbers");
              GUILayout.FlexibleSpace();
              GUILayout.EndVertical();
              if(oData.setTimeNumbering(GUILayout.Toggle(oData.time_numbering, ""))) {
                  // save
                  EditorUtility.SetDirty(oData);
              }
              GUILayout.EndHorizontal();
              // scrubby zoom cursor
              GUILayout.BeginHorizontal();
              GUILayout.Space(width_indent);
              GUILayout.BeginVertical(GUILayout.Height(26f));
              GUILayout.FlexibleSpace();
              GUILayout.Label("Scrubby zoom cursor");
              GUILayout.FlexibleSpace();
              GUILayout.EndVertical();
              if(oData.setScrubbyZoomCursor(GUILayout.Toggle(oData.scrubby_zoom_cursor, ""))) {
                  // save
                  EditorUtility.SetDirty(oData);
              }
              GUILayout.EndHorizontal();
              // scrubby zoom slider
              GUILayout.BeginHorizontal();
              GUILayout.Space(width_indent);
              GUILayout.BeginVertical(GUILayout.Height(26f));
              GUILayout.FlexibleSpace();
              GUILayout.Label("Scrubby zoom slider");
              GUILayout.FlexibleSpace();
              GUILayout.EndVertical();
              if(oData.setScrubbyZoomSlider(GUILayout.Toggle(oData.scrubby_zoom_slider, ""))) {
                  // save
                  EditorUtility.SetDirty(oData);
              }
              GUILayout.EndHorizontal();
              // show warning for lost references
              /*GUILayout.BeginHorizontal();
                  GUILayout.Space(width_indent);
                  GUILayout.BeginVertical(GUILayout.Height(26f));
                      GUILayout.FlexibleSpace();
                      GUILayout.Label ("Show warning for lost references");
                      GUILayout.FlexibleSpace();
                  GUILayout.EndVertical();
                  if(oData.setShowWarningForLostReferences(GUILayout.Toggle(oData.showWarningForLostReferences,""))) {
                      // save
                      EditorUtility.SetDirty(oData);
                  }
              GUILayout.EndHorizontal();*/
              // ignore minimum window size warning
              GUILayout.BeginHorizontal();
              GUILayout.Space(width_indent);
              GUILayout.BeginVertical(GUILayout.Height(26f));
              GUILayout.FlexibleSpace();
              GUILayout.Label("Ignore minimum window size warning");
              GUILayout.FlexibleSpace();
              GUILayout.EndVertical();
              if(oData.setIgnoreMinimumSizeWarning(GUILayout.Toggle(oData.ignoreMinSize, ""))) {
                  // save
                  EditorUtility.SetDirty(oData);
              }
              GUILayout.EndHorizontal();
              // show frames for collapsed tracks
              GUILayout.BeginHorizontal();
              GUILayout.Space(width_indent);
              GUILayout.BeginVertical(GUILayout.Height(26f));
              GUILayout.FlexibleSpace();
              GUILayout.Label("Show frames for collapsed tracks");
              GUILayout.FlexibleSpace();
              GUILayout.EndVertical();
              if(oData.setShowFramesForCollapsedTracks(GUILayout.Toggle(oData.showFramesForCollapsedTracks, ""))) {
                  // save
                  EditorUtility.SetDirty(oData);
              }
              GUILayout.EndHorizontal();
              // disable timeline actions
              GUILayout.BeginHorizontal();
              GUILayout.Space(width_indent);
              GUILayout.BeginVertical(GUILayout.Height(26f));
              GUILayout.FlexibleSpace();
              GUILayout.Label("Hide Timeline Actions (May increase editor performance)");
              GUILayout.FlexibleSpace();
              GUILayout.EndVertical();
              if(oData.setDisableTimelineActions(GUILayout.Toggle(oData.disableTimelineActions, ""))) {
                  // save
                  EditorUtility.SetDirty(oData);
                  AMTimeline.recalculateNumFramesToRender();
              }
              GUILayout.EndHorizontal();
              // disable timeline actions tooltip
              if(oData.disableTimelineActions) GUI.enabled = false;
              GUILayout.BeginHorizontal();
              GUILayout.Space(width_indent);
              GUILayout.BeginVertical(GUILayout.Height(26f));
              GUILayout.FlexibleSpace();
              GUILayout.Label("Enable Timeline Actions tooltip");
              GUILayout.FlexibleSpace();
              GUILayout.EndVertical();
              if(oData.disableTimelineActions) {
                  GUILayout.Toggle(false, "");
              }
              else {
                  if(oData.setDisableTimelineActionsTooltip(!GUILayout.Toggle(!oData.disableTimelineActionsTooltip, ""))) {
                      // save
                      EditorUtility.SetDirty(oData);
                  }
              }
              GUILayout.EndHorizontal();
              GUI.enabled = true;
              // skin
              GUILayout.BeginHorizontal();
              GUILayout.Space(width_indent);
              GUILayout.BeginVertical(GUILayout.Height(26f));
              GUILayout.Space(1f);
              GUILayout.Label("Skin");
              GUILayout.FlexibleSpace();
              GUILayout.EndVertical();
              skinIndex = EditorGUILayout.Popup(skinIndex, skin_names, GUILayout.Width(200f));
              if(oData.setSkin(skin_ids[skinIndex])) {
                  //if(playOnStartIndex == 0) aData.playOnStart = null;
                  //else aData.playOnStart = aData.getTake(takeNames[playOnStartIndex-1]);
              }
              GUILayout.EndHorizontal();
          }
          #endregion
          #region quick add
          else if(tabIndex == (int)tabType.QuickAdd) {
              EditorGUIUtility.LookLikeControls();
              GUILayout.Space(3f);
              GUILayout.BeginHorizontal();
              GUILayout.Space(width_indent);
              GUILayout.Label("Combinations");
              GUILayout.EndHorizontal();
              if(oData.quickAdd_Combos == null) oData.quickAdd_Combos = new List<List<int>>();
              for(int j = 0; j < oData.quickAdd_Combos.Count; j++) {
                  GUILayout.Space(3f);
                  GUILayout.BeginHorizontal();
                  GUILayout.Space(width_indent);
                  for(int i = 0; i < oData.quickAdd_Combos[j].Count; i++) {
                      if(oData.setQuickAddCombo(j, i, EditorGUILayout.Popup(oData.quickAdd_Combos[j][i], AMTimeline.TrackNames, GUILayout.Width(80f)))) {
                          oData.flatten_quickAdd_Combos();
                          EditorUtility.SetDirty(oData);
                      }
  
gt:                     if(i < oData.quickAdd_Combos[j].Count - 1) GUILayout.Label("+");