public static bool CheckValueExist <T>(CompositionPropertySet properties, string propName) where T : struct { var status = CompositionGetValueStatus.NotFound; if (typeof(T) == typeof(float)) { status = properties.TryGetScalar(propName, out _); } if (typeof(T) == typeof(Vector2)) { status = properties.TryGetVector2(propName, out _); } if (typeof(T) == typeof(Vector3)) { status = properties.TryGetVector3(propName, out _); } if (typeof(T) == typeof(Vector4)) { status = properties.TryGetVector4(propName, out _); } if (typeof(T) == typeof(Quaternion)) { status = properties.TryGetQuaternion(propName, out _); } return(status == CompositionGetValueStatus.Succeeded); }
public static CompositionGetValueStatus TryGetValue <T>(CompositionPropertySet properties, string propName, out T value) { var status = CompositionGetValueStatus.NotFound; value = default; if (typeof(T) == typeof(float)) { status = properties.TryGetScalar(propName, out var v); value = (T)(object)v; } if (typeof(T) == typeof(Vector2)) { status = properties.TryGetVector2(propName, out var v); value = (T)(object)v; } if (typeof(T) == typeof(Vector3)) { status = properties.TryGetVector3(propName, out var v); value = (T)(object)v; } if (typeof(T) == typeof(Vector4)) { status = properties.TryGetVector4(propName, out var v); value = (T)(object)v; } if (typeof(T) == typeof(Quaternion)) { status = properties.TryGetQuaternion(propName, out var v); value = (T)(object)v; } return(status); }
XElement FromCompositionPropertySet(CompositionPropertySet obj, IEnumerable <CompositionObject.Animator> animators = null) { return(new XElement("PropertySet", GetContents())); IEnumerable <XObject> GetContents() { foreach (var(name, type) in obj.Names) { switch (type) { case MetaData.PropertySetValueType.Color: { obj.TryGetColor(name, out var value); foreach (var item in FromAnimatableColor(name, animators, value)) { yield return(item); } break; } case MetaData.PropertySetValueType.Scalar: { obj.TryGetScalar(name, out var value); foreach (var item in FromAnimatableScalar(name, animators, value)) { yield return(item); } break; } case MetaData.PropertySetValueType.Vector2: { obj.TryGetVector2(name, out var value); foreach (var item in FromAnimatableVector2(name, animators, value)) { yield return(item); } break; } case MetaData.PropertySetValueType.Vector3: { obj.TryGetVector3(name, out var value); foreach (var item in FromAnimatableVector3(name, animators, value)) { yield return(item); } break; } case MetaData.PropertySetValueType.Vector4: { obj.TryGetVector4(name, out var value); foreach (var item in FromAnimatableVector4(name, animators, value)) { yield return(item); } break; } default: throw new InvalidOperationException(); } } } }
private static CompositionGetValueStatus TryGetValue <T>( T source, Dictionary <T, KeyValuePair <CompositionPropertySet, Dictionary <string, ExpressionAnimation> > > dictionary, string propertyName, CompositionPropertyType type, out object value) { value = null; if (source == null || string.IsNullOrWhiteSpace(propertyName)) { throw new ArgumentException(); } CompositionPropertySet propertySet = null; Dictionary <string, ExpressionAnimation> expressionAnimations = null; ExpressionAnimation expressionAnimation = null; string propertySetPropertyName = null; GetExpressionAnimation <T>( source, propertyName, dictionary, out propertySet, out expressionAnimations, out expressionAnimation, out propertySetPropertyName); if (propertySet != null) { propertySet.StopAnimation(propertySetPropertyName); CompositionGetValueStatus status = CompositionGetValueStatus.TypeMismatch; switch (type) { case CompositionPropertyType.Boolean: bool boolValue; status = propertySet.TryGetBoolean(propertySetPropertyName, out boolValue); value = boolValue; break; case CompositionPropertyType.Float: float floatValue; status = propertySet.TryGetScalar(propertySetPropertyName, out floatValue); value = floatValue; break; case CompositionPropertyType.Vector2: Vector2 vector2Value; status = propertySet.TryGetVector2(propertySetPropertyName, out vector2Value); value = vector2Value; break; case CompositionPropertyType.Vector3: Vector3 vector3Value; status = propertySet.TryGetVector3(propertySetPropertyName, out vector3Value); value = vector3Value; break; // Insert new case for any property type that is being added. } if (expressionAnimation != null) { propertySet.StartAnimation(propertySetPropertyName, expressionAnimation); } return(status); } return(CompositionGetValueStatus.NotFound); }
public static T Get <T>(this CompositionPropertySet propSet, string key) { var type = typeof(T); if (type == typeof(float)) { float res; if (propSet.TryGetScalar(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Vector2)) { Vector2 res; if (propSet.TryGetVector2(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Vector3)) { Vector3 res; if (propSet.TryGetVector3(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Vector4)) { Vector4 res; if (propSet.TryGetVector4(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Matrix3x2)) { Matrix3x2 res; if (propSet.TryGetMatrix3x2(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Matrix4x4)) { Matrix4x4 res; if (propSet.TryGetMatrix4x4(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Quaternion)) { Quaternion res; if (propSet.TryGetQuaternion(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } else if (type == typeof(Color)) { Color res; if (propSet.TryGetColor(key, out res) == CompositionGetValueStatus.Succeeded) { return((T)(object)res); } } throw new ArgumentException("Unsupported type"); }