Ejemplo n.º 1
0
        public static void Show(string text, bool useDefaultPos = true, Vector2 pos = default(Vector2), string color = "#FAB627", float offset = 500f, float delay = 1.5f, float duration = 1f, Ease easeType = Ease.InQuint, Font mFont = null, int fontSize = 48, bool multyLine = true)
        {
            GRunningTipModel model = new GRunningTipModel();

            model._UseDefaultPos = useDefaultPos;
            model._Pos           = pos;
            model._Text          = text;
            model._Color         = color;
            model._MultyLine     = multyLine;
            model._Offset        = offset;
            model._Delay         = delay;
            model._Duration      = duration;
            model._FontSize      = fontSize;
            model._EaseType      = easeType;

            Action <Font> showAction = font =>
            {
                model._Font = font;
                Show(model);
            };

            if (mFont == null)
            {
                if (_DefaultFont == null)
                {
#if UNITY_EDITOR
                    _DefaultFont = UnityEditor.AssetDatabase.LoadAssetAtPath <Font>("Assets/StandardAssets/Fonts/FZCYJ.ttf");
#else
                    _DefaultFont = Resources.GetBuiltinResource <Font>("Arial.ttf");
#endif


                    showAction(_DefaultFont);
                    //TODO lizhixiong
                    // CAssetBundleManager.AsyncLoadResource(GConfig.Instance.DefaultFontPath, font_obj =>
                    // {
                    //     _DefaultFont = font_obj as Font;
                    //     if (_DefaultFont == null)
                    //     {
                    //         Debug.LogWarning("the default font is null.");
                    //         return;
                    //     }
                    //     showAction(_DefaultFont);
                    // });
                }
                else
                {
                    showAction(_DefaultFont);
                }
            }
            else
            {
                showAction(mFont);
            }
        }
Ejemplo n.º 2
0
        public void SetData(object data)
        {
            _Model = data as GRunningTipModel;
            if (!IsActive())
            {
                gameObject.SetActive(true);
            }
            rectTransform.SetParent(GRunningTipModel.TipRoot, false);

            var startPos = _Model.GetStartPos() + Vector3.down * 500;

            startPos.z = 0;
            rectTransform.anchoredPosition3D = startPos;
            rectTransform.anchorMax          = rectTransform.anchorMin = rectTransform.pivot = Vector2.one * 0.5f;
            Text txt = gameObject.GetComponent <Text>();

            if (txt == null)
            {
                txt = gameObject.AddComponent <Text>();
            }
            txt.raycastTarget = false;
            txt.font          = _Model._Font;
            txt.fontSize      = _Model._FontSize;
            txt.text          = _Model.GetHtmlText();
            // txt.fontStyle = FontStyle.Bold;

            // var outline = gameObject.AddComponent<Outline>();
            // Color c;
            // if (ColorUtility.TryParseHtmlString("#573F0D", out c))
            // {
            //     c.a = 0.6f;
            //     outline.effectColor = c;
            //     var dis = Vector2.one * 3;
            //     outline.effectDistance = dis;
            // }

            ContentSizeFitter fitter = gameObject.GetComponent <ContentSizeFitter>();

            if (fitter == null)
            {
                fitter = gameObject.AddComponent <ContentSizeFitter>();
            }
            fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            fitter.verticalFit   = _Model._MultyLine ? ContentSizeFitter.FitMode.PreferredSize : ContentSizeFitter.FitMode.Unconstrained;
            Invoke("DoRun", _Model._Delay);
        }
Ejemplo n.º 3
0
        public static void Show(GRunningTipModel model)
        {
            if (model != null && model.IsValid())
            {
                GameObject obj = _TipPool.Get();
                obj.name  = "_running_text";
                obj.layer = LayerMask.NameToLayer("UI");
                GRunningTip tip = obj.GetComponent <GRunningTip>();
                if (tip == null)
                {
                    tip = obj.AddComponent <GRunningTip>();
                }
                tip.SetData(model);

                if (obj.GetComponent <Canvas>() == null)
                {
                    var cvs = obj.AddComponent <Canvas>();
                    cvs.overrideSorting  = true;
                    cvs.sortingOrder     = 999;
                    cvs.sortingLayerName = "UI";
                }
            }
        }