private void DrawPhonemePreview(Rect rect, Phonemes phonemes)
        {
            //No phonemes
            if (phonemes == null)
            {
                if (Utils.BoxWithLink("There is no refined phonemes.", "Rebuild", MessageType.Error))
                {
                    clip.phonemes.UpdateTable(clip.speech.phonemeTable);
                }
                return;
            }

            //Draw top rect
            Rect topRect = new Rect(rect.x, rect.y, rect.width, 18);

            EditorGUI.DrawRect(topRect, Phonemes_Editor.graphBgColor);

            //Draw curves and fields
            float  maxValue      = 0.0f;
            string maxValueName  = "";
            Color  maxValueColor = Color.white;

            for (int i = 0; i < phonemes.curves.Length; i++)
            {
                Color curveColor = Color.HSVToRGB((i * 0.13f) % 1.0f, 0.8f, 1.0f);
                EditorGUIUtility.DrawCurveSwatch(rect, phonemes.curves[i].curve, null, curveColor, Phonemes_Editor.transparent, new Rect(0, 0, 1, 1));

                float value = phonemes.curves[i].curve.Evaluate(clipTime);

                if (value > maxValue)
                {
                    maxValue      = value;
                    maxValueName  = phonemes.curves[i].name;
                    maxValueColor = curveColor;
                }
            }

            //Draw maxValue top label
            if (maxValue > 0.0001f)
            {
                topRect.x = rect.x + rect.width * clipTime;
                Color guiColor = GUI.color;
                GUI.color = maxValueColor;
                GUI.Label(topRect, maxValueName, Styles.whiteLabel);
                GUI.color = guiColor;
            }

            //Commands
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Rebuild"))
            {
                clip.phonemes.UpdateTable(clip.speech.phonemeTable);
            }
            GUILayout.EndHorizontal();
        }
        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;
            }
        }
Esempio n. 3
0
 private void DrawCurve(Rect rect, AnimationCurve[] curves)
 {
     if (curves != null)
     {
         for (int i = 0; i < curves.Length; i++)
         {
             EditorGUIUtility.DrawCurveSwatch(rect, curves[i], null, cSeq[i], backg);
         }
     }
 }
Esempio n. 4
0
    void DrawCurve(int nIndex, Rect gridRect, int nColumn, int nRow, NcCurveAnimation.NcInfoCurve curveInfo, GUIStyle styleButton)
    {
        int   nMargin       = styleButton.margin.left;
        int   nImageMargin  = 3;
        float fButtonWidth  = (gridRect.width / m_nObjectColumn);
        float fButtonHeight = (m_fButtonAspect * fButtonWidth);

        Rect buttonRect = new Rect(fButtonWidth * nColumn + nMargin, fButtonHeight * nRow + nMargin, fButtonWidth - nMargin * 2, fButtonHeight - nMargin * 2);

        buttonRect = FXMakerLayout.GetOffsetRect(buttonRect, -nImageMargin);
        EditorGUIUtility.DrawCurveSwatch(buttonRect, curveInfo.m_AniCurve, null, Color.green, Color.black, curveInfo.GetFixedDrawRange());
    }
Esempio n. 5
0
 static Rect DrawCurve(Rect controlRect, SerializedProperty property, Action <SerializedProperty> onClick, Color fgColor, Color bgColor)
 {
     if (GUI.Button(controlRect, GUIContent.none))
     {
         if (onClick != null)
         {
             onClick(property);
         }
     }
     EditorGUIUtility.DrawCurveSwatch(controlRect, null, property, fgColor, bgColor);
     return(controlRect);
 }
