Beispiel #1
0
        /// <summary>
        /// Apply target values to a starting point before tweening.
        /// </summary>
        /// <param name="values">The values to apply, in an anonymous type ( new { prop1 = 100, prop2 = 0} ).</param>
        /// <returns>A reference to this.</returns>
        public Tween From(object values)
        {
            foreach (var property in values.GetType().GetTypeInfo().DeclaredProperties)
            {
                var property1 = property;
                var index     = _vars.FindIndex(i => String.Compare(i.Name, property1.Name, StringComparison.OrdinalIgnoreCase) == 0);
                if (index >= 0)
                {
                    //	if we're already tweening this value, adjust the range
                    var info = _vars[index];

                    var to = new UnglideInfo(values, property.Name, false);
                    info.Value = to.Value;

                    _start[index] = Convert.ToSingle(info.Value);
                    _range[index] = _end[index] - _start[index];
                }
                else
                {
                    //	if we aren't tweening this value, just set it
                    var info = new UnglideInfo(Target, property.Name);
                    var to   = new UnglideInfo(values, property.Name, false);
                    info.Value = to.Value;
                }
            }

            return(this);
        }
        /// <summary>
        /// Activates the specified property name.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="valueSets">The value sets.</param>
        public void Activate(string propertyName, object valueSets)
        {
            // Get the Type object corresponding to MyClass.
            //Type myType = typeof(Control);
            // Get the PropertyInfo object by passing the property name.
            //PropertyInfo myPropInfo = myType.GetProperty(propertyName);

            Type myType = target.GetType();

            PropertyInfo myPropInfo = myType.GetProperty(target.GetType().GetProperty(propertyName).ToString());

            //	This tween will move the X and Y properties of the target
            UnglideInfo unglideInfo = new UnglideInfo(Target, myPropInfo.Name);

            //target.GetType().GetProperty(propertyName).SetValue(target, 10);

            var TweenAnimator = new Tweener();

            TweenAnimator.AddTween(new Tween());
            TweenAnimator.Tween(target, unglideInfo.Value, duration, delay);
            //TweenAnimator.Tween(Target, unglideInfo.Value = valueSets, duration, delay);


            //TweenAnimator.Tween(target.BackgroundImage, new { X = x, Y = y }, duration, delay);
            TweenAnimator.Update(30);
            TweenAnimator.Timer(duration, delay);
        }
Beispiel #3
0
            /// <summary>
            /// Tweens a set of numeric properties on an object.
            /// To tween instance properties/fields, pass the object.
            /// To tween static properties/fields, pass the type of the object, using typeof(ObjectType) or object.GetType().
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <param name="target">The object or type to tween.</param>
            /// <param name="values">The values to tween to, in an anonymous type ( new { prop1 = 100, prop2 = 0} ).</param>
            /// <param name="duration">Duration of the tween in seconds.</param>
            /// <param name="delay">Delay before the tween starts, in seconds.</param>
            /// <returns>The tween created, for setting properties on.</returns>
            /// <exception cref="Exception">Target of tween cannot be a struct!</exception>
            public Tween Tween <T>(T target, object values, float duration, float delay = 0) where T : class
            {
                var targetInfo = target.GetType().GetTypeInfo();

                if (targetInfo.IsValueType)
                {
                    throw new Exception("Target of tween cannot be a struct!");
                }

                var tween = new Tween();

                tween.Target   = target;
                tween.Duration = duration;
                tween.Delay    = delay;

                AddTween(tween);

                if (values == null) // in case of timer
                {
                    return(tween);
                }

                foreach (PropertyInfo property in values.GetType().GetTypeInfo().DeclaredProperties)
                {
                    var info = new UnglideInfo(target, property.Name);
                    var to   = Convert.ToSingle(new UnglideInfo(values, property.Name, false).Value);

                    float s = Convert.ToSingle(info.Value);
                    float r = to - s;

                    tween._vars.Add(info);
                    tween._start.Add(s);
                    tween._range.Add(r);
                    tween._end.Add(to);
                }

                return(tween);
            }