public static void UI_FadeSlideUp(Transform target, float distance, float duration, bool includeChildren) { target.position = new Vector3(target.transform.position.x, target.transform.position.y - distance, target.transform.position.z); target.gameObject.SetActive(true); Image target_img = target.gameObject.GetComponent <Image>(); Image[] targets_img = (includeChildren) ? target.GetComponentsInChildren <Image>(true) : null; Text [] targets_text = (includeChildren) ? target.GetComponentsInChildren <Text>(true) : null; Tween.Begin(target); Tween.Duration = duration; Tween.Move(new Vector3(target.transform.position.x, target.transform.position.y + distance, target.transform.position.z), Space.World, Ease.Berp); Tween.Custom(value => { target_img.color = new Color(target_img.color.r, target_img.color.g, target_img.color.b, value); if (includeChildren) { foreach (Image img in targets_img) { img.color = new Color(img.color.r, img.color.g, img.color.b, value); } foreach (Text txt in targets_text) { txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, value); } } }); Tween.Run(); }
public static void UI_FadeOut_Sprite(Transform target, float duration = .3f, bool includeChildren = false) { target.gameObject.SetActive(true); SpriteRenderer target_img = target.gameObject.GetComponent <SpriteRenderer>(); SpriteRenderer[] targets_img = (includeChildren) ? target.GetComponentsInChildren <SpriteRenderer>(true) : null; Text [] targets_text = (includeChildren) ? target.GetComponentsInChildren <Text>(true) : null; target_img.color = new Color(target_img.color.r, target_img.color.g, target_img.color.b, 0); Tween.Begin(target); Tween.Duration = duration; Tween.Custom(value => { target_img.color = new Color(target_img.color.r, target_img.color.g, target_img.color.b, 1 - value); if (includeChildren) { foreach (SpriteRenderer img in targets_img) { img.color = new Color(img.color.r, img.color.g, img.color.b, 1 - value); } foreach (Text txt in targets_text) { txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, value); } } }); Tween.Run(); }