internal static CompositionAnimation ApplyParameters(CompositionAnimation animation, CompositionAnimationPropertyCollection parameters)
        {
            foreach (var p in parameters.Keys.ToList())
            {
                var type = parameters[p].GetType();

                if (type == typeof(float))
                {
                    animation.SetScalarParameter(p, (float)parameters[p]);
                }
                else if (parameters[p] is CompositionObject)
                {
                    animation.SetReferenceParameter(p, (CompositionObject)parameters[p]);
                }
                else if (parameters[p] is CompositionPropertySetWrapper)
                {
                    parameters[p] = ((CompositionPropertySetWrapper)parameters[p]).PropertySet;
                    animation.SetReferenceParameter(p, (CompositionObject)parameters[p]);
                }
                else if (type == typeof(Vector2))
                {
                    animation.SetVector2Parameter(p, (Vector2)parameters[p]);
                }
                else if (type == typeof(Vector3))
                {
                    animation.SetVector3Parameter(p, (Vector3)parameters[p]);
                }
                else if (type == typeof(Vector4))
                {
                    animation.SetVector4Parameter(p, (Vector4)parameters[p]);
                }
                else if (type == typeof(Matrix3x2))
                {
                    animation.SetMatrix3x2Parameter(p, (Matrix3x2)parameters[p]);
                }
                else if (type == typeof(Matrix4x4))
                {
                    animation.SetMatrix4x4Parameter(p, (Matrix4x4)parameters[p]);
                }
                else if (type == typeof(Quaternion))
                {
                    animation.SetQuaternionParameter(p, (Quaternion)parameters[p]);
                }
                else if (type == typeof(Color))
                {
                    animation.SetColorParameter(p, (Color)parameters[p]);
                }
                else
                {
                    parameters[p] = CompositionPropertySetExtensions.ToPropertySet(parameters[p], animation.Compositor);
                    animation.SetReferenceParameter(p, (CompositionObject)parameters[p]);
                }
            }
            return(animation);
        }
Example #2
0
        internal void SetAllParameters(CompositionAnimation anim)
        {
            // Make sure the list is populated
            EnsureReferenceInfo();

            foreach (var refInfo in _objRefList)
            {
                anim.SetReferenceParameter(refInfo.ParameterName, refInfo.CompObject);
            }

            foreach (var constParam in _constParamMap)
            {
                if (constParam.Value.GetType() == typeof(bool))
                {
                    anim.SetBooleanParameter(constParam.Key, (bool)constParam.Value);
                }
                else if (constParam.Value.GetType() == typeof(float))
                {
                    anim.SetScalarParameter(constParam.Key, (float)constParam.Value);
                }
                else if (constParam.Value.GetType() == typeof(Vector2))
                {
                    anim.SetVector2Parameter(constParam.Key, (Vector2)constParam.Value);
                }
                else if (constParam.Value.GetType() == typeof(Vector3))
                {
                    anim.SetVector3Parameter(constParam.Key, (Vector3)constParam.Value);
                }
                else if (constParam.Value.GetType() == typeof(Vector4))
                {
                    anim.SetVector4Parameter(constParam.Key, (Vector4)constParam.Value);
                }
                else if (constParam.Value.GetType() == typeof(Color))
                {
                    anim.SetColorParameter(constParam.Key, (Color)constParam.Value);
                }
                else if (constParam.Value.GetType() == typeof(Quaternion))
                {
                    anim.SetQuaternionParameter(constParam.Key, (Quaternion)constParam.Value);
                }
                else if (constParam.Value.GetType() == typeof(Matrix3x2))
                {
                    anim.SetMatrix3x2Parameter(constParam.Key, (Matrix3x2)constParam.Value);
                }
                else if (constParam.Value.GetType() == typeof(Matrix4x4))
                {
                    anim.SetMatrix4x4Parameter(constParam.Key, (Matrix4x4)constParam.Value);
                }
                else
                {
                    throw new Exception($"Unexpected constant parameter datatype ({constParam.Value.GetType()})");
                }
            }
        }
 /// <summary>
 /// 将一个参数加入动画。
 /// </summary>
 /// <param name="key"></param>
 /// <param name="parameter"></param>
 /// <returns></returns>
 public AnimationFluentContext SetParameter(string key, CompositionObject parameter)
 {
     CompositionAnimation.SetReferenceParameter(key, parameter);
     return(this);
 }
 public override void AddParameterToAnimation(CompositionAnimation animation)
 {
     animation.SetReferenceParameter(Key, ObjectValue);
 }