예제 #1
0
        /// <summary>
        /// Add an action to this set
        /// </summary>
        /// <param name="action">The specified action.</param>
        public virtual void Add(StratusAction action)
        {
            //if (TraceStack)
            //{
            //  StackTrace stackTrace = new StackTrace();
            //  var methodName = stackTrace.GetFrame(2).GetMethod().Name;
            //  //var className = stackTrace.GetFrame(2).GetMethod().ReflectedType.Name;
            //  //Trace.Script("Adding " + action.type + " from " + methodName);
            //}

            //if (StratusActions.debug) Trace.Script("'" + action.type + "'");
            this.recentlyAddedActions.Add(action);
        }
예제 #2
0
 //---------------------------------------------------------------------/
 // Methods
 //---------------------------------------------------------------------/
 /// <summary>
 /// Add an action to this set
 /// </summary>
 /// <param name="action">The specified action.</param>
 public virtual void Add(StratusAction action)
 {
     this.recentlyAddedActions.Add(action);
 }
예제 #3
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);
        }