Пример #1
0
            public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
            {
                RangeFloatAttribute rangeAttribute = (RangeFloatAttribute)base.attribute;

                if (property.propertyType == SerializedPropertyType.Float)
                {
                    EditorGUI.Slider(position, property, rangeAttribute.min, rangeAttribute.max, label);
                }
                else if (property.propertyType == SerializedPropertyType.Integer)
                {
                    EditorGUI.IntSlider(position, property, (int)rangeAttribute.min, (int)rangeAttribute.max, label);
                }
                else
                {
                    EditorGUI.LabelField(position, label.text, "Use Range with float or int.");
                }
            }
Пример #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();
            }
        }
    }