public FloatFontAnimData GetAnimData(WarFloatFontType type) { foreach (FloatFontAnimData item in m_FontAnimList) { if (item.fontType == type) { return(item); } } return(null); }
public void Clear() { fontFrame.localScale = Vector3.one; fontFrame.anchoredPosition = Vector2.zero; m_FontVal = null; liveTime = 0; timer = 0; m_Entity = null; m_Property = null; m_enable = false; m_Sequence = null; m_Anim = null; m_type = WarFloatFontType.Invalid; }
//设置飘字类型 public bool ChangeType(WarFloatFontType type) { m_type = type; FloatFontAnimData anim = null; if (null == animManager) { animManager = GetRectTransform.parent.GetComponent <WarFloatFontAnim>(); } if (null != animManager) { anim = animManager.GetAnimData(type); } if (null != anim) { m_Anim = anim; return(true); } return(false); }
/// <summary> /// 计算屏幕位置,由世界坐标转换 /// </summary> /// <param name="type">飘字类型</param> /// <param name="entityPos">实体世界位置</param> /// <param name="creatureHeight">实体高度</param> /// <returns></returns> private Vector2 GenratePos(WarFloatFontType type, Vector3 entityPos) { Vector3 pixelPos = Vector3.zero; pixelPos = Initialize.mainCam.WorldToScreenPoint(entityPos); Vector2 UIlocalPos = Vector2.zero; RectTransformUtility.ScreenPointToLocalPointInRectangle(this.GetTransform.parent as RectTransform, pixelPos, UISystem.Instance.GetCamera(), out UIlocalPos); if (m_Anim.bRandomStartPos) { UIlocalPos.x += UnityEngine.Random.Range(-Mathf.Abs(m_Anim.startXOffset), Mathf.Abs(m_Anim.startXOffset)); } else { UIlocalPos.x += m_Anim.startXOffset; } UIlocalPos.y += m_Anim.startYOffset; return(UIlocalPos); }
/// <summary> /// 创建飘字 /// </summary>piaozi /// <param name="entry">实体</param> /// <param name="text">飘字内容</param> /// <param name="type">飘字类型</param> /// <returns></returns> public UWarFloatFontItem CreateFloatFont(GameObject entry, String text, WarFloatFontType type) { UWarFloatFontItem tempItem = null; //判断是否需要创建 if (!NeedToCreate(entry)) { return(null); } if (type == WarFloatFontType.Invalid) { return(null); } //先从非活动列表取 if (UnActiviteList.Count > 0) { tempItem = UnActiviteList.First.Value; UnActiviteList.RemoveFirst(); tempItem.ChangeHostEntity(entry); if (!tempItem.ChangeType(type)) { tempItem.SetEnable(false); tempItem.Clear(); UnActiviteList.AddLast(tempItem); return(null); } tempItem.SetText(text); if (tempItem.UpdatePos()) { tempItem.ActivateFont(); ActiviteList.AddLast(tempItem); } else { tempItem.SetEnable(false); tempItem.Clear(); UnActiviteList.AddLast(tempItem); return(null); } } //否则实例化新节点 else { tempItem = CreateNewFont(); if (null == tempItem) { return(null); } RectPosition(tempItem); tempItem.ChangeHostEntity(entry); if (!tempItem.ChangeType(type)) { tempItem.SetEnable(false); tempItem.Clear(); UnActiviteList.AddLast(tempItem); return(null); } tempItem.SetText(text); if (tempItem.UpdatePos()) { tempItem.ActivateFont(); ActiviteList.AddLast(tempItem); } else { tempItem.SetEnable(false); tempItem.Clear(); UnActiviteList.AddLast(tempItem); } } return(tempItem); }
//根据类型选择飘字样式及动画效果 private void ChooseFontStyle(WarFloatFontType type, string val) { if (null == t_txt || null == gradient || null == icon || null == m_Anim) { return; } t_txt.color = Color.white; t_txt.fontSize = m_Anim.fontSize; gradient.SetGradientColorKey(m_Anim.topColor, m_Anim.bottomColor); //gradient.vertex1 = m_Anim.topColor; //gradient.vertex2 = m_Anim.bottomColor; icon.gameObject.SetActive(false); Vector3 temp = t_txt.rectTransform.anchoredPosition; switch (type) { case WarFloatFontType.Fatal: { t_txt.text = val; if (null != FatalIcon) { int size = m_Anim.fontSize - 4; icon.sprite = FatalIcon; icon.rectTransform.sizeDelta = new Vector2(size, size); icon.gameObject.SetActive(true); } } break; case WarFloatFontType.TrueDamage: case WarFloatFontType.MagicAttack: case WarFloatFontType.PhysicalAttack: t_txt.text = val; break; case WarFloatFontType.Cure: t_txt.text = "+" + val; break; case WarFloatFontType.Coin: { t_txt.text = "+" + val; if (null != coinIcon) { int size = m_Anim.fontSize - 4; icon.sprite = coinIcon; icon.rectTransform.sizeDelta = new Vector2(size, size); icon.gameObject.SetActive(true); } } break; case WarFloatFontType.LevelUp: t_txt.text = "升 级"; break; default: break; } fontFrame.localScale = new Vector3(m_Anim.expandMinPercent, m_Anim.expandMinPercent, m_Anim.expandMinPercent); m_Sequence = DOTween.Sequence(); m_Sequence.Append(fontFrame.DOScale(m_Anim.expandMaxPercent, m_Anim.expandTime)) .Insert(0, fontFrame.DOJumpAnchorPos(new Vector2(fontFrame.anchoredPosition.x + m_Anim.xOffset, fontFrame.anchoredPosition.y), m_Anim.jumpPower, 1, m_Anim.disappearTime).SetDelay(m_Anim.expandTime + m_Anim.stagnationTime)) .Insert(0, fontFrame.DOAnchorPosY(fontFrame.anchoredPosition.y + m_Anim.yOffset, m_Anim.disappearTime).SetDelay(m_Anim.expandTime + m_Anim.stagnationTime)) .Insert(0, t_txt.DOFade(0, m_Anim.disappearTime).SetDelay(m_Anim.expandTime + m_Anim.stagnationTime)) .Insert(0, fontFrame.DOScale(0, m_Anim.disappearTime).SetDelay(m_Anim.expandTime + m_Anim.stagnationTime)) .OnComplete(SequenceComplete); }