Ejemplo n.º 1
0
protected void DoClipCurves(Event e, Rect posRect, Rect timeRect, System.Func <float, float> TimeToPos, IKeyable keyable)
{
    //track expanded bg
    GUI.color = new Color(0, 0, 0, 0.08f);
    GUI.Box(posRect, string.Empty, Styles.timeBoxStyle);
    GUI.color = Color.white;

    if (((keyable == null) || !ReferenceEquals(keyable.parent, this)) && !ReferenceEquals(keyable, this))
    {
        GUI.color = new Color(1, 1, 1, 0.3f);
        GUI.Label(posRect, "Select a Clip of this Track to view it's Animated Parameters here", Styles.centerLabel);
        GUI.color = Color.white;
        return;
    }

    var finalPosRect  = posRect;
    var finalTimeRect = timeRect;

    //adjust rects
    if (keyable is ActionClip)
    {
        finalPosRect.xMin  = Mathf.Max(posRect.xMin, TimeToPos(keyable.startTime));
        finalPosRect.xMax  = Mathf.Min(posRect.xMax, TimeToPos(keyable.endTime));
        finalTimeRect.xMin = Mathf.Max(timeRect.xMin, keyable.startTime) - keyable.startTime;
        finalTimeRect.xMax = Mathf.Min(timeRect.xMax, keyable.endTime) - keyable.startTime;
    }

    //add some top/bottom margins
    finalPosRect.yMin += 1;
    finalPosRect.yMax -= 3;
    finalPosRect.width = Mathf.Max(finalPosRect.width, 5);

    //dark bg
    GUI.color = new Color(0.1f, 0.1f, 0.1f, 0.5f);
    GUI.DrawTexture(posRect, Styles.whiteTexture);
    GUI.color = Color.white;


    //out of view range
    if (keyable is ActionClip)
    {
        if (keyable.startTime > timeRect.xMax || keyable.endTime < timeRect.xMin)
        {
            return;
        }
    }


    //keyable bg
    GUI.color = UnityEditor.EditorGUIUtility.isProSkin? new Color(0.25f, 0.25f, 0.25f, 0.9f) : new Color(0.7f, 0.7f, 0.7f, 0.9f);
    GUI.Box(finalPosRect, string.Empty, Styles.clipBoxFooterStyle);
    GUI.color = Color.white;

    //if too small do nothing more
    if (finalPosRect.width <= 5)
    {
        return;
    }

    if (keyable is ActionClip && !(keyable as ActionClip).isValid)
    {
        GUI.Label(finalPosRect, "Clip Is Invalid", Styles.centerLabel);
        return;
    }

    if (keyable.animationData == null || !keyable.animationData.isValid)
    {
        if (keyable is ActionClip)
        {
            GUI.Label(finalPosRect, "Clip has no Animatable Parameters", Styles.centerLabel);
        }
        else
        {
            GUI.Label(finalPosRect, "Track has no Animated Properties. You can add some on the left side", Styles.centerLabel);
        }
        return;
    }

    if (inspectedParameterIndex >= keyable.animationData.animatedParameters.Count)
    {
        inspectedParameterIndex = -1;
    }


    //vertical guides from params to dopesheet
    if (inspectedParameterIndex == -1)
    {
        var yPos = PARAMS_TOP_MARGIN;
        for (var i = 0; i < keyable.animationData.animatedParameters.Count; i++)
        {
            // var animParam = keyable.animationData.animatedParameters[i];
            var paramRect = new Rect(0, posRect.yMin + yPos, finalPosRect.xMin - 2, PARAMS_LINE_HEIGHT);
            yPos           += PARAMS_LINE_HEIGHT + PARAMS_LINE_MARGIN;
            paramRect.yMin += 1f;
            paramRect.yMax -= 1f;
            GUI.color       = new Color(0, 0.5f, 0.5f, 0.1f);
            GUI.DrawTexture(paramRect, Styles.whiteTexture);
            GUI.color = Color.white;
        }
    }


    //begin in group and neutralize rect
    GUI.BeginGroup(finalPosRect);
    finalPosRect = new Rect(0, 0, finalPosRect.width, finalPosRect.height);

    if (inspectedParameterIndex == -1)
    {
        var yPos = PARAMS_TOP_MARGIN;
        for (var i = 0; i < keyable.animationData.animatedParameters.Count; i++)
        {
            var animParam = keyable.animationData.animatedParameters[i];
            var paramRect = new Rect(finalPosRect.xMin, finalPosRect.yMin + yPos, finalPosRect.width, PARAMS_LINE_HEIGHT);
            yPos           += PARAMS_LINE_HEIGHT + PARAMS_LINE_MARGIN;
            paramRect.yMin += 1f;
            paramRect.yMax -= 1f;
            GUI.color       = new Color(1, 1, 1, 0.3f);
            GUI.Box(paramRect, string.Empty);
            GUI.color = Color.white;

            if (animParam.enabled)
            {
                DopeSheetEditor.DrawDopeSheet(animParam, keyable, paramRect, finalTimeRect.x, finalTimeRect.width, true);
            }
            else
            {
                GUI.color = new Color(0, 0, 0, 0.2f);
                GUI.DrawTextureWithTexCoords(paramRect, Styles.stripes, new Rect(0, 0, paramRect.width / 7, paramRect.height / 7));
                GUI.color = Color.white;
            }
        }
    }

    if (inspectedParameterIndex >= 0)
    {
        var animParam = keyable.animationData.animatedParameters[inspectedParameterIndex];
        var dopeRect  = finalPosRect;
        dopeRect.y     += 4f;
        dopeRect.height = 16f;
        GUI.color       = new Color(1, 1, 1, 0.3f);
        GUI.Box(dopeRect, string.Empty);
        GUI.color = Color.white;
        DopeSheetEditor.DrawDopeSheet(animParam, keyable, dopeRect, finalTimeRect.x, finalTimeRect.width, true);
        var curveRect = finalPosRect;
        curveRect.yMin = dopeRect.yMax + 4;
        CurveEditor.DrawCurves(animParam, keyable, curveRect, finalTimeRect);
    }

    //consume event
    if (e.type == EventType.MouseDown && finalPosRect.Contains(e.mousePosition))
    {
        e.Use();
    }

    GUI.EndGroup();

/*
 *                      //darken out of clip range time
 *                      //will use if I make curve editing full-width
 *                      if (Prefs.fullWidthCurveEditing){
 *                              var darkBefore = Rect.MinMaxRect( posRect.xMin, posRect.yMin, Mathf.Max(posRect.xMin, TimeToPos(keyable.startTime)), posRect.yMax );
 *                              var darkAfter = Rect.MinMaxRect( Mathf.Min(posRect.xMax, TimeToPos(keyable.endTime)), posRect.yMin, posRect.xMax, posRect.yMax );
 *                              GUI.color = new Color(0.1f,0.1f,0.1f,0.6f);
 *                              GUI.DrawTexture(darkBefore, Styles.whiteTexture);
 *                              GUI.DrawTexture(darkAfter, Styles.whiteTexture);
 *                              GUI.color = Color.white;
 *                      }
 */
}
Ejemplo n.º 2
0
        ///Inline curve editor box
        static void DoCurveBox(AnimatedParameter animParam, IKeyable keyable, bool isRecording)
        {
            var e             = Event.current;
            var keyableLength = keyable.GetLength();
            var keyableTime   = keyable.RootTimeToLocalTime();

            GUILayout.Label("INVISIBLE TEXT", GUILayout.Height(0));
            var lastRect = GUILayoutUtility.GetLastRect();

            GUILayout.Space(250);

            var timeRect = new Rect(0, 0, keyableLength, 0);
            var posRect  = new Rect();

            if (e.type == EventType.Repaint || !fixedCurveRects.TryGetValue(animParam, out posRect))
            {
                posRect = new Rect(lastRect.x, lastRect.yMax + 5, lastRect.width, 240);
                fixedCurveRects[animParam] = posRect;
            }

            GUI.color = EditorGUIUtility.isProSkin ? new Color(0, 0, 0, 0.5f) : new Color(0, 0, 0, 0.3f);
            GUI.Box(posRect, "", (GUIStyle)"textfield");
            GUI.color = Color.white;

            var dragTimeRect = new Rect(posRect.x, posRect.y + 1, posRect.width, 10);

            GUI.Box(dragTimeRect, "");
            if (dragTimeRect.Contains(e.mousePosition))
            {
                EditorGUIUtility.AddCursorRect(dragTimeRect, MouseCursor.SplitResizeLeftRight);
                if (e.type == EventType.MouseDown && e.button == 0)
                {
                    isDraggingTime = true;
                    e.Use();
                }
            }

            if (isDraggingTime)
            {
                var iLerp = Mathf.InverseLerp(posRect.x, posRect.xMax, e.mousePosition.x);
                keyable.root.currentTime = Mathf.Lerp(keyable.startTime, keyable.endTime, iLerp);
            }

            if (e.rawType == EventType.MouseUp)
            {
                isDraggingTime = false;
            }

            if (e.type == EventType.KeyDown && posRect.Contains(e.mousePosition))
            {
                if (e.keyCode == KeyCode.Comma)
                {
                    GUIUtility.keyboardControl = 0;
                    keyable.root.currentTime   = animParam.GetKeyPrevious(keyableTime) + keyable.startTime;
                    e.Use();
                }

                if (e.keyCode == KeyCode.Period)
                {
                    GUIUtility.keyboardControl = 0;
                    keyable.root.currentTime   = animParam.GetKeyNext(keyableTime) + keyable.startTime;
                    Event.current.Use();
                }
            }

            var dopeRect = new Rect(posRect.x, dragTimeRect.yMax + 1, posRect.width, 16);

            Handles.color = Color.black.WithAlpha(0.2f);
            Handles.DrawLine(new Vector2(dopeRect.xMin, dopeRect.yMin), new Vector2(dopeRect.xMax, dopeRect.yMin));
            Handles.DrawLine(new Vector2(dopeRect.xMin, dopeRect.yMax), new Vector2(dopeRect.xMax, dopeRect.yMax));
            Handles.color = Color.white;

            DopeSheetEditor.DrawDopeSheet(animParam, keyable, dopeRect, 0, keyableLength);

            var curvesRect = new Rect(posRect.x, dopeRect.yMax, posRect.width, posRect.height - dopeRect.height - dragTimeRect.height);

            CurveEditor.DrawCurves(animParam, keyable, curvesRect, timeRect);

            if (isRecording)
            {
                var iLerp = Mathf.InverseLerp(keyable.startTime, keyable.endTime, keyable.root.currentTime);
                var lerp  = Mathf.Lerp(posRect.x, posRect.xMax, iLerp);
                var a     = new Vector3(lerp, posRect.y, 0);
                var b     = new Vector3(lerp, posRect.yMax, 0);
                Handles.color = EditorGUIUtility.isProSkin ? Slate.Styles.recordingColor : Color.red;
                Handles.DrawAAPolyLine(a, b);
                Handles.color = Color.white;
            }
        }
