Пример #1
0
    // ---------------------------------------- //
    // MAIN ANIMATION LOOPS

    private void DoAnimation(ref ArrayList anims)
    {
        ArrayList finished = new ArrayList();

        foreach (System.Object[] anim in anims)
        {               // Loop through animations
            AniValue        val      = (anim[0] as AniValue);
            AniMator        mat      = (anim[1] as AniMator);
            DefaultCallback callback = (anim[2] as DefaultCallback);
            if (!mat.Running())
            {
                continue;
            }
            //if (callback == null) val.Set(mat.GetValue());
            //else callback(mat.GetValue());
            val.Set(mat.GetValue());
            if (callback != null)
            {
                callback(mat.GetValue());
            }
            if (mat.Finished())
            {
                finished.Add(anim);
            }
        }

        // Remove finished animations
        foreach (System.Object[] fin in finished)
        {
            anims.Remove(fin);
        }
    }
Пример #2
0
        // ---------------------------------------- //
        // CONSTRUCTOR

        public AniProp(AniValue v, AniMator m, AniType t, float d, DefaultCallback c, float s, System.Object a, Hashtable o) {
            value = v;
            mator = m;
            type = t;
            duration = d;
            callback = c;
            startTime = s;
            argument = a;
            options = o;
        }
Пример #3
0
    // Extract animation properties from Hash
    private void CreateAnimations(System.Object obj, Hashtable properties, float duration,
        Hashtable options, AniType type) {

        foreach (DictionaryEntry item in properties) {
            // Extract name and value
            string name = (string)item.Key;
            System.Object value = item.Value;
            // Create value object
            AniValue aniv = new AniValue(obj, name);
            // Get current value
            System.Object current = aniv.Get();

            System.Object start = null;
            System.Object target = null;
            System.Object diff = null;

            // Setup variables
            if (type == AniType.To) {
                start = current;
                target = value;
            } else if (type == AniType.From) {
                start = value;
                target = current;
            } else if (type == AniType.By) {
                start = current;
                diff = value;
            }

            // Cast value to destination type
            System.Object argument = System.Convert.ChangeType(item.Value, aniv.ValueType());
            // Callback
            DefaultCallback callback = (DefaultCallback)options["callback"];

            // Calculate difference for To and From
            if ((type == AniType.To ||
                 type == AniType.From) &&
                DriveNeedsDiff((AnimationDriveType)options["drive"])) {

                try {
                    //diff = target - start;
                    //test = start + 0.1 * diff;

                    System.Type startType = start.GetType();

                    // --- Builtin types
                    if (startType != target.GetType()) {
                        diff = (float)target - (float)start;
                    } else if (startType == typeof(short)) {
                        diff = (short)target - (short)start;
                    } else if (startType == typeof(int)) {
                        diff = (int)target - (int)start;
                    } else if (startType == typeof(long)) {
                        diff = (long)target - (long)start;
                    } else if (startType == typeof(float)) {
                        diff = (float)target - (float)start;
                    } else if (startType == typeof(double)) {
                        diff = (double)target - (double)start;
                    } else if (startType == typeof(decimal)) {
                        diff = (decimal)target - (decimal)start;
                    // --- Unity types
                    } else if (startType == typeof(Vector2)) {
                        diff = (Vector2)target - (Vector2)start;
                    } else if (startType == typeof(Vector3)) {
                        diff = (Vector3)target - (Vector3)start;
                    } else if (startType == typeof(Vector4)) {
                        diff = (Vector4)target - (Vector4)start;
                    } else if (startType == typeof(Color)) {
                        diff = (Color)target - (Color)start;
                    // --- Fallback
                    } else {
                        diff = (float)target - (float)start;
                    }
                } catch {
                    throw new System.Exception("Cannot find diff between " + start.GetType() + " and " + target.GetType() + ": Operation +, - or * not supported.");
                }
            }

            // Start time
            float startTime = 0;
            float delay = (float)options["delay"];
            if (delay > 0) {
                startTime = Time.time + delay;
            }

            // Create animation object
            AniMator mat = new AniMator(start, target, diff, duration, (float)options["delay"], (AnimationEasingType)options["easing"],
                (EasingType)options["direction"], (AnimationDriveType)options["drive"]);

            // Add animation to main list
            AniProp anim = new AniProp(aniv, mat, type, duration, callback, startTime, argument, options);
            // Regular animation
            animations.Add(anim);

            // From: Set to starting value
            if (type == AniType.From) {
                aniv.Set(start);
            }
        }
    }
