Ejemplo n.º 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 (PropertyInfo property in values.GetType().GetProperties())
            {
                int index = vars.FindIndex(i => String.Compare(i.Name, property.Name, true) == 0);
                if (index >= 0)
                {
                    //	if we're already tweening this value, adjust the range
                    var info = vars[index];

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

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

            return(this);
        }
Ejemplo n.º 2
0
        private void AddLerp(GlideLerper lerper, GlideInfo info, object from, object to) {
            varHash.Add(info.PropertyName, vars.Count);
            vars.Add(info);

            start.Add(from);
            end.Add(to);

            lerpers.Add(lerper);
        }
Ejemplo n.º 3
0
        private void AddLerp(GlideLerper lerper, GlideInfo info, object from, object to)
        {
            varHash.Add(info.PropertyName, vars.Count);
            vars.Add(info);

            start.Add(from);
            end.Add(to);

            lerpers.Add(lerper);
        }
Ejemplo n.º 4
0
            /// <summary>
            /// <para>Tweens a set of properties on an object.</para>
            /// <para>To tween instance properties/fields, pass the object.</para>
            /// <para>To tween static properties/fields, pass the type of the object, using typeof(ObjectType) or object.GetType().</para>
            /// </summary>
            /// <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>
            /// <param name="overwrite">Whether pre-existing tweens should be overwritten if this tween involves the same properties.</param>
            /// <returns>The tween created, for setting properties on.</returns>
            public Tween Tween <T>(T target, object values, float duration, float delay = 0, bool overwrite = true) where T : class
            {
                if (target == null)
                {
                    throw new ArgumentNullException("target");
                }

                //	Prevent tweening on structs if you cheat by casting target as Object
                var targetType = target.GetType();

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

                var tween = new Tween(target, duration, delay, this);

                AddAndRemove();
                toAdd.Add(tween);

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

                var props = values.GetType().GetProperties();

                for (int i = 0; i < props.Length; ++i)
                {
                    List <Tween> library = null;
                    if (overwrite && tweens.TryGetValue(target, out library))
                    {
                        for (int j = 0; j < library.Count; j++)
                        {
                            library[j].Cancel(props[i].Name);
                        }
                    }

                    var property = props[i];
                    var info     = new GlideInfo(target, property.Name);
                    var to       = new GlideInfo(values, property.Name, false);
                    var lerper   = CreateLerper(info.PropertyType);

                    tween.AddLerp(lerper, info, info.Value, to.Value);
                }

                return(tween);
            }
Ejemplo n.º 5
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)
        {
            var props = values.GetType().GetProperties();

            for (int i = 0; i < props.Length; ++i)
            {
                var property  = props[i];
                var propValue = property.GetValue(values, null);

                int index = -1;
                if (varHash.TryGetValue(property.Name, out index))
                {
                    //	if we're already tweening this value, adjust the range
                    start[index] = propValue;
                }

                //	if we aren't tweening this value, just set it
                var info = new GlideInfo(Target, property.Name, true);
                info.Value = propValue;
            }

            return(this);
        }
Ejemplo n.º 6
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>
            /// <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>
            public Tween Tween <T>(T target, object values, float duration, float delay = 0) where T : class
            {
                if (target.GetType().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().GetProperties())
                {
                    var info = new GlideInfo(target, property.Name);
                    var to   = Convert.ToSingle(new GlideInfo(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);
            }
Ejemplo n.º 7
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) {
            var props = values.GetType().GetProperties();
            for (int i = 0; i < props.Length; ++i) {
                var property = props[i];
                var propValue = property.GetValue(values, null);

                int index = -1;
                if (varHash.TryGetValue(property.Name, out index)) {
                    //	if we're already tweening this value, adjust the range
                    start[index] = propValue;
                }

                //	if we aren't tweening this value, just set it
                var info = new GlideInfo(Target, property.Name, true);
                info.Value = propValue;
            }

            return this;
        }
Ejemplo n.º 8
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 (PropertyInfo property in values.GetType().GetProperties()) {
                int index = vars.FindIndex(i => String.Compare(i.Name, property.Name, true) == 0);
                if (index >= 0) {
                    //	if we're already tweening this value, adjust the range
                    var info = vars[index];

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

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

            return this;
        }
Ejemplo n.º 9
0
            /// <summary>
            /// Tweens a set of numeric properties on an object.
            /// </summary>
            /// <param name="target">The object 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>
            public Glide Tween(object target, object values, float duration, float delay = 0)
            {
                var glide = new Glide();

                glide.target = target;
                glide.duration = duration;
                glide.delay = delay;

                glide.parent = this;

                toAdd.Add(glide);

                if (values == null) // in case of timer
                    return glide;

                foreach (PropertyInfo property in values.GetType().GetProperties()) {
                    var info = new GlideInfo(target, property.Name);
                    var to = new GlideInfo(values, property.Name, false).Value;

                    float s = info.Value;
                    float r = to - s;

                    glide.vars.Add(info);
                    glide.start.Add(s);
                    glide.range.Add(r);
                    glide.end.Add(to);
                }

                return glide;
            }