Ejemplo n.º 1
0
        /// <summary>
        /// Adds a trace, adding it to the specified set.
        /// </summary>
        /// <param name="set">A reference to the set.</param>
        /// <param name="message">The message which to print.</param>
        public static StratusAction Trace(StratusActionSet set, object message)
        {
            StratusAction trace = new StratusActionLog(message);

            set.Add(trace);
            return(trace);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an ActionDelay and adds it to the specified set.
        /// </summary>
        /// <param name="set">A reference to the ActionSet that this action belongs to.</param>
        /// <param name="duration"> duration How long should the delay run for.</param>
        public static StratusAction Delay(StratusActionSet set, float duration)
        {
            StratusAction delay = new StratusActionDelay(duration);

            set.Add(delay);
            return(delay);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a function to be invoked as part of the action set, alongside any arguments.
        /// Optionally, it also can add a delay before the function is invoked.
        /// </summary>
        /// <param name="set">A reference to the action set.</param>
        /// <param name="func">The function to which to call.</param>
        public static StratusAction Call(StratusActionSet set, StratusActionCall.Delegate func, float delay = 0.0f)
        {
            StratusAction call = new StratusActionCall(func);

            // Optionally, add a delay
            if (delay != 0.0f)
            {
                Delay(set, delay);
            }
            set.Add(call);
            return(call);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a property change to the action set.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="set">A reference to the set.</param>
        /// <param name="varExpr">A lambda expression encapsulating a reference to the property which will be modified</param>
        /// <param name="value">The new value for the property</param>
        /// <param name="duration">Over how long should the property be changed</param>
        /// <param name="ease">What interpolation algorithm to use</param>
        public static void Property <T>(StratusActionSet set, Expression <Func <T> > varExpr, T value, float duration, Ease ease)
        {
            var memberExpr   = varExpr.Body as MemberExpression;
            var inst         = memberExpr.Expression;
            var variableName = memberExpr.Member.Name;
            var targetObj    = Expression.Lambda <Func <object> >(inst).Compile()();

            // Construct an action then branch depending on whether the member to be
            // interpolated is a property or a field
            StratusAction action = null;

            // Property
            var property = targetObj.GetType().GetProperty(variableName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);

            if (property != null)
            {
                var propertyType = property.PropertyType;

                if (propertyType == typeof(float))
                {
                    action = new StratusActionPropertyFloat(targetObj, property, Convert.ToSingle(value), duration, ease);
                }
                else if (propertyType == typeof(int))
                {
                    action = new StratusActionPropertyInt(targetObj, property, Convert.ToInt32(value), duration, ease);
                }
                else if (propertyType == typeof(bool))
                {
                    action = new StratusActionPropertyBool(targetObj, property, Convert.ToBoolean(value), duration, ease);
                }
                else if (propertyType == typeof(Vector2))
                {
                    action = new StratusActionPropertyVector2(targetObj, property, (Vector2)Convert.ChangeType(value, typeof(Vector2)), duration, ease);
                }
                else if (propertyType == typeof(Vector3))
                {
                    action = new StratusActionPropertyVector3(targetObj, property, (Vector3)Convert.ChangeType(value, typeof(Vector3)), duration, ease);
                }
                else if (propertyType == typeof(Vector4))
                {
                    action = new StratusActionPropertyVector4(targetObj, property, (Vector4)Convert.ChangeType(value, typeof(Vector4)), duration, ease);
                }
                else if (propertyType == typeof(Color))
                {
                    action = new StratusActionPropertyColor(targetObj, property, (Color)Convert.ChangeType(value, typeof(Color)), duration, ease);
                }
                else if (propertyType == typeof(Quaternion))
                {
                    action = new StratusActionPropertyQuaternion(targetObj, property, (Quaternion)Convert.ChangeType(value, typeof(Quaternion)), duration, ease);
                }
                else
                {
                    Stratus.StratusDebug.Log("Couldn't find the property!");
                }
            }
            // Field
            else
            {
                var field     = targetObj.GetType().GetField(variableName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                var fieldType = field.FieldType;

                if (fieldType == typeof(float))
                {
                    action = new StratusActionPropertyFloat(targetObj, field, Convert.ToSingle(value), duration, ease);
                }
                else if (fieldType == typeof(int))
                {
                    action = new StratusActionPropertyInt(targetObj, field, Convert.ToInt32(value), duration, ease);
                }
                else if (fieldType == typeof(bool))
                {
                    action = new StratusActionPropertyBool(targetObj, field, Convert.ToBoolean(value), duration, ease);
                }
                else if (fieldType == typeof(Vector2))
                {
                    action = new StratusActionPropertyVector2(targetObj, field, (Vector2)Convert.ChangeType(value, typeof(Vector2)), duration, ease);
                }
                else if (fieldType == typeof(Vector3))
                {
                    action = new StratusActionPropertyVector3(targetObj, field, (Vector3)Convert.ChangeType(value, typeof(Vector3)), duration, ease);
                }
                else if (fieldType == typeof(Vector4))
                {
                    action = new StratusActionPropertyVector4(targetObj, field, (Vector4)Convert.ChangeType(value, typeof(Vector4)), duration, ease);
                }
                else if (fieldType == typeof(Color))
                {
                    action = new StratusActionPropertyColor(targetObj, field, (Color)Convert.ChangeType(value, typeof(Color)), duration, ease);
                }
                else if (fieldType == typeof(Quaternion))
                {
                    action = new StratusActionPropertyQuaternion(targetObj, field, (Quaternion)Convert.ChangeType(value, typeof(Quaternion)), duration, ease);
                }
                else
                {
                    Stratus.StratusDebug.Log("Couldn't find the field!");
                }
            }
            // Now add it!
            set.Add(action);
        }