Example #1
0
        private void InitializeAnimation(XmlLayoutAnimation animation, bool isSoloAnimation = true)
        {
            if (animation.hasValueFrom)
            {
                // set the initial value
                MethodInfo method = GetType().GetMethod("SetInitialValueForCustomAnimation", BindingFlags.Instance | BindingFlags.NonPublic)
                                    .MakeGenericMethod(new Type[] { animation.valueType });
                method.Invoke(this, new object[] { animation });
            }

            // Cache the MethodInfo if it hasn't been cached already
            // (caching it saves a small amount of time in the Update() method)
            if (!m_SetValueForCustomAnimationAtIndex_MethodInfoCache.ContainsKey(animation.valueType))
            {
                m_SetValueForCustomAnimationAtIndex_MethodInfoCache.Add(
                    animation.valueType,
                    GetType().GetMethod("SetValueForCustomAnimationAtIndex", BindingFlags.Instance | BindingFlags.NonPublic)
                    .MakeGenericMethod(new Type[] { animation.valueType }));
            }

            if (isSoloAnimation)
            {
                m_currentAnimation = animation;
            }
        }
Example #2
0
        private void SetInitialValueForCustomAnimation <T>(XmlLayoutAnimation animation)
            where T : struct
        {
            var tempAnim = animation as XmlLayoutAnimation <T>;

            tempAnim.setter(tempAnim.from);
        }
Example #3
0
        private void SetValueForCustomAnimationAtIndex <T>(XmlLayoutAnimation animation)
            where T : struct
        {
            var tempAnim = animation as XmlLayoutAnimation <T>;
            var value    = GetCurveValueAtIndex(animation.curve, tempAnim.from, tempAnim.to, animation.index);

            tempAnim.setter(value);
        }
Example #4
0
        private void Update_XmlLayoutAnimation(XmlLayoutAnimation animation)
        {
            animation.index = Mathf.Min(1, animation.index + GetIndexIncrement(animation.rate));

            m_SetValueForCustomAnimationAtIndex_MethodInfoCache[animation.valueType].Invoke(this, new object[] { animation });

            if (animation.index == 1f)
            {
                if (animation.onCompleteCallback != null)
                {
                    animation.onCompleteCallback();
                }

                NextAnimation();
            }
        }
Example #5
0
        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
            });
        }