Ejemplo n.º 3
0
//show selected clip animated parameters list info
protected void DoParamsInfoGUI(Event e, Rect trackRect, IKeyable keyable, bool showAddPropertyButton)
{
    //bg graphic
    var expansionRect = Rect.MinMaxRect(5, defaultHeight, trackRect.width - 3, finalHeight - 3);

    GUI.color = UnityEditor.EditorGUIUtility.isProSkin? new Color(0.22f, 0.22f, 0.22f) : new Color(0.7f, 0.7f, 0.7f);
    GUI.DrawTexture(expansionRect, Styles.whiteTexture);
    GUI.color = new Color(0, 0, 0, 0.05f);
    GUI.Box(expansionRect, string.Empty, Styles.shadowBorderStyle);
    GUI.color = Color.white;


    //allow resize height
    if (inspectedParameterIndex >= 0)
    {
        var resizeRect = Rect.MinMaxRect(0, finalHeight - 4, trackRect.width, finalHeight);
        UnityEditor.EditorGUIUtility.AddCursorRect(resizeRect, UnityEditor.MouseCursor.ResizeVertical);
        GUI.color = Color.grey;
        GUI.DrawTexture(resizeRect, Styles.whiteTexture);
        GUI.color = Color.white;
        if (e.type == EventType.MouseDown && e.button == 0 && resizeRect.Contains(e.mousePosition))
        {
            isResizingHeight = true; e.Use();
        }
        if (e.type == EventType.MouseDrag && isResizingHeight)
        {
            customHeight += e.delta.y;
        }
        if (e.rawType == EventType.MouseUp)
        {
            isResizingHeight = false;
        }
    }

    proposedHeight = 0f;

    if (((keyable == null) || !ReferenceEquals(keyable.parent, this)) && !ReferenceEquals(keyable, this))
    {
        GUI.Label(expansionRect, "No Clip Selected", Styles.centerLabel);
        inspectedParameterIndex = -1;
        return;
    }

    if (!showAddPropertyButton)
    {
        if (keyable is ActionClip && !(keyable as ActionClip).isValid)
        {
            GUI.Label(expansionRect, "Clip Is Invalid", Styles.centerLabel);
            return;
        }

        if (keyable.animationData == null || !keyable.animationData.isValid)
        {
            if (keyable is ActionClip)
            {
                GUI.Label(expansionRect, "Clip Has No Animatable Parameters", Styles.centerLabel);
                return;
            }
        }
    }

    proposedHeight = defaultHeight + PARAMS_TOP_MARGIN;
    if (keyable.animationData != null && keyable.animationData.animatedParameters != null)
    {
        if (inspectedParameterIndex >= keyable.animationData.animatedParameters.Count)
        {
            inspectedParameterIndex = -1;
        }

        var paramsCount = keyable.animationData.animatedParameters.Count;
        for (var i = 0; i < paramsCount; i++)
        {
            var animParam = keyable.animationData.animatedParameters[i];
            var paramRect = new Rect(expansionRect.xMin + 4, proposedHeight, expansionRect.width - 8, PARAMS_LINE_HEIGHT);
            proposedHeight += PARAMS_LINE_HEIGHT + PARAMS_LINE_MARGIN;

            GUI.color = inspectedParameterIndex == i? new Color(0.5f, 0.5f, 1f, 0.4f) : new Color(0, 0.5f, 0.5f, 0.5f);
            GUI.Box(paramRect, string.Empty, Styles.headerBoxStyle);
            GUI.color = Color.white;

            var paramName = string.Format(" <size=10><color=#252525>{0}</color></size>", animParam.ToString());
            paramName = inspectedParameterIndex == i?string.Format("<b>{0}</b>", paramName) : paramName;

            GUI.Label(paramRect, paramName, Styles.leftLabel);

            var gearRect = new Rect(paramRect.xMax - 16 - 4, paramRect.y, 16, 16);
            gearRect.center = new Vector2(gearRect.center.x, paramRect.y + (paramRect.height / 2) - 1);
            GUI.enabled     = animParam.enabled;
            if (GUI.Button(gearRect, Styles.gearIcon, GUIStyle.none))
            {
                AnimatableParameterEditor.DoParamGearContextMenu(animParam, keyable);
            }
            if (GUI.Button(paramRect, string.Empty, GUIStyle.none))
            {
                inspectedParameterIndex = inspectedParameterIndex == i? -1 : i;
                CurveEditor.FrameAllCurvesOf(animParam);
            }
            GUI.enabled = true;
        }

        proposedHeight += PARAMS_TOP_MARGIN;

        if (inspectedParameterIndex >= 0)
        {
            var controlRect = Rect.MinMaxRect(expansionRect.x + 6, proposedHeight + 5, expansionRect.xMax - 6, proposedHeight + 50);
            var animParam   = keyable.animationData.animatedParameters[inspectedParameterIndex];
            GUILayout.BeginArea(controlRect);
            AnimatableParameterEditor.ShowMiniParameterKeyControls(animParam, keyable);
            GUILayout.EndArea();
            proposedHeight = controlRect.yMax + 10;
        }
    }

    if (showAddPropertyButton && inspectedParameterIndex == -1)
    {
        var buttonRect = Rect.MinMaxRect(expansionRect.x + 6, proposedHeight + 5, expansionRect.xMax - 6, proposedHeight + 25);
        var go         = keyable.animatedParametersTarget as GameObject;
        GUI.enabled = go != null && root.currentTime <= 0;
        if (GUI.Button(buttonRect, "Add Property"))
        {
            EditorTools.ShowAnimatedPropertySelectionMenu(go, AnimatedParameter.supportedTypes, (prop, comp) => {
                        keyable.animationData.TryAddParameter(prop, keyable, comp.transform, go.transform);
                    });
        }
        GUI.enabled    = true;
        proposedHeight = buttonRect.yMax + 10;
    }

    //consume event
    if (e.type == EventType.MouseDown && expansionRect.Contains(e.mousePosition))
    {
        e.Use();
    }
}