float UpdateAnimation(float initialValue, float targetValue, float time, float duration, AnimType animationType) { switch (animationType) { case AnimType.Linear: return(Anim.Linear(initialValue, targetValue, time, duration)); case AnimType.Overshoot: return(Anim.Overshoot(initialValue, targetValue, time, duration)); case AnimType.Bounce: return(Anim.Bounce(initialValue, targetValue, time, duration)); case AnimType.EaseOutCubed: return(Anim.Cube.Out(initialValue, targetValue, time, duration)); case AnimType.EaseOutQuint: return(Anim.Quint.Out(initialValue, targetValue, time, duration)); case AnimType.EaseOutSept: return(Anim.Sept.Out(initialValue, targetValue, time, duration)); case AnimType.EaseInCubed: return(Anim.Cube.In(initialValue, targetValue, time, duration)); case AnimType.EaseInQuint: return(Anim.Quint.In(initialValue, targetValue, time, duration)); case AnimType.EaseInSept: return(Anim.Sept.In(initialValue, targetValue, time, duration)); case AnimType.EaseInOutCubed: return(Anim.Cube.InOut(initialValue, targetValue, time, duration)); case AnimType.EaseInOutQuint: return(Anim.Quint.InOut(initialValue, targetValue, time, duration)); case AnimType.EaseInOutSept: return(Anim.Sept.InOut(initialValue, targetValue, time, duration)); case AnimType.SoftEaseOutCubed: return(Anim.Cube.SoftOut(initialValue, targetValue, time, duration)); case AnimType.SoftEaseOutQuint: return(Anim.Quint.SoftOut(initialValue, targetValue, time, duration)); case AnimType.SoftEaseOutSept: return(Anim.Sept.SoftOut(initialValue, targetValue, time, duration)); } return(0f); }
void Update() { animDeltaTime = Time.realtimeSinceStartup - animStartTime; if (state == 1) { if (animDeltaTime <= animationDuration) { checkRectTransform.localScale = Anim.Overshoot(new Vector3(currentCheckSize, currentCheckSize, 1f), new Vector3(1f, 1f, 1f), animDeltaTime, animationDuration); frameImage.color = Anim.Quint.SoftOut(currentColor, onColor, animDeltaTime, animationDuration); frameCanvasGroup.alpha = Anim.Cube.SoftOut(currentFrameAlpha, 0f, animDeltaTime, animationDuration); if (changeTextColor) { text.color = Anim.Quint.SoftOut(currentTextColor, onColor, animDeltaTime, animationDuration); } if (changeRippleColor) { rippleConfig.rippleColor = frameImage.color; } } else { checkRectTransform.localScale = new Vector3(1f, 1f, 1f); frameImage.color = onColor; frameCanvasGroup.alpha = 0f; if (changeTextColor) { text.color = onColor; } if (changeRippleColor) { rippleConfig.rippleColor = onColor; } frameImage.enabled = false; state = 0; } } else if (state == 2) { if (animDeltaTime <= animationDuration * 0.75f) { checkRectTransform.localScale = Anim.Sept.InOut(new Vector3(currentCheckSize, currentCheckSize, 1f), new Vector3(0f, 0f, 1f), animDeltaTime, animationDuration * 0.75f); frameImage.color = Anim.Sept.InOut(currentColor, offColor, animDeltaTime, animationDuration * 0.75f); frameCanvasGroup.alpha = Anim.Sept.InOut(currentFrameAlpha, 1f, animDeltaTime, animationDuration * 0.75f); if (changeTextColor) { text.color = Anim.Quint.SoftOut(currentTextColor, textNormalColor, animDeltaTime, animationDuration * 0.75f); } if (changeRippleColor) { rippleConfig.rippleColor = frameImage.color; } } else { checkRectTransform.localScale = new Vector3(0f, 0f, 1f); frameImage.color = offColor; frameCanvasGroup.alpha = 1f; if (changeTextColor) { text.color = textNormalColor; } if (changeRippleColor) { rippleConfig.rippleColor = offColor; } checkImage.enabled = false; state = 0; } } if (lastToggleInteractableState != toggle.interactable) { lastToggleInteractableState = toggle.interactable; if (lastToggleInteractableState) { EnableCheckbox(); } else { DisableCheckbox(); } } if (!Application.isPlaying) { if (lastToggleState != toggle.isOn) { lastToggleState = toggle.isOn; if (lastToggleState) { TurnOnSilent(); } else { TurnOffSilent(); } } if (changeRippleColor) { rippleConfig.rippleColor = frameImage.color; } } }
void Update() { animDeltaTime = Time.realtimeSinceStartup - animStartTime; if (state == 1) // Turning on { if (animDeltaTime <= animationDuration) { dotRectTransform.localScale = Anim.Overshoot(new Vector3(currentDotSize, currentDotSize, 1f), new Vector3(1f, 1f, 1f), animDeltaTime, animationDuration); ringImage.color = Anim.Quint.SoftOut(currentColor, onColor, animDeltaTime, animationDuration); if (changeTextColor) { text.color = Anim.Quint.SoftOut(currentTextColor, onColor, animDeltaTime, animationDuration); } if (changeRippleColor) { rippleConfig.rippleColor = ringImage.color; } } else { dotRectTransform.localScale = new Vector3(1f, 1f, 1f); ringImage.color = onColor; if (changeTextColor) { text.color = onColor; } if (changeRippleColor) { rippleConfig.rippleColor = onColor; } state = 0; } } else if (state == 2) // Turning off { if (animDeltaTime <= animationDuration) { dotRectTransform.localScale = Anim.Sept.InOut(new Vector3(currentDotSize, currentDotSize, 1f), new Vector3(0f, 0f, 1f), animDeltaTime, animationDuration * 0.75f); ringImage.color = Anim.Sept.InOut(currentColor, offColor, animDeltaTime, animationDuration * 0.75f); if (changeTextColor) { text.color = Anim.Quint.SoftOut(currentTextColor, textNormalColor, animDeltaTime, animationDuration * 0.75f); } if (changeRippleColor) { rippleConfig.rippleColor = ringImage.color; } } else { dotRectTransform.localScale = new Vector3(0f, 0f, 1f); ringImage.color = offColor; if (changeTextColor) { text.color = textNormalColor; } if (changeRippleColor) { rippleConfig.rippleColor = offColor; } dotImage.enabled = false; state = 0; } } if (lastToggleInteractableState != toggle.interactable) { lastToggleInteractableState = toggle.interactable; if (lastToggleInteractableState) { EnableRadioButton(); } else { DisableRadioButton(); } } if (!Application.isPlaying) { if (lastToggleState != toggle.isOn) { lastToggleState = toggle.isOn; if (lastToggleState) { TurnOnSilent(); } else { TurnOffSilent(); } } if (changeRippleColor) { rippleConfig.rippleColor = ringImage.color; } } }
void Update() { animDeltaTime = Time.realtimeSinceStartup - animStartTime; if (state == 1) // Animating on { if (animDeltaTime <= animationDuration) { // Updates values checkRectTransform.localScale = Anim.Overshoot(new Vector3(currentCheckSize, currentCheckSize, 1f), new Vector3(1f, 1f, 1f), animDeltaTime, animationDuration); frameImage.color = Anim.Quint.SoftOut(currentColor, onColor, animDeltaTime, animationDuration); frameCanvasGroup.alpha = Anim.Cube.SoftOut(currentFrameAlpha, 0f, animDeltaTime, animationDuration); if (changeTextColor) { text.color = Anim.Quint.SoftOut(currentTextColor, onColor, animDeltaTime, animationDuration); } if (changeRippleColor) { rippleConfig.rippleColor = frameImage.color; } } else { // Animation has finished checkRectTransform.localScale = new Vector3(1f, 1f, 1f); frameImage.color = onColor; frameCanvasGroup.alpha = 0f; if (changeTextColor) { text.color = onColor; } if (changeRippleColor) { rippleConfig.rippleColor = onColor; } frameImage.enabled = false; state = 0; } } else if (state == 2) // Animating off { if (animDeltaTime <= animationDuration * 0.75f) // * 0.75f to make it shorter than the on animation (looks better) { // Update values checkRectTransform.localScale = Anim.Sept.InOut(new Vector3(currentCheckSize, currentCheckSize, 1f), new Vector3(0f, 0f, 1f), animDeltaTime, animationDuration * 0.75f); frameImage.color = Anim.Sept.InOut(currentColor, offColor, animDeltaTime, animationDuration * 0.75f); frameCanvasGroup.alpha = Anim.Sept.InOut(currentFrameAlpha, 1f, animDeltaTime, animationDuration * 0.75f); if (changeTextColor) { text.color = Anim.Quint.SoftOut(currentTextColor, textNormalColor, animDeltaTime, animationDuration * 0.75f); } if (changeRippleColor) { rippleConfig.rippleColor = frameImage.color; } } else { // Animation completed checkRectTransform.localScale = new Vector3(0f, 0f, 1f); frameImage.color = offColor; frameCanvasGroup.alpha = 1f; if (changeTextColor) { text.color = textNormalColor; } if (changeRippleColor) { rippleConfig.rippleColor = offColor; } checkImage.enabled = false; state = 0; } } // If the 'interactable' toggle on the Toggle has changed, call EnableCheckbox() or DisableCheckbox() accordingly if (lastToggleInteractableState != toggle.interactable) { lastToggleInteractableState = toggle.interactable; if (lastToggleInteractableState) { EnableCheckbox(); } else { DisableCheckbox(); } } // If the Toggle is toggled, update values and appearance accordingly if (!Application.isPlaying) { if (lastToggleState != toggle.isOn) { lastToggleState = toggle.isOn; if (lastToggleState) { TurnOnSilent(); } else { TurnOffSilent(); } } if (changeRippleColor) { rippleConfig.rippleColor = frameImage.color; } } }