Esempio n. 6
0
        /// <summary>
        ///     Draws the curve swatch.
        /// </summary>
        /// <param name="position">Position.</param>
        /// <param name="property">Property.</param>
        /// <param name="color">Color.</param>
        /// <param name="curveRanges">Curve ranges.</param>
        private void DrawCurveSwatch(Rect position, SerializedProperty property, Color color, Rect curveRanges)
        {
            Rect curvePosition = new Rect(position);

            // Special case - The curve is a flat line.
            if (HydraMathUtils.Approximately(curveRanges.height, 0.0f))
            {
                curveRanges.y      = -0.5f + curveRanges.y;
                curveRanges.height = 1.0f;
            }

            EditorGUIUtility.DrawCurveSwatch(curvePosition, property.animationCurveValue, property, color, s_CurveBackgroundColor,
                                             curveRanges);
        }
        void ShowEditorCurves(GameObject focusObject, string path)
        {
            ParameterModifier[] paramMod = focusObject.GetComponents <ParameterModifier>();
            foreach (ParameterModifier pm in paramMod)
            {
                GUILayout.Label("Node: " + path + focusObject.name + " Parameter: " + pm.m_parameter);
                if (m_showPitch || m_showVolume)
                {
                    Rect  curveRect = EditorGUILayout.BeginHorizontal(GUILayout.Height(100));
                    Color bgColor   = Color.grey;

                    if (m_showPitch)
                    {
                        //EditorGUILayout.CurveField(pm.m_pitchCurve, GUILayout.Height(100));
                        EditorGUIUtility.DrawCurveSwatch(curveRect, pm.m_pitchCurve, null, Color.red, bgColor, new Rect(0, 0, 1, 3));
                        bgColor.a = 0;
                    }
                    if (m_showVolume)
                    {
                        EditorGUIUtility.DrawCurveSwatch(curveRect, pm.m_volumeCurve, null, Color.green, bgColor, new Rect(0, 0, 1, 1));
                        bgColor.a = 0;
                    }

                    if (m_showPitch || m_showVolume)
                    {
                        float          param     = WingroveRoot.Instance.GetParameterForGameObject(pm.m_parameter, null);
                        AnimationCurve fakeCurve = new AnimationCurve(
                            new Keyframe[] { new Keyframe(param - 0.0001f, 0), new Keyframe(param + 0.0001f, 1) });
                        EditorGUIUtility.DrawCurveSwatch(curveRect, fakeCurve, null, Color.white, bgColor, new Rect(0, 0.1f, 1, 0.8f));
                    }

                    GUILayout.Space(100);
                    EditorGUILayout.EndHorizontal();
                    if (m_showPitch)
                    {
                        EditorGUILayout.CurveField("Edit pitch curve -->", pm.m_pitchCurve, Color.red, new Rect(0, 0, 1, 3));
                    }
                    if (m_showVolume)
                    {
                        EditorGUILayout.CurveField("Edit volume curve -->", pm.m_volumeCurve, Color.green, new Rect(0, 0, 1, 1));
                    }
                    GUILayout.Space(10);
                }
            }
            foreach (Transform t in focusObject.transform)
            {
                ShowEditorCurves(t.gameObject, path + focusObject.name + "/");
            }
        }
        private void RenderAllCurves(Rect curvesArea)
        {
            foreach (var clipInfo in cartSound.clips)
            {
                if (clipInfo.volumeVsSpeed == null)
                {
                    continue;
                }

                DrawReferenceLine(curvesArea, clipInfo.referenceSpeedPercent, referenceLineBackgroundColor);

                EditorGUIUtility.DrawCurveSwatch(
                    curvesArea,
                    //FIXYOU: this is needed due to the undo bug mentioned earlier
                    new AnimationCurve(clipInfo.volumeVsSpeed.keys), null,
                    inactiveCurve / 2f, transparent,
                    workingRange
                    );
            }
        }
        /// <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);
                }
            }
        }
