public override bool Update(float time) { if (!paused && startTime + delay < time) { int len = propertyNames.Count; float timePassed; bool finished = false; if (reversed) { timePassed = duration - (time - startTime - delay); if (timePassed <= 0) { timePassed = 0; finished = true; } } else { timePassed = time - startTime - delay; if (timePassed > duration) { timePassed = duration; finished = true; } } for (int i = 0; i < len; i++) { float startVal = propertyStartValues[i]; float targetVal = propertyTargetValues[i]; TSPlugin plugin = propertyPlugins[i]; if (plugin == null) { PropertyInfo pi = propertyInfos[i]; pi.SetValue(target, ease(timePassed, startVal, targetVal - startVal, duration, easeParams), null); } else { plugin.Value = ease(timePassed, startVal, targetVal - startVal, duration, easeParams); } if (onUpdate != null && !suppressEvents) { onUpdate(); } if (onUpdateArg != null && !suppressEvents) { onUpdateArg(onUpdateParams); } } return(finished); } return(false); }
public bool Update(float time) { if (startTime + delay < time) { int len = propertyNames.Count; float timePassed = time - startTime - delay; bool finished = false; if (timePassed > duration) { timePassed = duration; finished = true; } for (int i = 0; i < len; i++) { float startVal = propertyStartValues[i]; float targetVal = propertyTargetValues[i]; TSPlugin plugin = propertyPlugins[i]; if (plugin == null) { PropertyInfo pi = propertyInfos[i]; pi.SetValue(target, ease(timePassed, startVal, targetVal - startVal, duration), null); } else { plugin.Value = ease(timePassed, startVal, targetVal - startVal, duration); } if (onUpdate != null) { onUpdate(); } if (onUpdateArg != null) { onUpdateArg(onUpdateParams); } } return(finished); } return(false); }
private void ParseKeyValue(string key, object value) { propertyNames.Add(key); propertyInfos.Add(null); TSPlugin plugin = TSPluginManager.GetPlugin(key); if (plugin != null) { plugin.Target = target; } propertyPlugins.Add(plugin); TSTweenParams parameters = value as TSTweenParams; if (plugin != null) { propertyStartValues.Add(plugin.Value); plugin.parameters = parameters; } else { propertyStartValues.Add(0f); } if (value is float) { propertyTargetValues.Add((float)value); } else if (parameters != null) { propertyTargetValues.Add(parameters.Value); } else { propertyTargetValues.Add(0f); throw new Exception("Tweensharp: Value is not of type float."); } }
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); }