/// <summary> /// 设置透明度 /// </summary> /// <returns>The alpha.</returns> /// <param name="fAlpha">F alpha.</param> public static CUIControl SetAlpha(CUIControl control, float fAlpha) { control.gameObject.SetActive(true); CanvasGroup cgroup = control.GetComponent <CanvasGroup>(); if (cgroup != null) { cgroup.alpha = fAlpha; } else { Image img = control.GetComponent <Image> (); if (img != null) { img.color = new Color(img.color.r, img.color.g, img.color.b, fAlpha); } else { Text txt = control.GetComponent <Text>(); if (txt != null) { txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, fAlpha); } } } return(control); }
/// <summary> /// 屏幕外滑动退出 /// </summary> /// <param name="control"></param> /// <param name="stType"></param> /// <param name="fTime"></param> /// <param name="ltType"></param> /// <returns></returns> public static CUIControl SlideOut(CUIControl control, DirType stType = DirType.Top, float fTime = 0.25f, LeanTweenType ltType = LeanTweenType.easeInCirc) { control.show = true; Vector3 vFrom = control.transform.localPosition; Vector3 vTo; RectTransform rt = control.GetComponent <RectTransform>(); Rect rect = rt.rect; switch (stType) { default: case DirType.Top: vTo = new Vector3(0, Screen.height * 0.5f + rect.height * 0.5f, 0); break; case DirType.Bottom: vTo = new Vector3(0, -Screen.height * 0.5f - rect.height * 0.5f, 0); break; case DirType.Right: vTo = new Vector3(Screen.width * 0.5f + rect.width * 0.5f, 0, 0); break; case DirType.Left: vTo = new Vector3(-Screen.width * 0.5f - rect.width * 0.5f, 0, 0); break; } LeanTween.move(rt, vTo, fTime).setEase(ltType).setOnComplete(() => { control.show = false; }); return(control); }
/// <summary> /// 屏幕外滑动进入 /// </summary> /// <param name="control"></param> /// <param name="fTime"></param> /// <param name="stType"></param> /// <param name="ltType"></param> /// <returns></returns> public static CUIControl SlideIn(CUIControl control, Vector3 vIn, DirType stType = DirType.Top, float fTime = 0.25f, LeanTweenType ltType = LeanTweenType.easeOutCirc) { control.show = true; Vector3 vFrom = Vector3.zero; RectTransform rt = control.GetComponent <RectTransform>(); Rect rect = rt.rect; switch (stType) { default: case DirType.Top: vFrom = new Vector3(0, Screen.height * 0.5f + rect.height * 0.5f, 0); break; case DirType.Bottom: vFrom = new Vector3(0, -Screen.height * 0.5f - rect.height * 0.5f, 0); break; case DirType.Right: vFrom = new Vector3(Screen.width * 0.5f + rect.width * 0.5f, 0, 0); break; case DirType.Left: vFrom = new Vector3(-Screen.width * 0.5f - rect.width * 0.5f, 0, 0); break; } CUI.MoveTo(control, vFrom, vIn, fTime, ltType); return(control); }
/// <summary> /// 设置颜色 /// </summary> /// <returns>The color.</returns> /// <param name="color">Color.</param> public static CUIControl SetColor(CUIControl control, Color color) { Image img = control.GetComponent <Image>(); if (img != null) { img.color = color; } else { Text txt = control.GetComponent <Text>(); if (txt != null) { txt.color = color; } } return(control); }
/// <summary> /// 移动到 /// </summary> /// <param name="control"></param> /// <param name="vFrom"></param> /// <param name="vTo"></param> /// <param name="fTime"></param> /// <param name="ltType"></param> /// <returns></returns> public static CUIControl MoveTo(CUIControl control, Vector3 vFrom, Vector3 vTo, float fTime = 0.25f, LeanTweenType ltType = LeanTweenType.easeOutElastic) { control.show = true; RectTransform rt = control.GetComponent <RectTransform>(); //rt.localPosition = vFrom; //rt.position = vFrom; rt.anchoredPosition = new Vector2(vFrom.x, vFrom.y); LeanTween.move(rt, vTo, fTime).setEase(ltType); return(control); }
/// <summary> /// 显示 /// </summary> /// <param name="control">Control.</param> public static CUIControl Show(CUIControl control, bool bShow = true) { if (!bShow) { Hide(control); } control.gameObject.SetActive(true); Image img = control.GetComponent <Image>(); CanvasGroup cgroup = control.GetComponent <CanvasGroup>(); if (cgroup != null) { cgroup.alpha = 1; } if (img != null) { img.color = new Color(img.color.r, img.color.g, img.color.b, 1); } return(control); }
/// <summary> /// 渐变 /// </summary> /// <param name="control"></param> /// <param name="fFrom"></param> /// <param name="fTo"></param> /// <param name="fTime"></param> /// <returns></returns> public static CUIControl Fade(CUIControl control, float fFrom, float fTo, float fTime = 0.5f) { CanvasGroup cgroup = control.GetComponent <CanvasGroup>(); if (cgroup != null) { cgroup.alpha = fFrom; control.show = true; LeanTween.value(control.gameObject, fFrom, fTo, fTime).setOnUpdate((float val) => { cgroup.alpha = val; }); } else { Image img = control.GetComponent <Image>(); if (img != null) { img.color = new Color(img.color.r, img.color.g, img.color.b, fFrom); control.show = true; LeanTween.value(control.gameObject, fFrom, fTo, fTime).setOnUpdate((float val) => { img.color = new Color(img.color.r, img.color.g, img.color.b, val); }); } else { Text txt = control.GetComponent <Text>(); if (txt != null) { txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, fFrom); control.show = true; LeanTween.value(control.gameObject, fFrom, fTo, fTime).setOnUpdate((float val) => { txt.color = new Color(txt.color.r, txt.color.g, txt.color.b, val); }); } } } return(control); }