コード例 #1
0
    public override void OnValueChange(ValueSystem.ValueType Type)
    {
        if (!isActiveAndEnabled)
        {
            return;
        }

        base.OnValueChange(Type);
        if (Type == value)
        {
            SetValue(GetMinMaxValue(rangeMin, rangeMax, ValueSystem.instance.GetValue(value) * multiplier, curve));
        }
        if (Type == multiplyByValue)
        {
            multiplier = multiplyByCurve.Evaluate(ValueSystem.instance.GetValue(Type));
            OnValueChange(value);
        }
    }
コード例 #2
0
    public static void SetValue(object component, string property, object value, string subproperty = null)
    {
        object target = GetValue(component, property);

        System.Type targetType = target.GetType();

        if (targetType == typeof(Vector2))
        {
            Vector2 v;
            if (subproperty == null || subproperty.Length == 0)
            {
                v   = (component as Vector2?).GetValueOrDefault();
                v.x = v.y = (float)value;
            }
            else
            {
                v = (Vector2)target;
                if (subproperty == "x")
                {
                    v.x = (float)value;
                }
                if (subproperty == "y")
                {
                    v.y = (float)value;
                }
            }
            value = (object)v;
        }
        if (targetType == typeof(Vector3))
        {
            Vector3 v;
            if (subproperty == null || subproperty.Length == 0)
            {
                v   = (component as Vector3?).GetValueOrDefault();
                v.x = v.y = v.z = (float)value;
            }
            else
            {
                v = (Vector3)target;
                if (subproperty == "x")
                {
                    v.x = (float)value;
                }
                if (subproperty == "y")
                {
                    v.y = (float)value;
                }
                if (subproperty == "z")
                {
                    v.z = (float)value;
                }
            }
            value = (object)v;
        }
        if (targetType == typeof(Vector4))
        {
            Vector4 v;
            if (subproperty == null || subproperty.Length == 0)
            {
                v   = (component as Vector4?).GetValueOrDefault();
                v.x = v.y = v.z = v.w = (float)value;
            }
            else
            {
                v = (Vector4)target;
                if (subproperty == "x")
                {
                    v.x = (float)value;
                }
                if (subproperty == "y")
                {
                    v.y = (float)value;
                }
                if (subproperty == "z")
                {
                    v.z = (float)value;
                }
                if (subproperty == "w")
                {
                    v.w = (float)value;
                }
            }
            value = (object)v;
        }


        if (targetType == typeof(int))
        {
            value = System.Convert.ToInt32(value);
        }

        if (targetType == typeof(Color))
        {
            Color c = (Color)target;
            if (subproperty == null || subproperty.Length == 0)
            {
                c = (Color)value;
            }
            else
            {
                if (subproperty == "r")
                {
                    c.r = (float)value;
                }
                if (subproperty == "g")
                {
                    c.g = (float)value;
                }
                if (subproperty == "b")
                {
                    c.b = (float)value;
                }
                if (subproperty == "a")
                {
                    c.a = (float)value;
                }
            }
            value = (object)c;
        }

        System.Type  componentType = component.GetType();
        PropertyInfo propertyInfo  = componentType.GetProperty(property, bflags);

        if (propertyInfo != null)
        {
            propertyInfo.SetValue(component, value, null);
            return;
        }
        FieldInfo fieldInfo = componentType.GetField(property, bflags);

        if (fieldInfo != null)
        {
            fieldInfo.SetValue(component, value);
        }
    }