Esempio n. 10
0
        private static Rect DrawSustainGrap(SerializedProperty property, Rect rect, float totalWidth)
        {
            var sustainTime = property.FindPropertyRelative(nameof(Envelope.sustainTime)).floatValue;

            rect.width = sustainTime * totalWidth + minGraphWidth;
            var sustainValue = property.FindPropertyRelative(nameof(Envelope.sustainValue)).floatValue;

            DragSustainValue(rect, property);
            EditorGUIUtility.DrawCurveSwatch(
                rect,
                AnimationCurve.Constant(0, 1, sustainValue),
                null,
                sustainColor,
                curveBackgroundColor,
                ranges
                );
            DrawGraphCaption(rect, property.FindPropertyRelative(nameof(Envelope.sustainValue)), new GUIContent("Sustain"));

            rect.x += rect.width;
            return(rect);
        }
    public override void OnInspectorGUI()
    {
        /*
         * Todo: Find curve range dynamically
         */

        const float barH       = 50f;
        const float swatchH    = 200f;
        Color       background = new Color(0f, 0f, 0f, 0f);

        if (targets.Length == 1)
        {
            var def = target as AirfoilDefinition;

            Rect curveRange = new Rect(-10f, 0f, 110f, 1.5f);

            Rect liftRect = new Rect(0f, barH, Screen.width, swatchH);
            GUI.Box(liftRect, "", GUI.skin.box);
            for (int i = 0; i < def.Profiles.Length; i++)
            {
                if (!_filters[i])
                {
                    continue;
                }

                Color c = Color.HSVToRGB(0.33f + i * 0.05f, 1f, 1f);
                EditorGUIUtility.DrawCurveSwatch(
                    liftRect,
                    def.Profiles[i].Lift, null,
                    c, background,
                    curveRange);
            }

            Rect dragRect = new Rect(0f, barH + swatchH, Screen.width, swatchH);
            GUI.Box(dragRect, "", GUI.skin.box);
            for (int i = 0; i < def.Profiles.Length; i++)
            {
                if (!_filters[i])
                {
                    continue;
                }

                Color c = Color.HSVToRGB(0.00f + i * 0.05f, 1f, 1f);
                EditorGUIUtility.DrawCurveSwatch(
                    dragRect,
                    def.Profiles[i].Drag, null,
                    c, background,
                    curveRange);
            }

            GUILayout.BeginVertical();
            GUILayout.Space(swatchH); // Skip Lift view
            GUILayout.Space(swatchH); // Skip Drag view

            GUILayout.BeginHorizontal();
            for (int i = 0; i < 4; i++)
            {
                _filters[i] = GUILayout.Toggle(_filters[i], def.Profiles[i].Name);
            }
            GUILayout.EndHorizontal();

            DrawDefaultInspector();
            GUILayout.EndVertical();
        }
    }
