Exemple #1
0
        private void Init()
        {
            if (initialized)
            {
                return;
            }

            if (!_manuallyConfigured)
            {
                if (this.fieldInfo != null)
                {
                    var attrib = this.fieldInfo.GetCustomAttributes(typeof(DNAEvaluatorList.ConfigAttribute), true).FirstOrDefault() as DNAEvaluatorList.ConfigAttribute;
                    if (attrib != null)
                    {
                        _labelOption  = attrib.labelOption;
                        _defaultGraph = attrib.defaultGraph;
                    }
                }
            }
            _aggregationLabelStyle           = new GUIStyle(EditorStyles.label);
            _aggregationLabelStyle           = new GUIStyle(EditorStyles.centeredGreyMiniLabel);
            _aggregationLabelStyle.alignment = TextAnchor.MiddleLeft;

            if (ROLDefaults == null)
            {
                ROLDefaults = new ReorderableList.Defaults();
            }

            initialized = true;
        }
 private void ResetNewGraphFields()
 {
     newGraphName      = "";
     newGraphTooltip   = "";
     newGraph          = new AnimationCurve(DNAEvaluationGraph.Default.GraphKeys);
     nameError         = "";
     graphError        = "";
     _updatatingPreset = null;
 }
 private void PopupCallback(DNAEvaluationGraph selectedGraph, SerializedProperty property)
 {
     _helper = new DNAEvaluationGraph.EditorHelper(selectedGraph);
     CopyValuesFromHelper(property, _helper);
     UpdateCachedToolTip(_helper.Target);
     GUI.changed = true;
     //store the change for the next update
     changed = true;
     GUI.FocusControl("DNAEvaluationGraph");
 }
        /// <summary>
        /// Draws a swatch for the given DNAEvaluationGraph at the given position.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="dnaGraph"></param>
        /// <param name="tooltip">An optional tooltip for when the swatch is hovered</param>
        /// <param name="hovered">Draw the swatch is hovered</param>
        /// <param name="selected">Draw the swatch is selected</param>
        /// <param name="callback">An optional callback to trigger when the swatch is clicked</param>
        public void DrawSwatch(Rect position, DNAEvaluationGraph dnaGraph, string tooltip = "", bool hovered = false, bool selected = false, System.Action <DNAEvaluationGraph> callback = null)
        {
            Init();

            _drawhelper = new DNAEvaluationGraph.EditorHelper(dnaGraph);

            var thisBgColor = hovered ? _bgColorHovered : (selected ? _bgColorSelected : _bgColor);

            EditorGUIUtility.DrawCurveSwatch(position, _drawhelper._graph, null, new Color(1f, 1f, 0f, 0.7f), thisBgColor);
            var overlayRect = new Rect(position.xMin, position.yMin - 1f, position.width, position.height);

            EditorGUI.DropShadowLabel(overlayRect, new GUIContent(dnaGraph.name), graphLabelStyle);

            if (GUI.Button(overlayRect, new GUIContent(dnaGraph.name, tooltip), graphLabelStyle))
            {
                if (callback != null)
                {
                    callback(dnaGraph);
                }
            }
        }
 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();
        }
        public override void OnGUI(Rect position)
        {
            GUI.Label(position, GUIContent.none, GUI.skin.box);
            Event current = Event.current;

            //handle the user editing a field whose graph is not longer in any preset libraries
            var allPresets        = DNAEvaluationGraphPresetLibrary.AllGraphPresets;
            var allPresetTooltips = DNAEvaluationGraphPresetLibrary.AllGraphTooltips;

            if (_selectedPreset != null && !allPresets.Contains(_selectedPreset))
            {
                allPresets.Insert(0, _selectedPreset);
                allPresetTooltips.Insert(0, _selectedPreset.name + " (Not in Presets Library)");
            }
            scrollPosition = GUILayout.BeginScrollView(scrollPosition);
            if (DNAEvaluationGraphPresetLibrary.AllGraphPresets.Count > 0)
            {
                for (int index = 0; index < allPresets.Count; index++)
                {
                    Rect rect = GUILayoutUtility.GetRect(16f, entryHeight + (padding * 2f), new GUILayoutOption[1]
                    {
                        GUILayout.ExpandWidth(true)
                    });
                    rect.x     += padding;
                    rect.width -= padding * 2f;
                    Rect swatchRect   = new Rect(rect.xMin, rect.yMin + padding, rect.width, rect.height - (padding * 2f));
                    bool selectedFlag = false;
                    bool hoveredFlag  = false;
                    if (current.type == EventType.MouseDown && rect.Contains(current.mousePosition))
                    {
                        _selectedIndex  = index;
                        _selectedPreset = allPresets[index];
                        this.editorWindow.Close();
                    }
                    else if (current.type != EventType.MouseDown && (_selectedPreset != null && allPresets[index] == _selectedPreset))
                    {
                        _selectedIndex = index;
                    }
                    if (current.type == EventType.MouseMove && rect.Contains(current.mousePosition))
                    {
                        _hoveredIndex = index;
                        this.editorWindow.Repaint();
                    }
                    if (index == _selectedIndex)
                    {
                        selectedFlag = true;
                    }
                    if (index == _hoveredIndex)
                    {
                        hoveredFlag = true;
                    }
                    if (current.type == EventType.Repaint)
                    {
                        dnaEvalDrawer.DrawSwatch(swatchRect, allPresets[index], allPresetTooltips[index], hoveredFlag, selectedFlag);
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There were no DNAEvaluationGraph presets.", MessageType.Warning);
            }
            GUILayout.EndScrollView();

            GUILayout.Space(10f);
        }