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(); } } } }
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"); }