Esempio n. 12
0
    // ==========================================================================================================
    protected override void DrawBottomRect(Rect baseRect)
    {
        GUI.Box(baseRect, "");

        GUIContent guiCon;
        Rect       imageRect = baseRect;

        imageRect.width = FXMakerLayout.GetFixedWindowWidth();
        Rect rightRect = baseRect;

        rightRect.x     += imageRect.width;
        rightRect.width -= imageRect.width;
        rightRect        = FXMakerLayout.GetOffsetRect(rightRect, 5, 3, -5, -3);

        Rect buttonRect  = FXMakerLayout.GetInnerVerticalRect(rightRect, 12, 0, 5);
        Rect buttonRect2 = FXMakerLayout.GetInnerVerticalRect(rightRect, 12, 5, 5);

        // image
        if (m_SelObjectContent == null)
        {
            guiCon = new GUIContent("[Not Selected]");
        }
        else
        {
            guiCon = new GUIContent("", m_SelObjectContent.image, m_SelObjectContent.tooltip);
        }
        if (FXMakerLayout.GUIButton(imageRect, guiCon, GUI.skin.GetStyle("PopupBottom_ImageButton"), (m_SelObjectContent != null)))
        {
            if (Input.GetMouseButtonUp(0))
            {
                FXMakerMain.inst.CreateCurrentInstanceEffect(true);
            }
        }
        int nImageMargin = 3;

        imageRect = FXMakerLayout.GetOffsetRect(imageRect, -nImageMargin);
        EditorGUIUtility.DrawCurveSwatch(imageRect, m_CurrentCurveAnimation.GetCurveInfo(m_OriCurveInfoIndex).m_AniCurve, null, Color.green, Color.black, m_CurrentCurveAnimation.GetCurveInfo(m_OriCurveInfoIndex).GetFixedDrawRange());

        // text
//      GUI.Label(NgLayout.GetInnerVerticalRect(rightRect, 12, 5, 8), (m_SelObjectContent == null ? "[Not Selected]" : m_SelObjectContent.text));

        if (m_bSaveDialog)
        {
            bool bSaveEnable    = (0 <= m_nProjectIndex);
            bool bReadOnyFolder = false;

            if (bSaveEnable)
            {
                bReadOnyFolder = IsReadOnlyFolder(m_ProjectFolerContents[m_nProjectIndex].text);
                bSaveEnable    = !bReadOnyFolder;
            }

            // Cancel
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(buttonRect, 2, 0, 1), GetHelpContent("Cancel"), true))
            {
                ClosePopup(false);
                return;
            }
            // save
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(buttonRect, 2, 1, 1), (bReadOnyFolder ? FXMakerTooltip.GetGUIContent("Save", FXMakerTooltip.GetHsToolMessage("READONLY_FOLDER", "")) : GetHelpContent("Save")), bSaveEnable))
            {
                SaveAddCurvePrefab(false);
                ClosePopup(true);
            }
            // overwrite
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(buttonRect2, 2, 0, 2), (bReadOnyFolder ? FXMakerTooltip.GetGUIContent("Overwrite", FXMakerTooltip.GetHsToolMessage("READONLY_FOLDER", "")) : GetHelpContent("Overwrite")), (bSaveEnable && 0 <= m_nObjectIndex)))
            {
                SaveAddCurvePrefab(true);
                ClosePopup(true);
            }
            buttonRect.height *= 2;
            if (m_bDrawRedBottomButtom)
            {
                NgGUIDraw.DrawBox(FXMakerLayout.GetOffsetRect(buttonRect, 3), FXMakerLayout.m_ColorHelpBox, (bSaveEnable ? 2:1), false);
            }
        }
        else
        {
            // Undo
            if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(buttonRect, 2, 0, 1), GetHelpContent("Undo"), (m_SelCurveInfo != null)))
            {
                UndoCurveAni();
            }
            // close
            if (GUI.Button(FXMakerLayout.GetInnerHorizontalRect(buttonRect, 2, 1, 1), GetHelpContent("Close")))
            {
                ClosePopup(true);
            }
        }
    }
    public static void DrawGraph(Phonemes phonemes, ref float time, Callback repaint, CallbackIndex onDrawItem)
    {
        //Get area space
        Rect rect = GUILayoutUtility.GetRect(Screen.width, 300).Shrink(10);

        GUI.Box(rect, "", Styles.whiteFrame);
        rect = rect.Shrink(2);
        Event e = Event.current;

        Styles.Load();


        //Draw top rect
        Rect topRect = new Rect(rect.x, rect.y, rect.width, 18);

        EditorGUI.DrawRect(topRect, graphBgColor);

        //Draw background
        rect = rect.Offset(0, 20, 0, -20);
        EditorGUI.DrawRect(rect, graphBgColor);


        //Handle setTime events
        if ((e.type == EventType.MouseDown || e.type == EventType.MouseDrag) && rect.Contains(e.mousePosition))
        {
            time = Rect.PointToNormalized(rect, e.mousePosition).x;
            repaint.Invoke();
        }


        //Draw cursor
        Rect cursorRect = new Rect(rect.x + rect.width * time, rect.y, 2, rect.height);

        EditorGUI.DrawRect(cursorRect, Color.white);


        //Draw curves and fields
        bool   haveCustomItem = onDrawItem != null;
        float  width          = Screen.width - EditorGUIUtility.labelWidth - (haveCustomItem ? 180 : 50);
        float  maxValue       = 0.0f;
        string maxValueName   = "";
        Color  maxValueColor  = Color.white;

        for (int i = 0; i < phonemes.curves.Length; i++)
        {
            Color curveColor = Color.HSVToRGB((i * 0.13f) % 1.0f, 0.8f, 1.0f);
            EditorGUIUtility.DrawCurveSwatch(rect, phonemes.curves[i].curve, null, curveColor, transparent, new Rect(0, 0, 1, 1));

            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            GUILayout.Label(phonemes.curves[i].name, GUILayout.Width(EditorGUIUtility.labelWidth));

            Rect barRect = GUILayoutUtility.GetRect(width, 16);
            barRect.x    -= 10;
            barRect.width = width;
            GUI.Box(barRect, "", Styles.whiteFrame);
            float value    = phonemes.curves[i].curve.Evaluate(time);
            Rect  fillRect = barRect;
            fillRect.width *= Mathf.Clamp01(value);

            if (value > maxValue)
            {
                maxValue      = value;
                maxValueName  = phonemes.curves[i].name;
                maxValueColor = curveColor;
            }

            fillRect = fillRect.Shrink(1);
            EditorGUI.DrawRect(fillRect, curveColor);

            if (haveCustomItem)
            {
                barRect.Set(barRect.x + barRect.width + 10, barRect.y, 120, barRect.height);
                onDrawItem.Invoke(barRect, i);
            }


            GUILayout.EndHorizontal();
            GUILayout.Space(3);
        }


        //Draw maxValue top label
        if (maxValue > 0.0001f)
        {
            topRect.x = cursorRect.x - 10;
            Color guiColor = GUI.color;
            GUI.color = maxValueColor;
            GUI.Label(topRect, maxValueName, Styles.whiteLabel);
            GUI.color = guiColor;
        }
    }
        static void DoMinMaxCurvesField(Rect position, int id, SerializedProperty propertyMax, SerializedProperty propertyMin, SerializedProperty scalar, Color color, Color backgroundColor)
        {
            var evt = Event.current;

            if (MinMaxCurveEditorWindow.visible && Event.current.type != EventType.Layout && GUIUtility.keyboardControl == id)
            {
                if (s_CurveId != id)
                {
                    s_CurveId = id;
                    if (MinMaxCurveEditorWindow.visible)
                    {
                        MinMaxCurveEditorWindow.SetCurves(propertyMax, propertyMin, scalar, color);
                        MinMaxCurveEditorWindow.ShowPopup(GUIView.current);
                    }
                }
                else
                {
                    if (MinMaxCurveEditorWindow.visible && Event.current.type == EventType.Repaint)
                    {
                        MinMaxCurveEditorWindow.SetCurves(propertyMax, propertyMin, scalar, color);
                        MinMaxCurveEditorWindow.instance.Repaint();
                    }
                }
            }

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (position.Contains(evt.mousePosition))
                {
                    s_CurveId = id;
                    GUIUtility.keyboardControl = id;
                    MinMaxCurveEditorWindow.SetCurves(propertyMax, propertyMin, scalar, color);
                    MinMaxCurveEditorWindow.ShowPopup(GUIView.current);
                    evt.Use();
                    GUIUtility.ExitGUI();
                }
                break;

            case EventType.Repaint:
                if (propertyMin != null)
                {
                    EditorGUIUtility.DrawRegionSwatch(position, propertyMax, propertyMin, color, backgroundColor);
                }
                else
                {
                    EditorGUIUtility.DrawCurveSwatch(position, null, propertyMax, color, backgroundColor);
                }
                EditorStyles.colorPickerBox.Draw(position, GUIContent.none, id, false);
                break;

            case EventType.ExecuteCommand:

                if (s_CurveId == id && evt.commandName == "CurveChanged")
                {
                    GUI.changed = true;
                    AnimationCurvePreviewCache.ClearCache();
                    HandleUtility.Repaint();
                    if (propertyMax != null && MinMaxCurveEditorWindow.instance.maxCurve != null)
                    {
                        propertyMax.animationCurveValue = MinMaxCurveEditorWindow.instance.maxCurve;
                    }
                    if (propertyMin != null)
                    {
                        propertyMin.animationCurveValue = MinMaxCurveEditorWindow.instance.minCurve;
                    }
                }
                break;

            case EventType.KeyDown:
                if (evt.MainActionKeyForControl(id))
                {
                    s_CurveId = id;
                    MinMaxCurveEditorWindow.SetCurves(propertyMax, propertyMin, scalar, color);
                    MinMaxCurveEditorWindow.ShowPopup(GUIView.current);
                    evt.Use();
                    GUIUtility.ExitGUI();
                }
                break;
            }
        }
