コード例 #1
0
        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 DrawDNAEvaluationGraphAddBox()
        {
            GUIHelper.BeginVerticalPadded(3, new Color(0.75f, 0.875f, 1f, 0.3f));

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.Space(10f);
            var label = _updatatingPreset ? "Update '" + newGraphName + "' Preset" : "Add a new Preset";

            addPresetIsExpanded = EditorGUILayout.Foldout(addPresetIsExpanded, label, true);
            EditorGUILayout.EndHorizontal();
            if (addPresetIsExpanded)
            {
                EditorGUILayout.Space();

                EditorGUI.BeginChangeCheck();

                if (_updatatingPreset != null)
                {
                    //warn the user that updating a preset wont update any fields that created their values from it
                    EditorGUILayout.HelpBox("Note: Updating this preset will not update the graphs in any existing DNAEvaluationGraph fields", MessageType.Warning);
                }

                newGraphName = EditorGUILayout.TextField("Preset Name", newGraphName);

                var descRect = EditorGUILayout.GetControlRect(false, 45);
                newGraphTooltip = EditorGUI.TextArea(descRect, newGraphTooltip, wordwrappedTextArea);
                //I want the placeholder text in here
                if (newGraphTooltip == "")
                {
                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUI.TextArea(descRect, "Preset Tooltip", wordwrappedTextArea);
                    EditorGUI.EndDisabledGroup();
                }

                var graphRect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * 2f);

                if (EditorGUI.EndChangeCheck())
                {
                    ResetMessages();
                }

                newGraph = EditorGUI.CurveField(graphRect, "Preset Graph", newGraph);

                EditorGUILayout.Space();
                var btnRect = EditorGUILayout.GetControlRect();
                btnRect.width = btnRect.width / 2;
                var clearBtnRect = new Rect(btnRect.xMax, btnRect.yMin, btnRect.width, btnRect.height);
                var addBtnLabel  = "Add It!";
                if (_updatatingPreset != null)
                {
                    addBtnLabel = "Update '" + newGraphName + "'";
                }
                if (GUI.Button(btnRect, addBtnLabel))
                {
                    if (_target.AddNewPreset(newGraphName, newGraphTooltip, newGraph, ref nameError, ref graphError, _updatatingPreset))
                    {
                        serializedObject.Update();
                        serializedObject.ApplyModifiedProperties();
                        addSuccess = _updatatingPreset ? "Updated Graph " + newGraphName + " Successfully!" : "New Custom Graph " + newGraphName + " added Successfully!";
                        ResetNewGraphFields();
                        initialized = false;                        //force the cached custom list to Update
                        EditorUtility.SetDirty(_target);
                        AssetDatabase.SaveAssets();
                        Repaint();
                    }
                }
                if (GUI.Button(clearBtnRect, "Reset Fields"))
                {
                    ResetNewGraphFields();
                }
                if (graphError != "" || nameError != "")
                {
                    EditorGUILayout.HelpBox("There were the following issues when trying to add your graph:", MessageType.None);
                    if (nameError != "")
                    {
                        EditorGUILayout.HelpBox(nameError, MessageType.Error);
                    }
                    if (graphError != "")
                    {
                        EditorGUILayout.HelpBox(graphError, MessageType.Error);
                    }
                }
                else if (addSuccess != "")
                {
                    EditorGUILayout.HelpBox(addSuccess, MessageType.Info);
                }
            }
            else
            {
                ResetMessages();
            }

            GUIHelper.EndVerticalPadded(3);
        }