internal static StyleValues Interpolate(StyleValues start, StyleValues end, float ratio) { StyleValues result = default(StyleValues); foreach (StyleValue current in end.m_StyleValues.m_Values) { StyleValue styleValue = default(StyleValue); bool flag = !start.m_StyleValues.TryGetStyleValue(current.id, ref styleValue); if (flag) { throw new ArgumentException("Start StyleValues must contain the same values as end values. Missing property:" + current.id.ToString()); } StylePropertyId id = current.id; StylePropertyId stylePropertyId = id; if (stylePropertyId <= StylePropertyId.Width) { switch (stylePropertyId) { case StylePropertyId.Custom: case StylePropertyId.Unknown: case StylePropertyId.UnityFont: case StylePropertyId.UnityFontStyleAndWeight: case StylePropertyId.UnityTextAlign: case StylePropertyId.Visibility: case StylePropertyId.WhiteSpace: goto IL_203; case StylePropertyId.Color: goto IL_1DF; case StylePropertyId.FontSize: break; default: switch (stylePropertyId) { case StylePropertyId.AlignContent: case StylePropertyId.AlignItems: case StylePropertyId.AlignSelf: case StylePropertyId.BackgroundImage: case StylePropertyId.BorderBottomColor: case StylePropertyId.BorderLeftColor: case StylePropertyId.BorderRightColor: case StylePropertyId.BorderTopColor: case StylePropertyId.Cursor: case StylePropertyId.Display: case StylePropertyId.FlexDirection: case StylePropertyId.FlexWrap: case StylePropertyId.JustifyContent: case StylePropertyId.Overflow: case StylePropertyId.Position: case StylePropertyId.TextOverflow: case StylePropertyId.UnityBackgroundScaleMode: case StylePropertyId.UnityOverflowClipBox: case StylePropertyId.UnitySliceBottom: case StylePropertyId.UnitySliceLeft: case StylePropertyId.UnitySliceRight: case StylePropertyId.UnitySliceTop: case StylePropertyId.UnityTextOverflowPosition: goto IL_203; case StylePropertyId.BackgroundColor: case StylePropertyId.UnityBackgroundImageTintColor: goto IL_1DF; case StylePropertyId.BorderBottomLeftRadius: case StylePropertyId.BorderBottomRightRadius: case StylePropertyId.BorderBottomWidth: case StylePropertyId.BorderLeftWidth: case StylePropertyId.BorderRightWidth: case StylePropertyId.BorderTopLeftRadius: case StylePropertyId.BorderTopRightRadius: case StylePropertyId.BorderTopWidth: case StylePropertyId.Bottom: case StylePropertyId.FlexBasis: case StylePropertyId.FlexGrow: case StylePropertyId.FlexShrink: case StylePropertyId.Height: case StylePropertyId.Left: case StylePropertyId.MarginBottom: case StylePropertyId.MarginLeft: case StylePropertyId.MarginRight: case StylePropertyId.MarginTop: case StylePropertyId.MaxHeight: case StylePropertyId.MaxWidth: case StylePropertyId.MinHeight: case StylePropertyId.MinWidth: case StylePropertyId.Opacity: case StylePropertyId.PaddingBottom: case StylePropertyId.PaddingLeft: case StylePropertyId.PaddingRight: case StylePropertyId.PaddingTop: case StylePropertyId.Right: case StylePropertyId.Top: case StylePropertyId.Width: break; default: goto IL_203; } break; } result.SetValue(current.id, Lerp.Interpolate(styleValue.number, current.number, ratio)); } else { if (stylePropertyId == StylePropertyId.BorderColor) { goto IL_1DF; } if (stylePropertyId - StylePropertyId.BorderRadius > 4) { goto IL_203; } goto IL_203; } continue; IL_1DF: result.SetValue(current.id, Lerp.Interpolate(styleValue.color, current.color, ratio)); continue; IL_203: throw new ArgumentException("Style Value can't be animated"); } return(result); }
internal static StyleValues Interpolate(StyleValues start, StyleValues end, float ratio) { StyleValues result = new StyleValues(); //we assume both start/end have same values foreach (var endValue in end.m_StyleValues.m_Values) { StyleValue startValue = new StyleValue(); if (!start.m_StyleValues.TryGetStyleValue(endValue.id, ref startValue)) { throw new ArgumentException("Start StyleValues must contain the same values as end values. Missing property:" + endValue.id); } switch (endValue.id) { case StylePropertyId.MarginLeft: case StylePropertyId.MarginTop: case StylePropertyId.MarginRight: case StylePropertyId.MarginBottom: case StylePropertyId.PaddingLeft: case StylePropertyId.PaddingTop: case StylePropertyId.PaddingRight: case StylePropertyId.PaddingBottom: case StylePropertyId.Left: case StylePropertyId.Top: case StylePropertyId.Right: case StylePropertyId.Bottom: case StylePropertyId.Width: case StylePropertyId.Height: case StylePropertyId.MinWidth: case StylePropertyId.MinHeight: case StylePropertyId.MaxWidth: case StylePropertyId.MaxHeight: case StylePropertyId.FlexBasis: case StylePropertyId.FlexGrow: case StylePropertyId.FlexShrink: case StylePropertyId.BorderLeftWidth: case StylePropertyId.BorderTopWidth: case StylePropertyId.BorderRightWidth: case StylePropertyId.BorderBottomWidth: case StylePropertyId.BorderTopLeftRadius: case StylePropertyId.BorderTopRightRadius: case StylePropertyId.BorderBottomRightRadius: case StylePropertyId.BorderBottomLeftRadius: case StylePropertyId.FontSize: case StylePropertyId.Opacity: //We've got floats! { result.SetValue(endValue.id, Lerp.Interpolate(startValue.number, endValue.number, ratio)); } break; case StylePropertyId.Color: case StylePropertyId.BackgroundColor: case StylePropertyId.BorderColor: case StylePropertyId.UnityBackgroundImageTintColor: //We've got colors! { result.SetValue(endValue.id, Lerp.Interpolate(startValue.color, endValue.color, ratio)); } break; case StylePropertyId.Position: case StylePropertyId.FlexDirection: case StylePropertyId.FlexWrap: case StylePropertyId.JustifyContent: case StylePropertyId.AlignContent: case StylePropertyId.AlignSelf: case StylePropertyId.AlignItems: case StylePropertyId.UnityTextAlign: case StylePropertyId.WhiteSpace: case StylePropertyId.UnityFont: case StylePropertyId.UnityFontStyleAndWeight: case StylePropertyId.UnityBackgroundScaleMode: case StylePropertyId.Visibility: case StylePropertyId.Overflow: case StylePropertyId.Display: case StylePropertyId.BackgroundImage: case StylePropertyId.Custom: case StylePropertyId.Unknown: case StylePropertyId.UnitySliceLeft: case StylePropertyId.UnitySliceTop: case StylePropertyId.UnitySliceRight: case StylePropertyId.UnitySliceBottom: case StylePropertyId.BorderRadius: case StylePropertyId.BorderWidth: case StylePropertyId.Margin: case StylePropertyId.Padding: case StylePropertyId.Flex: case StylePropertyId.Cursor: case StylePropertyId.TextOverflow: case StylePropertyId.UnityTextOverflowPosition: default: throw new ArgumentException("Style Value can't be animated"); } } return(result); }