private void Update_XmlLayoutAnimationGroup(XmlLayoutAnimationGroup animationGroup) { m_completedAnimations.Clear(); for (ushort i = 0; i < animationGroup.animations.Count; i++) { var animation = animationGroup.animations[i]; animation.index = Mathf.Min(1, animation.index + GetIndexIncrement(animation.rate)); // Get the MethodInfo from the cache m_SetValueForCustomAnimationAtIndex_MethodInfoCache[animation.valueType].Invoke(this, new object[] { animation }); if (animation.index == 1f) { if (animation.onCompleteCallback != null) { animation.onCompleteCallback(); } m_completedAnimations.Add(i); } } if (m_completedAnimations.Count > 0) { m_completedAnimations.Reverse(); for (ushort i = 0; i < m_completedAnimations.Count; i++) { animationGroup.animations.RemoveAt(m_completedAnimations[i]); } // Finished the current block, play the next animation (if there is one) if (animationGroup.animations.Count == 0) { if (animationGroup.onCompleteCallback != null) { animationGroup.onCompleteCallback(); } NextAnimation(); } } }
private List <XmlLayoutAnimationBase> GetCustomAnimation(string animationName, Action onCompleteCallback) { if (!xmlElement.xmlLayoutInstance.animations.ContainsKey(animationName)) { Debug.LogWarningFormat("[XmlLayout] Unrecognised animation name : '{0}'", animationName); return(null); } var animation = xmlElement.xmlLayoutInstance.animations[animationName]; if (animation.type == Xml.XmlLayoutAnimation.eAnimationType.Chained) { List <XmlLayoutAnimationBase> animationList = new List <XmlLayoutAnimationBase>(); // chained animation foreach (var childAnimation in animation.animations) { animationList.AddRange(GetCustomAnimation(childAnimation, null)); } return(animationList); } else if (animation.type == Xml.XmlLayoutAnimation.eAnimationType.Simultaneous) { XmlLayoutAnimationGroup animationGroup = new XmlLayoutAnimationGroup(); foreach (var childAnimation in animation.animations) { animationGroup.animations.AddRange(GetCustomAnimation(childAnimation, null).Cast <XmlLayoutAnimation>()); } return(new List <XmlLayoutAnimationBase>() { animationGroup }); } // Normal animation if (!animation.attribute.Contains(".")) { Debug.LogWarningFormat("[XmlLayout] Unrecognised animation target attribute : '{0}'. Animation targets must use the following pattern: ComponentType.PropertyName, e.g. RectTransform.localScale, Image.color, RectTransform.eulerAngles, etc.", animation.attribute); return(null); } var componentName = animation.attribute.Substring(0, animation.attribute.IndexOf(".")); var propertyName = animation.attribute.Replace(componentName + ".", ""); var component = xmlElement.GetComponent(componentName); if (component == null) { Debug.LogWarningFormat("[XmlLayout] Unable to locate component '{0}'", componentName); return(null); } var propertyInfo = component.GetType().GetProperty(propertyName); if (propertyInfo == null) { Debug.LogWarningFormat("[XmlLayout] Unable to locate property '{0}' on component '{1}'.", propertyName, componentName); return(null); } if (!curves.ContainsKey(animation.curve)) { Debug.LogWarningFormat("[XmlLayout] Invalid curve type '{0}' for animation. Valid values are : {1}", animation.curve, string.Join(", ", curves.Keys.ToArray())); return(null); } // Using reflection to avoid having to write the same code for each value type MethodInfo method = GetType().GetMethod("GetCustomAnimationOfType", BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(new Type[] { animation.valueType }); XmlLayoutAnimation _animation = (XmlLayoutAnimation)method.Invoke(this, new object[] { animation, propertyInfo, component, onCompleteCallback }); return(new List <XmlLayoutAnimationBase>() { _animation }); }