Exemple #1
0
    // ---------------------------------------- //
    // MAIN ANIMATION LOOPS

    private void DoAnimation(ref List<AniProp> anims) {
        list = new List<AniProp>(32);

        // Loop through animations
        for (i = 0, len = anims.Count; i < len; i++) {
            if (i >= anims.Count) {
                continue;
            }

            AniProp anim = anims[i];
            DefaultCallback callback = (anim.callback as DefaultCallback);
            if (!anim.mator.Running()) {
                continue;
            }
            anim.value.Set(anim.mator.GetValue());

            if (callback != null) {
                callback(anim.mator.GetValue());
            }
            if (anim.mator.Finished()) {
                list.Add(anim);
            }
        }

        // Remove finished animations
        foreach (AniProp fin in list) {
            anims.Remove(fin);
        }
    }
    // ---------------------------------------- //
    // 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);
        }
    }
Exemple #3
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;
        }
Exemple #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) {
            // 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);
            }
        }
    }