Example #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);
        }
    }
Example #2
0
    private bool Apply(float position, AniProp anim, bool forceUpdate) {
        spf = (float)anim.options["fps"];

        // Ignore restrictions if forced
        if (!forceUpdate) {
            // Honor seconds per frame
            if (spf > 0) {
                anim.timeSinceLastFrame += Time.deltaTime;
                // Not yet time, skip
                if (anim.timeSinceLastFrame < spf) {
                    return true;
                } else {
                    // Update this frame
                    anim.timeSinceLastFrame = anim.timeSinceLastFrame % spf;
                }
            }
        }

        // Animate or call calback with value
        try {
            if (anim.callback == null) {
                anim.value.Set(anim.mator.GetValue(position));
            } else {
                anim.callback(anim.mator.GetValue(position));
            }
        } catch {
        }

        // Check if finished
        if (anim.mator.Finished()) {
            return false;
        }

        return true;
    }
Example #3
0
    // Remove animations
    private void Stop(System.Object obj, string name, AniProp exclude) {
        list = GetAnimations(obj, name);
        foreach (AniProp anim in list) {
            if (exclude == anim) {
                continue;
            }

            animations.Remove(anim);
            fixedAnimations.Remove(anim);
        }
    }
Example #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);
            }
        }
    }