private void DrawPopup(Rect position, SerializedProperty property)
        {
            var popupIconRect = new Rect((position.xMax - popupIconSize) + 1f, position.yMin, popupIconSize - 2f, position.height + 1f);
            var contentRect   = new Rect(position.xMin + 1f, position.yMin + 0.5f, position.width - popupIconSize + 3f, position.height - 2f);
            var overlayRect   = new Rect(position.xMin, position.yMin - 1f, position.width, position.height);

            //make this look like a popup that has this graph swatch in
            //draw a popup style background-this makes the field look highlighted (in blue)
            EditorGUI.LabelField(position, GUIContent.none, EditorStyles.miniButton);

            //draw a little popup icon aswell
            EditorGUI.LabelField(popupIconRect, GUIContent.none, EditorStyles.popup);

            //now draw the graph swatch in the center of that (there is an optional rangesRect param that we could add here if we always wanted to draw the swatch with a vertical axis going fro -1f -> 1f)
            EditorGUIUtility.DrawCurveSwatch(contentRect, _helper._graph, null, new Color(1f, 1f, 0f, 0.7f), new Color(0.337f, 0.337f, 0.337f, 1f));

            //now draw a button over the whole thing, with a label for the selected swatch, that will open up the swatch selector when its clicked
            EditorGUI.DropShadowLabel(overlayRect, new GUIContent(_helper._name), graphLabelStyle);
            if (GUI.Button(overlayRect, new GUIContent(_helper._name, cachedTooltip), graphLabelStyle))
            {
                GUI.FocusControl("DNAEvaluationGraph");

                //Deal with missing settings
                //If this field contains a graph that is no longer in any preset libraries
                //they wont be able to get that graph back unless they add it to a library
                //so show a warning dialog giving them the option of doing that
                if (_helper.Target != null && !DNAEvaluationGraphPresetLibrary.AllGraphPresets.Contains(_helper.Target))
                {
                    var _missingGraphChoice = EditorUtility.DisplayDialogComplex("Missing Preset", "The graph " + _helper.Target.name + " was not in any preset libraries in the project. If you change the graph this field is using you wont be able to select " + _helper.Target.name + " again. What would you like to do?", "Change Anyway", "Store and Change", "Cancel");
                    if (_missingGraphChoice == 1)
                    {
                        Debug.Log("_missingGraphChoice == 1");
                        //store and change
                        //add to the first found lib and then carry on
                        DNAEvaluationGraphPresetLibrary.AddNewPreset(_helper.Target.name, new AnimationCurve(_helper.Target.GraphKeys), _helper.Target.name);
                    }
                    else if (_missingGraphChoice == 2)
                    {
                        return;
                    }
                }
                //WHY is the content drawing disabled in play mode??!!??
                var prevEnabled = GUI.enabled;
                GUI.enabled = true;
                if (_popupContent == null)
                {
                    _popupContent = new DNAEvaluationGraphPopupContent();
                }
                _popupContent.width          = overlayRect.width;
                _popupContent.selectedPreset = new DNAEvaluationGraph(_helper.Target);
                _popupContent.property       = property;
                _popupContent.OnSelected     = PopupCallback;

                PopupWindow.Show(overlayRect, _popupContent);
                GUI.enabled = prevEnabled;
            }
        }
 private void Init()
 {
     if (!initialized)
     {
         _target = serializedObject.targetObject as DNAEvaluationGraphPresetLibrary;
         if (newGraph == null)
         {
             newGraph = new AnimationCurve(DNAEvaluationGraph.Default.GraphKeys);
         }
         wordwrappedTextArea          = new GUIStyle(EditorStyles.textArea);
         wordwrappedTextArea.wordWrap = true;
         _customPresets        = DNAEvaluationGraphPresetLibrary.AllCustomGraphPresets;
         _customPresetTooltips = DNAEvaluationGraphPresetLibrary.AllCustomGraphTooltips;
         initialized           = true;
     }
 }
 private void UpdateCachedToolTip(DNAEvaluationGraph graph)
 {
     cachedTooltip = DNAEvaluationGraphPresetLibrary.GetTooltipFor(graph);
 }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            Init();

            EditorGUILayout.LabelField("DNAEvaluationGraph Preset Library", EditorStyles.boldLabel);

            EditorGUILayout.HelpBox("A DNAEvaluationGraph Preset Library contains presets for graphs that will be available in a DNAEvaluationGraph field's dropdown list of available graphs. This asset does not need to be included in your build", MessageType.Info);

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.Space(10f);
            extraInfoIsExpanded = EditorGUILayout.Foldout(extraInfoIsExpanded, "What is a DNAEvaluationGraph?", true);
            EditorGUILayout.EndHorizontal();
            if (extraInfoIsExpanded)
            {
                DrawFullHelp();
            }
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.Space(10f);
            defaultPresetsIsExpanded = EditorGUILayout.Foldout(defaultPresetsIsExpanded, "Default Presets", true);
            EditorGUILayout.EndHorizontal();
            if (defaultPresetsIsExpanded)
            {
                GUIHelper.BeginVerticalPadded(3, new Color(0.75f, 0.875f, 1f, 0.3f));
                EditorGUILayout.HelpBox("These are the standard evaluation graphs that ship with UMA. You can add your own in the custom section below.", MessageType.Info);
                for (int i = 0; i < DNAEvaluationGraphPresetLibrary.DefaultGraphPresets.Count; i++)
                {
                    var rect = EditorGUILayout.GetControlRect(false, entryHeight + (padding * 2f));
                    rect.x     += padding;
                    rect.width -= padding * 2f;
                    Rect swatchRect = new Rect(rect.xMin, rect.yMin + padding, rect.width, rect.height - (padding * 2f));
                    dnaEvalDrawer.DrawSwatch(swatchRect, DNAEvaluationGraphPresetLibrary.DefaultGraphPresets[i], DNAEvaluationGraphPresetLibrary.DefaultGraphTooltips[i], false, false, (dnaGraph) =>
                    {
                        newGraph            = new AnimationCurve(DNAEvaluationGraphPresetLibrary.DefaultGraphPresets[i].GraphKeys);
                        addPresetIsExpanded = true;
                    }
                                             );
                }
                GUIHelper.EndVerticalPadded(3);
            }

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.Space(10f);
            customPresetsIsExpanded = EditorGUILayout.Foldout(customPresetsIsExpanded, "Custom Presets", true);
            EditorGUILayout.EndHorizontal();
            if (customPresetsIsExpanded)
            {
                GUIHelper.BeginVerticalPadded(3, new Color(0.75f, 0.875f, 1f, 0.3f));
                EditorGUILayout.HelpBox("Add your own graph presets to this section using the tools below.", MessageType.Info);
                List <int> custToDel = new List <int>();
                for (int i = 0; i < _customPresets.Count; i++)
                {
                    var rect = EditorGUILayout.GetControlRect(false, entryHeight + (padding * 2f));
                    rect.x     += padding;
                    rect.width -= padding * 2f;
                    Rect swatchRect = new Rect(rect.xMin, rect.yMin + padding, rect.width - (swatchButWidth + padding), rect.height - (padding * 2f));
                    dnaEvalDrawer.DrawSwatch(swatchRect, _customPresets[i], _customPresetTooltips[i] + " [Click To Edit]", false, false, (dnaGraph) =>
                    {
                        newGraphName        = _customPresets[i].name;
                        newGraphTooltip     = _customPresetTooltips[i];
                        newGraph            = new AnimationCurve(_customPresets[i].GraphKeys);
                        addPresetIsExpanded = true;
                        _updatatingPreset   = _customPresets[i];
                    }
                                             );
                    //editCallback

                    var delRect = new Rect(swatchRect.xMax, swatchRect.yMin + padding, swatchButWidth, swatchButWidth);
                    if (GUI.Button(delRect, new GUIContent("X", "Delete " + _customPresets[i].name)))
                    {
                        custToDel.Add(i);
                    }
                }
                if (custToDel.Count > 0)
                {
                    for (int i = 0; i < custToDel.Count; i++)
                    {
                        DNAEvaluationGraphPresetLibrary.DeleteCustomPreset(_customPresets[custToDel[i]]);
                    }
                    initialized = false;
                    EditorUtility.SetDirty(_target);
                    AssetDatabase.SaveAssets();
                }
                DrawDNAEvaluationGraphAddBox();
                GUIHelper.EndVerticalPadded(3);
            }
            else
            {
                ResetMessages();
            }

            serializedObject.ApplyModifiedProperties();
        }