public void SetValue(string name, float value) { if (indexMapping.ContainsKey(name)) { AnimationVariable variable = variables[indexMapping[name]]; if (variable.wrap) { variable.currentValue = (value - variable.minValue) % (variable.maxValue - variable.minValue) + variable.minValue; } else { variable.currentValue = Mathf.Clamp(value, variable.minValue, variable.maxValue); } } }
private bool IsVariableActive(AnimationVariable variable) { if (string.IsNullOrEmpty(variable.dependsOn)) { return(true); } else { if (indexMapping.ContainsKey(variable.dependsOn)) { AnimationVariable dependsOn = variables[indexMapping[variable.dependsOn]]; return(dependsOn.currentValue >= variable.minDependValue && dependsOn.currentValue <= variable.maxDependValue && IsVariableActive(dependsOn)); } else { return(false); } } }
public void LateUpdate() { float deltaTime = useUnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime; foreach (AnimatedVaraibles variable in animated) { float timeScalar = variable.fixedScalar * deltaTime; if (!string.IsNullOrEmpty(variable.namedScalar)) { timeScalar *= GetValue(variable.namedScalar); } SetValue(variable.targetVariable, GetValue(variable.targetVariable) + timeScalar); } Vector2 offset = baseOffset; for (int i = 0; i < variables.Count; ++i) { AnimationVariable variable = variables[i]; if (IsVariableActive(variable)) { float useValue = (variable.floor ? Mathf.Floor(variable.currentValue) : variable.currentValue); if (variable.mapping != null) { int valueAsInt = Mathf.FloorToInt(useValue); if (valueAsInt >= 0 && valueAsInt < variable.mapping.Length) { useValue += variable.mapping[valueAsInt] - valueAsInt; } } offset += variable.direction * useValue; } } spriteRenderer.sprite = Sprite.Create(image, new Rect(offset, spriteSize), Vector2.one * 0.5f, 32.0f, 0, SpriteMeshType.FullRect); }