public void Animate(DatePicker_Animation_Property property, float desiredValue, float duration, Action onComplete = null) { if (!Application.isPlaying) { SetPropertyValue(property, desiredValue); if (onComplete != null) { onComplete.Invoke(); } return; } var animation = animations.FirstOrDefault(a => a.property == property); if (animation == null) { animation = new DatePicker_Animation { property = property }; animations.Add(animation); } animation.initialValue = GetPropertyValue(animation.property); animation.desiredValue = desiredValue; animation.percentageComplete = 0; animation.startTime = Time.time; animation.duration = duration; animation.onComplete = onComplete; }
float GetPropertyValue(DatePicker_Animation_Property property) { switch (property) { case DatePicker_Animation_Property.Alpha: return(canvasGroup.alpha); case DatePicker_Animation_Property.ScaleX: return(rectTransform.localScale.x); case DatePicker_Animation_Property.ScaleY: return(rectTransform.localScale.y); } return(0f); }
void SetPropertyValue(DatePicker_Animation_Property property, float newValue) { switch (property) { case DatePicker_Animation_Property.Alpha: canvasGroup.alpha = newValue; break; case DatePicker_Animation_Property.ScaleX: rectTransform.localScale = new Vector3(newValue, rectTransform.localScale.y, rectTransform.localScale.z); break; case DatePicker_Animation_Property.ScaleY: rectTransform.localScale = new Vector3(rectTransform.localScale.x, newValue, rectTransform.localScale.z); break; } }