Ejemplo n.º 1
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        RangeIntAttribute attribute = this.attribute as RangeIntAttribute;

        property.intValue = Mathf.Clamp(property.intValue, attribute.min, attribute.max);
        EditorGUI.HelpBox(new Rect(position.x, position.y, position.width, 30), string.Format("范围{0}-{1}", attribute.min, attribute.max), MessageType.Info);
        EditorGUI.PropertyField(new Rect(position.x, position.y + 35, position.width, 20), property, label);
    }
Ejemplo n.º 2
0
    private void DrawCustomAttributes(VideoGlitchBase imageEffect)
    {
        PropertyInfo[] properties = imageEffect.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly);
        if (properties.Length > 0)
        {
            for (int i = 0; i < properties.Length; ++i)
            {
                object[] rangeAtts = properties[i].GetCustomAttributes(typeof(EnumAttribute), false);
                if (rangeAtts.Length > 0)
                {
                    EnumAttribute attb = rangeAtts[0] as EnumAttribute;
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label(@" " + properties[i].GetGetMethod().Name.Replace(@"get_", string.Empty), GUILayout.Width(125));

                        int value = (int)properties[i].GetValue(imageEffect, null);
                        for (int j = 0; j < attb.enumNames.Count; ++j)
                        {
                            if (GUILayout.Button(attb.enumNames[j]) == true)
                            {
                                value = j;

                                break;
                            }
                        }

                        properties[i].SetValue(imageEffect, value, null);
                    }
                    GUILayout.EndHorizontal();
                }

                rangeAtts = properties[i].GetCustomAttributes(typeof(RangeIntAttribute), false);
                if (rangeAtts.Length > 0)
                {
                    RangeIntAttribute attb = rangeAtts[0] as RangeIntAttribute;
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label(@" " + properties[i].GetGetMethod().Name.Replace(@"get_", string.Empty), GUILayout.Width(125));

                        int value = (int)GUILayout.HorizontalSlider((int)properties[i].GetValue(imageEffect, null), attb.min, attb.max, GUILayout.ExpandWidth(true));
                        properties[i].SetValue(imageEffect, value, null);
                    }
                    GUILayout.EndHorizontal();
                }

                rangeAtts = properties[i].GetCustomAttributes(typeof(RangeFloatAttribute), false);
                if (rangeAtts.Length > 0)
                {
                    RangeFloatAttribute attb = rangeAtts[0] as RangeFloatAttribute;
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label(@" " + properties[i].GetGetMethod().Name.Replace(@"get_", string.Empty), GUILayout.Width(125));

                        float value = GUILayout.HorizontalSlider((float)properties[i].GetValue(imageEffect, null), attb.min, attb.max, GUILayout.ExpandWidth(true));
                        properties[i].SetValue(imageEffect, value, null);
                    }
                    GUILayout.EndHorizontal();
                }

                rangeAtts = properties[i].GetCustomAttributes(typeof(RangeVector2Attribute), false);
                if (rangeAtts.Length > 0)
                {
                    RangeVector2Attribute attb = rangeAtts[0] as RangeVector2Attribute;

                    Vector2 value = (Vector2)properties[i].GetValue(imageEffect, null);

                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label(@" " + properties[i].GetGetMethod().Name.Replace(@"get_", string.Empty), GUILayout.Width(125));

                        value.x = GUILayout.HorizontalSlider(value.x, attb.min.x, attb.max.x, GUILayout.ExpandWidth(true));
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label(string.Empty, GUILayout.Width(125));

                        value.y = GUILayout.HorizontalSlider(value.y, attb.min.y, attb.max.y, GUILayout.ExpandWidth(true));
                    }
                    GUILayout.EndHorizontal();

                    properties[i].SetValue(imageEffect, value, null);
                }

                rangeAtts = properties[i].GetCustomAttributes(typeof(RangeVector3Attribute), false);
                if (rangeAtts.Length > 0)
                {
                    RangeVector3Attribute attb = rangeAtts[0] as RangeVector3Attribute;
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label(@" " + properties[i].GetGetMethod().Name.Replace(@"get_", string.Empty), GUILayout.Width(125));

                        Vector3 value = (Vector3)properties[i].GetValue(imageEffect, null);

                        value.x = GUILayout.HorizontalSlider(value.x, attb.min.x, attb.max.x, GUILayout.ExpandWidth(true));
                        value.y = GUILayout.HorizontalSlider(value.y, attb.min.y, attb.max.y, GUILayout.ExpandWidth(true));
                        value.z = GUILayout.HorizontalSlider(value.z, attb.min.z, attb.max.z, GUILayout.ExpandWidth(true));

                        properties[i].SetValue(imageEffect, value, null);
                    }
                    GUILayout.EndHorizontal();
                }
            }

            if (GUILayout.Button(@"Reset") == true)
            {
                imageEffect.ResetDefaultValues();
            }
        }
    }