Esempio n. 15
0
 public static void DrawCurveSwatch(Rect position, AnimationCurve curve, SerializedProperty property, Color color, Color bgColor, Color topFillColor, Color bottomFillColor)
 {
     EditorGUIUtility.DrawCurveSwatch(position, curve, property, color, bgColor, topFillColor, bottomFillColor);
 }
Esempio n. 16
0
 public static void DrawCurveSwatch(Rect position, AnimationCurve curve, SerializedProperty property, Color color, Color bgColor, Rect curveRanges)
 {
     EditorGUIUtility.DrawCurveSwatch(position, curve, property, color, bgColor, curveRanges);
 }
Esempio n. 17
0
    void OnGUI()
    {
        Color oldColor = GUI.color;
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical("", "box", GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false));
        GUILayout.Label("Last Curve");
        Rect R = GUILayoutUtility.GetRect(300,300,100,100,GUILayout.Width(200));
        GUI.enabled = m_Curve != null;
        if (GUI.GetNameOfFocusedControl() == "PresetName" && m_NewCurveName != null && m_Curve != null)
        {
            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return)
            {
                m_LocalPresets.Add(new AnimationCurvePreset(m_NewCurveName, m_Curve));
                SaveSettings();
            }
        }
 
        GUI.SetNextControlName("PresetName");
        m_NewCurveName = GUILayout.TextField(m_NewCurveName);
        if (m_NewCurveName != "" && GUILayout.Button("Save Curve As\n"+m_NewCurveName))
        {
            m_LocalPresets.Add(new AnimationCurvePreset(m_NewCurveName, m_Curve));
            SaveSettings();
            m_NewCurveName = "";
        }
        GUI.enabled = true;
        if (m_Curve != null)
        {
            EditorGUIUtility.DrawCurveSwatch(R, m_Curve, null, Color.green, Color.black);
        }
        else
        {
            GUI.Label(R,"No Curve yet","box");
        }
        GUILayout.EndVertical();
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUI.color = (m_AutoSet)?Color.green:Color.red;
        m_AutoSet = GUILayout.Toggle(m_AutoSet, "Overwrite Preset array", "Button");
        GUI.color = oldColor;
        m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos);
        GUILayout.BeginHorizontal("","box");
 
        foreach (var P in m_LocalPresets)
        {
            GUI.color = (P.active)?Color.green:oldColor;
 
            GUILayout.BeginVertical("", "box", GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false));
            GUILayout.Label(P.name);
            Rect R2 = GUILayoutUtility.GetRect(120, 120, 80, 80, GUILayout.Width(120));
            EditorGUIUtility.DrawCurveSwatch(R2, P.curve, null, Color.green, Color.black);
            GUILayout.BeginHorizontal();
            P.active = GUILayout.Toggle(P.active,"On","Button");
            if (GUILayout.Button("delete"))
            {
                if (EditorUtility.DisplayDialog("Delete Preset?", "Are you sure you want to delete the preset named '"+P.name+"' ?", "ok", "cancel"))
                {
                    m_DeleteList.Add(P);
                }
            }
            GUILayout.EndHorizontal();
 
            GUILayout.EndVertical();
        }
        GUI.color = oldColor;
        if (GUI.changed)
            SaveSettings();
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.EndScrollView();
        if (m_DeleteList.Count > 0 && Event.current.type == EventType.Repaint)
        {
            foreach (var P in m_DeleteList)
            {
                m_LocalPresets.Remove(P);
            }
            m_DeleteList.Clear();
            Repaint();
            SaveSettings();
        }
    }
        protected void RenderClipGUI()
        {
            EditorGUI.BeginChangeCheck();

            var cartSer   = this.cartSer;
            var cartSound = this.cartSound;

            cartSer.Update();

            var clipInfo = cartSound.clips[currentClip];

            if (!clipInfo)
            {
                //oh dear, how did this happen?
                Debug.LogWarning("Found bad data in unserialized object", cartSound);
                clipInfo = new CartSoundClipInfo();        //ScriptableObject.CreateInstance<CartSoundClipInfo>();
                cartSound.clips[currentClip] = clipInfo;
            }

//		Undo.RecordObject(cartSound, "Inspector");

            var clipProperty = "clips.Array.data[" + currentClip + "]";

            EditorGUILayout.PropertyField(cartSer.FindProperty(clipProperty + ".clip"));
            EditorGUILayout.PropertyField(cartSer.FindProperty(clipProperty + ".referenceSpeedPercent"));
            EditorGUILayout.PropertyField(cartSer.FindProperty(clipProperty + ".speedScale"));

            EditorGUILayout.LabelField("Volume vs. Speed");

            var curvesArea = GUILayoutUtility.GetRect(150, Screen.width, 230, 230);

            FillRect(curvesArea, curvesBackground);

            RenderAllCurves(curvesArea);

            //Show reference speed on graph.
            DrawReferenceLine(curvesArea, clipInfo.referenceSpeedPercent, referenceLineColor);


            //FIXYOU: Unity's draw curve swatch et al cache the curve shape too aggressively and won't update when you undo/redo.
            //To workaround it, we always pass a new curve instance to Unity so it can't cache based on reference.

            //FIXYOU: Unity doesn't support editing the curve directly here. WHHYYY? :-(
            var proxyCurve = new AnimationCurve(clipInfo.volumeVsSpeed.keys);

            EditorGUIUtility.DrawCurveSwatch(
                curvesArea,
                proxyCurve, null,        //graphProp,
                activeCurve, transparent,
                workingRange
                );

            //...so we'll make them edit it over here instead, I guess.
            //FIXYOU: This is affected by the undo bug mentioned above.
            //Fortunately, this is really small below a big version that will update correctly.
            EditorGUILayout.PropertyField(cartSer.FindProperty(clipProperty + ".volumeVsSpeed"), new GUIContent("Volume Curve"));

            if (Application.isPlaying)
            {
                //Show current speed when running
                var speed = cartSound.GetComponent <Rigidbody>().velocity.magnitude;
                speed = Mathf.Min(cartSound.maxSpeed, speed);
                DrawReferenceLine(curvesArea, speed / cartSound.maxSpeed, Color.red);
            }

            if (EditorGUI.EndChangeCheck())
            {
                cartSer.ApplyModifiedProperties();
            }

            //Buttons
            {
                GUILayout.BeginHorizontal(GUIStyle.none);

                int[] toReset = null;

                if (GUILayout.Button("Reset Curve"))
                {
                    toReset = new[] { currentClip };
                }

                if (GUILayout.Button("Reset All Curves"))
                {
                    toReset = Enumerable.Range(0, cartSound.clips.Count).ToArray();
                }

                if (toReset != null)
                {
                    ResetClips(toReset);
                }

                GUILayout.EndHorizontal();
            }
        }