Пример #4
0
    // Extract animation properties from Hash
    private void CreateAnimations(System.Object obj, Hashtable properties, float duration, Hashtable options, AniType type)
    {
        foreach (DictionaryEntry item in properties)
        {
            name = (string)item.Key;                            // Extract name and value
            System.Object value   = item.Value;
            AniValue      aniv    = new AniValue(obj, name);    // Create value object
            System.Object current = aniv.Get();                 // Get current value

            System.Object start  = null;
            System.Object target = null;
            System.Object diff   = null;

            // Setup variables
            if (type == AniType.To)
            {
                start  = current;
                target = value;
            }
            else if (type == AniType.From)
            {
                start  = value;
                target = current;
            }
            else if (type == AniType.By)
            {
                start = current;
                diff  = value;
            }
            // Calculate difference for To and From
            if ((type == AniType.To || type == AniType.From) && DriveNeedsDiff((AnimationDriveType)options["drive"]))
            {
                try
                {
                    //diff = target - start;
                    //test = start + 0.1 * diff;

                    System.Type startType = start.GetType();

                    // --- Builtin types
                    if (startType != target.GetType())
                    {
                        diff = (float)target - (float)start;
                    }
                    else if (startType == typeof(short))
                    {
                        diff = (short)target - (short)start;
                    }
                    else if (startType == typeof(int))
                    {
                        diff = (int)target - (int)start;
                    }
                    else if (startType == typeof(long))
                    {
                        diff = (long)target - (long)start;
                    }
                    else if (startType == typeof(float))
                    {
                        diff = (float)target - (float)start;
                    }
                    else if (startType == typeof(double))
                    {
                        diff = (double)target - (double)start;
                    }
                    else if (startType == typeof(decimal))
                    {
                        diff = (decimal)target - (decimal)start;
                    }

                    // --- Unity types
                    else if (startType == typeof(Vector2))
                    {
                        diff = (Vector2)target - (Vector2)start;
                    }
                    else if (startType == typeof(Vector3))
                    {
                        diff = (Vector3)target - (Vector3)start;
                    }
                    else if (startType == typeof(Vector4))
                    {
                        diff = (Vector4)target - (Vector4)start;
                    }
                    else if (startType == typeof(Color))
                    {
                        diff = (Color)target - (Color)start;
                    }

                    // --- Fallback
                    else
                    {
                        diff = (float)target - (float)start;
                    }
                }
                catch
                {
                    throw new System.Exception("Cannot find diff between " + start.GetType() + " and " + target.GetType() + ": Operation +, - or * not supported.");
                }
            }

            // Create animation object
            AniMator mat = new AniMator(start, target, diff, duration, (float)options["delay"], (AnimationEasingType)options["easing"], (EasingType)options["direction"], (AnimationDriveType)options["drive"]);
            // Add to animations
            //if ((bool)options["physics"] == false && options["rigidbody"] == null)
            //{
            // Regular animation
            animations.Add(new System.Object[] { aniv, mat, options["callback"] });
            //}

            /*else
             * {
             *      // Rigidbody animation
             *      DefaultCallback callback;
             *      //if (options["rigidbody"] != null && name == "position") {
             *      //	callback = (options["rigidbody"] as Rigidbody).MovePosition;
             *      //} else if (options["rigidbody"] != null && name == "rotation") {
             *      //	callback = (options["rigidbody"] as Rigidbody).MoveRotation;
             *      // Other callback
             *      //} else {
             *      callback = (DefaultCallback)options["callback"];
             *      //}
             *      // Physics animation
             *      fixedAnimations.Add(new System.Object[] { aniv, mat, callback });
             * }*/
            // From: Set to starting value
            if (type == AniType.From)
            {
                aniv.Set(start);
            }
        }
    }
