Beispiel #1
0
    // -- Internal functions --
    private void Init(Dictionary <string, object> args)
    {
        InitVariables();

        foreach (KeyValuePair <string, object> kvp in args)
        {
            string key   = kvp.Key;
            object value = kvp.Value;

            if (!TSKeywordParser.Parse(this, kvp))
            {
                ParseKeyValue(key, value);
            }
        }

        PropertyInfo[] pis = target.GetType().GetProperties();
        foreach (PropertyInfo pi in pis)
        {
            int ind = propertyNames.IndexOf(pi.Name);
            if (ind != -1 && propertyPlugins[ind] == null)
            {
                object val = pi.GetValue(target, null);
                if (val is float)
                {
                    propertyStartValues[ind] = (float)val;
                }
                propertyInfos[ind] = pi;
            }
        }

        int len = propertyNames.Count;

        for (int i = 0; i < len; i++)
        {
            if (propertyInfos[i] == null && propertyPlugins[i] == null)
            {
                throw new Exception("Tweensharp(): Property " + propertyNames[i] + " not found on object " + target + ".");
            }
        }

        TSScheduler.Register(this);
    }
Beispiel #2
0
    public TweenSharp(object target, float duration, Dictionary <string, object> args)
    {
        float f = 0;

        this.target   = target;
        this.duration = duration;

        startTime = Time.realtimeSinceStartup;

        propertyNames        = new List <string>();
        propertyStartValues  = new List <float>();
        propertyTargetValues = new List <float>();
        propertyPlugins      = new List <TSPlugin>();
        propertyInfos        = new List <PropertyInfo>();

        foreach (KeyValuePair <string, object> kvp in args)
        {
            string key = kvp.Key;

            if (!TSKeywordParser.Parse(this, kvp))
            {
                propertyNames.Add(key);
                propertyInfos.Add(null);

                TSPlugin plugin = PluginManager.GetPlugin(key);
                if (plugin != null)
                {
                    plugin.Target = target;
                }
                propertyPlugins.Add(plugin);

                if (kvp.Value is float)
                {
                    if (plugin != null)
                    {
                        propertyStartValues.Add(plugin.Value);
                    }
                    else
                    {
                        propertyStartValues.Add(0f);
                    }
                    propertyTargetValues.Add((float)kvp.Value);
                }
                else
                {
                    propertyStartValues.Add(0f);
                    propertyTargetValues.Add(0f);
                    throw new Exception("Tweensharp: Value is not of type float.");
                }
            }
        }

        PropertyInfo[] pis = target.GetType().GetProperties();
        foreach (PropertyInfo pi in pis)
        {
            int ind = propertyNames.IndexOf(pi.Name);
            if (ind != -1 && propertyPlugins[ind] == null)
            {
                object val = pi.GetValue(target, null);
                if (val is float)
                {
                    propertyStartValues[ind] = (float)val;
                }
                propertyInfos[ind] = pi;
            }
        }

        int len = propertyNames.Count;

        for (int i = 0; i < len; i++)
        {
            if (propertyInfos[i] == null && propertyPlugins[i] == null)
            {
                throw new Exception("Tweensharp(): Property " + propertyNames[i] + " not found on object " + target + ".");
            }
        }


        TSScheduler.Register(this);
    }