Example #1
0
 /// <summary>
 /// 缩放进入
 /// </summary>
 /// <param name="control"></param>
 /// <param name="fTime"></param>
 /// <returns></returns>
 public static CUIControl ScaleIn(CUIControl control, float fScaleFrom = 0.6f, float fTime = 0.25f, LeanTweenType ltType = LeanTweenType.easeOutElastic)
 {
     control.show = true;
     control.transform.localScale = new Vector3(fScaleFrom, fScaleFrom, fScaleFrom);
     LeanTween.scale(control.gameObject, Vector3.one, fTime).setEase(ltType);
     return(control);
 }
Example #2
0
        /// <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);
        }
Example #3
0
 /// <summary>
 /// 滑动
 /// </summary>
 /// <param name="control"></param>
 /// <param name="vIn"></param>
 /// <param name="stType"></param>
 /// <param name="fTime"></param>
 /// <param name="ltType"></param>
 /// <returns></returns>
 public static CUIControl Slide(CUIControl control, Vector3 vFrom, Vector3 vTo, float fAlphaForm = 0, float fAlphaTo = 1, float fTime = 0.25f, LeanTweenType ltType = LeanTweenType.easeOutCirc)
 {
     control.show = true;
     CUI.MoveTo(control, vFrom, vTo, fTime, ltType);
     CUI.Fade(control, fAlphaForm, fAlphaTo, fTime);
     return(control);
 }
Example #4
0
        /// <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);
        }
Example #5
0
        /// <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);
        }
Example #6
0
 /// <summary>
 /// Popup 模式窗口
 /// </summary>
 /// <param name="control"></param>
 /// <param name="evtCallback"></param>
 /// <param name="fAlpha"></param>
 /// <returns></returns>
 public static CUIControl ShowPopup(CUIControl control, ControlEvent evtCallback, float fAlpha = 0.5f)
 {
     ShowModel(control, fAlpha);
     ___evtMaskOutCallback = evtCallback;
     Get(mMaskPlane, ControlType.Plane).SetEvent(EType.PointerDown, MaskHide);
     return(control);
 }
Example #7
0
 /// <summary>
 /// 缩放出
 /// </summary>
 /// <param name="control"></param>
 /// <param name="fScaleTo"></param>
 /// <param name="fTime"></param>
 /// <param name="ltType"></param>
 /// <returns></returns>
 public static CUIControl ScaleOut(CUIControl control, float fScaleTo = 0.6f, float fTime = 0.25f, LeanTweenType ltType = LeanTweenType.easeInExpo)
 {
     LeanTween.scale(control.gameObject, new Vector3(fScaleTo, fScaleTo, fScaleTo), fTime).setEase(ltType).setOnComplete(() => {
         control.show = false;
     });
     return(control);
 }
Example #8
0
        /// <summary>
        /// 设置UI文字
        /// </summary>
        /// <param name="id"></param>
        /// <param name="text"></param>
        private void ChangeControlText(CUIControl control)
        {
            string name = listLangName[iCurLanguage];
            string key  = control.LangID + "_" + name;

            if (dictLang.ContainsKey(key))
            {
                control.SetText(dictLang[key]);
            }
        }
Example #9
0
        /// <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);
        }
 public override void OnPointerEnter(PointerEventData eventData)
 {
     if (mControl == null)
     {
         mControl = gameObject.GetComponent <CUIControl>();
     }
     if (onEnter != null && State == ControlState.Normal)
     {
         onEnter(mControl);
     }
 }
Example #11
0
        /// <summary>
        /// 得到控件
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static CUIControl Get(GameObject obj, ControlType controlType = ControlType.Button)
        {
            CUIControl control = obj.GetComponent <CUIControl>();

            if (control == null)
            {
                control      = obj.AddComponent <CUIControl>();
                control.Type = controlType;
            }
            return(control);
        }
 public override void OnUpdateSelected(BaseEventData eventData)
 {
     if (mControl == null)
     {
         mControl = gameObject.GetComponent <CUIControl>();
     }
     if (onUpdateSelect != null && State == ControlState.Normal)
     {
         onUpdateSelect(mControl);
     }
 }
Example #13
0
        /// <summary>
        /// 从资源中读取
        /// </summary>
        /// <param name="strPath"></param>
        /// <param name="controlType"></param>
        /// <param name="canvas"></param>
        /// <returns></returns>
        public static CUIControl GetRes(string strPath, Transform canvas = null, ControlType controlType = ControlType.Button)
        {
            GameObject objGameUI = Object.Instantiate(Resources.Load <GameObject>(strPath));
            CUIControl cc        = objGameUI.AddComponent <CUIControl>();

            cc.Type = controlType;
            if (canvas == null)
            {
                objGameUI.transform.parent = GameObject.Find("Canvas").transform;
            }
            return(cc);
        }
Example #14
0
        /// <summary>
        /// 显示模式窗口
        /// </summary>
        /// <param name="control"></param>
        /// <returns></returns>
        public static CUIControl ShowModel(CUIControl control, float fAlpha = 0.5f)
        {
            CreateMask(fAlpha);
            control.show        = true;
            ___lastControl      = control;
            ___lastParent       = control.transform.parent;
            ___lastSiblingIndex = control.transform.GetSiblingIndex();

            control.transform.parent = mCanvas.transform;
            control.transform.SetSiblingIndex(mCanvas.transform.childCount);
            return(control);
        }
Example #15
0
        public static void MaskHide(CUIControl control = null)
        {
            if (mMaskPlane == null)
            {
                return;
            }

            Get(mMaskPlane).show            = false;
            ___lastControl.transform.parent = ___lastParent;
            ___lastControl.transform.SetSiblingIndex(___lastSiblingIndex);

            if (___evtMaskOutCallback != null)
            {
                ___evtMaskOutCallback(___lastControl);
            }
        }
Example #16
0
        /// <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);
        }
Example #17
0
        /// <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);
        }
Example #18
0
        /// <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);
        }
Example #19
0
        /// <summary>
        /// 获得子对象
        /// </summary>
        /// <param name="strName"></param>
        /// <returns></returns>
        public virtual CUIControl Get(string strName, ControlType controlType = ControlType.Button)
        {
            Transform trans = this.transform.Find(strName);

            if (!trans)
            {
                return(null);
            }
            else
            {
                CUIControl ui = trans.GetComponent <CUIControl>();
                if (ui)
                {
                    return(ui);
                }
                else
                {
                    ui      = trans.gameObject.AddComponent <CUIControl>();
                    ui.Type = controlType;
                    return(ui);
                }
            }
        }
Example #20
0
 private void Awake()
 {
     CUIControl.Add(this);
 }
Example #21
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="c"></param>
 public static void Remove(CUIControl c)
 {
     GameObject.Destroy(c.gameObject);
     Store.Remove(c);
 }
Example #22
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="c"></param>
 /// <returns></returns>
 public static CUIControl Add(CUIControl c)
 {
     Store.Add(c);
     return(c);
 }
Example #23
0
 /// <summary>
 /// 隐藏
 /// </summary>
 /// <param name="control">Control.</param>
 public static CUIControl Hide(CUIControl control)
 {
     control.gameObject.SetActive(false);
     return(control);
 }
Example #24
0
 /// <summary>
 /// 淡出
 /// </summary>
 /// <param name="control"></param>
 /// <returns></returns>
 public static CUIControl FadeOut(CUIControl control, float fTime = 0.5f)
 {
     return(Fade(control, 1f, 0, fTime));
 }