Ejemplo n.º 1
0
        public void Show(string text, Vector3 uipos, MotionTextModel config, Sprite image = null)
        {
            if (!IsActive())
            {
                gameObject.SetActive(true);
            }

            CanvasGrp.alpha    = 1;
            currentModel       = config;
            RectTrans.position = uipos;
            var fontScale = config.fountScale;

            RectTrans.localScale = Vector3.one * fontScale;
            Label.text           = text;

            if (config.isUseBG && image != null)
            {
                Image.transform.localScale = Vector3.one;
                Image.sprite = image;
            }
            else
            {
                Image.rectTransform.localScale = Vector3.zero;
            }

            TotalTime   = config.GetTotalTime();
            currentTime = 0;
        }
Ejemplo n.º 2
0
        public HUDText ShowFollowText(string text, GameObject follow, string configId, Sprite image, bool isPlayEndHide = true)
        {
            if (!isInit)
            {
                Init();
            }
            if (string.IsNullOrEmpty(text) || AppConst.GlobalCahce.Main3DCamera == null || !AppConst.GlobalCahce.Main3DCamera.enabled || follow == null)
            {
                return(null);
            }

            MotionTextModel model = null;

            configId = path + configId;
            if (!motionTextModels.TryGetValue(configId, out model))
            {
                model = Resources.Load <MotionTextModel>(configId);
                motionTextModels.Add(configId, model);
            }
            if (model != null)
            {
                var hudtext = _HudTextPool.Get() as GameObject;
                if (hudtext != null)
                {
                    var hudTextComp = hudtext.GetComponent <HUDText>();
                    if (hudTextComp != null)
                    {
                        hudTextComp.FollowGameObject = follow;
                        hudTextComp.IsFollow         = true;
                        hudTextComp.IsPlayEndHide    = isPlayEndHide;
                        hudTextComp.RectTrans.SetParent(
                            model.isOnTopLayer ? AppConst.GlobalCahce.PanelHUD.GetChild(1) : AppConst.GlobalCahce.PanelHUD.GetChild(0), false);
                        var pos = follow.transform.position;
                        pos.y += GetModelHeight(follow, 1, false);
                        Vector3 offect = Vector3.zero;
                        offect.x += Random.Range(-model.randomNum, model.randomNum);
                        offect.y += Random.Range(-model.randomNum, model.randomNum);
                        offect.z += Random.Range(-model.randomNum, model.randomNum);
                        offect.x += model.offect.x;
                        offect.y += model.offect.y;
                        offect.z += model.offect.z;
                        hudTextComp.OffectVector3 = offect;
                        Vector3 uipos = TranslatePosToUIPos(pos + offect);
                        hudTextComp.Show(text, uipos, model);
                        currentShowHudTexts.Add(hudTextComp);
                        return(hudTextComp);
                    }
                }
            }
            return(null);
        }