Example #1
0
        protected object evaluate(MemberClipCurveData memberData, float time)
        {
            object value = null;

            switch (memberData.PropertyType)
            {
            case PropertyTypeInfo.Color:
                Color c;
                c.r   = memberData.Curve1.Evaluate(time);
                c.g   = memberData.Curve2.Evaluate(time);
                c.b   = memberData.Curve3.Evaluate(time);
                c.a   = memberData.Curve4.Evaluate(time);
                value = c;
                break;

            case PropertyTypeInfo.Double:
            case PropertyTypeInfo.Float:
            case PropertyTypeInfo.Int:
            case PropertyTypeInfo.Long:
                value = memberData.Curve1.Evaluate(time);
                break;

            case PropertyTypeInfo.Quaternion:
                Quaternion q;
                q.x   = memberData.Curve1.Evaluate(time);
                q.y   = memberData.Curve2.Evaluate(time);
                q.z   = memberData.Curve3.Evaluate(time);
                q.w   = memberData.Curve4.Evaluate(time);
                value = q;
                break;

            case PropertyTypeInfo.Vector2:
                Vector2 v2;
                v2.x  = memberData.Curve1.Evaluate(time);
                v2.y  = memberData.Curve2.Evaluate(time);
                value = v2;
                break;

            case PropertyTypeInfo.Vector3:
                Vector3 v3;
                v3.x  = memberData.Curve1.Evaluate(time);
                v3.y  = memberData.Curve2.Evaluate(time);
                v3.z  = memberData.Curve3.Evaluate(time);
                value = v3;
                break;

            case PropertyTypeInfo.Vector4:
                Vector4 v4;
                v4.x  = memberData.Curve1.Evaluate(time);
                v4.y  = memberData.Curve2.Evaluate(time);
                v4.z  = memberData.Curve3.Evaluate(time);
                v4.w  = memberData.Curve4.Evaluate(time);
                value = v4;
                break;
            }
            return(value);
        }
Example #2
0
        public void AddClipCurveData(Component component, string name, bool isProperty, Type type)
        {
            MemberClipCurveData data = new MemberClipCurveData();

            data.Type         = component.GetType().Name;
            data.PropertyName = name;
            data.IsProperty   = isProperty;
            data.PropertyType = UnityPropertyTypeInfo.GetMappedType(type);
            if (initializeClipCurves(data, component))
            {
                curveData.Add(data);
            }
            else
            {
                Debug.LogError("Could not initialize curve clip, invalid initial values.");
            }
        }
Example #3
0
 protected virtual bool initializeClipCurves(MemberClipCurveData data, Component component)
 {
     return(false);
 }
Example #4
0
        protected override bool initializeClipCurves(MemberClipCurveData data, Component component)
        {
            object           value     = GetCurrentValue(component, data.PropertyName, data.IsProperty);
            PropertyTypeInfo typeInfo  = data.PropertyType;
            float            startTime = Firetime;
            float            endTime   = Firetime + Duration;

            if (typeInfo == PropertyTypeInfo.Int || typeInfo == PropertyTypeInfo.Long || typeInfo == PropertyTypeInfo.Float || typeInfo == PropertyTypeInfo.Double)
            {
                float x;
                float.TryParse(value.ToString(), out x);

                if (float.IsInfinity(x) || float.IsNaN(x))
                {
                    return(false);
                }

                data.Curve1 = AnimationCurve.Linear(startTime, x, endTime, x);
            }
            else if (typeInfo == PropertyTypeInfo.Vector2)
            {
                Vector2 vec2 = (Vector2)value;

                if (float.IsInfinity(vec2.x) || float.IsNaN(vec2.x) ||
                    float.IsInfinity(vec2.y) || float.IsNaN(vec2.y))
                {
                    return(false);
                }

                data.Curve1 = AnimationCurve.Linear(startTime, vec2.x, endTime, vec2.x);
                data.Curve2 = AnimationCurve.Linear(startTime, vec2.y, endTime, vec2.y);
            }
            else if (typeInfo == PropertyTypeInfo.Vector3)
            {
                Vector3 vec3 = (Vector3)value;

                if (float.IsInfinity(vec3.x) || float.IsNaN(vec3.x) ||
                    float.IsInfinity(vec3.y) || float.IsNaN(vec3.y) ||
                    float.IsInfinity(vec3.z) || float.IsNaN(vec3.z))
                {
                    return(false);
                }

                data.Curve1 = AnimationCurve.Linear(startTime, vec3.x, endTime, vec3.x);
                data.Curve2 = AnimationCurve.Linear(startTime, vec3.y, endTime, vec3.y);
                data.Curve3 = AnimationCurve.Linear(startTime, vec3.z, endTime, vec3.z);
            }
            else if (typeInfo == PropertyTypeInfo.Vector4)
            {
                Vector4 vec4 = (Vector4)value;

                if (float.IsInfinity(vec4.x) || float.IsNaN(vec4.x) ||
                    float.IsInfinity(vec4.y) || float.IsNaN(vec4.y) ||
                    float.IsInfinity(vec4.z) || float.IsNaN(vec4.z) ||
                    float.IsInfinity(vec4.w) || float.IsNaN(vec4.w))
                {
                    return(false);
                }

                data.Curve1 = AnimationCurve.Linear(startTime, vec4.x, endTime, vec4.x);
                data.Curve2 = AnimationCurve.Linear(startTime, vec4.y, endTime, vec4.y);
                data.Curve3 = AnimationCurve.Linear(startTime, vec4.z, endTime, vec4.z);
                data.Curve4 = AnimationCurve.Linear(startTime, vec4.w, endTime, vec4.w);
            }
            else if (typeInfo == PropertyTypeInfo.Quaternion)
            {
                Quaternion quaternion = (Quaternion)value;

                if (float.IsInfinity(quaternion.x) || float.IsNaN(quaternion.x) ||
                    float.IsInfinity(quaternion.y) || float.IsNaN(quaternion.y) ||
                    float.IsInfinity(quaternion.z) || float.IsNaN(quaternion.z) ||
                    float.IsInfinity(quaternion.w) || float.IsNaN(quaternion.w))
                {
                    return(false);
                }

                data.Curve1 = AnimationCurve.Linear(startTime, quaternion.x, endTime, quaternion.x);
                data.Curve2 = AnimationCurve.Linear(startTime, quaternion.y, endTime, quaternion.y);
                data.Curve3 = AnimationCurve.Linear(startTime, quaternion.z, endTime, quaternion.z);
                data.Curve4 = AnimationCurve.Linear(startTime, quaternion.w, endTime, quaternion.w);
            }
            else if (typeInfo == PropertyTypeInfo.Color)
            {
                Color color = (Color)value;

                if (float.IsInfinity(color.r) || float.IsNaN(color.r) ||
                    float.IsInfinity(color.g) || float.IsNaN(color.g) ||
                    float.IsInfinity(color.b) || float.IsNaN(color.b) ||
                    float.IsInfinity(color.a) || float.IsNaN(color.a))
                {
                    return(false);
                }

                data.Curve1 = AnimationCurve.Linear(startTime, color.r, endTime, color.r);
                data.Curve2 = AnimationCurve.Linear(startTime, color.g, endTime, color.g);
                data.Curve3 = AnimationCurve.Linear(startTime, color.b, endTime, color.b);
                data.Curve4 = AnimationCurve.Linear(startTime, color.a, endTime, color.a);
            }

            return(true);
        }