コード例 #1
0
        public override void OnGUI(Rect rect, SerializedProperty prop, GUIContent label)
        {
            var keyable = prop.serializedObject.targetObject as IKeyable;

            if (keyable != null)
            {
                var animParam = keyable.animationData != null?keyable.animationData.GetParameterOfName(fieldInfo.Name) : null;

                if (animParam != null)
                {
                    AnimatableParameterEditor.ShowParameter(animParam, keyable, prop);
                }
            }
        }
コード例 #2
0
        public override void OnGUI(Rect rect, SerializedProperty prop, GUIContent label)
        {
            var keyable = prop.serializedObject.targetObject as IKeyable;

            if (keyable == null)
            {
                GUILayout.Label("Parameter is not serialized within a IKeyable object");
                return;
            }
            var animParam = keyable.animationData != null?keyable.animationData.GetParameterOfName(prop.propertyPath) : null;

            if (animParam == null)
            {
                GUILayout.Label(string.Format("No AnimatedParameter '{0}' was created or found in IKeyable object", prop.propertyPath));
                return;
            }

            //move xmin acording to indent level
            rect.xMin += (EditorGUI.indentLevel * 10);
            //zero out intend level so that sub properties (serialized within a nested serialized class) show correctly
            EditorGUI.indentLevel = 0;
            //real width is only available in repaint
            if (Event.current.type == EventType.Repaint)
            {
                width = rect.width;
            }

            GUI.BeginGroup(rect);
            GUILayout.BeginArea(new Rect(0, 0, width, height));
            AnimatableParameterEditor.ShowParameter(animParam, keyable, prop);
            //real height is only available in repaint
            if (Event.current.type == EventType.Repaint)
            {
                height = GUILayoutUtility.GetLastRect().yMax;
            }
            GUILayout.EndArea();
            GUI.EndGroup();

            //if you know a better way to show proper GUILayout stuff in nested serialized classes let me know :)
        }
コード例 #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();
    }
}