private static void InitVarDefs(SpriterAnimation animation) { if (animation.Meta == null || animation.Meta.Varlines == null || animation.Meta.Varlines.Length == 0) { return; } foreach (SpriterVarline varline in animation.Meta.Varlines) { SpriterVarDef varDefs = animation.Entity.Variables[varline.Def]; Init(varDefs, varline); } foreach (SpriterTimeline timeline in animation.Timelines) { if (timeline.Meta == null || timeline.Meta.Varlines == null || timeline.Meta.Varlines.Length == 0) { continue; } SpriterObjectInfo objInfo = animation.Entity.ObjectInfos.First(o => o.Name == timeline.Name); foreach (SpriterVarline varline in timeline.Meta.Varlines) { SpriterVarDef varDef = objInfo.Variables[varline.Def]; Init(varDef, varline); } } }
private static SpriterVarValue GetVariableValue(SpriterAnimation animation, SpriterVarDef varDef, SpriterVarline varline, float targetTime) { SpriterVarlineKey[] keys = varline.Keys; if (keys == null) { return(varDef.VariableValue); } SpriterVarlineKey keyA = LastKeyForTime(keys, targetTime) ?? keys[keys.Length - 1]; if (keyA == null) { return(varDef.VariableValue); } SpriterVarlineKey keyB = GetNextXLineKey(varline.Keys, keyA, animation.Looping); if (keyB == null) { return(keyA.VariableValue); } float adjustedTime = keyA.Time == keyB.Time ? targetTime : AdjustTime(keyA, keyB, animation.Length, targetTime); float factor = GetFactor(keyA, keyB, animation.Length, targetTime); return(Interpolate(keyA.VariableValue, keyB.VariableValue, factor)); }
private static void Init(SpriterVarDef varDef, SpriterVarline varline) { varDef.VariableValue = GetVarValue(varDef.DefaultValue, varDef.Type); foreach (SpriterVarlineKey key in varline.Keys) { key.VariableValue = GetVarValue(key.Value, varDef.Type); } }
protected virtual SpriterVarValue GetVariableValue(SpriterAnimation animation, SpriterVarDef varDef, SpriterVarline varline, float targetTime) { SpriterVarlineKey[] keys = varline.Keys; if (keys == null) { return(varDef.VariableValue); } SpriterVarlineKey keyA = keys.GetLastKey(targetTime) ?? keys[keys.Length - 1]; if (keyA == null) { return(varDef.VariableValue); } SpriterVarlineKey keyB = varline.Keys.GetNextKey(keyA, animation.Looping); if (keyB == null) { return(keyA.VariableValue); } float adjustedTime = keyA.Time == keyB.Time ? targetTime : SpriterHelper.AdjustTime(targetTime, keyA, keyB, animation.Length); float factor = SpriterHelper.GetFactor(keyA, keyB, animation.Length, adjustedTime); SpriterVarValue varVal = Pool.GetObject <SpriterVarValue>(); varVal.Interpolate(keyA.VariableValue, keyB.VariableValue, factor); return(varVal); }
protected virtual void AddVariableAndTagData(SpriterAnimation animation, float targetTime) { if (animation.Meta == null) { return; } if (Config.VarsEnabled && animation.Meta.Varlines != null && animation.Meta.Varlines.Length > 0) { for (int i = 0; i < animation.Meta.Varlines.Length; ++i) { SpriterVarline varline = animation.Meta.Varlines[i]; SpriterVarDef variable = animation.Entity.Variables[varline.Def]; FrameData.AnimationVars[variable.Name] = GetVariableValue(animation, variable, varline, targetTime); } } SpriterElement[] tags = animation.Entity.Spriter.Tags; SpriterTagline tagline = animation.Meta.Tagline; if (Config.TagsEnabled && tagline != null && tagline.Keys != null && tagline.Keys.Length > 0) { SpriterTaglineKey key = tagline.Keys.GetLastKey(targetTime); if (key != null && key.Tags != null) { for (int i = 0; i < key.Tags.Length; ++i) { SpriterTag tag = key.Tags[i]; FrameData.AnimationTags.Add(tags[tag.TagId].Name); } } } for (int i = 0; i < animation.Timelines.Length; ++i) { SpriterTimeline timeline = animation.Timelines[i]; SpriterMeta meta = timeline.Meta; if (meta == null) { continue; } SpriterObjectInfo objInfo = GetObjectInfo(animation, timeline.Name); if (Config.VarsEnabled && meta.Varlines != null && meta.Varlines.Length > 0) { for (int j = 0; j < timeline.Meta.Varlines.Length; ++j) { SpriterVarline varline = timeline.Meta.Varlines[j]; SpriterVarDef variable = objInfo.Variables[varline.Def]; FrameData.AddObjectVar(objInfo.Name, variable.Name, GetVariableValue(animation, variable, varline, targetTime)); } } if (Config.TagsEnabled && meta.Tagline != null && meta.Tagline.Keys != null && meta.Tagline.Keys.Length > 0) { SpriterTaglineKey key = tagline.Keys.GetLastKey(targetTime); if (key != null && key.Tags != null) { for (int j = 0; j < key.Tags.Length; ++j) { SpriterTag tag = key.Tags[j]; FrameData.AddObjectTag(objInfo.Name, tags[tag.TagId].Name); } } } } }
private static void Init(SpriterVarDef varDef, SpriterVarline varline) { varDef.VariableValue = GetVarValue(varDef.DefaultValue, varDef.Type); foreach (SpriterVarlineKey key in varline.Keys) key.VariableValue = GetVarValue(key.Value, varDef.Type); }
private static void AddVariableAndTagData(SpriterAnimation animation, float targetTime, FrameMetadata metadata) { if (animation.Meta == null) { return; } if (animation.Meta.Varlines != null && animation.Meta.Varlines.Length > 0) { foreach (SpriterVarline varline in animation.Meta.Varlines) { SpriterVarDef variable = animation.Entity.Variables[varline.Def]; metadata.AnimationVars[variable.Name] = GetVariableValue(animation, variable, varline, targetTime); } } SpriterElement[] tags = animation.Entity.Spriter.Tags; SpriterTagline tagline = animation.Meta.Tagline; if (tagline != null && tagline.Keys != null && tagline.Keys.Length > 0) { SpriterTaglineKey key = LastKeyForTime <SpriterTaglineKey>(tagline.Keys, targetTime); if (key != null && key.Tags != null) { foreach (SpriterTag tag in key.Tags) { metadata.AnimationTags.Add(tags[tag.TagId].Name); } } } foreach (SpriterTimeline timeline in animation.Timelines) { SpriterMeta meta = timeline.Meta; if (meta == null) { continue; } SpriterObjectInfo objInfo = GetObjectInfo(animation, timeline.Name); if (meta.Varlines != null && meta.Varlines.Length > 0) { foreach (SpriterVarline varline in timeline.Meta.Varlines) { SpriterVarDef variable = objInfo.Variables[varline.Def]; metadata.AddObjectVar(objInfo.Name, variable.Name, GetVariableValue(animation, variable, varline, targetTime)); } } if (meta.Tagline != null && meta.Tagline.Keys != null && meta.Tagline.Keys.Length > 0) { SpriterTaglineKey key = LastKeyForTime <SpriterTaglineKey>(tagline.Keys, targetTime); if (key != null && key.Tags != null) { foreach (SpriterTag tag in key.Tags) { metadata.AddObjectTag(objInfo.Name, tags[tag.TagId].Name); } } } } }