Пример #5
0
    // Extract animation properties from Hash
    private void CreateAnimations(System.Object obj, Hashtable properties, float duration, Hashtable options, AniType type)
    {
        foreach (DictionaryEntry item in properties)
        {

            name = (string)item.Key;				// Extract name and value
            System.Object value = item.Value;
            AniValue aniv = new AniValue(obj, name);// Create value object
            System.Object current = aniv.Get();		// Get current value

            System.Object start = null;
            System.Object target = null;
            System.Object diff = null;

            // Setup variables
            if (type == AniType.To)
            {
                start = current;
                target = value;
            }
            else if (type == AniType.From)
            {
                start = value;
                target = current;
            }
            else if (type == AniType.By)
            {
                start = current;
                diff = value;
            }
            // Calculate difference for To and From
            if ((type == AniType.To || type == AniType.From) && DriveNeedsDiff((AnimationDriveType)options["drive"]))
            {
                try
                {
                    //diff = target - start;
                    //test = start + 0.1 * diff;

                    System.Type startType = start.GetType();

                    // --- Builtin types
                    if (startType != target.GetType()) diff = (float)target - (float)start;
                    else if (startType == typeof(short)) diff = (short)target - (short)start;
                    else if (startType == typeof(int)) diff = (int)target - (int)start;
                    else if (startType == typeof(long)) diff = (long)target - (long)start;
                    else if (startType == typeof(float)) diff = (float)target - (float)start;
                    else if (startType == typeof(double)) diff = (double)target - (double)start;
                    else if (startType == typeof(decimal)) diff = (decimal)target - (decimal)start;

                    // --- Unity types
                    else if (startType == typeof(Vector2)) diff = (Vector2)target - (Vector2)start;
                    else if (startType == typeof(Vector3)) diff = (Vector3)target - (Vector3)start;
                    else if (startType == typeof(Vector4)) diff = (Vector4)target - (Vector4)start;
                    else if (startType == typeof(Color)) diff = (Color)target - (Color)start;

                    // --- Fallback
                    else diff = (float)target - (float)start;
                }
                catch
                {
                    throw new System.Exception("Cannot find diff between " + start.GetType() + " and " + target.GetType() + ": Operation +, - or * not supported.");
                }
            }

            // Create animation object
            AniMator mat = new AniMator(start, target, diff, duration, (float)options["delay"], (AnimationEasingType)options["easing"], (EasingType)options["direction"], (AnimationDriveType)options["drive"]);
            // Add to animations
            //if ((bool)options["physics"] == false && options["rigidbody"] == null)
            //{
                // Regular animation
                animations.Add(new System.Object[] { aniv, mat, options["callback"] });
            //}
            /*else
            {
                // Rigidbody animation
                DefaultCallback callback;
                //if (options["rigidbody"] != null && name == "position") {
                //	callback = (options["rigidbody"] as Rigidbody).MovePosition;
                //} else if (options["rigidbody"] != null && name == "rotation") {
                //	callback = (options["rigidbody"] as Rigidbody).MoveRotation;
                // Other callback
                //} else {
                callback = (DefaultCallback)options["callback"];
                //}
                // Physics animation
                fixedAnimations.Add(new System.Object[] { aniv, mat, callback });
            }*/
            // From: Set to starting value
            if (type == AniType.From)
            {
                aniv.Set(start);
            }
        }
    }