Ejemplo n.º 1
0
    protected override void RenderBody(SerializedPropertyX considerationProperty, RenderData _data, int index)
    {
        ConsiderationRenderData data          = _data as ConsiderationRenderData;
        Consideration           consideration = considerationProperty.GetValue <Consideration>();

        //manually render description and curve to make sure they come first
        DrawerUtil.PushLabelWidth(125);
        DrawerUtil.PushIndentLevel(1);
        consideration.description = EditorGUILayout.TextField(new GUIContent("Description"),
                                                              consideration.description);
        GUIContent content = new GUIContent();

        content.text = Util.SplitAndTitlize(consideration.GetType().Name);
        EditorGUILayout.BeginHorizontal();
        data.isInputDisplayed = EditorGUILayout.Foldout(data.isInputDisplayed, content);
        EditorGUILayout.EndHorizontal();
        if (data.isInputDisplayed)
        {
            EditorGUI.indentLevel++;
            for (int i = 0; i < considerationProperty.ChildCount; i++)
            {
                SerializedPropertyX child = considerationProperty.GetChildAt(i);
                if (skipRenderingFields.IndexOf(child.name) != -1)
                {
                    continue;
                }
                EditorGUILayoutX.PropertyField(child, child.label, child.isExpanded);
            }
            EditorGUI.indentLevel--;
        }
        RenderCurve(considerationProperty.FindProperty("curve"), data);
        DrawerUtil.PopLabelWidth();
        DrawerUtil.PopIndentLevel();
    }
Ejemplo n.º 2
0
    private void RenderCurve(SerializedPropertyX curveProperty, ConsiderationRenderData data)
    {
        ResponseCurve curve         = curveProperty.GetValue <ResponseCurve>();
        bool          updateTexture = false;
        Texture2D     graphTexture  = data.graphTexture;

        if (graphTexture == null)
        {
            data.graphTexture = new Texture2D(1, 1, TextureFormat.RGBA32, true);
        }
        EditorGUILayout.BeginHorizontal();
        data.isCurveShown = EditorGUILayout.Foldout(data.isCurveShown, "Curve(" + curve.curveType.ToString() + ")");
        if (!data.isCurveShown)
        {
            if (graphTexture.width != 64)
            {
                graphTexture.Resize(64, 32);

                Rect rect = new Rect()
                {
                    x      = 0,
                    y      = 0,
                    width  = graphTexture.width,
                    height = graphTexture.height
                };
                GraphHelper.DrawGraphLines(rect, graphTexture, (float input) => {
                    return(curve.Evaluate(input));
                });
                graphTexture.FlipVertically();
                graphTexture.Apply(true);
            }
            GUILayout.FlexibleSpace();
            GUIContent content = new GUIContent();
            content.text  = curve.DisplayString;
            content.image = graphTexture;
            GUIStyle style = new GUIStyle(GUI.skin.box);
            style.alignment = TextAnchor.MiddleLeft;
            GUILayout.Box(content, style);
        }

        EditorGUILayout.EndHorizontal();

        if (!data.isCurveShown)
        {
            return;
        }

        DrawerUtil.PushIndentLevel(1);

        EditorGUILayout.BeginHorizontal();
        {
            EditorGUI.BeginChangeCheck();
            GUILayout.BeginVertical(GUILayout.MaxWidth(400f));
            curve.curveType = (ResponseCurveType)EditorGUILayout.EnumPopup("Curve Type", curve.curveType);
            curve.slope     = EditorGUILayout.FloatField("Slope", curve.slope);
            curve.exp       = EditorGUILayout.FloatField("Exp", curve.exp);
            curve.vShift    = EditorGUILayout.FloatField("Vertical Shift", curve.vShift);
            curve.hShift    = EditorGUILayout.FloatField("Horizontal Shift", curve.hShift);
            curve.threshold = EditorGUILayout.FloatField("Threshold", curve.threshold);
            curve.invert    = EditorGUILayout.Toggle(new GUIContent("Inverted"), curve.invert);
            GUILayout.BeginHorizontal();
            GUILayout.Space(EditorGUIUtility.labelWidth);
            if (GUILayout.Button("Reset"))
            {
                curve.Reset();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            updateTexture = EditorGUI.EndChangeCheck();
        }
        //draw the graph
        {
            if (updateTexture || graphTexture.width != 512)
            {
                curveProperty.Update();
                graphTexture.Resize(512, (int)(8.75f * EditorGUIUtility.singleLineHeight));
                Rect rect = new Rect()
                {
                    x      = 0,
                    y      = 0,
                    width  = graphTexture.width,
                    height = graphTexture.height
                };
                GraphHelper.DrawGraphLines(rect, graphTexture, (float input) => {
                    return(curve.Evaluate(input));
                });
                graphTexture.FlipVertically();
                graphTexture.Apply(true);
            }
            DrawerUtil.DrawLayoutTexture(graphTexture);
        }

        EditorGUILayout.EndHorizontal();
        DrawerUtil.PopIndentLevel();
    }
Ejemplo n.º 3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (graphTexture == null)
            {
                graphTexture = new Texture2D(1, 1, TextureFormat.RGBA32, true);
            }

            curve = SerializedPropertyUtil.GetTargetObjectOfProperty(property) as ResponseCurve ?? new ResponseCurve();
            GUIRect rect = new GUIRect(position);

            isCurveShown = curve.__editorOnlyFoldout__ = EditorGUI.Foldout(rect.GetFieldRect(), curve.__editorOnlyFoldout__, label.text);

            GUIStyle style = new GUIStyle(GUI.skin.box);

            if (!isCurveShown)
            {
                DrawGraph(64, 32);
                GUIContent content = new GUIContent();
                content.text    = curve.DisplayString;
                content.image   = graphTexture;
                style.alignment = TextAnchor.MiddleLeft;
                GUI.Box(rect.GetFieldRect(2), content, style);
                return;
            }

            GUIRect[] splits = rect.SplitHorizontal(0.5f);
            GUIRect   left   = splits[0];
            GUIRect   right  = splits[1];

            DrawGraph(right.GetRect().width, right.GetRect().height);

            GUIContent graphContent = new GUIContent();

            graphContent.image = graphTexture;
            GUI.Box(right.GetRect(), graphContent, style);
            float oldWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 100;

            DrawerUtil.PushIndentLevel(1);
            EditorGUI.BeginChangeCheck();
            {
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("curveType"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("slope"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("exp"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("vShift"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("hShift"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("threshold"));
                GUIRect   lineRect      = new GUIRect(left.GetFieldRect());
                GUIRect[] lineRectParts = lineRect.SplitHorizontal(0.5f);
                EditorGUI.PropertyField(lineRectParts[0].GetRect(), property.FindPropertyRelative("invert"));


                if (GUI.Button(lineRectParts[1].GetRect(), "Reset Curve"))
                {
                    property.FindPropertyRelative("curveType").intValue   = (int)ResponseCurveType.Polynomial;
                    property.FindPropertyRelative("slope").floatValue     = 1f;
                    property.FindPropertyRelative("exp").floatValue       = 1f;
                    property.FindPropertyRelative("vShift").floatValue    = 0f;
                    property.FindPropertyRelative("hShift").floatValue    = 0f;
                    property.FindPropertyRelative("threshold").floatValue = 0f;
                    property.FindPropertyRelative("invert").boolValue     = false;
                }
            }
            DrawerUtil.PopIndentLevel();
            EditorGUIUtility.labelWidth = oldWidth;
            if (EditorGUI.EndChangeCheck())
            {
                property.serializedObject.ApplyModifiedProperties();
            }
        }